/** * Initialise the classes in this plugin. * * @since 1.1.0 * * @todo Consider moving this to a dependency injection container, so we can avoid globals? */ function sg_cachepress_start() { global $sg_cachepress, $sg_cachepress_options, $sg_cachepress_environment, $sg_cachepress_memcache, $sg_cachepress_admin, $sg_cachepress_supercacher; $sg_cachepress_options = new SG_CachePress_Options(); $sg_cachepress = new SG_CachePress($sg_cachepress_options); $sg_cachepress_environment = new SG_CachePress_Environment($sg_cachepress_options); $sg_cachepress_admin = new SG_CachePress_Admin($sg_cachepress_options); $sg_cachepress_memcache = new SG_CachePress_Memcache($sg_cachepress_options, $sg_cachepress_environment); $sg_cachepress_supercacher = new SG_CachePress_Supercacher($sg_cachepress_options, $sg_cachepress_environment); $sg_cachepress->run(); $sg_cachepress_admin->run(); if ($sg_cachepress_environment->cache_is_enabled()) { if ($sg_cachepress_environment->autoflush_enabled()) { $sg_cachepress_supercacher->run(); } } if ($sg_cachepress_environment->memcached_is_enabled()) { $sg_cachepress_memcache->run(); } }
/** * Updates a param from ajax request * * @since 1.1.0 */ public function update_parameter() { $paramTranslator = array('dynamic-cache' => 'enable_cache', 'memcached' => 'enable_memcached', 'autoflush-cache' => 'autoflush_cache'); $paramName = $paramTranslator[$_POST['parameterName']]; $currentValue = (int) $this->options_handler->get_option($paramName); $toggledValue = (int) (!$currentValue); //if cache is turned on or off it's a good idea to flush it on right away if ($paramName == 'enable_cache') { SG_CachePress_Supercacher::purge_cache(); } if ($paramName == 'enable_memcached') { global $sg_cachepress_memcache; //check if we can actually enable memcached and display error if not if ($toggledValue == 1) { if (!$sg_cachepress_memcache->check_and_create_memcached_dropin()) { die("Please, first enable Memcached from your cPanel!"); } } else { if (!$sg_cachepress_memcache->remove_memcached_dropin()) { die("Could not disable memcache!"); } } } if ($this->options_handler->update_option($paramName, $toggledValue)) { if ($paramName == 'enable_cache' && $toggledValue == 1) { SG_CachePress::check_if_plugin_caches(); } else { if ($paramName == 'enable_cache' && $toggledValue == 0) { $sg_cachepress_options = new SG_CachePress_Options(); $sg_cachepress_options->disable_option('show_notice'); } } die((string) $toggledValue); } else { die((string) $currentValue); } }