[wordpress插件] Clear Cache for Me为我清除缓存

wordpress 插件 文章 2020-03-24 15:40 469 0 全屏看文

AI助手支持GPT4.0

评分
96
描述

W3 Total Cache and WP Super Cache are great caching plugins, but they do not know when a widget is updated.

W3 Total Cache和WP Super Cache是​​很棒的缓存插件,但是它们不知道何时更新小部件。

WPEngine is the best place to host your WordPress installation, but their caching system is no smarter when it comes to updating widgets and menus.

WPEngine是托管WordPress安装的最佳场所,但是在更新小部件和菜单时,它们的缓存系统并不聪明。

I created this plugin because my website did not see any changes when saving widgets or menus using these caching systems.

我创建此插件的原因是,使用这些缓存系统保存小部件或菜单时,我的网站没有看到任何更改。

Clear Cache For Me will purge ALL your cache each time you do a save without having to press an additional button.

每次保存时,Clear Cache For Me都会清除所有缓存,而无需按其他按钮。

It may be overkill, which may be why it’s not built in, but some people need simplicity.

可能是矫kill过正,这也许就是为什么它不是内置的,但有些人需要简单。

In addition to clearing those pesky caching engines, Clear Cache for Me can force your browser to reload your current theme’s CSS and JS files.

除了清除那些讨厌的缓存引擎之外,Clear Cache for Me还可以强制浏览器重新加载当前主题的CSS和JS文件。

I modify my theme’s CSS and JS files every so often and always have trouble with the browser not getting the latest version.

我经常修改主题的CSS和JS文件,并且总是遇到浏览器无法获取最新版本的麻烦。

So now after clicking on the “Clear Cache Now!”

因此,现在点击“立即清除缓存!”

button on the dashboard the browser will be forced to reload the current theme’s CSS and JS files.

按钮,将迫使浏览器重新加载当前主题的CSS和JS文件。

If you do not click the “Clear Cache Now!”

如果您不单击“立即清除缓存!”

button, the browser will cache the CSS and JS files like it normally does.

按钮,浏览器将像往常一样缓存CSS和JS文件。

The popular Qode themes has a options to set your own custom CSS and JS.

流行的Qode主题具有用于设置您自己的自定义CSS和JS的选项。

Sometimes you may not see your changes for a long while because your browser is trying to get the cached file.

有时您可能很长一段时间都看不到更改,因为您的浏览器正在尝试获取缓存的文件。

Whenever you save your Qode’s options, the CSS and JS files will be forced to reload in the browser on the public side.

每当您保存Qode的选项时,CSS和JS文件都将被迫在公共端的浏览器中重新加载。

Works with the following caching systems:

适用于以下缓存系统:

    • W3 Total Cache
    • W3总缓存

    • WP Super Cache
    • WP超级缓存

    • WP Fastest Cache
    • WP最快的缓存

    • WPEngine Cache
    • WPEngine缓存

    • Kinsta Cache
    • Kinsta缓存

    • GoDaddy Cache
    • GoDaddy缓存

    Clears all cache for following actions:

    清除所有缓存以进行以下操作:

      • When Widgets are saved
      • 保存小部件时

      • When Customizer is saved
      • 保存定制程序时

      • When Menus are saved
      • 保存菜单时

      • When Settings from a settings page is saved.
      • 保存设置页面中的设置后。

      • When a Contact Form 7 form is saved.
      • 保存联系表单7表单时。

      • When a Formidable Form form is saved.
      • 保存强大表格时。

      • When WooThemes settings are saved.
      • 保存WooThemes设置时。

      • When NextGen Gallery albums and galleries are updated (beta – may not clear cache on all actions).
      • NextGen Gallery专辑和画廊更新后(测试版–可能不会清除所有操作的缓存)。

      • When Qode options are saved this plugin forces browsers to reload the custom css and custom js.
      • 保存Qode选项后,此插件会强制浏览器重新加载自定义的CSS和自定义的js。

      There is a convenient clear cache button on the dashboard for users with the right capability.

      仪表板上有一个方便的清除缓存按钮,供具有适当功能的用户使用。

      Admins (users with the ‘manage_options’ capability) can set which capability a user needs to view the button.

      管理员(具有“ manage_options”功能的用户)可以设置用户查看按钮所需的功能。

      If you are using this button often, please consider submitting a request to have this plugin do your button-pushing for you.

      如果您经常使用此按钮,请考虑提交请求,让该插件为您完成按钮推送。

      This plugin is meant to work behind the scenes to make your life easier and less frustrating.

      该插件旨在在幕后工作,使您的生活更轻松,更省心。

      Developer Options

      开发者选项

      ccfm_supported_caching_exists

      ccfm_supported_caching_exists

      Use this filter to determine if this plugin should do anything including showing the button on the dashboard.

      使用此过滤器确定此插件是否应该执行任何操作,包括在仪表板上显示按钮。

      Return true if a caching system is supported.

      如果支持缓存系统,则返回true。

      Default: True if any of the supported caching systems is active.

      默认值:如果任何受支持的缓存系统处于活动状态,则为true。

      See Example 1 below.

      请参阅下面的示例1。

      ccfm_admin_init

      ccfm_admin_init

      Use this action to add hooks when cache is to be cleared.

      使用此操作在要清除缓存时添加挂钩。

      Or do any other setup activity.

      或执行其他任何设置活动。

      ccfm_clear_cache_for_me_before

      ccfm_clear_cache_for_me_before

      Use this action to clear cache from an unsupported caching system before the default caching systems clear their cache.

      在默认缓存系统清除其缓存之前,使用此操作从不受支持的缓存系统清除缓存。

      ccfm_clear_cache_for_me

      ccfm_clear_cache_for_me

      Use this action to clear cache from an unsupported caching system after the default caching systems clear their cache.

      在默认缓存系统清除其缓存后,使用此操作从不受支持的缓存系统清除缓存。

      Example 1

      示例1

      Thanks to Benjamin Pick – If you are using Autoptimize and need to clear the CSS or JS files automatically, you can add the code below to your theme’s functions.php file.

      感谢Benjamin Pick –如果您使用的是Autoptimize,并且需要自动清除CSS或JS文件,则可以将以下代码添加到主题的functions.php文件中。

      This code also demonstrates how you can add an unsupported caching system and have its cache cleared for you.

      此代码还演示了如何添加不受支持的缓存系统并为您清除其缓存。

      https://gist.github.com/benjaminpick/94b487ce995454797143

      https://gist.github.com/benjaminpick/94b487ce995454797143

      also pasted below:
          

      也粘贴在下面:
          

          

      <?php
          

      function yt_cache_enable($return) {
              

      函数yt_cache_enable($ return){
              

      if (class_exists(‘autoptimizeCache’))
                  

      如果(class_exists('autoptimizeCache'))
                  

      return true;

      返回true;

          return $return;

        return $ return;

      }

      }

      add_filter('ccfm_supported_caching_exists', 'yt_cache_enable');

      add_filter('ccfm_supported_caching_exists','yt_cache_enable');

      function yt_cache_clear() {    

      函数yt_cache_clear(){    

      if (class_exists('autoptimizeCache'))        

      如果(class_exists('autoptimizeCache'))        

      autoptimizeCache::clearall();

      autoptimizeCache :: clearall();

      }

      }

      add_action('ccfm_clear_cache_for_me', 'yt_cache_clear');

      add_action('ccfm_clear_cache_for_me','yt_cache_clear');

      Similarly, if you are using the LiteSpeed Cache plugin, you can add the following (untested) code.

      同样,如果您使用的是LiteSpeed Cache插件,则可以添加以下(未经测试的)代码。

      I don’t have a LiteSpeed server so I’m unable to verify this actually works.

      我没有LiteSpeed服务器,因此无法验证它是否可以正常工作。

        <?php

      function my_lt_cache_enable( $return = false ) {    

      函数my_lt_cache_enable($ return = false){    

      if ( class_exists( 'LiteSpeed_Cache_Purge' ) )        

      如果(class_exists('LiteSpeed_Cache_Purge'))        

      return true;    

      返回true;    

      return $return;

      返回$ return;

      }

      }

      add_filter('ccfm_supported_caching_exists', 'my_lt_cache_enable');

      add_filter('ccfm_supported_caching_exists','my_lt_cache_enable');

      function my_lt_cache_clear() {    

      函数my_lt_cache_clear(){    

      if ( my_lt_cache_enable() )        

      如果(my_lt_cache_enable())        

      LiteSpeed_Cache_Purge::purge_all( 'Clear Cache For Me' );

      LiteSpeed_Cache_Purge :: purge_all('为我清除缓存');

      }

      }

      add_action('ccfm_clear_cache_for_me', 'my_lt_cache_clear');

      add_action('ccfm_clear_cache_for_me','my_lt_cache_clear');

      Example 2

      示例2

      Thanks to Benjamin Pick – If you have an automatic deployment setup and need a webhook to clear the caches, you can add this code to your theme’s functions.php file.

      感谢Benjamin Pick –如果您具有自动部署设置,并且需要使用Webhook清除缓存,则可以将此代码添加到主题的functions.php文件中。

      https://gist.github.com/benjaminpick/67b6b9a49ef7991172f9

      https://gist.github.com/benjaminpick/67b6b9a49ef7991172f9

      also pasted below:
          

      也粘贴在下面:
          

          

      <?php
          

      if (!defined(‘CLEAR_CACHE_HOOK_KEY’))
              

      如果(!defined(‘CLEAR_CACHE_HOOK_KEY’))
              

      define(‘CLEAR_CACHE_HOOK_KEY’, ‘some_secret_key_please’);

      define('CLEAR_CACHE_HOOK_KEY','some_secret_key_please');

      function yt_cache_clear_web_hook() {    

        function yt_cache_clear_web_hook(){    

      if (isset($_GET['key']) && $_GET['key'] == CLEAR_CACHE_HOOK_KEY) {        

      如果(isset($ _ GET ['key'])&& $ _GET ['key'] == CLEAR_CACHE_HOOK_KEY){        

      if (function_exists('ccfm_clear_cache_for_me')) {            

      如果(function_exists('ccfm_clear_cache_for_me')){            

      ccfm_clear_cache_for_me( 'ajax' );            

      ccfm_clear_cache_for_me('ajax');            

      echo 'Cache was cleared.';        

      回显“缓存已清除”。        

      } else {            

      }其他{            

      echo 'Install the plugin "Clear Cache For Me" first';        

      echo'首先安装插件“为我清除缓存”;        

      }        

      }        

      exit;    

      出口;    

      }

      }

      }

      }

      // Call this URL to clear the cache:

      //调用此URL清除缓存:

      // /wp-admin/admin-ajax.php?action=clear_cache&key=some_secret_key_please

      // /wp-admin/admin-ajax.php?action=clear_cache&key=some_secret_key_please

      add_action( 'wp_ajax_clear_cache', 'yt_cache_clear_web_hook' );

      add_action('wp_ajax_clear_cache','yt_cache_clear_web_hook');

      add_action( 'wp_ajax_nopriv_clear_cache', 'yt_cache_clear_web_hook' );

      add_action('wp_ajax_nopriv_clear_cache','yt_cache_clear_web_hook');

下载地址
https://downloads.wordpress.org/plugin/clear-cache-for-widgets.1.1.zip
-EOF-

AI助手支持GPT4.0