7 Commits
5531b456a2
...
95bb4da39b
| Author | SHA1 | Message | Date |
|---|---|---|---|
|
|
95bb4da39b |
Merge branch 'testing' of https://git.weblibre.ca/gabriel/wordpress_cache_ynh
|
5 years ago |
|
|
f7f96b002e |
update
|
5 years ago |
|
|
a1f5170497
|
fix the url
|
5 years ago |
|
|
232c2a1cde
|
5.7.2
|
5 years ago |
|
|
cec3f6705c
|
Merge pull request #141 from YunoHost-Apps/fix-upgrade
fix upgrade |
5 years ago |
|
|
9a8862cc87
|
replace db_prefix in the install script
|
5 years ago |
|
|
31018d9a47
|
fix upgrade
|
5 years ago |
17 changed files with 1044 additions and 45 deletions
-
2README.md
-
2README_fr.md
-
4conf/app.src
-
6conf/extra_php-fpm.conf
-
123conf/fastcgi.conf
-
31conf/nginx-cache-custom/includes/settings-page.css
-
41conf/nginx-cache-custom/includes/settings-page.php
-
95conf/nginx-cache-custom/languages/nginx-cache.pot
-
316conf/nginx-cache-custom/nginx-cache.php
-
66conf/nginx-cache-custom/readme.txt
-
325conf/nginx.conf
-
2conf/sql/multisite.sql
-
2conf/sql/single.sql
-
7manifest.json
-
46scripts/install
-
15scripts/remove
-
6scripts/upgrade
@ -1,5 +1,5 @@ |
|||||
SOURCE_URL=https://wordpress.org/wordpress-5.7.tar.gz |
|
||||
SOURCE_SUM=92be8c4afd0186f783a12bad994baecc8f941a88535acddecbae0d7702169b71 |
|
||||
|
SOURCE_URL=https://wordpress.org/wordpress-5.7.2.tar.gz |
||||
|
SOURCE_SUM=eb8d05208159469d0be3cb339f7b6a150a39f503faf679c255028433f5131219 |
||||
SOURCE_SUM_PRG=sha256sum |
SOURCE_SUM_PRG=sha256sum |
||||
ARCH_FORMAT=tar.gz |
ARCH_FORMAT=tar.gz |
||||
SOURCE_IN_SUBDIR=true |
SOURCE_IN_SUBDIR=true |
||||
|
|||||
@ -1,5 +1,5 @@ |
|||||
; Additional php.ini defines, specific to this pool of workers. |
; Additional php.ini defines, specific to this pool of workers. |
||||
|
|
||||
php_admin_value[upload_max_filesize] = 50M |
|
||||
php_admin_value[memory_limit] = 64M |
|
||||
php_admin_value[post_max_size] = 50M |
|
||||
|
php_admin_value[upload_max_filesize] = 1G |
||||
|
php_admin_value[memory_limit] = 128M |
||||
|
php_admin_value[post_max_size] = 1G |
||||
@ -0,0 +1,123 @@ |
|||||
|
fastcgi_cache_key "$scheme$request_method$host$request_uri"; |
||||
|
fastcgi_cache_use_stale error timeout invalid_header updating http_500 http_503; |
||||
|
fastcgi_cache_lock on; |
||||
|
fastcgi_cache_lock_age 5s; |
||||
|
fastcgi_cache_lock_timeout 5s; |
||||
|
fastcgi_cache_methods GET HEAD; |
||||
|
fastcgi_cache_background_update on; |
||||
|
fastcgi_cache_valid 200 24h; |
||||
|
fastcgi_cache_valid 301 302 30m; |
||||
|
fastcgi_cache_valid 499 502 503 1m; |
||||
|
fastcgi_cache_valid 404 1h; |
||||
|
fastcgi_cache_valid any 1h; |
||||
|
fastcgi_buffers 16 16k; |
||||
|
fastcgi_buffer_size 32k; |
||||
|
fastcgi_param SERVER_NAME $http_host; |
||||
|
fastcgi_ignore_headers Cache-Control Expires Set-Cookie; |
||||
|
fastcgi_keep_conn on; |
||||
|
|
||||
|
# do not cache xhtml request |
||||
|
map $http_x_requested_with $http_request_no_cache { |
||||
|
default 0; |
||||
|
XMLHttpRequest 1; |
||||
|
} |
||||
|
|
||||
|
# do not cache requests on cookies |
||||
|
map $http_cookie $cookie_no_cache { |
||||
|
default 0; |
||||
|
"~*wordpress_[a-f0-9]+" 1; |
||||
|
"~*wp-postpass" 1; |
||||
|
"~*wordpress_logged_in" 1; |
||||
|
"~*wordpress_no_cache" 1; |
||||
|
"~*comment_author" 1; |
||||
|
"~*woocommerce_items_in_cart" 1; |
||||
|
"~*edd_items_in_cart" 1; |
||||
|
"~*woocommerce_cart_hash" 1; |
||||
|
"~*wptouch_switch_toogle" 1; |
||||
|
"~*comment_author_email_" 1; |
||||
|
"~*wptouch_switch_toggle" 1; |
||||
|
"~*edd" 1; |
||||
|
} |
||||
|
|
||||
|
# do not cache the following uri |
||||
|
map $request_uri $uri_no_cache { |
||||
|
default 0; |
||||
|
"~*/wp-admin/" 1; |
||||
|
"~*/wp-[a-zA-Z0-9-]+.php" 1; |
||||
|
"~*/feed/" 1; |
||||
|
"~*/index.php" 1; |
||||
|
"~*/[a-z0-9_-]+-sitemap([0-9]+)?.xml" 1; |
||||
|
"~*/sitemap(_index)?.xml" 1; |
||||
|
"~*/wp-comments-popup.php" 1; |
||||
|
"~*/wp-links-opml.php" 1; |
||||
|
"~*/xmlrpc.php" 1; |
||||
|
"~*/edd-sl/*" 1; |
||||
|
"~*/add_to_cart/" 1; |
||||
|
"~*/cart/" 1; |
||||
|
"~*/account/" 1; |
||||
|
"~*/my-account/" 1; |
||||
|
"~*/checkout/" 1; |
||||
|
"~*/addons/" 1; |
||||
|
"~*/wc-api/*" 1; |
||||
|
"~*/logout/" 1; |
||||
|
"~*/lost-password/" 1; |
||||
|
"~*/panier/" 1; |
||||
|
"~*/mon-compte/" 1; |
||||
|
"~*/embed" 1; |
||||
|
"~*/commande/" 1; |
||||
|
"~*/resetpass/" 1; |
||||
|
} |
||||
|
|
||||
|
# do not cache requests with query strings |
||||
|
map $is_args $query_no_cache { |
||||
|
default 1; |
||||
|
"" 0; |
||||
|
} |
||||
|
|
||||
|
# if all previous check are passed, $skip_cache = 0 |
||||
|
map $http_request_no_cache$cookie_no_cache$uri_no_cache$query_no_cache $skip_cache { |
||||
|
default 1; |
||||
|
0000 0; |
||||
|
} |
||||
|
|
||||
|
map $http_accept $webp_suffix_valid { |
||||
|
default 1; |
||||
|
"~*webp" 0; |
||||
|
} |
||||
|
|
||||
|
map $realip_remote_addr $webp_suffix_cf { |
||||
|
default 0; |
||||
|
103.21.244.0/22 1; |
||||
|
103.22.200.0/22 1; |
||||
|
103.31.4.0/22 1; |
||||
|
104.16.0.0/12 1; |
||||
|
108.162.192.0/18 1; |
||||
|
131.0.72.0/22 1; |
||||
|
141.101.64.0/18 1; |
||||
|
162.158.0.0/15 1; |
||||
|
172.64.0.0/13 1; |
||||
|
173.245.48.0/20 1; |
||||
|
188.114.96.0/20 1; |
||||
|
190.93.240.0/20 1; |
||||
|
197.234.240.0/22 1; |
||||
|
198.41.128.0/17 1; |
||||
|
199.27.128.0/21 1; |
||||
|
2400:cb00::/32 1; |
||||
|
2405:8100::/32 1; |
||||
|
2405:b500::/32 1; |
||||
|
2606:4700::/32 1; |
||||
|
2803:f800::/32 1; |
||||
|
2a06:98c0::/29 1; |
||||
|
2c0f:f248::/32 1; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
map $webp_suffix_cf$webp_suffix_valid $webp_suffix { |
||||
|
default ""; |
||||
|
00 ".webp"; |
||||
|
} |
||||
|
|
||||
|
# Limit Request |
||||
|
limit_req_status 403; |
||||
|
limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s; |
||||
|
limit_req_zone $binary_remote_addr zone=two:10m rate=10r/s; |
||||
@ -0,0 +1,31 @@ |
|||||
|
|
||||
|
.wrap .button.delete { |
||||
|
background: #d54e21; |
||||
|
border-color: #a83d1a; |
||||
|
color: white; |
||||
|
-webkit-box-shadow: inset 0 1px 0 #e68260, 0 1px 0 rgba(0, 0, 0, 0.15); |
||||
|
box-shadow: inset 0 1px 0 #e68260, 0 1px 0 rgba(0, 0, 0, 0.15); |
||||
|
} |
||||
|
|
||||
|
.wrap .button.delete:hover, |
||||
|
.wrap .button.delete:focus { |
||||
|
background: #be461d; |
||||
|
border-color: #923517; |
||||
|
color: white; |
||||
|
box-shadow: inset 0 1px 0 #e3704a; |
||||
|
} |
||||
|
|
||||
|
.wrap .button.delete:focus { |
||||
|
box-shadow: inset 0 1px 0 #e3704a, |
||||
|
0 0 0 1px #d54e21, |
||||
|
0 0 2px 1px rgba( 30, 140, 190, .8 ); |
||||
|
} |
||||
|
|
||||
|
.wrap .button.delete:active { |
||||
|
background: #a83d1a; |
||||
|
border-color: #923517; |
||||
|
color: white; |
||||
|
box-shadow: inset 0 2px 5px -3px rgba( 0, 0, 0, 0.5 ), |
||||
|
0 0 0 1px #d54e21, |
||||
|
0 0 2px 1px rgba( 30, 140, 190, .8 ); |
||||
|
} |
||||
@ -0,0 +1,41 @@ |
|||||
|
|
||||
|
<?php if ( ! defined( 'ABSPATH' ) ) exit; ?>
|
||||
|
|
||||
|
<div class="wrap"> |
||||
|
|
||||
|
<h1><?php _e( 'Nginx Cache', 'nginx' ); ?></h1>
|
||||
|
|
||||
|
<?php settings_errors(); ?>
|
||||
|
|
||||
|
<form method="post" action="options.php"> |
||||
|
|
||||
|
<?php settings_fields( 'nginx-cache' ); ?>
|
||||
|
|
||||
|
<table class="form-table"> |
||||
|
<tr valign="top"> |
||||
|
<th scope="row"><?php _e( 'Cache Zone Path', 'nginx-cache' ); ?></th>
|
||||
|
<td> |
||||
|
<input type="text" class="regular-text code" name="nginx_cache_path" placeholder="/data/nginx/cache" value="<?php echo esc_attr( get_option( 'nginx_cache_path' ) ); ?>" /> |
||||
|
<p class="description"><?php _e( 'The absolute path to the location of the cache zone, specified in the Nginx <code>fastcgi_cache_path</code> or <code>proxy_cache_path</code> directive.', 'nginx-cache' ); ?></p>
|
||||
|
</td> |
||||
|
</tr> |
||||
|
<tr valign="top"> |
||||
|
<th scope="row"><?php _e( 'Purge Cache', 'nginx-cache' ); ?></th>
|
||||
|
<td> |
||||
|
<label for="nginx_auto_purge"> |
||||
|
<input name="nginx_auto_purge" type="checkbox" id="nginx_auto_purge" value="1" <?php checked( get_option( 'nginx_auto_purge' ), '1' ); ?> />
|
||||
|
<?php _e( 'Automatically flush the cache when content changes', 'nginx-cache' ); ?>
|
||||
|
</label> |
||||
|
</td> |
||||
|
</tr> |
||||
|
</table> |
||||
|
|
||||
|
<p class="submit"> |
||||
|
<?php echo get_submit_button( null, 'primary large', 'submit', false ); ?>
|
||||
|
|
||||
|
<a href="<?php echo wp_nonce_url( admin_url( add_query_arg( 'action', 'purge-cache', $this->admin_page ) ), 'purge-cache' ); ?>" class="button button-secondary button-large delete<?php if ( is_wp_error( $this->is_valid_path() ) ) : ?> disabled<?php endif; ?>"><?php _e( 'Purge Cache', 'nginx-cache' ); ?></a>
|
||||
|
</p> |
||||
|
|
||||
|
</form> |
||||
|
|
||||
|
</div> |
||||
@ -0,0 +1,95 @@ |
|||||
|
# Copyright (C) 2020 Till Krüss |
||||
|
# This file is distributed under the GPLv3. |
||||
|
msgid "" |
||||
|
msgstr "" |
||||
|
"Project-Id-Version: Nginx Cache 1.0.5\n" |
||||
|
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/trunk\n" |
||||
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
||||
|
"Language-Team: LANGUAGE <LL@li.org>\n" |
||||
|
"MIME-Version: 1.0\n" |
||||
|
"Content-Type: text/plain; charset=UTF-8\n" |
||||
|
"Content-Transfer-Encoding: 8bit\n" |
||||
|
"POT-Creation-Date: 2020-11-21T22:49:14+00:00\n" |
||||
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" |
||||
|
"X-Generator: WP-CLI 2.4.0\n" |
||||
|
"X-Domain: nginx-cache\n" |
||||
|
|
||||
|
#. Plugin Name of the plugin |
||||
|
#: nginx-cache.php:138 |
||||
|
#: nginx-cache.php:139 |
||||
|
msgid "Nginx Cache" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. Plugin URI of the plugin |
||||
|
msgid "http://wordpress.org/plugins/nginx-cache/" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. Description of the plugin |
||||
|
msgid "Purge the Nginx cache (FastCGI, Proxy, uWSGI) automatically when content changes or manually within WordPress." |
||||
|
msgstr "" |
||||
|
|
||||
|
#. Author of the plugin |
||||
|
msgid "Till Krüss" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. Author URI of the plugin |
||||
|
msgid "http://till.im/" |
||||
|
msgstr "" |
||||
|
|
||||
|
#: includes/settings-page.php:16 |
||||
|
msgid "Cache Zone Path" |
||||
|
msgstr "" |
||||
|
|
||||
|
#: includes/settings-page.php:19 |
||||
|
msgid "The absolute path to the location of the cache zone, specified in the Nginx <code>fastcgi_cache_path</code> or <code>proxy_cache_path</code> directive." |
||||
|
msgstr "" |
||||
|
|
||||
|
#: includes/settings-page.php:23 |
||||
|
#: includes/settings-page.php:36 |
||||
|
#: nginx-cache.php:128 |
||||
|
msgid "Purge Cache" |
||||
|
msgstr "" |
||||
|
|
||||
|
#: includes/settings-page.php:27 |
||||
|
msgid "Automatically flush the cache when content changes" |
||||
|
msgstr "" |
||||
|
|
||||
|
#: nginx-cache.php:80 |
||||
|
msgid "Cache purged." |
||||
|
msgstr "" |
||||
|
|
||||
|
#: nginx-cache.php:85 |
||||
|
msgid "Cache could not be purged. %s" |
||||
|
msgstr "" |
||||
|
|
||||
|
#: nginx-cache.php:120 |
||||
|
msgid "Nginx" |
||||
|
msgstr "" |
||||
|
|
||||
|
#: nginx-cache.php:155 |
||||
|
msgid "Settings" |
||||
|
msgstr "" |
||||
|
|
||||
|
#: nginx-cache.php:177 |
||||
|
msgid "\"Cache Zone Path\" is not set." |
||||
|
msgstr "" |
||||
|
|
||||
|
#: nginx-cache.php:183 |
||||
|
msgid "\"Cache Zone Path\" does not exist." |
||||
|
msgstr "" |
||||
|
|
||||
|
#: nginx-cache.php:187 |
||||
|
msgid "\"Cache Zone Path\" is not a directory." |
||||
|
msgstr "" |
||||
|
|
||||
|
#: nginx-cache.php:193 |
||||
|
msgid "\"Cache Zone Path\" does not appear to be a Nginx cache zone directory." |
||||
|
msgstr "" |
||||
|
|
||||
|
#: nginx-cache.php:197 |
||||
|
msgid "\"Cache Zone Path\" is not writable." |
||||
|
msgstr "" |
||||
|
|
||||
|
#: nginx-cache.php:204 |
||||
|
msgid "Filesystem API could not be initialized." |
||||
|
msgstr "" |
||||
@ -0,0 +1,316 @@ |
|||||
|
<?php |
||||
|
/* |
||||
|
Plugin Name: Nginx Cache Custom |
||||
|
Plugin URI: http://wordpress.org/plugins/nginx-cache/ |
||||
|
Description: Purge the Nginx cache (FastCGI, Proxy, uWSGI) automatically when content changes or manually within WordPress. |
||||
|
Version: 1.0.4 |
||||
|
Text Domain: nginx-cache |
||||
|
Domain Path: /languages |
||||
|
Author: Till Krüss |
||||
|
Author URI: http://till.im/ |
||||
|
License: GPLv3 |
||||
|
License URI: http://www.gnu.org/licenses/gpl-3.0.html |
||||
|
*/ |
||||
|
|
||||
|
if ( ! defined( 'ABSPATH' ) ) exit; |
||||
|
|
||||
|
class NginxCache { |
||||
|
|
||||
|
private $screen = 'tools_page_nginx-cache'; |
||||
|
private $capability = 'manage_options'; |
||||
|
private $admin_page = 'tools.php?page=nginx-cache'; |
||||
|
|
||||
|
public function __construct() { |
||||
|
|
||||
|
load_plugin_textdomain( 'nginx-cache', false, 'nginx-cache/languages' ); |
||||
|
|
||||
|
add_filter( 'option_nginx_cache_path', 'sanitize_text_field' ); |
||||
|
add_filter( 'option_nginx_auto_purge', 'absint' ); |
||||
|
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'add_plugin_actions_links' ) ); |
||||
|
|
||||
|
// if ( get_option( 'nginx_auto_purge' ) ) {
|
||||
|
add_action( 'init', array( $this, 'register_purge_actions' ), 20 ); |
||||
|
// }
|
||||
|
|
||||
|
add_action( 'admin_init', array( $this, 'register_settings' ) ); |
||||
|
add_action( 'admin_menu', array( $this, 'add_admin_menu_page' ) ); |
||||
|
add_action( 'admin_bar_menu', array( $this, 'add_admin_bar_node' ), 100 ); |
||||
|
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles' ) ); |
||||
|
add_action( 'load-' . $this->screen, array( $this, 'do_admin_actions' ) ); |
||||
|
add_action( 'load-' . $this->screen, array( $this, 'add_settings_notices' ) ); |
||||
|
} |
||||
|
|
||||
|
public function register_purge_actions() { |
||||
|
|
||||
|
// use `nginx_cache_purge_actions` filter to alter default purge actions
|
||||
|
$purge_actions = (array) apply_filters( |
||||
|
'nginx_cache_purge_actions', |
||||
|
array( |
||||
|
'publish_phone', 'save_post', 'edit_post', 'delete_post', 'wp_trash_post', 'clean_post_cache', |
||||
|
'trackback_post', 'pingback_post', 'comment_post', 'edit_comment', 'delete_comment', 'wp_set_comment_status', |
||||
|
'switch_theme', 'wp_update_nav_menu', 'edit_user_profile_update' |
||||
|
) |
||||
|
); |
||||
|
|
||||
|
foreach ( $purge_actions as $action ) { |
||||
|
if ( did_action( $action ) ) { |
||||
|
$this->purge_zone_once(); |
||||
|
} else { |
||||
|
add_action( $action, array( $this, 'purge_zone_once' ) ); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public function register_settings() { |
||||
|
|
||||
|
register_setting( 'nginx-cache', 'nginx_cache_path', 'sanitize_text_field' ); |
||||
|
register_setting( 'nginx-cache', 'nginx_auto_purge', 'absint' ); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public function add_settings_notices() { |
||||
|
|
||||
|
// $path_error = $this->is_valid_path();
|
||||
|
|
||||
|
if ( isset( $_GET[ 'message' ] ) && ! isset( $_GET[ 'settings-updated' ] ) ) { |
||||
|
|
||||
|
// show cache purge success message
|
||||
|
if ( $_GET[ 'message' ] === 'cache-purged' ) { |
||||
|
add_settings_error( '', 'nginx_cache_path', __( 'Cache purged.', 'nginx-cache' ), 'updated' ); |
||||
|
} |
||||
|
|
||||
|
// show cache purge failure message
|
||||
|
if ( $_GET[ 'message' ] === 'purge-cache-failed' ) { |
||||
|
add_settings_error( '', 'nginx_cache_path', sprintf( __( 'Cache could not be purged. %s', 'nginx-cache' ), wptexturize( $path_error->get_error_message() ) ) ); |
||||
|
} |
||||
|
|
||||
|
} elseif ( is_wp_error( $path_error ) && $path_error->get_error_code() === 'fs' ) { |
||||
|
|
||||
|
// show cache path problem message
|
||||
|
add_settings_error( '', 'nginx_cache_path', wptexturize( $path_error->get_error_message( 'fs' ) ) ); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public function do_admin_actions() { |
||||
|
|
||||
|
// purge cache
|
||||
|
if ( isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] === 'purge-cache' && wp_verify_nonce( $_GET[ '_wpnonce' ], 'purge-cache' ) ) { |
||||
|
|
||||
|
$result = $this->purge_zone(); |
||||
|
wp_safe_redirect( admin_url( add_query_arg( 'message', is_wp_error( $result ) ? 'purge-cache-failed' : 'cache-purged', $this->admin_page ) ) ); |
||||
|
exit; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public function add_admin_bar_node( $wp_admin_bar ) { |
||||
|
|
||||
|
// verify user capability
|
||||
|
if ( ! current_user_can( $this->capability ) ) { |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
// add "Nginx" node to admin-bar
|
||||
|
$wp_admin_bar->add_node( array( |
||||
|
'id' => 'nginx-cache', |
||||
|
'title' => __( 'Nginx', 'nginx-cache' ), |
||||
|
'href' => admin_url( $this->admin_page ) |
||||
|
) ); |
||||
|
|
||||
|
// add "Purge Cache" to "Nginx" node
|
||||
|
$wp_admin_bar->add_node( array( |
||||
|
'parent' => 'nginx-cache', |
||||
|
'id' => 'purge-cache', |
||||
|
'title' => __( 'Purge Cache', 'nginx-cache' ), |
||||
|
'href' => wp_nonce_url( admin_url( add_query_arg( 'action', 'purge-cache', $this->admin_page ) ), 'purge-cache' ) |
||||
|
) ); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public function add_admin_menu_page() { |
||||
|
|
||||
|
// add "Tools" sub-page
|
||||
|
add_management_page( |
||||
|
__( 'Nginx Cache', 'nginx-cache' ), |
||||
|
__( 'Nginx Cache', 'nginx-cache' ), |
||||
|
$this->capability, |
||||
|
'nginx-cache', |
||||
|
array( $this, 'show_settings_page' ) |
||||
|
); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public function show_settings_page() { |
||||
|
require_once plugin_dir_path( __FILE__ ) . '/includes/settings-page.php'; |
||||
|
} |
||||
|
|
||||
|
public function add_plugin_actions_links( $links ) { |
||||
|
|
||||
|
// add settings link to plugin actions
|
||||
|
return array_merge( |
||||
|
array( '<a href="' . admin_url( $this->admin_page ) . '">' . __( 'Settings', 'nginx-cache' ) . '</a>' ), |
||||
|
$links |
||||
|
); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public function enqueue_admin_styles( $hook_suffix ) { |
||||
|
|
||||
|
if ( $hook_suffix === $this->screen ) { |
||||
|
$plugin = get_plugin_data( __FILE__ ); |
||||
|
wp_enqueue_style( 'nginx-cache', plugin_dir_url( __FILE__ ) . 'includes/settings-page.css', null, $plugin[ 'Version' ] ); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
private function is_valid_path() { |
||||
|
|
||||
|
global $wp_filesystem; |
||||
|
|
||||
|
$path = get_option( 'nginx_cache_path' ); |
||||
|
|
||||
|
if ( empty( $path ) ) { |
||||
|
return new WP_Error( 'empty', __( '"Cache Zone Path" is not set.', 'nginx-cache' ) ); |
||||
|
} |
||||
|
|
||||
|
if ( $this->initialize_filesystem() ) { |
||||
|
|
||||
|
if ( ! $wp_filesystem->exists( $path ) ) { |
||||
|
return new WP_Error( 'fs', __( '"Cache Zone Path" does not exist.', 'nginx-cache' ) ); |
||||
|
} |
||||
|
|
||||
|
if ( ! $wp_filesystem->is_dir( $path ) ) { |
||||
|
return new WP_Error( 'fs', __( '"Cache Zone Path" is not a directory.', 'nginx-cache' ) ); |
||||
|
} |
||||
|
|
||||
|
$list = $wp_filesystem->dirlist( $path, true, true ); |
||||
|
|
||||
|
if ( is_array( $list ) && ! $this->validate_dirlist( $list ) ) { |
||||
|
return new WP_Error( 'fs', __( '"Cache Zone Path" does not appear to be a Nginx cache zone directory.', 'nginx-cache' ) ); |
||||
|
} |
||||
|
|
||||
|
if ( ! $wp_filesystem->is_writable( $path ) ) { |
||||
|
return new WP_Error( 'fs', __( '"Cache Zone Path" is not writable.', 'nginx-cache' ) ); |
||||
|
} |
||||
|
|
||||
|
return true; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
return new WP_Error( 'fs', __( 'Filesystem API could not be initialized.', 'nginx-cache' ) ); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
private function validate_dirlist( $list ) { |
||||
|
|
||||
|
foreach ( $list as $item ) { |
||||
|
|
||||
|
// abort if file is not a MD5 hash
|
||||
|
if ( $item[ 'type' ] === 'f' && ( strlen( $item[ 'name' ] ) !== 32 || ! ctype_xdigit( $item[ 'name' ] ) ) ) { |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
// validate subdirectories recursively
|
||||
|
if ( $item[ 'type' ] === 'd' && ! $this->validate_dirlist( $item[ 'files' ] ) ) { |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
return true; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public function purge_zone_once() { |
||||
|
|
||||
|
static $completed = false; |
||||
|
|
||||
|
if ( ! $completed ) { |
||||
|
$this->purge_zone(); |
||||
|
$completed = true; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
private function purge_zone() { |
||||
|
|
||||
|
global $wp_filesystem; |
||||
|
|
||||
|
if ( ! $this->should_purge() ) { |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
// $path = get_option( 'nginx_cache_path' );
|
||||
|
// $path_error = $this->is_valid_path();
|
||||
|
|
||||
|
// abort if cache zone path is not valid
|
||||
|
// if ( is_wp_error( $path_error ) ) {
|
||||
|
// return $path_error;
|
||||
|
// }
|
||||
|
|
||||
|
// delete cache directory (recursively)
|
||||
|
// $wp_filesystem->rmdir( $path, true );
|
||||
|
|
||||
|
// recreate empty cache directory
|
||||
|
// $wp_filesystem->mkdir( $path );
|
||||
|
|
||||
|
system('sudo /bin/rm -r /var/run/nginx-cache/APP_NAME/*'); |
||||
|
|
||||
|
do_action( 'nginx_cache_zone_purged', $path ); |
||||
|
|
||||
|
return true; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
private function should_purge() { |
||||
|
|
||||
|
$post_type = get_post_type(); |
||||
|
|
||||
|
if ( ! $post_type ) { |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
if ( ! in_array( $post_type, (array) apply_filters( 'nginx_cache_excluded_post_types', array() ) ) ) { |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
private function initialize_filesystem() { |
||||
|
|
||||
|
$path = get_option( 'nginx_cache_path' ); |
||||
|
|
||||
|
// if the cache directory doesn't exist, try to create it
|
||||
|
if ( ! file_exists( $path ) ) { |
||||
|
mkdir( $path ); |
||||
|
} |
||||
|
|
||||
|
// load WordPress file API?
|
||||
|
if ( ! function_exists( 'request_filesystem_credentials' ) ) { |
||||
|
require_once ABSPATH . 'wp-admin/includes/file.php'; |
||||
|
} |
||||
|
|
||||
|
ob_start(); |
||||
|
$credentials = request_filesystem_credentials( '', '', false, $path, null, true ); |
||||
|
ob_end_clean(); |
||||
|
|
||||
|
if ( $credentials === false ) { |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
if ( ! WP_Filesystem( $credentials, $path, true ) ) { |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
return true; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
new NginxCache; |
||||
@ -0,0 +1,66 @@ |
|||||
|
=== Nginx Cache === |
||||
|
Contributors: tillkruess |
||||
|
Donate link: https://github.com/sponsors/tillkruss |
||||
|
Tags: nginx, nginx cache, cache, caching, purge, purge cache, flush, flush cache, server, performance, optimize, speed, load, fastcgi, fastcgi purge, proxy, proxy purge, reverse proxy |
||||
|
Requires at least: 3.1 |
||||
|
Tested up to: 5.6 |
||||
|
Stable tag: 1.0.5 |
||||
|
License: GPLv3 |
||||
|
License URI: http://www.gnu.org/licenses/gpl-3.0.html |
||||
|
|
||||
|
Purge the Nginx cache (FastCGI, Proxy, uWSGI) automatically when content changes or manually within WordPress. |
||||
|
|
||||
|
|
||||
|
== Description == |
||||
|
|
||||
|
Purge the [Nginx](http://nginx.org) cache (FastCGI, Proxy, uWSGI) automatically when content changes or manually within WordPress. |
||||
|
|
||||
|
Requirements: |
||||
|
|
||||
|
* The [Filesystem API](http://codex.wordpress.org/Filesystem_API) needs to function without asking for credentials. |
||||
|
* Nginx and PHP need to run under the same user, or PHP's user needs write access to Nginx's cache path. |
||||
|
|
||||
|
|
||||
|
== Installation == |
||||
|
|
||||
|
For detailed installation instructions, please read the [standard installation procedure for WordPress plugins](http://codex.wordpress.org/Managing_Plugins#Installing_Plugins). |
||||
|
|
||||
|
1. Install and activate plugin. |
||||
|
2. Enter "Cache Zone Path" under _Tools -> Nginx_. |
||||
|
3. Done. |
||||
|
|
||||
|
|
||||
|
== Screenshots == |
||||
|
|
||||
|
1. Plugin settings page. |
||||
|
|
||||
|
|
||||
|
== Changelog == |
||||
|
|
||||
|
= 1.0.5 = |
||||
|
|
||||
|
* Added `nginx_cache_zone_purged` action |
||||
|
|
||||
|
= 1.0.4 = |
||||
|
|
||||
|
* Improved translatable strings |
||||
|
* Fixed auto-purge bug |
||||
|
* Fixed bug when validating directory |
||||
|
|
||||
|
= 1.0.3 = |
||||
|
|
||||
|
* Create cache directory if it doesn't exists |
||||
|
* Re-create cache directory after cache purge |
||||
|
* Allow post types to be excluded from triggering a cache purge |
||||
|
|
||||
|
= 1.0.2 = |
||||
|
|
||||
|
* Fixed 4.6 issue with file-system credentials |
||||
|
|
||||
|
= 1.0.1 = |
||||
|
|
||||
|
* Improved testing of file-system credentials |
||||
|
|
||||
|
= 1.0 = |
||||
|
|
||||
|
* Initial release |
||||
@ -1 +1 @@ |
|||||
REPLACE INTO wp_sitemeta VALUES(NULL,1,'authLDAPOptions','a:22:{s:7:"Enabled";s:1:"1";s:7:"CachePW";b:0;s:3:"URI";s:44:"ldap://localhost/ou=users,dc=yunohost,dc=org";s:12:"URISeparator";s:1:" ";s:6:"Filter";s:__LENGTH__:"(&(|(objectclass=posixAccount))(uid=%s)(permission=cn=__APP__.admin,ou=permission,dc=yunohost,dc=org))";s:8:"NameAttr";s:9:"givenName";s:7:"SecName";s:2:"sn";s:7:"UidAttr";s:3:"uid";s:8:"MailAttr";s:4:"mail";s:7:"WebAttr";s:0:"";s:6:"Groups";a:5:{s:13:"administrator";s:0:"";s:6:"editor";s:0:"";s:6:"author";s:0:"";s:11:"contributor";s:0:"";s:10:"subscriber";s:0:"";}s:5:"Debug";b:0;s:9:"GroupAttr";s:0:"";s:11:"GroupFilter";s:0:"";s:11:"DefaultRole";s:10:"subscriber";s:11:"GroupEnable";b:0;s:13:"GroupOverUser";b:0;s:7:"Version";i:1;s:26:"DoNotOverwriteNonLdapUsers";b:0;s:8:"StartTLS";b:0;s:14:"GroupSeparator";s:0:"";s:9:"GroupBase";s:0:"";}'); |
|
||||
|
REPLACE INTO __DB_PREFIX__sitemeta VALUES(NULL,1,'authLDAPOptions','a:22:{s:7:"Enabled";s:1:"1";s:7:"CachePW";b:0;s:3:"URI";s:44:"ldap://localhost/ou=users,dc=yunohost,dc=org";s:12:"URISeparator";s:1:" ";s:6:"Filter";s:__LENGTH__:"(&(|(objectclass=posixAccount))(uid=%s)(permission=cn=__APP__.admin,ou=permission,dc=yunohost,dc=org))";s:8:"NameAttr";s:9:"givenName";s:7:"SecName";s:2:"sn";s:7:"UidAttr";s:3:"uid";s:8:"MailAttr";s:4:"mail";s:7:"WebAttr";s:0:"";s:6:"Groups";a:5:{s:13:"administrator";s:0:"";s:6:"editor";s:0:"";s:6:"author";s:0:"";s:11:"contributor";s:0:"";s:10:"subscriber";s:0:"";}s:5:"Debug";b:0;s:9:"GroupAttr";s:0:"";s:11:"GroupFilter";s:0:"";s:11:"DefaultRole";s:10:"subscriber";s:11:"GroupEnable";b:0;s:13:"GroupOverUser";b:0;s:7:"Version";i:1;s:26:"DoNotOverwriteNonLdapUsers";b:0;s:8:"StartTLS";b:0;s:14:"GroupSeparator";s:0:"";s:9:"GroupBase";s:0:"";}'); |
||||
@ -1 +1 @@ |
|||||
REPLACE INTO wp_options VALUES(NULL,'authLDAPOptions','a:22:{s:7:"Enabled";s:1:"1";s:7:"CachePW";b:0;s:3:"URI";s:44:"ldap://localhost/ou=users,dc=yunohost,dc=org";s:12:"URISeparator";s:1:" ";s:6:"Filter";s:__LENGTH__:"(&(|(objectclass=posixAccount))(uid=%s)(permission=cn=__APP__.admin,ou=permission,dc=yunohost,dc=org))";s:8:"NameAttr";s:9:"givenName";s:7:"SecName";s:2:"sn";s:7:"UidAttr";s:3:"uid";s:8:"MailAttr";s:4:"mail";s:7:"WebAttr";s:0:"";s:6:"Groups";a:5:{s:13:"administrator";s:0:"";s:6:"editor";s:0:"";s:6:"author";s:0:"";s:11:"contributor";s:0:"";s:10:"subscriber";s:0:"";}s:5:"Debug";b:0;s:9:"GroupAttr";s:0:"";s:11:"GroupFilter";s:0:"";s:11:"DefaultRole";s:10:"subscriber";s:11:"GroupEnable";b:0;s:13:"GroupOverUser";b:0;s:7:"Version";i:1;s:26:"DoNotOverwriteNonLdapUsers";b:0;s:8:"StartTLS";b:0;s:14:"GroupSeparator";s:0:"";s:9:"GroupBase";s:0:"";}','yes'); |
|
||||
|
REPLACE INTO __DB_PREFIX__options VALUES(NULL,'authLDAPOptions','a:22:{s:7:"Enabled";s:1:"1";s:7:"CachePW";b:0;s:3:"URI";s:44:"ldap://localhost/ou=users,dc=yunohost,dc=org";s:12:"URISeparator";s:1:" ";s:6:"Filter";s:__LENGTH__:"(&(|(objectclass=posixAccount))(uid=%s)(permission=cn=__APP__.admin,ou=permission,dc=yunohost,dc=org))";s:8:"NameAttr";s:9:"givenName";s:7:"SecName";s:2:"sn";s:7:"UidAttr";s:3:"uid";s:8:"MailAttr";s:4:"mail";s:7:"WebAttr";s:0:"";s:6:"Groups";a:5:{s:13:"administrator";s:0:"";s:6:"editor";s:0:"";s:6:"author";s:0:"";s:11:"contributor";s:0:"";s:10:"subscriber";s:0:"";}s:5:"Debug";b:0;s:9:"GroupAttr";s:0:"";s:11:"GroupFilter";s:0:"";s:11:"DefaultRole";s:10:"subscriber";s:11:"GroupEnable";b:0;s:13:"GroupOverUser";b:0;s:7:"Version";i:1;s:26:"DoNotOverwriteNonLdapUsers";b:0;s:8:"StartTLS";b:0;s:14:"GroupSeparator";s:0:"";s:9:"GroupBase";s:0:"";}','yes'); |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue