: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* The file that defines File System class
* Themify_Filesystem class provide instance of Filesystem Api to do some file operation.
* Based on WP_Filesystem the class method will remain same.
if (!class_exists('Themify_Filesystem',false)) {
* The Themify_Filesystem class.
* This is used to initialize WP_Filesytem Api instance
* check for filesytem method and return correct filesystem method
class Themify_Filesystem {
* Instance of WP_Filesytem api class.
* @var $execute Store the instance of WP_Filesystem class being used.
private function __construct() {
* Return an instance of this class.
* @return object A single instance of this class.
public static function get_instance() {
if ($instance === null) {
* Initialize filesystem method.
private function initialize() {
if (!defined('FS_METHOD')) {
define('FS_METHOD', 'direct');
if (!function_exists('WP_Filesystem')) {
require_once ABSPATH . 'wp-admin/includes/file.php';
if (is_a($wp_filesystem, 'WP_Filesystem_Direct')) {
$this->execute = $wp_filesystem;
$this->execute = self::load_direct();
* Initialize Filesystem direct method.
private static function load_direct() {
require_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-base.php';
require_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-direct.php';
return new WP_Filesystem_Direct(array());
public static function get_file_content($file, $check = false) {
static $content_url = null;
if ($site_url === null) {
$site_url = rtrim(site_url(), '/') . '/';
if ($content_url === null) {
$content_url = rtrim(content_url(), '/');
$upload_dir = themify_upload_dir();
if (strpos($file, $site_url) !== false || strpos($file, $upload_dir['baseurl']) !== false || strpos($file, $content_url) !== false) {
$file = urldecode($file);
if (strpos($file, $upload_dir['baseurl']) !== false) {
$dir = str_replace($upload_dir['baseurl'], $upload_dir['basedir'], $file);
} elseif (strpos($file, '/' . WPINC . '/') !== false || strpos($file, '/wp-admin/') !== false) {
$dir = str_replace($site_url, ABSPATH, $file);
} elseif (strpos($file, $site_url) !== false) {
$dir = str_replace($site_url, rtrim(dirname(WP_CONTENT_DIR), '/') . '/', $file);
$dir = str_replace($content_url, rtrim(WP_CONTENT_DIR, '/'), $file);
$dir = strtok($dir, '?');
return self::is_readable($dir);
$data = self::get_contents($dir);
return !empty($data) ? $data : null;
public static function is_dir($dir) {
public static function is_file($file) {
public static function is_readable($dir) {
return is_readable($dir);
public static function is_writable($dir) {
return is_writable($dir);
public static function exists($file) {
return file_exists($file);
public static function size($file) {
public static function delete($dir, $type = false) {
set_error_handler(array(__CLASS__, 'errorHandler'), E_WARNING);
$removed = self::remove($dir, $type);
private static function remove($dir, $type = false) {
if ($type !== 'f' && self::is_dir($dir)) {
$dirHandle = opendir($dir);
$dir=trailingslashit($dir);
while (false !== ($f = readdir($dirHandle))) {
if ($f !== '.' && $f !== '..') {
} elseif (self::is_file($d) || is_link($d)) {
} elseif (self::is_file($dir) || is_link($dir)) {
public static function put_contents($file, $contents, $mode = false) {
$instance = self::get_instance();
return $instance->execute->put_contents($file, $contents, $mode);
public static function get_contents($file) {
return self::is_file($file) ? file_get_contents($file) : '';
public static function errorHandler($errno, $errstr, $errfile, $errline) {
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
public static function mkdir($dir, $r = false, $perm = 0755) {
if (!self::is_dir($dir)) {
set_error_handler(array(__CLASS__, 'errorHandler'), E_WARNING);
$check = mkdir($dir, $perm, $r);
return self::is_dir($dir);
public static function rename($from, $to) {
set_error_handler(array(__CLASS__, 'errorHandler'), E_WARNING);
$check = rename($from, $to);
return self::is_dir($to) && !self::is_dir($from);