-
Notifications
You must be signed in to change notification settings - Fork 2
Developer Hooks
Rapid Cache is very extendible and supports various developer hooks. Here are some examples:
-
Filter: rapid_cache_ob_callback_filter
Definition:
apply_filters('rapid_cache_ob_callback_filter', $cache)
This filter is similar to WP Super Cache
wp_cache_ob_callback_filter
and allows you to modify the html output before it is cached in a file.add_filter('rapid_cache_ob_callback_filter', 'wp_912129_rapid_cache_ob_callback_filter'); function wp_912129_rapid_cache_ob_callback_filter($cache) { // Do modifications here return $cache; }
-
Filter: rapid_cache_version_salt
Definition:
apply_filters('rapid_cache_version_salt', $salt)
This filter is really powerful and makes it easy for you to create multiple dynamic variations of the cache. These dynamic variations will be served to visitors who meet the criteria defined by your Version Salt. ~ Yes, that sounds complex (and it can be), but it's actually quite simple in most cases.
For example, if your Version Salt is a cookie, and a visitor has this cookie (of a certain value) they will see pages which were cached with a Version Salt that was based on that cookie's value. A Version Salt could be just about anything; but a cookie is a good way to demonstrate the power of a Version Salt.
Good example is WooCommerce
Recently Viewed Products
widget. This widget is updating whenever you visit a product. Obviously the cache has to be purged as well to refresh the view.The following example demonstrates how to make
Recently Viewed Products
work with Rapid Cacheadd_filter('rapid_cache_version_salt', 'wp_912129_rapid_cache_version_salt'); function wp_912129_rapid_cache_version_salt($salt) { if(isset($_COOKIE['woocommerce_recently_viewed']) && !empty($_COOKIE['woocommerce_recently_viewed'])) { $salt .= $_COOKIE['woocommerce_recently_viewed']; } // or for YITH Recently Viewed Products if(isset($_COOKIE['yith_wrvp_products_list']) && !empty($_COOKIE['yith_wrvp_products_list'])) { $salt .= $_COOKIE['yith_wrvp_products_list']; } return $salt; }
Read more abou this at:
-
Filter: rapid_cache_wp_htaccess_nginx_notice
Definition:
apply_filters('rapid_cache_wp_htaccess_nginx_notice', true)
Allows you to control the nginx warning notice in the dashboard. If you want to disable it simply return false as follows:
add_filter('rapid_cache_wp_htaccess_nginx_notice', '__return_false');
-
Filter: rapid_cache_disable_cache_locking
Definition:
apply_filters('rapid_cache_disable_cache_locking', false)
Allows you to control the file locking. We don't reccommend to disable file locking.
-
Filter: rapid_cache_options
Definition:
apply_filters('rapid_cache_options', $options_array)
Allows you to modify the plugin options via filter. You can use this as follows:
add_filter('rapid_cache_options', 'wp_912129_rapid_cache_options'); function wp_912129_rapid_cache_options($options_array) { // eg. // $options_array['cache_404_requests'] = 0; return $options_array; }