return boolval( $result );
}
/**
* Remove the object-cache.php file.
*
* @since 5.0.0
*/
public function remove_memcached_dropin() {
$dropin = $this->dropin_exists();
// Enable the memcache if the file is not readable.
if ( false !== $dropin ) {
// Delete the file.
$is_removed = unlink( $dropin );
if ( false === $is_removed ) {
// Enable memcache if the dropin cannot be removed.
Options::enable_option( 'siteground_optimizer_enable_memcached' );
return false;
}
}
return true;
}
/**
* Check if there are any options that should be excluded from the memcache.
*
* @since 5.6.1
*
* @param array $alloptions Array of all autoload options.
*
* @return array Array without excluded autload options.
*/
public function maybe_exclude( $alloptions ) {
// Bail if the excludes files doesn't exists.
if ( ! file_exists( self::EXCLUDES_FILENAME ) ) {
return $alloptions;
}
// Get the content of the excludes file.
$excludes = $this->get_excludes_content();
// Bail if the excludes file is empty.
if ( empty( $excludes ) ) {
return $alloptions;
}
foreach ( $excludes as $option ) {
// Bail if the option name is empty.
if ( empty( $option ) ) {
continue;
}
// Unset the option from the cache.
unset( $alloptions[ $option ] );
}
// Return the options.
return $alloptions;
}
/**
* Prepare memcache excludes.
*
* @since 5.6.1
*/
public function prepare_memcache_excludes() {
global $wp_filesystem;
// Bail if the crashed file doesn't exists.
if ( ! $wp_filesystem->exists( self::CRASHED_FILENAME ) ) {
return;
}
// Remove the error flag file.
$wp_filesystem->delete( self::CRASHED_FILENAME );
// Create the excludes file if doesn't exists.
if ( ! file_exists( self::EXCLUDES_FILENAME ) ) {
$wp_filesystem->touch( self::EXCLUDES_FILENAME );
}
// Get the content of the excludes file.
$excludes = $this->get_excludes_content();
// Load the wpdb.
global $wpdb;
// Get the biggest option from the database.
$result = $wpdb->get_results( "
SELECT option_name
FROM $wpdb->options
WHERE autoload = 'yes'
AND option_name NOT IN ( " . implode( ',', array_map( function( $item ) {
return "'" . esc_sql( $item ) . "'";
}, $excludes )
) . " )
ORDER BY LENGTH(option_value) DESC
LIMIT 1"
);
// Bail if the query doesn't return results.
if ( empty( $result[0]->option_name ) ) {
return;
}
// Add the option to the exclude list.
$excludes[] = $result[0]->option_name;
// Open the exclude list file.
$handle = fopen( self::EXCLUDES_FILENAME, 'a' );
// Write the option to the exclude list.
fputcsv( $handle, array( $result[0]->option_name ) );
// Close the file.
fclose( $handle );
}
/**
* Get the content of the excludes file.
*
* @since 5.6.1
*
* @return array Content of the excludes file in array.
*/
public function get_excludes_content() {
// Get the content of the excludes file.
$excludes_content = file_get_contents( self::EXCLUDES_FILENAME );
// Convert the csv to array.
return str_getcsv( $excludes_content, "\n" );
}
/**
* Enable memcached.
*
* @since @version
*/
public function enable_memcache() {
// Bail if we cannot create a dropin.
if ( ! $this->create_memcached_dropin() ) {
return false;
}
Options::enable_option( 'siteground_optimizer_enable_memcached' );
// Remove notices.
Options::disable_option( 'siteground_optimizer_memcache_notice' );
Options::disable_option( 'siteground_optimizer_memcache_crashed' );
Options::disable_option( 'siteground_optimizer_memcache_dropin_crashed' );
// Remove the transient if woo is present.
if ( class_exists( 'WooCommerce' ) ) {
delete_transient( 'wc_attribute_taxonomies' );
}
return true;
}
/**
* Disable memcached.
*
* @since @version
*/
public function disable_memcache() {
// First disable the option.
$result = Options::disable_option( 'siteground_optimizer_enable_memcached' );
// True if the option has been disabled and the dropin doesn't exist.
if ( ! $this->dropin_exists() ) {
return true;
}
// Try to remove the dropin.
$is_dropin_removed = $this->remove_memcached_dropin();
// Remove notices.
Options::disable_option( 'siteground_optimizer_memcache_notice' );
Options::disable_option( 'siteground_optimizer_memcache_crashed' );
Options::disable_option( 'siteground_optimizer_memcache_dropin_crashed' );
// Remove the transient if woo is present.
if ( class_exists( 'WooCommerce' ) ) {
delete_transient( 'wc_attribute_taxonomies' );
}
// True if the droping has been removed.
if ( $is_dropin_removed ) {
return true;
}
// Bail if the dropin could not be removed.
return false;
}
}
Fatal error: Uncaught Error: Class 'SiteGround_Optimizer\Memcache\Memcache' not found in /home/sportuga/public_html/wp-content/plugins/sg-cachepress/core/Install_Service/Install_5_0_6.php:28
Stack trace:
#0 /home/sportuga/public_html/wp-content/plugins/sg-cachepress/core/Install_Service/Install_Service.php(61): SiteGround_Optimizer\Install_Service\Install_5_0_6->__construct()
#1 /home/sportuga/public_html/wp-content/plugins/sg-cachepress/core/Helper/Factory_Trait.php(32): SiteGround_Optimizer\Install_Service\Install_Service->__construct()
#2 /home/sportuga/public_html/wp-content/plugins/sg-cachepress/core/Loader/Loader.php(208): SiteGround_Optimizer\Loader\Loader->factory('install_service', 'install_service')
#3 /home/sportuga/public_html/wp-content/plugins/sg-cachepress/core/Loader/Loader.php(118): SiteGround_Optimizer\Loader\Loader->load_dependencies()
#4 /home/sportuga/public_html/wp-content/plugins/sg-cachepress/sg-cachepress.php(72): SiteGround_Optimizer\Loader\Loader->__construct()
#5 /home/sportuga/public_html/wp-s in /home/sportuga/public_html/wp-content/plugins/sg-cachepress/core/Install_Service/Install_5_0_6.php on line 28