diff --git a/README.md b/README.md index fee3ca7..cc9ba90 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # 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, vincent-lu, murrayjbrown, bryant1410, 1gor, matt-h, pySilver, johan-chassaing, dotsam, sanketio, petenelson, nathanielks, rigagoogoo, dslatten, jinschoi, kelin1003, vaishuagola27, rahulsprajapati, Joel-James, utkarshpatel, gsayed786, shashwatmittal, sudhiryadav, thrijith, stayallive, jaredwsmith, abhijitrakas, umeshnevase, sid177, souptik, arafatkn, subscriptiongroup, akrocks +**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, vincent-lu, murrayjbrown, bryant1410, 1gor, matt-h, pySilver, johan-chassaing, dotsam, sanketio, petenelson, nathanielks, rigagoogoo, dslatten, jinschoi, kelin1003, vaishuagola27, rahulsprajapati, Joel-James, utkarshpatel, gsayed786, shashwatmittal, sudhiryadav, thrijith, stayallive, jaredwsmith, abhijitrakas, umeshnevase, sid177, souptik, arafatkn, subscriptiongroup, akrocks, gnif, jeffcleverley(GridPane) **Tags:** nginx, cache, purge, nginx map, nginx cache, maps, fastcgi, proxy, redis, redis-cache, rewrite, permalinks @@ -61,17 +61,67 @@ For proper configuration, check out our **tutorial list** in the [Description ta No. You need to make some changes at the Nginx end. Please check our [tutorial list](https://easyengine.io/wordpress-nginx/tutorials/). +**Q. Can I set the cache type using wp-config.php constants** + +Nginx Helper only helps purge the cache, but it needs to know what type of Nginx page caching you are using. + +You can set these in the nginx-helper admin settings, or control them using constants defined in the `wp-config.php` file: + +```php +# Tell the plugin you are using fastcgi caching + +define( ' RT_WP_NGINX_HELPER_CACHE_METHOD', 'enable_fastcgi' ); + +# Tell the plugin you are using redis caching + +define( ' RT_WP_NGINX_HELPER_CACHE_METHOD', 'enable_redis' ); +``` + ### FAQ - Nginx Fastcgi Cache Purge ### **Q. There's a 'purge all' button? Does it purge the whole site?** -Yes, it does. It physically empties the cache directory. It is set by default to `/var/run/nginx-cache/`. +Well that depends on your server configuration. + +There are three options -If your cache directory is different, you can override this in your wp-config.php by adding -`define('RT_WP_NGINX_HELPER_CACHE_PATH','/var/run/nginx-cache/');` +1. Purge by GET request - using the FRiCKLE ngx_cache_purge module +2. Purge by GET request - using the Torden ngx_cache_purge module +3. Delete local server cache files + +If your Nginx server has a the same webserver system user (likely www-data) as your sites directory/files owner then option 3 will purge all by physically emptying the cache directory. It is set by default to `/var/run/nginx-cache/`. +If your server has multiple sites, then this would be a security risk however, so it is likely the Nginx User and Site system user will differ... and purge all will not work. + +If your cache directory is different, you can override this in your wp-config.php by adding: + +```php +define( 'RT_WP_NGINX_HELPER_CACHE_PATH', '/path/to/your/nginx-cache/' ); +``` Replace the path with your own. +If your Nginx server is compiled with the FRiCKLE ngx_cache_purge module, then Purge All is not available + +If your Nginx server is compiled with the Torden ngx_cache_purge module, then Purge All will work. + +**Q. Can I set the fastcgi purge type using constants** + +You can set the purge type from the nginx-helper wp-admin settings page, or use a constants defined in the `wp-config.php: + +```php +# Delete local server cache files with unlink_files + +define( 'RT_WP_NGINX_HELPER_PURGE_METHOD', 'unlink_files' ); + +# Delete cache using GET requests when Nginx is compiled with FRiCKLE ngx_cache_purge module + +define( 'RT_WP_NGINX_HELPER_PURGE_METHOD', 'get_request' ); + +# Delete cache using GET requests when Nginx is compiled with Tordent ngx_cache_purge module + +define( 'RT_WP_NGINX_HELPER_PURGE_METHOD', 'get_request_torden' ); +``` + **Q. Does it work for custom posts and taxonomies?** Yes. It handles all post-types the same way. @@ -101,16 +151,40 @@ To purge a page immediately, follow these instructions: ### FAQ - Nginx Redis Cache ### -**Q. Can I override the redis hostname, port and prefix?** +**Q. What connection settings does Nginx Helper suppor for purging the cache?** + +The plugin supports: +* Hostname + Port (will be ignored if Unix socket is set) +* Unix sockets (will override Hostname + Port) +* Redis Prefix +* Redis Databases +* Redis ACLs (username and password) -Yes, you can force override the redis hostname, port or prefix by defining constant in wp-config.php. For example: +You can set these parameters via the Nginx Helper wp-admin settings + +**Q. Can I set the Redis Connection parameters using constants** + +Yes you can, setting them via constant will override these settings in the wp-admin ```php -define( 'RT_WP_NGINX_HELPER_REDIS_HOSTNAME', '10.0.0.1' ); +# If using hostname and port both must be set - either in config or via wp-admin + +define( 'RT_WP_NGINX_HELPER_REDIS_HOSTNAME', '127.0.0.1' ); +define( 'RT_WP_NGINX_HELPER_REDIS_PORT', '6379' ); + +# If Unix Socket is set then hostname and port will be ignored. + +define( 'RT_WP_NGINX_HELPER_REDIS_UNIX_SOCKET', '/run/redis/redis.sock' ); -define( 'RT_WP_NGINX_HELPER_REDIS_PORT', '6000' ); +# Prefix and database allow for some degree of cache isolation for performance -define( 'RT_WP_NGINX_HELPER_REDIS_PREFIX', 'page-cache:' ); +define( 'RT_WP_NGINX_HELPER_REDIS_PREFIX', 'nginx-cache:' ); +define( 'RT_WP_NGINX_HELPER_REDIS_DATABASE', '0' ); + +# Username and password require Redis ACLs but allow for secure cache isolation + +define( 'RT_WP_NGINX_HELPER_REDIS_USERNAME', 'user' ); +define( 'RT_WP_NGINX_HELPER_REDIS_PASSWORD', 'password' ); ``` ### FAQ - Nginx Map ### @@ -139,6 +213,14 @@ Please post your problem in [our free support forum](https://github.com/rtCamp/n ## Changelog ## +### 2.2.6 ### + +* Added Fastcgi purge all capability using GET requests IF Torden ngx_cache_purge module is available. [#323](https://github.com/rtCamp/nginx-helper/issues/323) - by [Geoffrey McRae - gnif](https://github.com/gnif) and [GridPane - Jeff Cleverley](https://github.com/gridpane) +* Added Redis Unix Socket connections. [325](https://github.com/rtCamp/nginx-helper/issues/325) - by [GridPane - Jeff Cleverley](https://github.com/gridpane) +* Added Redis DB selection. [343](https://github.com/rtCamp/nginx-helper/issues/343) - by [GridPane - Jeff Cleverley](https://github.com/gridpane) +* Added Redis ACL. [343](https://github.com/rtCamp/nginx-helper/issues/343) - by [GridPane - Jeff Cleverley](https://github.com/gridpane) +* Added Management of all FastCGI and Redis Connection Parameters by wp-config.php constants. [343](https://github.com/rtCamp/nginx-helper/issues/343) - by [GridPane - Jeff Cleverley](https://github.com/gridpane) + ### 2.2.5 ### * Add the capability to enable/disable purging of feeds. [#281](https://github.com/rtCamp/nginx-helper/issues/281) - by [Amaan Khan](https://github.com/pathan-amaankhan) diff --git a/admin/class-fastcgi-purger.php b/admin/class-fastcgi-purger.php index cce53b5..108dbdc 100644 --- a/admin/class-fastcgi-purger.php +++ b/admin/class-fastcgi-purger.php @@ -69,6 +69,10 @@ public function purge_url( $url, $feed = true ) { case 'get_request': // Go to default case. + + case 'get_request_torden': + // Go to default case. + default: $_url_purge_base = $this->purge_base_url() . $parse['path']; $_url_purge = $_url_purge_base; @@ -137,6 +141,10 @@ public function custom_purge_urls() { case 'get_request': // Go to default case. + + case 'get_request_torden': + // Go to default case. + default: $_url_purge_base = $this->purge_base_url(); @@ -166,9 +174,55 @@ public function custom_purge_urls() { */ public function purge_all() { - $this->unlink_recursive( RT_WP_NGINX_HELPER_CACHE_PATH, false ); + global $nginx_helper_admin; + + $purge_method = $nginx_helper_admin->options['purge_method']; + + switch ( $purge_method ) { + + case 'get_request_torden': + $site = get_site_url(); + /** @noinspection PhpLanguageLevelInspection */ + // Torden GET is guarded to detect 5.5+ in admin page and inform of incompatibility + $find = [ 'http://', 'https://' ]; + $replace = ''; + $host = str_replace( $find, $replace, $site); + + if ( is_ssl() ) { + $purgeurl = $site . '/purgeall' ; + $curl = curl_init( $purgeurl ); + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PURGE" ); + curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + /** @noinspection PhpElementIsNotAvailableInCurrentPhpVersionInspection */ + // Torden GET is guarded to detect 5.5+ in admin page and inform of incompatibility + curl_setopt($curl, CURLOPT_RESOLVE, array($host . ":443:127.0.0.1" )); + } else { + $curl = curl_init( "http://127.0.0.1/purgeall" ); + curl_setopt($curl, CURLOPT_HTTPHEADER, array('Host:' . $host )); + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PURGE" ); + curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE); + } + + $response = curl_exec($curl); + if ($response === false) + $this->log( curl_errno($curl) .': '. curl_error($curl) ); + curl_close($curl); + break; + + case 'get_request': + // Go to default case. + + default: + $this->unlink_recursive( RT_WP_NGINX_HELPER_CACHE_PATH, false ); + break; + } + + $log_purge_method = '* Using: ' . $purge_method; + $this->log( '* * * * *' ); $this->log( '* Purged Everything!' ); + $this->log( $log_purge_method ); $this->log( '* * * * *' ); /** diff --git a/admin/class-nginx-helper-admin.php b/admin/class-nginx-helper-admin.php index f91289a..0dffdfd 100644 --- a/admin/class-nginx-helper-admin.php +++ b/admin/class-nginx-helper-admin.php @@ -255,29 +255,43 @@ public function nginx_helper_setting_page() { public function nginx_helper_default_settings() { return array( - 'enable_purge' => 0, - 'cache_method' => 'enable_fastcgi', - 'purge_method' => 'get_request', - 'enable_map' => 0, - 'enable_log' => 0, - 'log_level' => 'INFO', - 'log_filesize' => '5', - 'enable_stamp' => 0, - 'purge_homepage_on_edit' => 1, - 'purge_homepage_on_del' => 1, - 'purge_archive_on_edit' => 1, - 'purge_archive_on_del' => 1, - 'purge_archive_on_new_comment' => 0, - 'purge_archive_on_deleted_comment' => 0, - 'purge_page_on_mod' => 1, - 'purge_page_on_new_comment' => 1, - 'purge_page_on_deleted_comment' => 1, - 'purge_feeds' => 1, - 'redis_hostname' => '127.0.0.1', - 'redis_port' => '6379', - 'redis_prefix' => 'nginx-cache:', - 'purge_url' => '', - 'redis_enabled_by_constant' => 0, + 'enable_purge' => 0, + 'cache_method' => 'enable_fastcgi', + 'purge_method' => 'get_request', + 'enable_map' => 0, + 'enable_log' => 0, + 'log_level' => 'INFO', + 'log_filesize' => '5', + 'enable_stamp' => 0, + 'purge_homepage_on_edit' => 1, + 'purge_homepage_on_del' => 1, + 'purge_archive_on_edit' => 1, + 'purge_archive_on_del' => 1, + 'purge_archive_on_new_comment' => 0, + 'purge_archive_on_deleted_comment' => 0, + 'purge_page_on_mod' => 1, + 'purge_page_on_new_comment' => 1, + 'purge_page_on_deleted_comment' => 1, + 'purge_feeds' => 1, + 'redis_hostname' => '127.0.0.1', + 'redis_port' => '6379', + 'redis_prefix' => 'nginx-cache:', + 'redis_unix_socket' => '', + 'redis_username' => '', + 'redis_password' => '', + 'redis_database' => 0, + 'purge_url' => '', + 'auth_enabled_by_constant' => 0, + 'cache_method_set_by_constant' => 0, + 'purge_method_set_by_constant' => 0, + 'redis_hostname_set_by_constant' => 0, + 'redis_port_set_by_constant' => 0, + 'redis_unix_socket_set_by_constant' => 0, + 'redis_prefix_set_by_constant' => 0, + 'redis_database_set_by_constant' => 0, + 'redis_username_set_by_constant' => 0, + 'redis_password_socket_set_by_constant' => 0, + 'homepage_purge_post_type_exceptions' => array(), ); } @@ -303,22 +317,83 @@ public function nginx_helper_settings() { $this->nginx_helper_default_settings() ); - $is_redis_enabled = ( - defined( 'RT_WP_NGINX_HELPER_REDIS_HOSTNAME' ) && - defined( 'RT_WP_NGINX_HELPER_REDIS_PORT' ) && - defined( 'RT_WP_NGINX_HELPER_REDIS_PREFIX' ) - ); + if ( defined( 'RT_WP_NGINX_HELPER_HOMEPAGE_PURGE_EXCEPTIONS' ) ) { + $data['homepage_purge_post_type_exceptions'] = RT_WP_NGINX_HELPER_HOMEPAGE_PURGE_EXCEPTIONS; + } + + if ( defined( 'RT_WP_NGINX_HELPER_PURGE_METHOD' ) ) { + $data['purge_method'] = RT_WP_NGINX_HELPER_PURGE_METHOD; + $data['purge_method_set_by_constant'] = 1; + } + + if ( defined( 'RT_WP_NGINX_HELPER_CACHE_METHOD' ) ) { + $data['cache_method'] = RT_WP_NGINX_HELPER_CACHE_METHOD; + $data['cache_method_set_by_constant'] = 1; + + if ( 'enable_fastcgi' === RT_WP_NGINX_HELPER_CACHE_METHOD ) { + $data['enable_purge'] = 1; + return $data; + } + } + + $redis_tcp_connection_enabled_by_constants = false; + $redis_unix_socket_enabled_by_constants = false; + $redis_prefix = false; + $redis_hostname = false; + $redis_port = false; + $redis_unix_socket = false; + + if ( defined( 'RT_WP_NGINX_HELPER_REDIS_PREFIX' ) ) { + $redis_prefix = RT_WP_NGINX_HELPER_REDIS_PREFIX; + $data['redis_prefix'] = $redis_prefix; + $data['redis_prefix_set_by_constant'] = 1; + } + + if ( defined( 'RT_WP_NGINX_HELPER_REDIS_PORT' ) ) { + $redis_port = RT_WP_NGINX_HELPER_REDIS_PORT; + $data['redis_port'] = $redis_port; + $data['redis_port_set_by_constant'] = 1; + } + + if ( defined( 'RT_WP_NGINX_HELPER_REDIS_HOSTNAME' ) ) { + $redis_hostname = RT_WP_NGINX_HELPER_REDIS_HOSTNAME; + $data['redis_hostname'] = $redis_hostname; + $data['redis_hostname_set_by_constant'] = 1; + } + + if ( defined( 'RT_WP_NGINX_HELPER_REDIS_UNIX_SOCKET' ) ) { + $redis_unix_socket = RT_WP_NGINX_HELPER_REDIS_UNIX_SOCKET; + $data['redis_unix_socket'] = $redis_unix_socket; + $data['redis_unix_socket_set_by_constant'] = 1; + } - if ( ! $is_redis_enabled ) { - return $data; + if ( defined( 'RT_WP_NGINX_HELPER_REDIS_DATABASE' ) ) { + $data['redis_database'] = RT_WP_NGINX_HELPER_REDIS_DATABASE; + $data['redis_database_set_by_constant'] = 1; } - $data['redis_enabled_by_constant'] = $is_redis_enabled; - $data['enable_purge'] = $is_redis_enabled; - $data['cache_method'] = 'enable_redis'; - $data['redis_hostname'] = RT_WP_NGINX_HELPER_REDIS_HOSTNAME; - $data['redis_port'] = RT_WP_NGINX_HELPER_REDIS_PORT; - $data['redis_prefix'] = RT_WP_NGINX_HELPER_REDIS_PREFIX; + if ( defined( 'RT_WP_NGINX_HELPER_REDIS_USERNAME' ) ) { + $data['redis_username'] = RT_WP_NGINX_HELPER_REDIS_USERNAME; + $data['redis_username_set_by_constant'] = 1; + } + + if ( defined( 'RT_WP_NGINX_HELPER_REDIS_PASSWORD' ) ) { + $data['redis_password'] = RT_WP_NGINX_HELPER_REDIS_PASSWORD; + $data['redis_password_set_by_constant'] = 1; + } + + if ( $redis_prefix && $redis_hostname && $redis_port ) { + $redis_tcp_connection_enabled_by_constants = true; + } + + if ( $redis_prefix && $redis_unix_socket ) { + $redis_unix_socket_enabled_by_constants = true; + } + + if ( $redis_tcp_connection_enabled_by_constants || $redis_unix_socket_enabled_by_constants ) { + $data['enable_purge'] = 1; + $data['cache_method'] = 'enable_redis'; + } return $data; @@ -599,9 +674,17 @@ public function set_future_post_option_on_future_status( $new_status, $old_statu global $blog_id, $nginx_purger; - $exclude_post_types = array( 'nav_menu_item' ); + $exclude_post_types = apply_filters( 'rt_nginx_helper_exclude_post_types', array( 'nav_menu_item' ) ); + + $post_type = $post->post_type; - if ( in_array( $post->post_type, $exclude_post_types, true ) ) { + if ( in_array( $post_type, $exclude_post_types, true ) ) { + if ( 'nav_menu_item' !== $post_type ) { + $nginx_purger->log('* * * * *'); + $nginx_purger->log('* Post Type update - ' . $post_type . ' - purge trigger excluded...'); + $nginx_purger->log('* Filter: -> rt_nginx_helper_exclude_post_types'); + $nginx_purger->log('* * * * *'); + } return; } @@ -621,10 +704,10 @@ public function set_future_post_option_on_future_status( $new_status, $old_statu if ( 'future' === $new_status && $post && 'future' === $post->post_status && ( - ( 'post' === $post->post_type || 'page' === $post->post_type ) || + ( 'post' === $post_type || 'page' === $post_type ) || ( isset( $this->options['custom_post_types_recognized'] ) && - in_array( $post->post_type, $this->options['custom_post_types_recognized'], true ) + in_array( $post_type, $this->options['custom_post_types_recognized'], true ) ) ) ) { diff --git a/admin/class-phpredis-purger.php b/admin/class-phpredis-purger.php index 10a8483..b297d6a 100644 --- a/admin/class-phpredis-purger.php +++ b/admin/class-phpredis-purger.php @@ -39,12 +39,41 @@ public function __construct() { try { $this->redis_object = new Redis(); + + /*Composer sets default to version that doesn't allow modern php*/ + $redis_connection_others_array = array(); + + $path = $nginx_helper_admin->options['redis_unix_socket']; + + if ( $path ) { + $host = $path; + $port = 0; + } else { + $host = $nginx_helper_admin->options['redis_hostname']; + $port = $nginx_helper_admin->options['redis_port']; + } + + $username = $nginx_helper_admin->options['redis_username']; + $password = $nginx_helper_admin->options['redis_password']; + + if ( $username && $password ) { + $redis_connection_others_array['auth'] = [$username, $password]; + } + $this->redis_object->connect( - $nginx_helper_admin->options['redis_hostname'], - $nginx_helper_admin->options['redis_port'], - 5 + $host, + $port, + 5, + '', + 100, + 1.5, + $redis_connection_others_array ); + $redis_database = $nginx_helper_admin->options['redis_database']; + + $this->redis_object->select($redis_database); + } catch ( Exception $e ) { $this->log( $e->getMessage(), 'ERROR' ); } diff --git a/admin/class-predis-purger.php b/admin/class-predis-purger.php index 1290a0d..1f4771f 100644 --- a/admin/class-predis-purger.php +++ b/admin/class-predis-purger.php @@ -38,13 +38,28 @@ public function __construct() { Predis\Autoloader::register(); + /*Composer sets default to version that doesn't allow modern php*/ + $predis_connection_array = array(); + + $path = $nginx_helper_admin->options['redis_unix_socket']; + $username = $nginx_helper_admin->options['redis_username']; + $password = $nginx_helper_admin->options['redis_password']; + $predis_connection_array['database'] = $nginx_helper_admin->options['redis_database']; + + if ( $path ) { + $predis_connection_array['path'] = $path; + } else { + $predis_connection_array['host'] = $nginx_helper_admin->options['redis_hostname'];; + $predis_connection_array['port'] = $nginx_helper_admin->options['redis_port']; + } + + if ( $username && $password ) { + $predis_connection_array['username'] = $username; + $predis_connection_array['password'] = $password; + } + // redis server parameter. - $this->redis_object = new Predis\Client( - array( - 'host' => $nginx_helper_admin->options['redis_hostname'], - 'port' => $nginx_helper_admin->options['redis_port'], - ) - ); + $this->redis_object = new Predis\Client( $predis_connection_array ); try { $this->redis_object->connect(); diff --git a/admin/class-purger.php b/admin/class-purger.php index ee07019..683afd5 100644 --- a/admin/class-purger.php +++ b/admin/class-purger.php @@ -86,6 +86,19 @@ public function purge_post_on_comment_change( $newstatus, $oldstatus, $comment ) $_post_id = $comment->comment_post_ID; $_comment_id = $comment->comment_ID; + $_post_type = get_post_type( $_post_id ); + + $exclude_post_types = apply_filters( 'rt_nginx_helper_comment_change_exclude_post_types', array() ); + + if ( in_array( $_post_type, $exclude_post_types, true ) ) { + if ( 'nav_menu_item' !== $_post_type ) { + $this->log( '* * * * *' ); + $this->log('* Post Type comment update - ' . $_post_type . ' - purge trigger excluded...'); + $this->log('* Filter: rt_nginx_helper_comment_change_exclude_post_types'); + $this->log( '* * * * *' ); + } + return; + } $this->log( '* * * * *' ); $this->log( '* Blog :: ' . addslashes( get_bloginfo( 'name' ) ) . ' ( ' . $blog_id . ' ). ' ); @@ -134,6 +147,8 @@ public function purge_post( $post_id ) { return; } + $_post_type = get_post_type( $post_id ); + switch ( current_filter() ) { case 'publish_post': @@ -157,7 +172,6 @@ public function purge_post( $post_id ) { break; default: - $_post_type = get_post_type( $post_id ); $this->log( '* * * * *' ); $this->log( '* Blog :: ' . addslashes( get_bloginfo( 'name' ) ) . ' ( ' . $blog_id . ' ).' ); $this->log( "* Custom post type '" . $_post_type . "' :: " . get_the_title( $post_id ) . ' ( ' . $post_id . ' ).' ); @@ -169,8 +183,22 @@ public function purge_post( $post_id ) { $this->log( 'Function purge_post BEGIN ===' ); + # Here we need something more granular + # to allow a post type to trigger its purge + # but skip the homepage purge + # can use array, if found, skip purge homepage + # [ 'post_type1', 'post_type1' ] + # we can also do exceptions by post/page slug too + if ( 1 === (int) $nginx_helper_admin->options['purge_homepage_on_edit'] ) { - $this->_purge_homepage(); + if ( ! in_array( $_post_type, $nginx_helper_admin->options['homepage_purge_post_type_exceptions'], true ) ) { + $this->_purge_homepage(); + } else { + $this->log('* * * * *'); + $this->log('* Post Type update - ' . $_post_type . ' - homepage purge trigger excluded...'); + $this->log('* ' . $_post_type . ' in constant array: RT_WP_NGINX_HELPER_HOMEPAGE_PURGE_EXCEPTIONS'); + $this->log('* * * * *'); + } } if ( 'comment_post' === current_filter() || 'wp_set_comment_status' === current_filter() ) { diff --git a/admin/partials/nginx-helper-general-options.php b/admin/partials/nginx-helper-general-options.php index a91eb53..6d0ff5d 100644 --- a/admin/partials/nginx-helper-general-options.php +++ b/admin/partials/nginx-helper-general-options.php @@ -22,6 +22,10 @@ 'redis_hostname', 'redis_port', 'redis_prefix', + 'redis_unix_socket', + 'redis_username', + 'redis_password', + 'redis_database', 'purge_homepage_on_edit', 'purge_homepage_on_del', 'purge_url', @@ -93,9 +97,60 @@ } -$nginx_helper_settings = $nginx_helper_admin->nginx_helper_settings(); -$log_path = $nginx_helper_admin->functional_asset_path(); -$log_url = $nginx_helper_admin->functional_asset_url(); +$php_version = phpversion(); +$nginx_helper_settings = $nginx_helper_admin->nginx_helper_settings(); +$log_path = $nginx_helper_admin->functional_asset_path(); +$log_url = $nginx_helper_admin->functional_asset_url(); +$cache_method = $nginx_helper_settings['cache_method']; +$cache_method_set_by_constant = $nginx_helper_settings['cache_method_set_by_constant']; +$purge_method_constant_warning = false; +$get_purge_method_radio_disabled = false; +$torden_get_purge_method_radio_disabled = false; +$unlink_files_purge_method_radio_disabled = false; +$purge_method_php_version_unsupported = false; +$redis_hostname_set_by_constant = false; +$redis_unix_socket_set_by_constant = false; +$redis_port_set_by_constant = false; +$redis_prefix_set_by_constant = false; +$redis_database_set_by_constant = false; +$redis_username_set_by_constant = false; +$redis_password_set_by_constant = false; + +// For testing +//$php_version = 5.4; + +if ( 'enable_fastcgi' === $cache_method ) { + $purge_method = $nginx_helper_settings['purge_method']; + $purge_method_set_by_constant = $nginx_helper_settings['purge_method_set_by_constant']; + + if (version_compare($php_version, '5.5', '<') && $purge_method === 'get_request_torden' ) { + $purge_method_php_version_unsupported = true; + } + + if ( ! $purge_method_set_by_constant ) { + if ( $purge_method_php_version_unsupported ) { + $torden_get_purge_method_radio_disabled = true; + $purge_method = 'get_request'; + } + } else { + $get_purge_method_radio_disabled = true; + $torden_get_purge_method_radio_disabled = true; + $unlink_files_purge_method_radio_disabled = true; + if ( $purge_method_php_version_unsupported ) { + $purge_method_constant_warning = true; + } + } +} + +if ( 'enable_redis' === $cache_method ) { + $redis_hostname_set_by_constant = $nginx_helper_settings['redis_hostname_set_by_constant']; + $redis_port_set_by_constant = $nginx_helper_settings['redis_port_set_by_constant']; + $redis_unix_socket_set_by_constant = $nginx_helper_settings['redis_unix_socket_set_by_constant']; + $redis_prefix_set_by_constant = $nginx_helper_settings['redis_prefix_set_by_constant']; + $redis_database_set_by_constant = $nginx_helper_settings['redis_database_set_by_constant']; + $redis_username_set_by_constant = $nginx_helper_settings['redis_username_set_by_constant']; + $redis_password_set_by_constant = $nginx_helper_settings['redis_password_set_by_constant']; +} /** * Get setting url for single multiple with subdomain OR multiple with subdirectory site. @@ -136,16 +191,29 @@
+ '; + esc_html_e( + sprintf( + __("Set by wp-config.php constant: define( 'RT_WP_NGINX_HELPER_CACHE_METHOD', '%s' );", 'nginx-helper'), + $cache_method + ) + ); + echo ''; + echo '

'; + } + ?>
- /> + />
- /> + /> @@ -166,11 +234,30 @@
-
> +
>

+ '; + esc_html_e( + sprintf( + __("Set by wp-config.php constant: define( 'RT_WP_NGINX_HELPER_PURGE_METHOD', '%s' );", 'nginx-helper'), + $purge_method + ) + ); + if ( $purge_method_constant_warning ) { + echo '

'; + echo wp_kses( + __( 'WARNING!! The running version of PHP does not support this method!!!', 'nginx-helper' ), + array( 'strong' => array() ) + ); + } + echo '

'; + } + ?>
@@ -182,14 +269,14 @@
+ +