function save_settings()
 {
     $options = get_option($this->optionname);
     if (isset($_REQUEST['reset']) && $_REQUEST['reset'] == "true" && isset($_REQUEST['plugin']) && $_REQUEST['plugin'] == 'google-analytics-for-wordpress') {
         $options = $this->set_defaults();
         $options['msg'] = "<div class=\"updated\"><p>" . __('Google Analytics settings reset.') . "</p></div>\n";
     } elseif (isset($_POST['submit']) && isset($_POST['plugin']) && $_POST['plugin'] == 'google-analytics-for-wordpress') {
         if (!current_user_can('manage_options')) {
             die(__('You cannot edit the Google Analytics for WordPress options.'));
         }
         check_admin_referer('analyticspp-config');
         foreach (array('uastring', 'dlextensions', 'domainorurl', 'position', 'domain', 'customcode', 'ga_token', 'extraseurl', 'gajsurl', 'gfsubmiteventpv', 'trackprefix', 'ignore_userlevel', 'internallink', 'internallinklabel', 'primarycrossdomain', 'othercrossdomains') as $option_name) {
             if (isset($_POST[$option_name])) {
                 $options[$option_name] = $_POST[$option_name];
             } else {
                 $options[$option_name] = '';
             }
         }
         foreach (array('extrase', 'trackoutbound', 'admintracking', 'trackadsense', 'allowanchor', 'allowlinker', 'allowhash', 'rsslinktagging', 'advancedsettings', 'trackregistration', 'theme_updated', 'cv_loggedin', 'cv_authorname', 'cv_category', 'cv_all_categories', 'cv_tags', 'cv_year', 'cv_post_type', 'outboundpageview', 'downloadspageview', 'trackcrossdomain', 'gajslocalhosting', 'manual_uastring', 'taggfsubmit', 'wpec_tracking', 'shopp_tracking', 'anonymizeip', 'trackcommentform', 'debug', 'firebuglite', 'yoast_tracking') as $option_name) {
             if (isset($_POST[$option_name]) && $_POST[$option_name] == 'on') {
                 $options[$option_name] = true;
             } else {
                 $options[$option_name] = false;
             }
         }
         if (isset($_POST['manual_uastring']) && isset($_POST['uastring_man'])) {
             $options['uastring'] = $_POST['uastring_man'];
         }
         if ($options['trackcrossdomain']) {
             if (!$options['allowlinker']) {
                 $options['allowlinker'] = true;
             }
             if (empty($options['primarycrossdomain'])) {
                 $origin = GA_Filter::ga_get_domain($_SERVER["HTTP_HOST"]);
                 $options['primarycrossdomain'] = $origin["domain"];
             }
         }
         if (function_exists('w3tc_pgcache_flush')) {
             w3tc_pgcache_flush();
         }
         if (function_exists('w3tc_dbcache_flush')) {
             w3tc_dbcache_flush();
         }
         if (function_exists('w3tc_minify_flush')) {
             w3tc_minify_flush();
         }
         if (function_exists('w3tc_objectcache_flush')) {
             w3tc_objectcache_flush();
         }
         if (function_exists('wp_cache_clear_cache')) {
             wp_cache_clear_cache();
         }
         $options['msg'] = "<div id=\"updatemessage\" class=\"updated fade\"><p>Google Analytics <strong>settings updated</strong>.</p></div>\n";
         $options['msg'] .= "<script type=\"text/javascript\">setTimeout(function(){jQuery('#updatemessage').hide('slow');}, 3000);</script>";
     }
     update_option($this->optionname, $options);
 }
Example #2
1
 /**
  * Clear something from the cache
  *
  * @param array $args
  * @param array $vars
  */
 function flush($args = array(), $vars = array())
 {
     if (function_exists('w3tc_pgcache_flush')) {
         $args = array_unique($args);
         do {
             $cache_type = array_shift($args);
             switch ($cache_type) {
                 case 'db':
                 case 'database':
                     if (w3tc_dbcache_flush()) {
                         WP_CLI::success('The object cache is flushed successfully.');
                     } else {
                         WP_CLI::error('Flushing the object cache failed.');
                     }
                     break;
                 case 'minify':
                     if (w3tc_minify_flush()) {
                         WP_CLI::success('The object cache is flushed successfully.');
                     } else {
                         WP_CLI::error('Flushing the object cache failed.');
                     }
                     break;
                 case 'object':
                     if (w3tc_objectcache_flush()) {
                         WP_CLI::success('The object cache is flushed successfully.');
                     } else {
                         WP_CLI::error('Flushing the object cache failed.');
                     }
                     break;
                 case 'post':
                 default:
                     if (isset($vars['post_id'])) {
                         if (is_numeric($vars['post_id'])) {
                             w3tc_pgcache_flush_post($vars['post_id']);
                         } else {
                             WP_CLI::error('This is not a valid post id.');
                         }
                         w3tc_pgcache_flush_post($vars['post_id']);
                     } elseif (isset($vars['permalink'])) {
                         $id = url_to_postid($vars['permalink']);
                         if (is_numeric($id)) {
                             w3tc_pgcache_flush_post($id);
                         } else {
                             WP_CLI::error('There is no post with this permalink.');
                         }
                     } else {
                         if (isset($flushed_page_cache) && $flushed_page_cache) {
                             break;
                         }
                         $flushed_page_cache = true;
                         w3tc_pgcache_flush();
                     }
             }
         } while (!empty($args));
     } else {
         WP_CLI::error('The W3 Total Cache could not be found, is it installed?');
     }
 }
 /**
  * Clear caches.
  *
  * Clears popular WordPress caching mechanisms.
  *
  * @since 4.0.0
  *
  * @param bool $page [optional] true to clear page cache
  *
  * @return void
  */
 public static function clear_caches($page = false)
 {
     //clear APC Cache
     if (function_exists('apc_store')) {
         apc_clear_cache();
         //Let's clear APC (if it exists) when big stuff is saved.
     }
     //clear w3 total cache or wp super cache
     if (function_exists('w3tc_pgcache_flush')) {
         if (true == $page) {
             w3tc_pgcache_flush();
             w3tc_minify_flush();
         }
         w3tc_dbcache_flush();
         w3tc_objectcache_flush();
     } else {
         if (function_exists('wp_cache_clear_cache') && true == $page) {
             wp_cache_clear_cache();
         }
     }
 }
Example #4
0
 function supernova_writer()
 {
     // @since Supernova 1.4.8 temporarily unavailable.
     update_option('supernova_file_write_status', 'failed');
     return false;
     $test = get_option('supernova_test');
     $file_status = get_option('supernova_file_write_status');
     if ($test != 2) {
         update_option('supernova_test', 1);
         // To track the first attempt
     }
     if ($test == 1) {
         if ($file_status == 'failed') {
             update_option('supernova_test', 2);
             return false;
             //We wont try to write files after one attempt was failed and will stop right here.
         }
     }
     // else go ahead.
     if (!isset($_GET['settings-updated']) && !isset($_GET['_wpnonce'])) {
         update_option('supernova_file_write_status', 'failed');
         // @since Supernova 1.4.
     } else {
         // okay, let's see about getting credentials
         $url = wp_nonce_url('themes.php?page=theme-options');
         $method = '';
         if (false === ($creds = request_filesystem_credentials($url, $method, false, false, null))) {
             // if we get here, then we don't have credentials yet,
             return true;
         }
         // now we have some credentials, try to get the wp_filesystem running
         if (!WP_Filesystem($creds)) {
             // our credentials were no good, ask the user for them again
             request_filesystem_credentials($url, '', true, false, $_POST);
             return true;
         }
         global $wp_filesystem;
         $upload_dir = wp_upload_dir();
         if (!is_dir(trailingslashit($upload_dir['basedir']) . 'supernova_directory')) {
             if (!$wp_filesystem->mkdir(trailingslashit($upload_dir['basedir']) . 'supernova_directory')) {
                 update_option('supernova_file_write_status', 'failed');
                 // We will hook it normally if something goes wrong
                 echo "after here";
             } else {
                 update_option('supernova_old_user_check', 'no');
             }
         }
         $filename = trailingslashit($upload_dir['basedir']) . 'supernova_directory/custom-styles.css';
         if (!$wp_filesystem->put_contents($filename, supernova_user_css(), FS_CHMOD_FILE)) {
             update_option('supernova_file_write_status', 'failed');
         } else {
             update_option('supernova_old_user_check', 'no');
             update_option('supernova_file_write_status', 'passed');
             if (function_exists('wp_cache_clear_cache')) {
                 wp_cache_clear_cache();
             } elseif (function_exists('w3tc_minify_flush')) {
                 w3tc_minify_flush();
             }
         }
         return true;
     }
 }
Example #5
0
/**
 * Save config, can't decline save process. (difference from action_save)
 *
 * Do some actions on config keys update
 * Used in several places such as:
 *
 * 1. common config save
 * 2. import settings
 *
 * @param W3_Config $current_config
 * @param W3_Config $new_config
 * @param W3_ConfigAdmin $new_config_admin
 * @return bool
 * @throws Exception
 */
function w3_config_save($current_config, $new_config, $new_config_admin)
{
    $master_config = $new_config->is_master() ? $new_config : new W3_Config(true);
    if ($master_config->get_integer('common.instance_id', 0) == 0) {
        $master_config->set('common.instance_id', mt_rand());
        if (!$new_config->is_master()) {
            $master_config->save();
        }
    }
    $old_config = new W3_Config();
    $browsercache_dependencies = array();
    if ($new_config->get_boolean('browsercache.enabled')) {
        $browsercache_dependencies = array_merge($browsercache_dependencies, array('browsercache.cssjs.replace', 'browsercache.html.replace', 'browsercache.other.replace'));
        if ($new_config->get_boolean('browsercache.cssjs.replace')) {
            $browsercache_dependencies = array_merge($browsercache_dependencies, array('browsercache.cssjs.compression', 'browsercache.cssjs.expires', 'browsercache.cssjs.lifetime', 'browsercache.cssjs.cache.control', 'browsercache.cssjs.cache.policy', 'browsercache.cssjs.etag', 'browsercache.cssjs.w3tc'));
        }
        if ($new_config->get_boolean('browsercache.html.replace')) {
            $browsercache_dependencies = array_merge($browsercache_dependencies, array('browsercache.html.compression', 'browsercache.html.expires', 'browsercache.html.lifetime', 'browsercache.html.cache.control', 'browsercache.html.cache.policy', 'browsercache.html.etag', 'browsercache.html.w3tc'));
        }
        if ($new_config->get_boolean('browsercache.other.replace')) {
            $browsercache_dependencies = array_merge($browsercache_dependencies, array('browsercache.other.compression', 'browsercache.other.expires', 'browsercache.other.lifetime', 'browsercache.other.cache.control', 'browsercache.other.cache.policy', 'browsercache.other.etag', 'browsercache.other.w3tc'));
        }
    }
    /**
     * Show need empty page cache notification
     */
    if ($new_config->get_boolean('pgcache.enabled')) {
        $pgcache_dependencies = array_merge($browsercache_dependencies, array('pgcache.debug', 'dbcache.enabled', 'objectcache.enabled', 'minify.enabled', 'mobile.enabled', 'referrer.enabled'));
        if ($new_config->get_boolean('dbcache.enabled')) {
            $pgcache_dependencies = array_merge($pgcache_dependencies, array('dbcache.debug'));
        }
        if ($new_config->get_boolean('objectcache.enabled')) {
            $pgcache_dependencies = array_merge($pgcache_dependencies, array('objectcache.debug'));
        }
        if ($new_config->get_boolean('minify.enabled')) {
            $pgcache_dependencies = array_merge($pgcache_dependencies, array('minify.auto', 'minify.debug', 'minify.rewrite', 'minify.html.enable', 'minify.html.engine', 'minify.html.inline.css', 'minify.html.inline.js', 'minify.html.strip.crlf', 'minify.html.comments.ignore', 'minify.css.enable', 'minify.css.engine', 'minify.css.groups', 'minify.js.enable', 'minify.js.engine', 'minify.js.groups', 'minify.htmltidy.options.clean', 'minify.htmltidy.options.hide-comments', 'minify.htmltidy.options.wrap', 'minify.reject.logged', 'minify.reject.ua', 'minify.reject.uri'));
        }
        /**
         * @var W3_ModuleStatus $modules
         */
        $modules = w3_instance('W3_ModuleStatus');
        if ($modules->is_running('cdn')) {
            $pgcache_dependencies = array_merge($pgcache_dependencies, array('cdn.enabled', 'cdn.debug', 'cdn.engine', 'cdn.uploads.enable', 'cdn.includes.enable', 'cdn.includes.files', 'cdn.theme.enable', 'cdn.theme.files', 'cdn.minify.enable', 'cdn.custom.enable', 'cdn.custom.files', 'cdn.ftp.domain', 'cdn.ftp.ssl', 'cdn.s3.cname', 'cdn.s3.ssl', 'cdn.cf.cname', 'cdn.cf.ssl', 'cdn.cf2.cname', 'cdn.cf2.ssl', 'cdn.rscf.cname', 'cdn.rscf.ssl', 'cdn.azure.cname', 'cdn.azure.ssl', 'cdn.mirror.domain', 'cdn.mirror.ssl', 'cdn.netdna.domain', 'cdn.netdna.ssl', 'cdn.cotendo.domain', 'cdn.cotendo.ssl', 'cdn.edgecast.domain', 'cdn.edgecast.ssl', 'cdn.att.domain', 'cdn.att.ssl', 'cdn.reject.logged_roles', 'cdn.reject.roles', 'cdn.reject.ua', 'cdn.reject.uri', 'cdn.reject.files'));
        } elseif ($old_config->get_boolean('cdn.enabled') && !$new_config->get_boolean('cdn.enabled')) {
            $pgcache_dependencies = array_merge($pgcache_dependencies, array('cdn.enabled'));
        }
        if ($new_config->get_boolean('mobile.enabled')) {
            $pgcache_dependencies = array_merge($pgcache_dependencies, array('mobile.rgroups'));
        }
        if ($new_config->get_boolean('referrer.enabled')) {
            $pgcache_dependencies = array_merge($pgcache_dependencies, array('referrer.rgroups'));
        }
        if ($new_config->get_boolean('browsercache.enabled') && $new_config->get_string('pgcache.engine') == 'file_generic') {
            $pgcache_dependencies = array_merge($pgcache_dependencies, array('browsercache.html.last_modified', 'browsercache.other.last_modified'));
        }
        $old_pgcache_dependencies_values = array();
        $new_pgcache_dependencies_values = array();
        foreach ($pgcache_dependencies as $pgcache_dependency) {
            $old_pgcache_dependencies_values[] = $old_config->get($pgcache_dependency);
            $new_pgcache_dependencies_values[] = $new_config->get($pgcache_dependency);
        }
        if (serialize($old_pgcache_dependencies_values) != serialize($new_pgcache_dependencies_values)) {
            $new_config->set('notes.need_empty_pgcache', true);
        }
    }
    /**
     * Show need empty minify notification
     */
    if ($current_config->get_boolean('minify.enabled') && $new_config->get_boolean('minify.enabled') && ($new_config->get_boolean('minify.css.enable') && ($new_config->get_boolean('minify.auto') || count($new_config->get_array('minify.css.groups'))) || $new_config->get_boolean('minify.js.enable') && ($new_config->get_boolean('minify.auto') || count($new_config->get_array('minify.js.groups'))))) {
        $minify_dependencies = array_merge($browsercache_dependencies, array('minify.auto', 'minify.debug', 'minify.options', 'minify.symlinks', 'minify.css.enable', 'minify.js.enable'));
        if ($new_config->get_boolean('minify.css.enable') && ($new_config->get_boolean('minify.auto') || count($new_config->get_array('minify.css.groups')))) {
            $minify_dependencies = array_merge($minify_dependencies, array('minify.css.engine', 'minify.css.combine', 'minify.css.strip.comments', 'minify.css.strip.crlf', 'minify.css.imports', 'minify.css.groups', 'minify.yuicss.path.java', 'minify.yuicss.path.jar', 'minify.yuicss.options.line-break', 'minify.csstidy.options.remove_bslash', 'minify.csstidy.options.compress_colors', 'minify.csstidy.options.compress_font-weight', 'minify.csstidy.options.lowercase_s', 'minify.csstidy.options.optimise_shorthands', 'minify.csstidy.options.remove_last_;', 'minify.csstidy.options.case_properties', 'minify.csstidy.options.sort_properties', 'minify.csstidy.options.sort_selectors', 'minify.csstidy.options.merge_selectors', 'minify.csstidy.options.discard_invalid_properties', 'minify.csstidy.options.css_level', 'minify.csstidy.options.preserve_css', 'minify.csstidy.options.timestamp', 'minify.csstidy.options.template'));
        }
        if ($new_config->get_boolean('minify.js.enable') && ($new_config->get_boolean('minify.auto') || count($new_config->get_array('minify.js.groups')))) {
            $minify_dependencies = array_merge($minify_dependencies, array('minify.js.engine', 'minify.js.combine.header', 'minify.js.combine.body', 'minify.js.combine.footer', 'minify.js.strip.comments', 'minify.js.strip.crlf', 'minify.js.groups', 'minify.yuijs.path.java', 'minify.yuijs.path.jar', 'minify.yuijs.options.line-break', 'minify.yuijs.options.nomunge', 'minify.yuijs.options.preserve-semi', 'minify.yuijs.options.disable-optimizations', 'minify.ccjs.path.java', 'minify.ccjs.path.jar', 'minify.ccjs.options.compilation_level', 'minify.ccjs.options.formatting'));
        }
        /**
         * @var W3_ModuleStatus $modules
         */
        $modules = w3_instance('W3_ModuleStatus');
        if ($modules->is_running('cdn')) {
            $minify_dependencies = array_merge($minify_dependencies, array('cdn.engine', 'cdn.enabled'));
        } elseif ($old_config->get_boolean('cdn.enabled') && !$new_config->get_boolean('cdn.enabled')) {
            $minify_dependencies = array_merge($minify_dependencies, array('cdn.enabled'));
        }
        $old_minify_dependencies_values = array();
        $new_minify_dependencies_values = array();
        foreach ($minify_dependencies as $minify_dependency) {
            $old_minify_dependencies_values[] = $old_config->get($minify_dependency);
            $new_minify_dependencies_values[] = $new_config->get($minify_dependency);
        }
        if (serialize($old_minify_dependencies_values) != serialize($new_minify_dependencies_values)) {
            $new_config->set('notes.need_empty_minify', true);
        }
    }
    if ($new_config->get_boolean('cdn.enabled') && !w3_is_cdn_mirror($new_config->get_string('cdn.engine'))) {
        /**
         * Show notification when CDN enabled
         */
        if (!$old_config->get_boolean('cdn.enabled')) {
            $new_config->set('notes.cdn_upload', true);
        }
        /**
         * Show notification when Browser Cache settings changes
         */
        $cdn_dependencies = array('browsercache.enabled');
        if ($new_config->get_boolean('cdn.enabled')) {
            $cdn_dependencies = array('browsercache.cssjs.compression', 'browsercache.cssjs.expires', 'browsercache.cssjs.lifetime', 'browsercache.cssjs.cache.control', 'browsercache.cssjs.cache.policy', 'browsercache.cssjs.etag', 'browsercache.cssjs.w3tc', 'browsercache.html.compression', 'browsercache.html.expires', 'browsercache.html.lifetime', 'browsercache.html.cache.control', 'browsercache.html.cache.policy', 'browsercache.html.etag', 'browsercache.html.w3tc', 'browsercache.other.compression', 'browsercache.other.expires', 'browsercache.other.lifetime', 'browsercache.other.cache.control', 'browsercache.other.cache.policy', 'browsercache.other.etag', 'browsercache.other.w3tc');
        }
        $old_cdn_dependencies_values = array();
        $new_cdn_dependencies_values = array();
        foreach ($cdn_dependencies as $cdn_dependency) {
            $old_cdn_dependencies_values[] = $old_config->get($cdn_dependency);
            $new_cdn_dependencies_values[] = $new_config->get($cdn_dependency);
        }
        if (serialize($old_cdn_dependencies_values) != serialize($new_cdn_dependencies_values)) {
            $new_config->set('notes.cdn_reupload', true);
        }
    }
    /**
     * Show need empty object cache notification
     */
    if ($current_config->get_boolean('objectcache.enabled')) {
        $objectcache_dependencies = array('objectcache.groups.global', 'objectcache.groups.nonpersistent');
        $old_objectcache_dependencies_values = array();
        $new_objectcache_dependencies_values = array();
        foreach ($objectcache_dependencies as $objectcache_dependency) {
            $old_objectcache_dependencies_values[] = $old_config->get($objectcache_dependency);
            $new_objectcache_dependencies_values[] = $new_config->get($objectcache_dependency);
        }
        if (serialize($old_objectcache_dependencies_values) != serialize($new_objectcache_dependencies_values)) {
            $new_config->set('notes.need_empty_objectcache', true);
        }
    }
    if ($current_config->get_boolean('newrelic.enabled')) {
        if ($current_config->get_boolean('pgcache.enabled')) {
            if (w3_is_network() && $current_config->get_boolean('common.force_master')) {
                $new_config->set('pgcache.late_init', true);
            }
        }
    }
    do_action('w3tc_saved_options', $new_config, $new_config_admin);
    /**
     * Save config
     */
    try {
        $new_config_admin->save();
        $new_config->save();
    } catch (Exception $ex) {
        // try to fix environment, it potentially can be fixed silently
        // dont show error here, it will be called again later
        // in admin_notices
        try {
            $environment = w3_instance('W3_AdminEnvironment');
            $environment->fix_in_wpadmin($new_config);
        } catch (Exception $ex) {
        }
        // retry save process and complain now on failure
        try {
            $new_config_admin->save();
            $new_config->save();
        } catch (Exception $ex) {
            throw new Exception('<strong>Can\'t change configuration</strong>: ' . $ex->getMessage());
        }
    }
    $w3_plugin_cdn = w3_instance('W3_Plugin_CdnAdmin');
    /**
     * Empty caches on engine change or cache enable/disable
     */
    if ($old_config->get_string('pgcache.engine') != $new_config->get_string('pgcache.engine') || $old_config->get_string('pgcache.enabled') != $new_config->get_string('pgcache.enabled')) {
        w3tc_pgcache_flush();
    }
    if ($old_config->get_string('dbcache.engine') != $new_config->get_string('dbcache.engine') || $old_config->get_string('dbcache.enabled') != $new_config->get_string('dbcache.enabled')) {
        w3tc_dbcache_flush();
    }
    if ($old_config->get_string('objectcache.engine') != $new_config->get_string('objectcache.engine') || $old_config->get_string('objectcache.enabled') != $new_config->get_string('objectcache.enabled')) {
        w3tc_objectcache_flush();
    }
    if ($old_config->get_string('minify.engine') != $new_config->get_string('minify.engine') || $old_config->get_string('minify.enabled') != $new_config->get_string('minify.enabled')) {
        w3tc_minify_flush();
    }
    /**
     * Update CloudFront CNAMEs
     */
    $update_cf_cnames = false;
    if ($new_config->get_boolean('cdn.enabled') && in_array($new_config->get_string('cdn.engine'), array('cf', 'cf2'))) {
        if ($new_config->get_string('cdn.engine') == 'cf') {
            $old_cnames = $old_config->get_array('cdn.cf.cname');
            $new_cnames = $new_config->get_array('cdn.cf.cname');
        } else {
            $old_cnames = $old_config->get_array('cdn.cf2.cname');
            $new_cnames = $new_config->get_array('cdn.cf2.cname');
        }
        if (count($old_cnames) != count($new_cnames) || count(array_diff($old_cnames, $new_cnames))) {
            $update_cf_cnames = true;
        }
    }
    /**
     * Refresh config
     */
    $current_config->load();
    /**
     * React to config changes
     */
    $environment = w3_instance('W3_AdminEnvironment');
    $environment->fix_on_event($new_config, 'config_change', $old_config);
    /**
     * Update support us option
     */
    w3_instance('W3_AdminLinks')->link_update($current_config);
    /**
     * Auto upload minify files to CDN
     */
    if ($new_config->get_boolean('minify.enabled') && $new_config->get_boolean('minify.upload') && $new_config->get_boolean('cdn.enabled') && !w3_is_cdn_mirror($new_config->get_string('cdn.engine'))) {
        w3_cdn_upload_minify();
    }
    /**
     * Auto upload browsercache files to CDN
     */
    if ($new_config->get_boolean('cdn.enabled') && $new_config->get_string('cdn.engine') == 'ftp') {
        w3_cdn_delete_browsercache($current_config);
        w3_cdn_upload_browsercache($current_config);
    }
    /**
     * Update CloudFront CNAMEs
     */
    if ($update_cf_cnames) {
        $error = null;
        $w3_plugin_cdn->update_cnames($error);
    }
    return true;
}
Example #6
0
 /**
  * Flush minify cache
  *
  * @return void
  */
 function flush_minify()
 {
     _doing_it_wrong('flush_minify', 'This function is deprecated. Use w3tc_minify_flush() instead.', '0.9.3');
     w3tc_minify_flush();
 }
Example #7
0
 public function clear_cache()
 {
     if (function_exists('wp_cache_clear_cache')) {
         $GLOBALS["super_cache_enabled"] = 1;
         wp_cache_clear_cache();
     } else {
         if (function_exists('simple_cache_clear')) {
             simple_cache_clear();
         } else {
             if (function_exists('w3tc_pgcache_flush')) {
                 w3tc_pgcache_flush();
             }
             if (function_exists('w3tc_dbcache_flush')) {
                 w3tc_dbcache_flush();
             }
             if (function_exists('w3tc_minify_flush')) {
                 w3tc_minify_flush();
             }
             if (function_exists('w3tc_objectcache_flush')) {
                 w3tc_objectcache_flush();
             }
             if (function_exists('wp_cache_clear_cache')) {
                 wp_cache_clear_cache();
             }
         }
     }
 }
Example #8
0
 /**
  * Flush the CSS minification cache of W3 Total Cache
  *
  * @since 1.4.0
  */
 protected function _flush_caching_plugins_css_minify_caches()
 {
     /** This filter is documented in models/model-table.php */
     if (!apply_filters('tablepress_flush_caching_plugins_caches', true)) {
         return;
     }
     // W3 Total Cache
     if (function_exists('w3tc_minify_flush')) {
         w3tc_minify_flush();
     }
 }
 /**
  * Fired for each blog when the plugin is activated.
  *
  * @since	1.0.0
  */
 private static function single_activate()
 {
     wp_cache_flush();
     if (function_exists('w3tc_pgcache_flush')) {
         w3tc_pgcache_flush();
     }
     if (function_exists('w3tc_minify_flush')) {
         w3tc_minify_flush();
     }
 }
 /**
  * Clear cache(s) based on HTTP GET parameters. Allows another site to tell this site to clear its cache.
  * Will only run if GET params include correct secret key, which is defined in SitePush options
  *
  * @return mixed result code echoed to screen, or FALSE if command/key not set
  */
 private function clear_cache()
 {
     //check $_GET to see if someone has asked us to clear the cache
     //for example a push from another server to this one
     $cmd = isset($_GET['sitepush_cmd']) ? $_GET['sitepush_cmd'] : FALSE;
     $key = isset($_GET['sitepush_key']) ? $_GET['sitepush_key'] : FALSE;
     //no command and/or key so return to normal WP initialisation
     if (!$cmd || !$key) {
         return FALSE;
     }
     //do nothing if the secret key isn't correct
     $options = get_option('sitepush_options');
     $result = '';
     if ($key != urlencode($options['cache_key'])) {
         status_header('403');
         //return an HTTP error so we know cache clear wasn't successful
         $result .= "[1] Unrecognized cache key\n";
         die(trim($result));
     }
     switch ($cmd) {
         case 'clear_cache':
             // Purge the entire w3tc page cache:
             if (function_exists('w3tc_pgcache_flush')) {
                 /** @noinspection PhpUndefinedFunctionInspection */
                 w3tc_pgcache_flush();
                 /** @noinspection PhpUndefinedFunctionInspection */
                 w3tc_dbcache_flush();
                 /** @noinspection PhpUndefinedFunctionInspection */
                 w3tc_minify_flush();
                 /** @noinspection PhpUndefinedFunctionInspection */
                 w3tc_objectcache_flush();
                 $result .= "[0] W3TC cache cleared\n";
             }
             // Purge the entire supercache page cache:
             if (function_exists('wp_cache_clear_cache')) {
                 /** @noinspection PhpUndefinedFunctionInspection */
                 wp_cache_clear_cache();
                 $result .= "[0] Supercache cleared\n";
             }
             break;
         default:
             $result .= "[2] Unrecognised cache command\n";
             status_header('400');
             //return an HTTP error so we know cache clear wasn't successful
             break;
     }
     if (!$result) {
         $result = "[3] No supported cache present\n";
     }
     die(trim($result));
 }
Example #11
0
function top_generate_query($can_requery = true)
{
    global $wpdb;
    $rtrn_msg = "";
    $omitCats = get_option('top_opt_omit_cats');
    $maxAgeLimit = get_option('top_opt_max_age_limit');
    $ageLimit = get_option('top_opt_age_limit');
    $exposts = get_option('top_opt_excluded_post');
    $exposts = preg_replace('/,,+/', ',', $exposts);
    $top_opt_tweeted_posts = array();
    $top_opt_tweeted_posts = get_option('top_opt_tweeted_posts');
    if (!$top_opt_tweeted_posts) {
        $top_opt_tweeted_posts = array();
    }
    if ($top_opt_tweeted_posts != null) {
        $already_tweeted = implode(",", $top_opt_tweeted_posts);
    } else {
        $already_tweeted = "";
    }
    if (substr($exposts, 0, 1) == ",") {
        $exposts = substr($exposts, 1, strlen($exposts));
    }
    if (substr($exposts, -1, 1) == ",") {
        $exposts = substr($exposts, 0, strlen($exposts) - 1);
    }
    if (!(isset($ageLimit) && is_numeric($ageLimit))) {
        $ageLimit = top_opt_AGE_LIMIT;
    }
    if (!(isset($maxAgeLimit) && is_numeric($maxAgeLimit))) {
        $maxAgeLimit = top_opt_MAX_AGE_LIMIT;
    }
    if (!isset($omitCats)) {
        $omitCats = top_opt_OMIT_CATS;
    }
    $as_post_type = get_option('as_post_type');
    $as_number_tweet = get_option('as_number_tweet');
    if ($as_number_tweet <= 0) {
        $as_number_tweet = 1;
    }
    if ($as_number_tweet > 10) {
        $as_number_tweet = 10;
    }
    //trying to fix multiposts
    //if($last<1){$as_number_tweet = 0;}
    $pt = '';
    if ($as_post_type != 'all') {
        $pt = "post_type = '{$as_post_type}' AND";
    }
    $sql = "SELECT ID\n            FROM {$wpdb->posts}\n            WHERE {$pt} post_status = 'publish' ";
    if (is_numeric($ageLimit)) {
        if ($ageLimit > 0) {
            $sql = $sql . " AND post_date <= curdate( ) - INTERVAL " . $ageLimit . " day";
        }
    }
    if ($maxAgeLimit != 0) {
        $sql = $sql . " AND post_date >= curdate( ) - INTERVAL " . $maxAgeLimit . " day";
    }
    if (isset($exposts)) {
        if (trim($exposts) != '') {
            $sql = $sql . " AND ID Not IN (" . $exposts . ") ";
        }
    }
    if (isset($already_tweeted)) {
        if (trim($already_tweeted) != "") {
            $sql = $sql . " AND ID Not IN (" . $already_tweeted . ") ";
        }
    }
    if ($omitCats != '') {
        $sql = $sql . " AND NOT (ID IN (SELECT tr.object_id FROM " . $wpdb->prefix . "term_relationships AS tr INNER JOIN " . $wpdb->prefix . "term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy = 'category' AND tt.term_id IN (" . $omitCats . ")))";
    }
    $sql = $sql . "\n            ORDER BY RAND() \n            LIMIT {$as_number_tweet} ";
    $oldest_post = $wpdb->get_results($sql);
    if ($oldest_post == null) {
        if ($can_requery) {
            $top_opt_tweeted_posts = array();
            update_option('top_opt_tweeted_posts', $top_opt_tweeted_posts);
            return top_generate_query(false);
        } else {
            return "No post found to tweet. Please check your settings and try again.--" . $sql;
        }
    }
    if (isset($oldest_post)) {
        $ret = '';
        foreach ($oldest_post as $k => $odp) {
            array_push($top_opt_tweeted_posts, $odp->ID);
            $ret .= 'Tweet ' . $k . ' : ' . top_opt_tweet_post($odp->ID) . '<br/>';
        }
        update_option('top_opt_tweeted_posts', $top_opt_tweeted_posts);
        if (function_exists('w3tc_pgcache_flush')) {
            w3tc_pgcache_flush();
            w3tc_dbcache_flush();
            w3tc_minify_flush();
            w3tc_objectcache_flush();
            $cache = ' and W3TC Caches cleared';
        }
        $next_tweet_time = time() + get_option('top_opt_interval') * 60 * 60;
        update_option('next_tweet_time', $next_tweet_time);
        return $ret;
    }
    return $rtrn_msg;
}
Example #12
0
 protected function cache_flush()
 {
     // W3 Total Cache
     if (function_exists('w3tc_pgcache_flush')) {
         w3tc_pgcache_flush();
     }
     if (function_exists('w3tc_dbcache_flush')) {
         w3tc_dbcache_flush();
     }
     if (function_exists('w3tc_minify_flush')) {
         w3tc_minify_flush();
     }
     if (function_exists('w3tc_objectcache_flush')) {
         w3tc_objectcache_flush();
     }
     // WP Super Cache
     if (function_exists('wp_cache_clear_cache')) {
         wp_cache_clear_cache();
     }
 }
 /**
  * Clear cache
  */
 public function clear_pagecache()
 {
     if (function_exists('w3tc_pgcache_flush')) {
         // clean the page cache
         w3tc_pgcache_flush();
     }
     if (function_exists('w3tc_minify_flush')) {
         // clean minify cache
         w3tc_minify_flush();
     }
 }
Example #14
0
 /**
  * Clear something from the cache.
  *
  * @synopsis <cache-type>... [--post_id=<post-id>] [--permalink=<permalink>]
  */
 function flush($args = array(), $assoc_args = array())
 {
     $args = array_unique($args);
     do {
         $cache_type = array_shift($args);
         switch ($cache_type) {
             case 'db':
             case 'database':
                 if (w3tc_dbcache_flush()) {
                     WP_CLI::success('The database cache is flushed successfully.');
                 } else {
                     WP_CLI::error('Flushing the database cache failed.');
                 }
                 break;
             case 'minify':
                 if (w3tc_minify_flush()) {
                     WP_CLI::success('The minify cache is flushed successfully.');
                 } else {
                     WP_CLI::error('Flushing the minify cache failed.');
                 }
                 break;
             case 'object':
                 if (w3tc_objectcache_flush()) {
                     WP_CLI::success('The object cache is flushed successfully.');
                 } else {
                     WP_CLI::error('Flushing the object cache failed.');
                 }
                 break;
             case 'page':
                 if (w3tc_pgcache_flush()) {
                     WP_CLI::success('The page cache is flushed successfully.');
                 } else {
                     WP_CLI::error('Flushing the page cache failed.');
                 }
                 break;
             case 'post':
             default:
                 if (isset($assoc_args['post_id'])) {
                     if (is_numeric($assoc_args['post_id']) && get_post($assoc_args['post_id'])) {
                         if (w3tc_pgcache_flush_post($assoc_args['post_id'])) {
                             WP_CLI::success('Post ' . $assoc_args['post_id'] . ' is flushed successfully.');
                         } else {
                             WP_CLI::error('Flushing ' . $assoc_args['post_id'] . ' from cache failed.');
                         }
                     } else {
                         WP_CLI::error('This is not a valid post id.');
                     }
                 } elseif (isset($assoc_args['permalink'])) {
                     $id = url_to_postid($assoc_args['permalink']);
                     if (is_numeric($id) && $id > 0) {
                         if (w3tc_pgcache_flush_post($id)) {
                             WP_CLI::success($id . ' is flushed successfully.');
                         } else {
                             WP_CLI::error('Flushing ' . $id . ' from cache failed.');
                         }
                     } else {
                         WP_CLI::error('There is no post with this permalink.');
                     }
                 }
         }
     } while (!empty($args));
 }
Example #15
0
function swift_write_file($force = FALSE)
{
    if (!$force) {
        if (!isset($_GET['settings-updated']) && !isset($_GET['_wpnonce'])) {
            return false;
        }
    }
    if (!$force) {
        $url = wp_nonce_url('admin.php?page=' . $_GET['page']);
    } else {
        $url = '';
    }
    if (false === ($creds = request_filesystem_credentials($url, '', false, false, null))) {
        // if we get here, then we don't have credentials yet,
        // but have just produced a form for the user to fill in,
        // so stop processing for now
        return true;
        // stop the normal page form from displaying
    }
    // now we have some credentials, try to get the wp_filesystem running
    if (!WP_Filesystem($creds)) {
        // our credentials were no good, ask the user for them again
        request_filesystem_credentials($url, '', true, false, $_POST);
        return true;
    }
    $upload_dir = wp_upload_dir();
    global $wp_filesystem;
    $msg = '';
    if (!is_dir(trailingslashit($upload_dir['basedir']) . 'swift-magic')) {
        if (!$wp_filesystem->mkdir(trailingslashit($upload_dir['basedir']) . 'swift-magic')) {
            $msg .= "<li>Error creating directory <strong>swift-magic</strong> at" . trailingslashit($upload_dir['basedir']) . '</li>';
            $error = 1;
        } else {
            //$msg .= "<li>Created <strong>swift-magic</strong> at" . trailingslashit($upload_dir['basedir']) . '</li>';
        }
    }
    $filename = trailingslashit($upload_dir['basedir']) . 'swift-magic/custom-styles.css';
    if (!$wp_filesystem->put_contents($filename, swift_generate_stylesheet(), FS_CHMOD_FILE)) {
        $msg .= '<li>Error creating file ' . $filename . '</li>';
        $error = 1;
    } else {
        //$msg .= '<li>Wrote to file ' . $filename . '</li>';
    }
    $filename = trailingslashit($upload_dir['basedir']) . 'swift-magic/swift-js.js';
    if (!$wp_filesystem->put_contents($filename, swift_generate_js(), FS_CHMOD_FILE)) {
        $msg .= '<li>Error creating file ' . $filename . '</li>';
        $error = 1;
    } else {
        //$msg .= '<li>Wrote to file ' . $filename . '</li>';
    }
    if (function_exists('w3tc_minify_flush')) {
        //w3tc_pgcache_flush();
        w3tc_minify_flush();
        //$msg .= '<li>' . __('W3 Total Cache Minify Cache flushed', 'swift') . '</li>';
    } else {
        if (function_exists('wp_cache_clear_cache')) {
            wp_cache_clear_cache();
            //$msg .= __('WP Super Cache flushed', 'swift');
        }
    }
    if (isset($error) && $error) {
        $buttons = 'Please download the below files and upload theme to' . trailingslashit($upload_dir['basedir']) . 'swift-magic';
        $buttons .= '<form action="" method="post">
				<input type="submit" class="button" value="' . __('Download custom-styles.css', 'swift') . '" name="download_css">
						</form>';
        $buttons .= '<form action="" method="post">
				<input type="submit" class="button" value="' . __('Download swift-js.js', 'swift') . '" name="download_js">
						</form>';
        $msg = $msg . $buttons;
    }
    $filename = trailingslashit($upload_dir['basedir']) . 'swift-magic/editor-styles.css';
    if (!$wp_filesystem->put_contents($filename, swift_editor_stylesheet_generator(), FS_CHMOD_FILE)) {
        $msg .= '<li>Error creating file ' . $filename . '</li>';
        $error = 1;
    } else {
        //$msg .= '<li>Wrote to file ' . $filename . '</li>';
    }
    if (!isset($error) || !$error) {
        $msg .= "Successfully saved changes.";
    }
    if (isset($error) && $error) {
        update_option('swift_error', true);
    } else {
        update_option('swift_error', false);
    }
    return $msg;
}