: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
class ET_Core_Cache_Directory {
protected static $_instance;
* Whether or not we can write to the cache directory.
* Absolute path to cache directory
* URL for {@see self::$path}
* @var WP_Filesystem_Base
* ET_Core_Cache_Directory constructor.
public function __construct() {
if ( self::$_instance ) {
et_wrong( 'Use "ET_Core_Cache_Directory::instance()" instead of "new ET_Core_Cache_Directory".' );
self::$_instance = $this;
* Determines the cache directory path and url based on where we can write files
* and whether or not the user has defined a custom path and url.
protected function _initialize() {
$this->_initialize_wpfs();
if ( $this->_maybe_use_custom_path() ) {
$uploads_dir_info = (object) wp_get_upload_dir();
$path = et_()->path( WP_CONTENT_DIR, 'et-cache' );
$url = content_url( 'et-cache' );
$can_write = $this->wpfs->is_writable( $path ) && ! is_file( $path );
$can_create = ! $can_write && $this->wpfs->is_writable( WP_CONTENT_DIR );
if ( ! $can_write && ! $can_create && $this->wpfs->is_writable( $uploads_dir_info->basedir ) ) {
// We can create our cache directory in the uploads directory
$path = et_()->path( $uploads_dir_info->basedir, 'et-cache' );
$url = et_()->path( $uploads_dir_info->baseurl, 'et-cache' );
$this->can_write = $can_write || $can_create;
$this->_maybe_adjust_path_for_multisite( $uploads_dir_info );
* Absolute path to directory where we can store cache files.
define( 'ET_CORE_CACHE_DIR', $this->path );
* URL to {@see ET_CORE_CACHE_DIR}.
define( 'ET_CORE_CACHE_DIR_URL', $this->url );
$this->can_write && et_()->ensure_directory_exists( $this->path );
* Ensures that the WP Filesystem API has been initialized.
* @return WP_Filesystem_Base
protected function _initialize_wpfs() {
require_once ABSPATH . 'wp-admin/includes/file.php';
if ( defined( 'ET_CORE_CACHE_DIR' ) && @WP_Filesystem( array(), ET_CORE_CACHE_DIR, true ) ) {
// We can write to a user-specified directory
return $this->wpfs = $GLOBALS['wp_filesystem'];
if ( @WP_Filesystem( array(), false, true ) ) {
// We can write to WP_CONTENT_DIR
return $this->wpfs = $GLOBALS['wp_filesystem'];
$uploads_dir = (object) wp_get_upload_dir();
if ( @WP_Filesystem( array(), $uploads_dir->basedir, true ) ) {
// We can write to the uploads directory
return $this->wpfs = $GLOBALS['wp_filesystem'];
// We aren't able to write to the filesystem so let's just make sure $this->wpfs
// is an instance of the filesystem base class so that calling it won't cause errors.
require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php';
// Write notice to log when WP_DEBUG is enabled.
$msg = 'Unable to write to filesystem. Please ensure that PHP has write access to one of ';
$msg .= "the following directories:{$nl}{$nl}\t- WP_CONTENT_DIR{$nl}\t- wp_upload_dir(){$nl}\t- ET_CORE_CACHE_DIR.";
return $this->wpfs = new WP_Filesystem_Base;
* Adjusts the path for multisite if necessary.
* @param stdClass $uploads_dir_info (object) wp_get_upload_dir()
protected function _maybe_adjust_path_for_multisite( $uploads_dir_info ) {
if ( et_()->starts_with( $this->path, $uploads_dir_info->basedir ) || ! is_multisite() ) {
$network_id = $site->site_id;
$site_id = $site->blog_id;
$this->path = et_()->path( $this->path, $network_id, $site_id );
$this->url = et_()->path( $this->url, $network_id, $site_id );
* Whether or not the user has defined a custom path for the cache directory.
protected function _maybe_use_custom_path() {
if ( ! defined( 'ET_CORE_CACHE_DIR' ) ) {
$this->path = ET_CORE_CACHE_DIR;
if ( ! $this->can_write = $this->wpfs->is_writable( $this->path ) ) {
et_wrong( 'ET_CORE_CACHE_DIR is defined but not writable.', true );
if ( defined( 'ET_CORE_CACHE_DIR_URL' ) ) {
$this->url = ET_CORE_CACHE_DIR_URL;
et_wrong( 'When ET_CORE_CACHE_DIR is defined, ET_CORE_CACHE_DIR_URL must also be defined.', true );
* Returns the class instance.
* @return ET_Core_Cache_Directory
public static function instance() {
if ( ! self::$_instance ) {
self::$_instance = new self;