-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from wp-media/branch-2.0.3
v2.0.3: update, bugfixes, new stuff
- Loading branch information
Showing
15 changed files
with
327 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# NOT A PLUGIN! DON’T INSTALL THIS IN YOUR WORDPRESS! | ||
_ZIP file not provided on purpose._ | ||
|
||
Cron script to clear the cache and run a cache preload. | ||
|
||
🚧 **ADVANCED CUSTOMIZATION, HANDLE WITH CARE!** | ||
📝 **Manual code edit required before use!** | ||
|
||
Edit `WPROCKETHELPERS_WP_LOAD_FILE` to reflect the absolute path to wp-load.php from wherever on your server you run this script. | ||
|
||
This script does the following: | ||
|
||
- Checks WP Rocket is active on the website. If so: | ||
- Clears the cache. | ||
- Checks if sitemap preload is configured. | ||
- If so, runs a sitemap preload; otherwise calls the preload bot. | ||
- Checks if the website is a multisite network. | ||
- If so, iterates over each site in the network, and performs the steps above. | ||
|
||
Documentation: | ||
* [How to clear cache via cron job](http://docs.wp-rocket.me/article/494-how-to-clear-cache-via-cron-job) | ||
|
||
To be used with: | ||
* any setup where the cache should be cleared and preloaded with a custom cron job rather than wp-cron | ||
|
||
Last tested with: | ||
* WP Rocket 2.11.x | ||
* WordPress 4.9.x |
93 changes: 93 additions & 0 deletions
93
_experimental/wp-rocket-cache-purge-cron/wp-rocket-cache-purge-cron.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
/** | ||
* ********************************************************************* | ||
* THIS IS NOT A PLUGIN! DON’T INSTALL THIS IN YOUR WORDPRESS! | ||
* ********************************************************************* | ||
* Read the documentation: | ||
* http://docs.wp-rocket.me/article/494-how-to-clear-cache-via-cron-job | ||
* ********************************************************************* | ||
* URI: https://github.com/wp-media/wp-rocket-helpers/tree/master/cache/wp-rocket-cache-purge-cron/ | ||
* Author: WP Rocket Support Team | ||
* Author URI: http://wp-rocket.me/ | ||
* License: GNU General Public License v2 or later | ||
* License URI: http://www.gnu.org/licenses/gpl-2.0.html | ||
* | ||
* Copyright SAS WP MEDIA 2018 | ||
*/ | ||
|
||
namespace WP_Rocket\Helpers\cache\cron\purge_preload; | ||
|
||
// EDIT THIS TO REFLECT THE ABSOLUTE PATH TO wp-load.php ON YOUR SERVER: | ||
|
||
define( 'WPROCKETHELPERS_WP_LOAD_FILE', '/path/to/wp-load.php' ); | ||
|
||
// STOP EDITING. | ||
|
||
// If we are in WordPress at this point, something is not right, so nope. | ||
if ( defined( 'ABSPATH' ) ) { | ||
die( 'This is not a WordPress plugin! Read the <a href="http://docs.wp-rocket.me/article/494-how-to-clear-cache-via-cron-job">documentation</a>.' ); | ||
} | ||
|
||
// Check if wp-load.php exists at this path. | ||
file_exists( WPROCKETHELPERS_WP_LOAD_FILE ) or die( 'Please enter the absolute path to wp-load.php.' ); | ||
|
||
// Load WordPress. | ||
require( WPROCKETHELPERS_WP_LOAD_FILE ); | ||
|
||
/** | ||
* Clear cache and run preload. | ||
* In a multisite network, this applies only to the main site. | ||
*/ | ||
clear_cache_run_preload(); | ||
|
||
|
||
// Stop here if this is a regular single WordPress site, not a multisite. | ||
if ( ! is_multisite() ) { | ||
return; | ||
} | ||
|
||
/** | ||
* Clear cache and run preload on each sub-site in the network. | ||
*/ | ||
$subsites = get_sites(); | ||
foreach( $subsites as $subsite ) { | ||
|
||
// Check if WP Rocket is active. | ||
if ( wp_rocket_maybe_active() ) { | ||
|
||
// Clear cache, run preload. | ||
clear_cache_run_preload(); | ||
} | ||
} | ||
|
||
/** | ||
* Checks functions from WP Rocket are available. | ||
* | ||
* @author Caspar Hübinger | ||
* @return bool True if specified functions exist, else false | ||
*/ | ||
function wp_rocket_maybe_active() { | ||
return function_exists( '\rocket_clean_domain' ) && function_exists( '\run_rocket_preload_cache' ); | ||
} | ||
|
||
/** | ||
* Checks if WP Rocket is active; if so, clears cache, and runs preload. | ||
* | ||
* @author Caspar Hübinger | ||
* @uses wp_rocket_maybe_active | ||
* @return bool False if WP Rocket is not active, else true | ||
*/ | ||
function clear_cache_run_preload() { | ||
|
||
if ( ! wp_rocket_maybe_active() ) { | ||
return false; | ||
} | ||
|
||
// Clear global cache. | ||
\rocket_clean_domain(); | ||
|
||
// Run preload (bot + sitemap as configured). | ||
\run_rocket_preload_cache( 'cache-preload' ); | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# WP Rocket | Optimize WooCommerce Cart, Checkout, Account | ||
|
||
Disables page caching for WooCommerce cart, checkout, and account pages, but keeps other optimization features applicable. | ||
|
||
🚧  **ADVANCED CUSTOMIZATION, HANDLE WITH CARE!** | ||
|
||
To be used with: | ||
* WooCommerce | ||
|
||
Last tested with: | ||
* WooCommerce 3.x | ||
* WP Rocket 3.x | ||
* WordPress 4.9.x |
56 changes: 56 additions & 0 deletions
56
_experimental/wp-rocket-compat-wc-optimize/wp-rocket-compat-wc-optimize.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
/** | ||
* Plugin Name: WP Rocket | Optimize WooCommerce Cart, Checkout, Account | ||
* Description: Disables page caching for WooCommerce cart, checkout, and account pages, but keeps other optimization features applicable. | ||
* Author: WP Rocket Support Team | ||
* Author URI: http://wp-rocket.me/ | ||
* License: GNU General Public License v2 or later | ||
* License URI: http://www.gnu.org/licenses/gpl-2.0.html | ||
* | ||
* Copyright SAS WP MEDIA 2018 | ||
*/ | ||
|
||
// Standard plugin security, keep this line in place. | ||
defined( 'ABSPATH' ) or die(); | ||
|
||
/** | ||
* Remove WP Rocket core behaviour. | ||
* | ||
* @see wp-rocket/inc/3rd-party/plugins/ecommerce/woocommerce.php#L6 | ||
*/ | ||
add_action( 'wp_rocket_loaded', function () { | ||
remove_filter( 'rocket_cache_reject_uri', 'rocket_exclude_woocommerce_pages' ); | ||
}); | ||
|
||
/** | ||
* Alters WP Rocket’s core behaviours so that page caching is still disabled on | ||
* cart, checkout, and account pages, but other optimization features (LazyLoad, | ||
* Minify, Optimize CSS, deferred JS etc.) are applied. | ||
* | ||
* @return [type] [description] | ||
*/ | ||
add_action( 'template_redirect', function () { | ||
|
||
if ( ! function_exists( 'rocket_exclude_woocommerce_pages' ) ) { | ||
return; | ||
} | ||
|
||
if ( ! class_exists( 'WooCommerce' ) ) { | ||
return; | ||
} | ||
|
||
if ( ! function_exists( 'is_cart' ) || ! function_exists( 'is_checkout' ) || ! function_exists( 'is_account_page' ) ) { | ||
return; | ||
} | ||
|
||
/** | ||
* Disable page caching on dedicated pages. | ||
* | ||
* @see https://docs.woocommerce.com/document/conditional-tags/ | ||
*/ | ||
if ( is_cart() || is_checkout() || is_account_page() ) { | ||
// var_dump( 'HELLO'); | ||
add_filter( 'rocket_override_donotcachepage', '__return_true', PHP_INT_MAX ); | ||
add_filter( 'do_rocket_generate_caching_files', '__return_false' ); | ||
} | ||
}); |
Binary file added
BIN
+1.69 KB
_experimental/wp-rocket-compat-wc-optimize/wp-rocket-compat-wc-optimize.zip
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# WP Rocket | Toolbar Clear Cache Link | ||
|
||
Adds a “Clear cache” link to the toolbar for users who can publish posts. | ||
|
||
You can edit `WPROCKETHELPERS_CACHE_PURGE_TOOLBAR_LINK_CAPACITY` to define the user role you want the new toolbar link to be displayed for. Default: `publish_posts` (Author) | ||
|
||
Requires: | ||
* PHP 5.4 or greater | ||
* WP Rocket 3.0 or greater | ||
|
||
To be used with: | ||
* any setup where a “Clear cache” link should be available to non-admin users | ||
|
||
Last tested with: | ||
* WP Rocket 3.0.x | ||
* WordPress 4.9.x |
77 changes: 77 additions & 0 deletions
77
cache/wp-rocket-cache-purge-toolbar-link/wp-rocket-cache-purge-toolbar-link.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
/** | ||
* Plugin Name: WP Rocket | Toolbar Clear Cache Link | ||
* Description: Adds a “Clear cache” link to the toolbar for users who can publish posts. | ||
* Plugin URI: https://github.com/wp-media/wp-rocket-helpers/tree/master/cache/wp-rocket-cache-purge-toolbar-link/ | ||
* Author: WP Rocket Support Team | ||
* Author URI: http://wp-rocket.me/ | ||
* License: GNU General Public License v2 or later | ||
* License URI: http://www.gnu.org/licenses/gpl-2.0.html | ||
* | ||
* Copyright SAS WP MEDIA 2018 | ||
*/ | ||
|
||
namespace WP_Rocket\Helpers\cache\clear_cache_toolbar_link; | ||
|
||
// Standard plugin security, keep this line in place. | ||
defined( 'ABSPATH' ) or die(); | ||
|
||
/** | ||
* The minimum capability for users to see the new Clear cache button in the | ||
* toolbar is `publish_posts` which translates into the user role of “Author”. | ||
* | ||
* This makes sense in most cases, since a person who can’t publish new content | ||
* usually won’t have to clear the cache. | ||
* | ||
* However, if a different capability or user role is required in your case, | ||
* feel free to edit the following constant. | ||
*/ | ||
|
||
// EDIT THIS TO CUSTOMIZE THE MINIMUM CAPACITY FOR THE NEW TOOLBAR LINK: | ||
define( 'WPROCKETHELPERS_CACHE_PURGE_TOOLBAR_LINK_CAPACITY', 'publish_posts' ); | ||
// STOP EDITING. | ||
|
||
/** | ||
* Renders a “Clear cache” button in the toolbar. | ||
* | ||
* @author Caspar Hübinger | ||
* @link https://developer.wordpress.org/reference/classes/wp_admin_bar/ | ||
* @param object $wp_admin_bar WP_Admin_Bar object | ||
* @return object WP_Admin_Bar object | ||
*/ | ||
function render( $wp_admin_bar ) { | ||
|
||
$icon_html = '<span class="ab-icon dashicons-before dashicons-trash" style="top:2px;" aria-hidden="true"></span>'; | ||
|
||
$wp_admin_bar->add_menu([ | ||
'id' => 'wp-rocket-clear-cache-button', | ||
'href' => wp_nonce_url( admin_url( 'admin-post.php?action=purge_cache&type=all' ), 'purge_cache_all' ), | ||
// 'parent' => 'top-secondary', // uncomment to place next to user menu in secondary toolbar | ||
'title' => $icon_html . esc_html__( 'Clear cache', 'rocket' ), | ||
]); | ||
|
||
return $wp_admin_bar; | ||
} | ||
|
||
/** | ||
* Adds toolbar link for users with sufficient capabilities. | ||
* | ||
* @author Caspar Hübinger | ||
*/ | ||
function maybe_add() { | ||
|
||
// Not for WP Rocket admins since those already have a full toolbar menu. | ||
if ( current_user_can( apply_filters( 'rocket_capacity', 'manage_options' ) ) ) { | ||
return; | ||
} | ||
|
||
// Only for users with sufficient capabilities. | ||
if ( ! current_user_can( WPROCKETHELPERS_CACHE_PURGE_TOOLBAR_LINK_CAPACITY ) ) { | ||
return; | ||
} | ||
|
||
add_action( 'admin_bar_menu', __NAMESPACE__ . '\render', | ||
200 // editing this priority will move the button within the toolbar | ||
); | ||
} | ||
add_action( 'wp_rocket_loaded', __NAMESPACE__ . '\maybe_add' ); |
Binary file added
BIN
+2.34 KB
cache/wp-rocket-cache-purge-toolbar-link/wp-rocket-cache-purge-toolbar-link.zip
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+6 Bytes
(100%)
compatibility/wp-rocket-compat-dreampress/wp-rocket-compat-dreampress.zip
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
-57 Bytes
(97%)
htaccess/wp-rocket-htaccess-www-nonwww/wp-rocket-htaccess-www-nonwww.zip
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.