Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 34 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Nginx Helper #
# EasyEngine Cache Helper for Nginx & Cloudflare (formerly Nginx Helper) #
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)

**Contributors:** rtcamp, rahul286, saurabhshukla, manishsongirkar36, faishal, desaiuditd, darren-slatten, jk3us, daankortenbach, telofy, pjv, llonchj, jinnko, weskoop, bcole808, gungeekatx, rohanveer, chandrapatel, gagan0123, ravanh, michaelbeil, samedwards, niwreg, entr, nuvoPoint, iam404, rittesh.patel, vishalkakadiya, BhargavBhandari90, bryant1410, 1gor, matt-h, dotsam, nathanielks, rigagoogoo, dslatten, jinschoi, kelin1003, vaishuagola27, rahulsprajapati, utkarshpatel, gsayed786, shashwatmittal, sudhiryadav, thrijith, stayallive, jaredwsmith, abhijitrakas, umeshnevase, sid177, souptik, arafatkn, subscriptiongroup, akrocks, vedantgandhi28, GridPane, stefanfisk, SGr33n, agvs, diepbui4157, pratiklondhe, webdados, ghost, ravanh, tjalexander70, mrrobot47, alexliii, joelmcdwebworks, bozzmedia, millionleave, kubajosef, alexsina, tomeryatir, minzak, peterdowney01, rayeason, gnif
Expand All @@ -17,14 +17,15 @@

**Donate Link:** http://rt.cx/eedonate

Cleans nginx's fastcgi/proxy cache or redis-cache whenever a post is edited/published. Also does a few more things.
Cleans nginx's fastcgi/proxy cache or redis-cache whenever a post is edited/published. Also provides cloudflare edge cache purging with Cache-Tags.

## Description ##

1. Removes `index.php` from permalinks when using WordPress with nginx.
1. Adds support for purging redis-cache when used as full-page cache created using [nginx-srcache-module](https://github.com/openresty/srcache-nginx-module#caching-with-redis)
1. Adds support for nginx fastcgi_cache_purge & proxy_cache_purge directive from [module](https://github.com/FRiCKLE/ngx_cache_purge "ngx_cache_purge module"). Provides settings so you can customize purging rules.
1. Adds support for nginx `map{..}` on a WordPress-multisite network installation. Using it, Nginx can serve PHP file uploads even if PHP/MySQL crashes. Please check the tutorial list below for related Nginx configurations.
1. Add support for purging on Cloudflare Edge Cache with Cache-Tags.

### Tutorials ###

Expand Down Expand Up @@ -78,12 +79,12 @@ Yes. It handles all post-types the same way.

**Q. How can I purge cache automatically after WordPress/plugin/theme updates?**

By default, Nginx Helper does **not** purge cache on WordPress core, plugin, or theme updates.
By default, Nginx Helper does **not** purge cache on WordPress core, plugin, or theme updates.
If you want this behavior, you can enable it using a filter:

`add_filter( 'rt_wp_nginx_helper_enable_auto_purge_on_any_update', '__return_true' );`

Once enabled, cache will be purged automatically whenever WordPress core, plugins, or themes are updated.
Once enabled, cache will be purged automatically whenever WordPress core, plugins, or themes are updated.
If left disabled (default), Nginx Helper will instead show an admin notice after updates, reminding you to purge cache manually.

**Q. How do I know my Nginx config is correct for fastcgi purging?**
Expand Down Expand Up @@ -127,6 +128,10 @@ This ensures customers always see up-to-date stock status and product informatio

Note: This option will only be visible if WooCommerce is active.

**Q. What are the two different options for ngx_cache_purge module?**

We have added support for two versions of the ngx_cache_purge module. The module developed by FRiCKLE is the original implementation that we have supported for a long time. We have now added support for a fork of the module developed by torden, which introduces Nginx module-level wildcard-based purging to help improve performance up to a certain level. You can purge it directly using the following format: `https://example.com/*` with the PURGE method, which will purge the cache of all descendants.

### FAQ - Nginx Redis Cache ###

**Q. Can I override the redis hostname, port and prefix?**
Expand Down Expand Up @@ -172,20 +177,41 @@ Most likely yes. A wordpress plugin, if not using explicitly any Apache-only mod
wp option patch update rt_wp_nginx_helper_options <option_name> <option_value>
```

### FAQ - Cloudflare Edge Cache ###

**Q. Why is the setup cache rule button not visible?**

You need to enter the Zone ID and a API key to allow setting up the Cache Rule.

**Q. Why is my cache rule setup failing?**

Always ensure that the API key has the permissions listed in the description under the API Key field. If any of the permission is missing, we will not be able to set up the cache rule.

**Q. What happens if I already have rulesets for Cloudflare Edge Cache?**

The plugin will update those rules to add the required configuration.

**Q. How can I purge the entire cache when Cloudflare Edge Cache is activated?**

You can use the default Purge Entire Cache button on the settings page to purge the cache. It will purge the Nginx cache if it is activated as well as Cloudflare Edge Cache.

**Q. How can I purge the cache of a single page only for Cloudflare Edge Cache?**

If you are logged in as a user with purge permissions, you can purge a page by visiting it (for example, https://mydomain.com/my-page) and clicking the `Clear Cloudflare Edge Cache` button in the admin toolbar.

### Still need help! ###

Please post your problem in [our free support forum](https://github.com/rtCamp/nginx-helper/issues).

## Screenshots ##

### 1. Nginx plugin settings ###
### 1. Nginx settings ###

![Nginx plugin settings](https://ps.w.org/nginx-helper/assets/screenshot-1.png)
![Nginx plugin settings](wpassets/screenshot-1.png)

### 2. Remaining settings ###
### 2. Cloudflare settings ###

![Remaining settings](https://ps.w.org/nginx-helper/assets/screenshot-2.png)
![Remaining settings](wpassets/screenshot-2.png)

## Changelog ##

Expand Down
48 changes: 22 additions & 26 deletions admin/class-nginx-helper-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @subpackage nginx-helper/admin
*/

use EasyCache\Cloudflare_Client;
use EECacheHelper\Cloudflare_Client;

/**
* The admin-specific functionality of the plugin.
Expand Down Expand Up @@ -106,13 +106,9 @@ public function initialize_setting_tab() {
'rt_nginx_helper_settings_tabs',
array(
'general' => array(
'menu_title' => __( 'General', 'nginx-helper' ),
'menu_title' => __( 'Nginx', 'nginx-helper' ),
'menu_slug' => 'general',
),
'support' => array(
'menu_title' => __( 'Support', 'nginx-helper' ),
'menu_slug' => 'support',
),
'cloudflare' => array(
'menu_title' => __( 'Cloudflare', 'nginx-helper' ),
'menu_slug' => 'cloudflare',
Expand Down Expand Up @@ -196,8 +192,8 @@ public function nginx_helper_admin_menu() {

add_submenu_page(
'settings.php',
__( 'Nginx Helper', 'nginx-helper' ),
__( 'Nginx Helper', 'nginx-helper' ),
__( 'EasyEngine Cache Helper for Nginx & Cloudflare', 'nginx-helper' ),
__( 'EasyEngine Cache Helper for Nginx & Cloudflare', 'nginx-helper' ),
'manage_options',
'nginx',
array( &$this, 'nginx_helper_setting_page' )
Expand All @@ -207,8 +203,8 @@ public function nginx_helper_admin_menu() {

add_submenu_page(
'options-general.php',
__( 'Nginx Helper', 'nginx-helper' ),
__( 'Nginx Helper', 'nginx-helper' ),
__( 'EasyEngine Cache Helper for Nginx & Cloudflare', 'nginx-helper' ),
__( 'EasyEngine Cache Helper for Nginx & Cloudflare', 'nginx-helper' ),
'manage_options',
'nginx',
array( &$this, 'nginx_helper_setting_page' )
Expand Down Expand Up @@ -362,10 +358,10 @@ public function get_cloudflare_default_settings() {
public function get_cloudflare_settings() {
$default_settings = $this->get_cloudflare_default_settings();

$stored_options = get_site_option( 'easycache_cf_settings', array() );
$stored_options = get_site_option( 'easyengine_cache_manager_cf_settings', array() );

if ( defined( 'EASYCACHE_CLOUDFLARE_API_TOKEN' ) && !empty( EASYCACHE_CLOUDFLARE_API_TOKEN ) ) {
$stored_options['api_token'] = EASYCACHE_CLOUDFLARE_API_TOKEN;
if ( defined( 'EASYENGINE_CACHE_MANAGER_CLOUDFLARE_API_TOKEN' ) && !empty( EASYENGINE_CACHE_MANAGER_CLOUDFLARE_API_TOKEN ) ) {
$stored_options['api_token'] = EASYENGINE_CACHE_MANAGER_CLOUDFLARE_API_TOKEN;
$stored_options['api_token_enabled_by_constant'] = true;
}

Expand All @@ -384,11 +380,11 @@ public function get_cloudflare_settings() {
public function store_cloudflare_settings() {
$default_settings = $this->get_cloudflare_default_settings();

$stored_options = get_site_option( 'easycache_cf_settings', array() );
$stored_options = get_site_option( 'easyengine_cache_manager_cf_settings', array() );

$diff_options = wp_parse_args( $stored_options, $default_settings );

add_site_option( 'easycache_cf_settings', $diff_options );
add_site_option( 'easyengine_cache_manager_cf_settings', $diff_options );
}

/**
Expand Down Expand Up @@ -526,7 +522,7 @@ public function nginx_helper_get_feeds() {
$rss_items = array();

// Get a SimplePie feed object from the specified feed source.
$rss = fetch_feed( 'https://rtcamp.com/blog/feed/' );
$rss = fetch_feed( 'https://easyengine.io/blog/feed/' );

if ( ! is_wp_error( $rss ) ) { // Checks that the object is created correctly.

Expand Down Expand Up @@ -614,7 +610,7 @@ public function add_timestamps() {
}

$timestamps = "\n<!--" .
'Cached using Nginx-Helper on ' . current_time( 'mysql' ) . '. ' .
'Cached using EasyEngine Cache Helper for Nginx & Cloudflare on ' . current_time( 'mysql' ) . '. ' .
'It took ' . get_num_queries() . ' queries executed in ' . timer_stop() . ' seconds.' .
"-->\n" .
'<!--Visit http://wordpress.org/extend/plugins/nginx-helper/faq/ for more details-->';
Expand Down Expand Up @@ -1208,15 +1204,15 @@ public function purge_product_cache_on_update( $product_id ) {
* @return void
*/
public function handle_cf_cache_rule_update() {
$nonce = isset( $_POST['easycache_add_cache_rule_nonce'] ) ? wp_unslash( $_POST['easycache_add_cache_rule_nonce'] ) : '';
$nonce = isset( $_POST['easyengine_cache_manager_add_cache_rule_nonce'] ) ? wp_unslash( $_POST['easyengine_cache_manager_add_cache_rule_nonce'] ) : '';

if ( wp_verify_nonce( $nonce, 'easycache_add_cache_rule_nonce' ) ) {
if ( wp_verify_nonce( $nonce, 'easyengine_cache_manager_add_cache_rule_nonce' ) ) {

if ( ! current_user_can( 'manage_options' ) ) {
return;
}

$result = EasyCache\Cloudflare_Client::setupCacheRule();
$result = EECacheHelper\Cloudflare_Client::setupCacheRule();

set_transient( 'ec_page_rule_save_state_admin_notice', $result, 60 );
}
Expand Down Expand Up @@ -1261,9 +1257,9 @@ public static function add_cloudflare_admin_bar_purge( $wp_admin_bar ) {
}

if ( ! empty( $_GET['message'] ) && 'ec-cleared-url-cache' === $_GET['message'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
$title = esc_html__( 'URL Cache Cleared', 'easycache' );
$title = esc_html__( 'URL Cache Cleared', 'nginx-helper' );
} else {
$title = esc_html__( 'Clear URL Cache', 'easycache' );
$title = esc_html__( 'Clear Cloudflare Edge Cache', 'nginx-helper' );
}

$request_uri = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( $_SERVER['REQUEST_URI'] ) : '';
Expand All @@ -1272,7 +1268,7 @@ public static function add_cloudflare_admin_bar_purge( $wp_admin_bar ) {
'id' => 'clear-page-cache',
'title' => $title,
'meta' => [
'title' => __( 'Purge the current URL from Cloudflare cache.', 'easycache' ),
'title' => __( 'Purge the current URL from Cloudflare cache.', 'nginx-helper' ),
],
'href' => wp_nonce_url( admin_url( 'admin-ajax.php?action=ec_clear_url_cache&path=' . rawurlencode( home_url( $request_uri ) ) ), 'ec-clear-url-cache' ),
] );
Expand All @@ -1288,17 +1284,17 @@ public static function handle_cloudflare_clear_cache_ajax() {
if ( empty( $nonce )
|| ! wp_verify_nonce( $nonce, 'ec-clear-url-cache' )
|| ! current_user_can( 'manage_options' ) ) {
wp_die( esc_html__( "You shouldn't be doing this.", 'easycache' ) );
wp_die( esc_html__( "You shouldn't be doing this.", 'nginx-helper' ) );
}

$path = isset( $_GET['path'] ) ? esc_url_raw( $_GET['path'] ) : '';
if ( empty( $path ) ) {
wp_die( esc_html__( 'No path provided.', 'easycache' ) );
wp_die( esc_html__( 'No path provided.', 'nginx-helper' ) );
}

$ret = Cloudflare_Client::purgeByUrls( [ $path ] );
if ( ! $ret ) {
wp_die( esc_html__( 'Failed to clear URL cache.', 'easycache' ) );
wp_die( esc_html__( 'Failed to clear URL cache.', 'nginx-helper' ) );
}

wp_safe_redirect( add_query_arg( 'message', 'ec-cleared-url-cache', $path ) );
Expand Down
3 changes: 2 additions & 1 deletion admin/css/nginx-helper-admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ pre#map {
padding: 10px;
}
.wrap h2.rt_option_title {
background: url(../icons/nginx-icon-32x32.png) 0 6px no-repeat rgba(0, 0, 0, 0);
background: url(../icons/icon-64x64.png) 0 6px no-repeat rgba(0, 0, 0, 0);
padding-left: 40px;
background-size: 36px 36px;
}
#poststuff h2 {
padding: 0 0 0 10px;
Expand Down
Binary file added admin/icons/icon-64x64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed admin/icons/nginx-icon-32x32.png
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
'api_token',
'zone_id',
'default_cache_ttl',
'easycache_cf_settings_nonce',
'easycache_settings_save'
'easyengine_cache_manager_cf_settings_nonce',
'easyengine_cache_manager_settings_save'
);

foreach ( $settings_save_args as $val ) {
Expand All @@ -26,9 +26,9 @@
}
}

if ( isset( $all_inputs['easycache_settings_save'] ) && isset( $all_inputs['easycache_cf_settings_nonce'] ) && wp_verify_nonce( $all_inputs['easycache_cf_settings_nonce'], 'easycache_cf_settings_nonce' ) ) {
unset( $all_inputs['easycache_cf_settings_nonce'] );
unset( $all_inputs['easycache_settings_save'] );
if ( isset( $all_inputs['easyengine_cache_manager_settings_save'] ) && isset( $all_inputs['easyengine_cache_manager_cf_settings_nonce'] ) && wp_verify_nonce( $all_inputs['easyengine_cache_manager_cf_settings_nonce'], 'easyengine_cache_manager_cf_settings_nonce' ) ) {
unset( $all_inputs['easyengine_cache_manager_cf_settings_nonce'] );
unset( $all_inputs['easyengine_cache_manager_settings_save'] );

if ( ! $nginx_helper_admin || ! method_exists( $nginx_helper_admin, 'get_cloudflare_default_settings' ) ) {
return;
Expand All @@ -38,7 +38,7 @@

$args = wp_parse_args( $all_inputs, $default_args );

update_site_option( 'easycache_cf_settings', $args );
update_site_option( 'easyengine_cache_manager_cf_settings', $args );

echo '<div class="updated"><p>' . esc_html__( 'Settings saved.', 'nginx-helper' ) . '</p></div>';
}
Expand All @@ -57,9 +57,9 @@
?>

<div class="ec-cf-settings">
<form id="post_form" method="post" action="#" name="easycache_cf_settings_form" class="clearfix">
<?php wp_nonce_field( 'easycache_cf_settings_nonce', 'easycache_cf_settings_nonce' ); ?>
<input type="hidden" value="1" name="easycache_settings_save"/>
<form id="post_form" method="post" action="#" name="easyengine_cache_manager_cf_settings_form" class="clearfix">
<?php wp_nonce_field( 'easyengine_cache_manager_cf_settings_nonce', 'easyengine_cache_manager_cf_settings_nonce' ); ?>
<input type="hidden" value="1" name="easyengine_cache_manager_settings_save"/>
<div class="postbox">
<h3 class="hndle"><?php esc_html_e( 'Cloudflare Settings', 'nginx-helper' ); ?></h3>
<div class="inside">
Expand Down Expand Up @@ -129,18 +129,18 @@ class="dashicons dashicons-hidden password-input-icon"></span></button>

</div>
<?php
submit_button( __( 'Save Changes', 'nginx-helper' ), 'primary large', 'easycache_cf_settings_save', true );
submit_button( __( 'Save Changes', 'nginx-helper' ), 'primary large', 'easyengine_cache_manager_cf_settings_save', true );
?>
</form>
</div>

<?php
if ( $ec_site_settings['is_enabled'] ) {
?>
<form name="easycache_add_cache_rule" method="POST" >
<form name="easyengine_cache_manager_add_cache_rule" method="POST" >
<?php
wp_nonce_field( 'easycache_add_cache_rule_nonce', 'easycache_add_cache_rule_nonce' );
submit_button( __( 'Setup Cache Rules', 'nginx-helper' ), 'secondary large', 'easycache_add_cache_rule_save', false );
wp_nonce_field( 'easyengine_cache_manager_add_cache_rule_nonce', 'easyengine_cache_manager_add_cache_rule_nonce' );
submit_button( __( 'Setup Cache Rules', 'nginx-helper' ), 'secondary large', 'easyengine_cache_manager_add_cache_rule_save', false );
?>

</form>
Expand Down
7 changes: 2 additions & 5 deletions admin/partials/nginx-helper-admin-display.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<div class="wrap rt-nginx-wrapper">
<h2 class="rt_option_title">
<?php esc_html_e( 'Nginx Settings', 'nginx-helper' ); ?>
<?php esc_html_e( 'EasyEngine Cache Helper for Nginx & Cloudflare Settings', 'nginx-helper' ); ?>
</h2>
<div id="poststuff">
<div id="post-body" class="metabox-holder columns-2">
Expand Down Expand Up @@ -46,11 +46,8 @@
case 'general':
include plugin_dir_path( __FILE__ ) . 'nginx-helper-general-options.php';
break;
case 'support':
include plugin_dir_path( __FILE__ ) . 'nginx-helper-support-options.php';
break;
case 'cloudflare':
include plugin_dir_path( __FILE__ ) . 'easycache-cloudflare-options.php';
include plugin_dir_path( __FILE__ ) . 'easyengine-cache-manager-cloudflare-options.php';
break;

}
Expand Down
13 changes: 5 additions & 8 deletions admin/partials/nginx-helper-sidebar-display.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
printf(
'%s <a href=\'%s\'>%s</a>.',
esc_html__( 'Please use our', 'nginx-helper' ),
esc_url( 'http://rtcamp.com/support/forum/wordpress-nginx/' ),
esc_url( 'https://wordpress.org/support/plugin/nginx-helper/' ),
esc_html__( 'free support forum', 'nginx-helper' )
);
?>
Expand All @@ -52,8 +52,8 @@
</span>
</h3>
<div style="text-align:center;" class="inside">
<a class="nginx-helper-facebook" title="<?php esc_attr_e( 'Become a fan on Facebook', 'nginx-helper' ); ?>" target="_blank" href="http://www.facebook.com/rtCamp.solutions/"></a>
<a class="nginx-helper-twitter" title="<?php esc_attr_e( 'Follow us on Twitter', 'nginx-helper' ); ?>" target="_blank" href="https://twitter.com/rtcamp/"></a>
<a class="nginx-helper-facebook" title="<?php esc_attr_e( 'Become a fan on Facebook', 'nginx-helper' ); ?>" target="_blank" href="https://www.facebook.com/easyengine/"></a>
<a class="nginx-helper-twitter" title="<?php esc_attr_e( 'Follow us on Twitter', 'nginx-helper' ); ?>" target="_blank" href="https://x.com/easyengine"></a>
</div>
</div>

Expand All @@ -64,16 +64,13 @@
<div class="inside">
<ul role="list">
<li role="listitem">
<a href="https://rtcamp.com/tutorials/nginx/" title="<?php esc_attr_e( 'Nginx Tutorials', 'nginx-helper' ); ?>"><?php esc_html_e( 'Nginx Tutorials', 'nginx-helper' ); ?></a>
<a href="https://easyengine.io/tutorials/nginx/" title="<?php esc_attr_e( 'Nginx Tutorials', 'nginx-helper' ); ?>"><?php esc_html_e( 'Nginx Tutorials', 'nginx-helper' ); ?></a>
</li>
<li role="listitem">
<a href="https://easyengine.io/" title="<?php esc_attr_e( 'EasyEngine (ee)', 'nginx-helper' ); ?>"><?php esc_html_e( 'EasyEngine (ee)', 'nginx-helper' ); ?></a>
</li>
<li role="listitem">
<a href="https://github.com/rtcamp/" title="<?php esc_attr_e( 'rtCamp GitHub', 'nginx-helper' ); ?>"><?php esc_html_e( 'rtCamp GitHub', 'nginx-helper' ); ?></a>
</li>
<li role="listitem">
<a href="https://rtcamp.com/solutions/" title="<?php esc_attr_e( 'Enterprise WordPress Consultancy', 'nginx-helper' ); ?>"><?php esc_html_e( 'Enterprise WordPress Consultancy', 'nginx-helper' ); ?></a>
<a href="https://github.com/EasyEngine" title="<?php esc_attr_e( 'EasyEngine GitHub', 'nginx-helper' ); ?>"><?php esc_html_e( 'EasyEngine GitHub', 'nginx-helper' ); ?></a>
</li>
</ul>
</div>
Expand Down
Loading