plugin install
This commit is contained in:
@@ -0,0 +1,221 @@
|
||||
<?php
|
||||
/**
|
||||
* The admin-specific functionality of the plugin.
|
||||
*
|
||||
* @link https://rtcamp.com/nginx-helper/
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @package nginx-helper
|
||||
* @subpackage nginx-helper/admin
|
||||
*/
|
||||
|
||||
/**
|
||||
* Description of FastCGI_Purger
|
||||
*
|
||||
* @package nginx-helper
|
||||
* @subpackage nginx-helper/admin
|
||||
* @author rtCamp
|
||||
*/
|
||||
class FastCGI_Purger extends Purger {
|
||||
|
||||
/**
|
||||
* Function to purge url.
|
||||
*
|
||||
* @param string $url URL.
|
||||
* @param bool $feed Weather it is feed or not.
|
||||
*/
|
||||
public function purge_url( $url, $feed = true ) {
|
||||
|
||||
global $nginx_helper_admin;
|
||||
|
||||
/**
|
||||
* Filters the URL to be purged.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*
|
||||
* @param string $url URL to be purged.
|
||||
*/
|
||||
$url = apply_filters( 'rt_nginx_helper_purge_url', $url );
|
||||
|
||||
$this->log( '- Purging URL | ' . $url );
|
||||
|
||||
$parse = wp_parse_url( $url );
|
||||
|
||||
if ( ! isset( $parse['path'] ) ) {
|
||||
$parse['path'] = '';
|
||||
}
|
||||
|
||||
switch ( $nginx_helper_admin->options['purge_method'] ) {
|
||||
|
||||
case 'unlink_files':
|
||||
$_url_purge_base = $parse['scheme'] . '://' . $parse['host'] . $parse['path'];
|
||||
$_url_purge = $_url_purge_base;
|
||||
|
||||
if ( ! empty( $parse['query'] ) ) {
|
||||
$_url_purge .= '?' . $parse['query'];
|
||||
}
|
||||
|
||||
$this->delete_cache_file_for( $_url_purge );
|
||||
|
||||
if ( $feed && ! empty( $nginx_helper_admin->options['purge_feeds'] ) ) {
|
||||
|
||||
$feed_url = rtrim( $_url_purge_base, '/' ) . '/feed/';
|
||||
$this->delete_cache_file_for( $feed_url );
|
||||
$this->delete_cache_file_for( $feed_url . 'atom/' );
|
||||
$this->delete_cache_file_for( $feed_url . 'rdf/' );
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
case 'get_request':
|
||||
// Go to default case.
|
||||
default:
|
||||
$_url_purge_base = $this->purge_base_url() . $parse['path'];
|
||||
$_url_purge = $_url_purge_base;
|
||||
|
||||
if ( isset( $parse['query'] ) && '' !== $parse['query'] ) {
|
||||
$_url_purge .= '?' . $parse['query'];
|
||||
}
|
||||
|
||||
$this->do_remote_get( $_url_purge );
|
||||
|
||||
if ( $feed && ! empty( $nginx_helper_admin->options['purge_feeds'] ) ) {
|
||||
|
||||
$feed_url = rtrim( $_url_purge_base, '/' ) . '/feed/';
|
||||
$this->do_remote_get( $feed_url );
|
||||
$this->do_remote_get( $feed_url . 'atom/' );
|
||||
$this->do_remote_get( $feed_url . 'rdf/' );
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to custom purge urls.
|
||||
*/
|
||||
public function custom_purge_urls() {
|
||||
|
||||
global $nginx_helper_admin;
|
||||
|
||||
$parse = wp_parse_url( home_url() );
|
||||
|
||||
$purge_urls = isset( $nginx_helper_admin->options['purge_url'] ) && ! empty( $nginx_helper_admin->options['purge_url'] ) ?
|
||||
explode( "\r\n", $nginx_helper_admin->options['purge_url'] ) : array();
|
||||
|
||||
/**
|
||||
* Allow plugins/themes to modify/extend urls.
|
||||
*
|
||||
* @param array $purge_urls URLs which needs to be purged.
|
||||
* @param bool $wildcard If wildcard in url is allowed or not. default false.
|
||||
*/
|
||||
$purge_urls = apply_filters( 'rt_nginx_helper_purge_urls', $purge_urls, false );
|
||||
|
||||
switch ( $nginx_helper_admin->options['purge_method'] ) {
|
||||
|
||||
case 'unlink_files':
|
||||
$_url_purge_base = $parse['scheme'] . '://' . $parse['host'];
|
||||
|
||||
if ( is_array( $purge_urls ) && ! empty( $purge_urls ) ) {
|
||||
|
||||
foreach ( $purge_urls as $purge_url ) {
|
||||
|
||||
$purge_url = trim( $purge_url );
|
||||
|
||||
if ( strpos( $purge_url, '*' ) === false ) {
|
||||
|
||||
$purge_url = $_url_purge_base . $purge_url;
|
||||
$this->log( '- Purging URL | ' . $purge_url );
|
||||
$this->delete_cache_file_for( $purge_url );
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'get_request':
|
||||
// Go to default case.
|
||||
default:
|
||||
$_url_purge_base = $this->purge_base_url();
|
||||
|
||||
if ( is_array( $purge_urls ) && ! empty( $purge_urls ) ) {
|
||||
|
||||
foreach ( $purge_urls as $purge_url ) {
|
||||
|
||||
$purge_url = trim( $purge_url );
|
||||
|
||||
if ( strpos( $purge_url, '*' ) === false ) {
|
||||
|
||||
$purge_url = $_url_purge_base . $purge_url;
|
||||
$this->log( '- Purging URL | ' . $purge_url );
|
||||
$this->do_remote_get( $purge_url );
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Purge everything.
|
||||
*/
|
||||
public function purge_all() {
|
||||
|
||||
$this->unlink_recursive( RT_WP_NGINX_HELPER_CACHE_PATH, false );
|
||||
$this->log( '* * * * *' );
|
||||
$this->log( '* Purged Everything!' );
|
||||
$this->log( '* * * * *' );
|
||||
|
||||
/**
|
||||
* Fire an action after the FastCGI cache has been purged.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
do_action( 'rt_nginx_helper_after_fastcgi_purge_all' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs the base url to call when purging using the "get_request" method.
|
||||
*
|
||||
* @since 2.2.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function purge_base_url() {
|
||||
|
||||
$parse = wp_parse_url( home_url() );
|
||||
|
||||
/**
|
||||
* Filter to change purge suffix for FastCGI cache.
|
||||
*
|
||||
* @param string $suffix Purge suffix. Default is purge.
|
||||
*
|
||||
* @since 2.2.0
|
||||
*/
|
||||
$path = apply_filters( 'rt_nginx_helper_fastcgi_purge_suffix', 'purge' );
|
||||
|
||||
// Prevent users from inserting a trailing '/' that could break the url purging.
|
||||
$path = trim( $path, '/' );
|
||||
|
||||
$purge_url_base = $parse['scheme'] . '://' . $parse['host'] . '/' . $path;
|
||||
|
||||
/**
|
||||
* Filter to change purge URL base for FastCGI cache.
|
||||
*
|
||||
* @param string $purge_url_base Purge URL base.
|
||||
*
|
||||
* @since 2.2.0
|
||||
*/
|
||||
$purge_url_base = apply_filters( 'rt_nginx_helper_fastcgi_purge_url_base', $purge_url_base );
|
||||
|
||||
// Prevent users from inserting a trailing '/' that could break the url purging.
|
||||
return untrailingslashit( $purge_url_base );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,779 @@
|
||||
<?php
|
||||
/**
|
||||
* The admin-specific functionality of the plugin.
|
||||
*
|
||||
* @link https://rtcamp.com/nginx-helper/
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @package nginx-helper
|
||||
* @subpackage nginx-helper/admin
|
||||
*/
|
||||
|
||||
/**
|
||||
* The admin-specific functionality of the plugin.
|
||||
*
|
||||
* Defines the plugin name, version, and two examples hooks for how to
|
||||
* enqueue the admin-specific stylesheet and JavaScript.
|
||||
*
|
||||
* @package nginx-helper
|
||||
* @subpackage nginx-helper/admin
|
||||
* @author rtCamp
|
||||
*/
|
||||
class Nginx_Helper_Admin {
|
||||
|
||||
/**
|
||||
* The ID of this plugin.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access private
|
||||
* @var string $plugin_name The ID of this plugin.
|
||||
*/
|
||||
private $plugin_name;
|
||||
|
||||
/**
|
||||
* The version of this plugin.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access private
|
||||
* @var string $version The current version of this plugin.
|
||||
*/
|
||||
private $version;
|
||||
|
||||
/**
|
||||
* Various settings tabs.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access private
|
||||
* @var string $settings_tabs Various settings tabs.
|
||||
*/
|
||||
private $settings_tabs;
|
||||
|
||||
/**
|
||||
* Purge options.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string[] $options Purge options.
|
||||
*/
|
||||
public $options;
|
||||
|
||||
/**
|
||||
* WP-CLI Command.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string $options WP-CLI Command.
|
||||
*/
|
||||
const WP_CLI_COMMAND = 'nginx-helper';
|
||||
|
||||
/**
|
||||
* Initialize the class and set its properties.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @param string $plugin_name The name of this plugin.
|
||||
* @param string $version The version of this plugin.
|
||||
*/
|
||||
public function __construct( $plugin_name, $version ) {
|
||||
|
||||
$this->plugin_name = $plugin_name;
|
||||
$this->version = $version;
|
||||
|
||||
/**
|
||||
* Define settings tabs
|
||||
*/
|
||||
$this->settings_tabs = apply_filters(
|
||||
'rt_nginx_helper_settings_tabs',
|
||||
array(
|
||||
'general' => array(
|
||||
'menu_title' => __( 'General', 'nginx-helper' ),
|
||||
'menu_slug' => 'general',
|
||||
),
|
||||
'support' => array(
|
||||
'menu_title' => __( 'Support', 'nginx-helper' ),
|
||||
'menu_slug' => 'support',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$this->options = $this->nginx_helper_settings();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the stylesheets for the admin area.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param string $hook The current admin page.
|
||||
*/
|
||||
public function enqueue_styles( $hook ) {
|
||||
|
||||
/**
|
||||
* This function is provided for demonstration purposes only.
|
||||
*
|
||||
* An instance of this class should be passed to the run() function
|
||||
* defined in Nginx_Helper_Loader as all of the hooks are defined
|
||||
* in that particular class.
|
||||
*
|
||||
* The Nginx_Helper_Loader will then create the relationship
|
||||
* between the defined hooks and the functions defined in this
|
||||
* class.
|
||||
*/
|
||||
|
||||
if ( 'settings_page_nginx' !== $hook ) {
|
||||
return;
|
||||
}
|
||||
|
||||
wp_enqueue_style( $this->plugin_name . '-icons', plugin_dir_url( __FILE__ ) . 'icons/css/nginx-fontello.css', array(), $this->version, 'all' );
|
||||
wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/nginx-helper-admin.css', array(), $this->version, 'all' );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the JavaScript for the admin area.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param string $hook The current admin page.
|
||||
*/
|
||||
public function enqueue_scripts( $hook ) {
|
||||
|
||||
/**
|
||||
* This function is provided for demonstration purposes only.
|
||||
*
|
||||
* An instance of this class should be passed to the run() function
|
||||
* defined in Nginx_Helper_Loader as all of the hooks are defined
|
||||
* in that particular class.
|
||||
*
|
||||
* The Nginx_Helper_Loader will then create the relationship
|
||||
* between the defined hooks and the functions defined in this
|
||||
* class.
|
||||
*/
|
||||
|
||||
if ( 'settings_page_nginx' !== $hook ) {
|
||||
return;
|
||||
}
|
||||
|
||||
wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/nginx-helper-admin.js', array( 'jquery' ), $this->version, false );
|
||||
|
||||
$do_localize = array(
|
||||
'purge_confirm_string' => esc_html__( 'Purging entire cache is not recommended. Would you like to continue?', 'nginx-helper' ),
|
||||
);
|
||||
wp_localize_script( $this->plugin_name, 'nginx_helper', $do_localize );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add admin menu.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function nginx_helper_admin_menu() {
|
||||
|
||||
if ( is_multisite() ) {
|
||||
|
||||
add_submenu_page(
|
||||
'settings.php',
|
||||
__( 'Nginx Helper', 'nginx-helper' ),
|
||||
__( 'Nginx Helper', 'nginx-helper' ),
|
||||
'manage_options',
|
||||
'nginx',
|
||||
array( &$this, 'nginx_helper_setting_page' )
|
||||
);
|
||||
|
||||
} else {
|
||||
|
||||
add_submenu_page(
|
||||
'options-general.php',
|
||||
__( 'Nginx Helper', 'nginx-helper' ),
|
||||
__( 'Nginx Helper', 'nginx-helper' ),
|
||||
'manage_options',
|
||||
'nginx',
|
||||
array( &$this, 'nginx_helper_setting_page' )
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to add toolbar purge link.
|
||||
*
|
||||
* @param object $wp_admin_bar Admin bar object.
|
||||
*/
|
||||
public function nginx_helper_toolbar_purge_link( $wp_admin_bar ) {
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( is_admin() ) {
|
||||
$nginx_helper_urls = 'all';
|
||||
$link_title = __( 'Purge Cache', 'nginx-helper' );
|
||||
} else {
|
||||
$nginx_helper_urls = 'current-url';
|
||||
$link_title = __( 'Purge Current Page', 'nginx-helper' );
|
||||
}
|
||||
|
||||
$purge_url = add_query_arg(
|
||||
array(
|
||||
'nginx_helper_action' => 'purge',
|
||||
'nginx_helper_urls' => $nginx_helper_urls,
|
||||
)
|
||||
);
|
||||
|
||||
$nonced_url = wp_nonce_url( $purge_url, 'nginx_helper-purge_all' );
|
||||
|
||||
$wp_admin_bar->add_menu(
|
||||
array(
|
||||
'id' => 'nginx-helper-purge-all',
|
||||
'title' => $link_title,
|
||||
'href' => $nonced_url,
|
||||
'meta' => array( 'title' => $link_title ),
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Display settings.
|
||||
*
|
||||
* @global $string $pagenow Contain current admin page.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function nginx_helper_setting_page() {
|
||||
include plugin_dir_path( __FILE__ ) . 'partials/nginx-helper-admin-display.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Default settings.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return array
|
||||
*/
|
||||
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,
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get settings.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function nginx_helper_settings() {
|
||||
|
||||
$options = get_site_option(
|
||||
'rt_wp_nginx_helper_options',
|
||||
array(
|
||||
'redis_hostname' => '127.0.0.1',
|
||||
'redis_port' => '6379',
|
||||
'redis_prefix' => 'nginx-cache:',
|
||||
)
|
||||
);
|
||||
|
||||
$data = wp_parse_args(
|
||||
$options,
|
||||
$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 ( ! $is_redis_enabled ) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
$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;
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Nginx helper setting link function.
|
||||
*
|
||||
* @param array $links links.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function nginx_helper_settings_link( $links ) {
|
||||
|
||||
if ( is_network_admin() ) {
|
||||
$setting_page = 'settings.php';
|
||||
} else {
|
||||
$setting_page = 'options-general.php';
|
||||
}
|
||||
|
||||
$settings_link = '<a href="' . network_admin_url( $setting_page . '?page=nginx' ) . '">' . __( 'Settings', 'nginx-helper' ) . '</a>';
|
||||
array_unshift( $links, $settings_link );
|
||||
|
||||
return $links;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the nginx log is enabled.
|
||||
*
|
||||
* @since 2.2.4
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_nginx_log_enabled() {
|
||||
|
||||
$options = get_site_option( 'rt_wp_nginx_helper_options', array() );
|
||||
|
||||
if ( ! empty( $options['enable_log'] ) && 1 === (int) $options['enable_log'] ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( defined( 'NGINX_HELPER_LOG' ) && true === NGINX_HELPER_LOG ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the asset path.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return string asset path of the plugin.
|
||||
*/
|
||||
public function functional_asset_path() {
|
||||
|
||||
$log_path = WP_CONTENT_DIR . '/uploads/nginx-helper/';
|
||||
|
||||
return apply_filters( 'nginx_asset_path', $log_path );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the asset url.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return string asset url of the plugin.
|
||||
*/
|
||||
public function functional_asset_url() {
|
||||
|
||||
$log_url = WP_CONTENT_URL . '/uploads/nginx-helper/';
|
||||
|
||||
return apply_filters( 'nginx_asset_url', $log_url );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get latest news.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function nginx_helper_get_feeds() {
|
||||
|
||||
// Get RSS Feed(s).
|
||||
require_once ABSPATH . WPINC . '/feed.php';
|
||||
|
||||
$maxitems = 0;
|
||||
$rss_items = array();
|
||||
|
||||
// Get a SimplePie feed object from the specified feed source.
|
||||
$rss = fetch_feed( 'https://rtcamp.com/blog/feed/' );
|
||||
|
||||
if ( ! is_wp_error( $rss ) ) { // Checks that the object is created correctly.
|
||||
|
||||
// Figure out how many total items there are, but limit it to 5.
|
||||
$maxitems = $rss->get_item_quantity( 5 );
|
||||
// Build an array of all the items, starting with element 0 (first element).
|
||||
$rss_items = $rss->get_items( 0, $maxitems );
|
||||
|
||||
}
|
||||
?>
|
||||
<ul role="list">
|
||||
<?php
|
||||
if ( 0 === $maxitems ) {
|
||||
echo '<li role="listitem">' . esc_html_e( 'No items', 'nginx-helper' ) . '.</li>';
|
||||
} else {
|
||||
|
||||
// Loop through each feed item and display each item as a hyperlink.
|
||||
foreach ( $rss_items as $item ) {
|
||||
?>
|
||||
<li role="listitem">
|
||||
<?php
|
||||
printf(
|
||||
'<a href="%s" title="%s">%s</a>',
|
||||
esc_url( $item->get_permalink() ),
|
||||
esc_attr__( 'Posted ', 'nginx-helper' ) . esc_attr( $item->get_date( 'j F Y | g:i a' ) ),
|
||||
esc_html( $item->get_title() )
|
||||
);
|
||||
?>
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
<?php
|
||||
die();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add time stamps in html.
|
||||
*/
|
||||
public function add_timestamps() {
|
||||
|
||||
global $pagenow;
|
||||
|
||||
if ( is_admin() || 1 !== (int) $this->options['enable_purge'] || 1 !== (int) $this->options['enable_stamp'] ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! empty( $pagenow ) && 'wp-login.php' === $pagenow ) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( headers_list() as $header ) {
|
||||
list( $key, $value ) = explode( ':', $header, 2 );
|
||||
$key = strtolower( $key );
|
||||
if ( 'content-type' === $key && strpos( trim( $value ), 'text/html' ) !== 0 ) {
|
||||
return;
|
||||
}
|
||||
if ( 'content-type' === $key ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Don't add timestamp if run from ajax, cron or wpcli.
|
||||
*/
|
||||
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( defined( 'WP_CLI' ) && WP_CLI ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$timestamps = "\n<!--" .
|
||||
'Cached using Nginx-Helper 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-->';
|
||||
|
||||
echo wp_kses( $timestamps, array() );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get map
|
||||
*
|
||||
* @global object $wpdb
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_map() {
|
||||
|
||||
if ( ! $this->options['enable_map'] ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( is_multisite() ) {
|
||||
|
||||
global $wpdb;
|
||||
|
||||
$rt_all_blogs = $wpdb->get_results(
|
||||
$wpdb->prepare(
|
||||
'SELECT blog_id, domain, path FROM ' . $wpdb->blogs . " WHERE site_id = %d AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0'",
|
||||
$wpdb->siteid
|
||||
)
|
||||
);
|
||||
|
||||
$wpdb->dmtable = $wpdb->base_prefix . 'domain_mapping';
|
||||
|
||||
$rt_domain_map_sites = '';
|
||||
|
||||
if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->dmtable}'" ) === $wpdb->dmtable ) { // phpcs:ignore
|
||||
$rt_domain_map_sites = $wpdb->get_results( "SELECT blog_id, domain FROM {$wpdb->dmtable} ORDER BY id DESC" );
|
||||
}
|
||||
|
||||
$rt_nginx_map = '';
|
||||
$rt_nginx_map_array = array();
|
||||
|
||||
if ( $rt_all_blogs ) {
|
||||
|
||||
foreach ( $rt_all_blogs as $blog ) {
|
||||
|
||||
if ( true === SUBDOMAIN_INSTALL ) {
|
||||
$rt_nginx_map_array[ $blog->domain ] = $blog->blog_id;
|
||||
} else {
|
||||
|
||||
if ( 1 !== $blog->blog_id ) {
|
||||
$rt_nginx_map_array[ $blog->path ] = $blog->blog_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $rt_domain_map_sites ) {
|
||||
|
||||
foreach ( $rt_domain_map_sites as $site ) {
|
||||
$rt_nginx_map_array[ $site->domain ] = $site->blog_id;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $rt_nginx_map_array as $domain => $domain_id ) {
|
||||
$rt_nginx_map .= "\t" . $domain . "\t" . $domain_id . ";\n";
|
||||
}
|
||||
|
||||
return $rt_nginx_map;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Update map
|
||||
*/
|
||||
public function update_map() {
|
||||
|
||||
if ( is_multisite() ) {
|
||||
|
||||
$rt_nginx_map = $this->get_map();
|
||||
|
||||
$fp = fopen( $this->functional_asset_path() . 'map.conf', 'w+' );
|
||||
if ( $fp ) {
|
||||
fwrite( $fp, $rt_nginx_map );
|
||||
fclose( $fp );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Purge url when post status is changed.
|
||||
*
|
||||
* @global string $blog_id Blog id.
|
||||
* @global object $nginx_purger Nginx purger variable.
|
||||
*
|
||||
* @param string $new_status New status.
|
||||
* @param string $old_status Old status.
|
||||
* @param object $post Post object.
|
||||
*/
|
||||
public function set_future_post_option_on_future_status( $new_status, $old_status, $post ) {
|
||||
|
||||
global $blog_id, $nginx_purger;
|
||||
|
||||
$exclude_post_types = array( 'nav_menu_item' );
|
||||
|
||||
if ( in_array( $post->post_type, $exclude_post_types, true ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! $this->options['enable_purge'] ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$purge_status = array( 'publish', 'future' );
|
||||
|
||||
if ( in_array( $old_status, $purge_status, true ) || in_array( $new_status, $purge_status, true ) ) {
|
||||
|
||||
$nginx_purger->log( 'Purge post on transition post STATUS from ' . $old_status . ' to ' . $new_status );
|
||||
$nginx_purger->purge_post( $post->ID );
|
||||
|
||||
}
|
||||
|
||||
if (
|
||||
'future' === $new_status && $post && 'future' === $post->post_status &&
|
||||
(
|
||||
( 'post' === $post->post_type || 'page' === $post->post_type ) ||
|
||||
(
|
||||
isset( $this->options['custom_post_types_recognized'] ) &&
|
||||
in_array( $post->post_type, $this->options['custom_post_types_recognized'], true )
|
||||
)
|
||||
)
|
||||
) {
|
||||
|
||||
$nginx_purger->log( 'Set/update future_posts option ( post id = ' . $post->ID . ' and blog id = ' . $blog_id . ' )' );
|
||||
$this->options['future_posts'][ $blog_id ][ $post->ID ] = strtotime( $post->post_date_gmt ) + 60;
|
||||
update_site_option( 'rt_wp_nginx_helper_options', $this->options );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Unset future post option on delete
|
||||
*
|
||||
* @global string $blog_id Blog id.
|
||||
* @global object $nginx_purger Nginx helper object.
|
||||
*
|
||||
* @param int $post_id Post id.
|
||||
*/
|
||||
public function unset_future_post_option_on_delete( $post_id ) {
|
||||
|
||||
global $blog_id, $nginx_purger;
|
||||
|
||||
if (
|
||||
! $this->options['enable_purge'] ||
|
||||
empty( $this->options['future_posts'] ) ||
|
||||
empty( $this->options['future_posts'][ $blog_id ] ) ||
|
||||
isset( $this->options['future_posts'][ $blog_id ][ $post_id ] ) ||
|
||||
wp_is_post_revision( $post_id )
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$nginx_purger->log( 'Unset future_posts option ( post id = ' . $post_id . ' and blog id = ' . $blog_id . ' )' );
|
||||
|
||||
unset( $this->options['future_posts'][ $blog_id ][ $post_id ] );
|
||||
|
||||
if ( ! count( $this->options['future_posts'][ $blog_id ] ) ) {
|
||||
unset( $this->options['future_posts'][ $blog_id ] );
|
||||
}
|
||||
|
||||
update_site_option( 'rt_wp_nginx_helper_options', $this->options );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update map when new blog added in multisite.
|
||||
*
|
||||
* @global object $nginx_purger Nginx purger class object.
|
||||
*
|
||||
* @param string $blog_id blog id.
|
||||
*/
|
||||
public function update_new_blog_options( $blog_id ) {
|
||||
|
||||
global $nginx_purger;
|
||||
|
||||
$nginx_purger->log( "New site added ( id $blog_id )" );
|
||||
$this->update_map();
|
||||
$nginx_purger->log( "New site added to nginx map ( id $blog_id )" );
|
||||
$helper_options = $this->nginx_helper_default_settings();
|
||||
update_blog_option( $blog_id, 'rt_wp_nginx_helper_options', $helper_options );
|
||||
$nginx_purger->log( "Default options updated for the new blog ( id $blog_id )" );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Purge all urls.
|
||||
* Purge current page cache when purging is requested from front
|
||||
* and all urls when requested from admin dashboard.
|
||||
*
|
||||
* @global object $nginx_purger
|
||||
*/
|
||||
public function purge_all() {
|
||||
|
||||
global $nginx_purger, $wp;
|
||||
|
||||
$method = null;
|
||||
if ( isset( $_SERVER['REQUEST_METHOD'] ) ) {
|
||||
$method = wp_strip_all_tags( $_SERVER['REQUEST_METHOD'] );
|
||||
}
|
||||
|
||||
$action = '';
|
||||
if ( 'POST' === $method ) {
|
||||
if ( isset( $_POST['nginx_helper_action'] ) ) {
|
||||
$action = wp_strip_all_tags( $_POST['nginx_helper_action'] );
|
||||
}
|
||||
} else {
|
||||
if ( isset( $_GET['nginx_helper_action'] ) ) {
|
||||
$action = wp_strip_all_tags( $_GET['nginx_helper_action'] );
|
||||
}
|
||||
}
|
||||
|
||||
if ( empty( $action ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
wp_die( 'Sorry, you do not have the necessary privileges to edit these options.' );
|
||||
}
|
||||
|
||||
if ( 'done' === $action ) {
|
||||
|
||||
add_action( 'admin_notices', array( &$this, 'display_notices' ) );
|
||||
add_action( 'network_admin_notices', array( &$this, 'display_notices' ) );
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
check_admin_referer( 'nginx_helper-purge_all' );
|
||||
|
||||
$current_url = user_trailingslashit( home_url( $wp->request ) );
|
||||
|
||||
if ( ! is_admin() ) {
|
||||
$action = 'purge_current_page';
|
||||
$redirect_url = $current_url;
|
||||
} else {
|
||||
$redirect_url = add_query_arg( array( 'nginx_helper_action' => 'done' ) );
|
||||
}
|
||||
|
||||
switch ( $action ) {
|
||||
case 'purge':
|
||||
$nginx_purger->purge_all();
|
||||
break;
|
||||
case 'purge_current_page':
|
||||
$nginx_purger->purge_url( $current_url );
|
||||
break;
|
||||
}
|
||||
|
||||
if ( 'purge' === $action ) {
|
||||
|
||||
/**
|
||||
* Fire an action after the entire cache has been purged whatever caching type is used.
|
||||
*
|
||||
* @since 2.2.2
|
||||
*/
|
||||
do_action( 'rt_nginx_helper_after_purge_all' );
|
||||
|
||||
}
|
||||
|
||||
wp_redirect( esc_url_raw( $redirect_url ) );
|
||||
exit();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispay plugin notices.
|
||||
*/
|
||||
public function display_notices() {
|
||||
echo '<div class="updated"><p>' . esc_html__( 'Purge initiated', 'nginx-helper' ) . '</p></div>';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,272 @@
|
||||
<?php
|
||||
/**
|
||||
* The admin-specific functionality of the plugin.
|
||||
*
|
||||
* @link https://rtcamp.com/nginx-helper/
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @package nginx-helper
|
||||
* @subpackage nginx-helper/admin
|
||||
*/
|
||||
|
||||
/**
|
||||
* Description of PhpRedis_Purger
|
||||
*
|
||||
* @package nginx-helper
|
||||
* @subpackage nginx-helper/admin
|
||||
* @author rtCamp
|
||||
*/
|
||||
class PhpRedis_Purger extends Purger {
|
||||
|
||||
/**
|
||||
* PHP Redis api object.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string $redis_object PHP Redis api object.
|
||||
*/
|
||||
public $redis_object;
|
||||
|
||||
/**
|
||||
* Initialize the class and set its properties.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
global $nginx_helper_admin;
|
||||
|
||||
try {
|
||||
|
||||
$this->redis_object = new Redis();
|
||||
$this->redis_object->connect(
|
||||
$nginx_helper_admin->options['redis_hostname'],
|
||||
$nginx_helper_admin->options['redis_port'],
|
||||
5
|
||||
);
|
||||
|
||||
} catch ( Exception $e ) {
|
||||
$this->log( $e->getMessage(), 'ERROR' );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Purge all cache.
|
||||
*/
|
||||
public function purge_all() {
|
||||
|
||||
global $nginx_helper_admin;
|
||||
|
||||
$prefix = trim( $nginx_helper_admin->options['redis_prefix'] );
|
||||
|
||||
$this->log( '* * * * *' );
|
||||
|
||||
// If Purge Cache link click from network admin then purge all.
|
||||
if ( is_network_admin() ) {
|
||||
|
||||
$total_keys_purged = $this->delete_keys_by_wildcard( $prefix . '*' );
|
||||
$this->log( '* Purged Everything! * ' );
|
||||
|
||||
} else { // Else purge only site specific cache.
|
||||
|
||||
$parse = wp_parse_url( get_home_url() );
|
||||
$parse['path'] = empty( $parse['path'] ) ? '/' : $parse['path'];
|
||||
$total_keys_purged = $this->delete_keys_by_wildcard( $prefix . $parse['scheme'] . 'GET' . $parse['host'] . $parse['path'] . '*' );
|
||||
$this->log( '* ' . get_home_url() . ' Purged! * ' );
|
||||
|
||||
}
|
||||
|
||||
if ( $total_keys_purged ) {
|
||||
$this->log( "Total {$total_keys_purged} urls purged." );
|
||||
} else {
|
||||
$this->log( 'No Cache found.' );
|
||||
}
|
||||
|
||||
$this->log( '* * * * *' );
|
||||
|
||||
/**
|
||||
* Fire an action after the Redis cache has been purged.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
do_action( 'rt_nginx_helper_after_redis_purge_all' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Purge url.
|
||||
*
|
||||
* @param string $url URL to purge.
|
||||
* @param bool $feed Feed or not.
|
||||
*/
|
||||
public function purge_url( $url, $feed = true ) {
|
||||
|
||||
global $nginx_helper_admin;
|
||||
|
||||
/**
|
||||
* Filters the URL to be purged.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*
|
||||
* @param string $url URL to be purged.
|
||||
*/
|
||||
$url = apply_filters( 'rt_nginx_helper_purge_url', $url );
|
||||
|
||||
$parse = wp_parse_url( $url );
|
||||
|
||||
if ( ! isset( $parse['path'] ) ) {
|
||||
$parse['path'] = '';
|
||||
}
|
||||
|
||||
$prefix = $nginx_helper_admin->options['redis_prefix'];
|
||||
$_url_purge_base = $prefix . $parse['scheme'] . 'GET' . $parse['host'] . $parse['path'];
|
||||
|
||||
/**
|
||||
* To delete device type caches such as `<URL>--mobile`, `<URL>--desktop`, `<URL>--lowend`, etc.
|
||||
* This would need $url above to be changed with this filter `rt_nginx_helper_purge_url` by cache key that Nginx sets while generating cache.
|
||||
*
|
||||
* For example: If page is accessed from desktop, then cache will be generated by appending `--desktop` to current URL.
|
||||
* Add this filter in separate plugin or simply in theme's function.php file:
|
||||
* ```
|
||||
* add_filter( 'rt_nginx_helper_purge_url', function( $url ) {
|
||||
* $url = $url . '--*';
|
||||
* return $url;
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* Regardless of what key / suffix is being to store `$device_type` cache , it will be deleted.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
if ( strpos( $_url_purge_base, '*' ) === false ) {
|
||||
|
||||
$status = $this->delete_single_key( $_url_purge_base );
|
||||
|
||||
if ( $status ) {
|
||||
$this->log( '- Purge URL | ' . $_url_purge_base );
|
||||
} else {
|
||||
$this->log( '- Cache Not Found | ' . $_url_purge_base, 'ERROR' );
|
||||
}
|
||||
} else {
|
||||
|
||||
$status = $this->delete_keys_by_wildcard( $_url_purge_base );
|
||||
|
||||
if ( $status ) {
|
||||
$this->log( '- Purge Wild Card URL | ' . $_url_purge_base . ' | ' . $status . ' url purged' );
|
||||
} else {
|
||||
$this->log( '- Cache Not Found | ' . $_url_purge_base, 'ERROR' );
|
||||
}
|
||||
}
|
||||
|
||||
$this->log( '* * * * *' );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom purge urls.
|
||||
*/
|
||||
public function custom_purge_urls() {
|
||||
|
||||
global $nginx_helper_admin;
|
||||
|
||||
$parse = wp_parse_url( home_url() );
|
||||
$prefix = $nginx_helper_admin->options['redis_prefix'];
|
||||
$_url_purge_base = $prefix . $parse['scheme'] . 'GET' . $parse['host'];
|
||||
|
||||
$purge_urls = isset( $nginx_helper_admin->options['purge_url'] ) && ! empty( $nginx_helper_admin->options['purge_url'] ) ?
|
||||
explode( "\r\n", $nginx_helper_admin->options['purge_url'] ) : array();
|
||||
|
||||
/**
|
||||
* Allow plugins/themes to modify/extend urls.
|
||||
*
|
||||
* @param array $purge_urls URLs which needs to be purged.
|
||||
* @param bool $wildcard If wildcard in url is allowed or not. default true.
|
||||
*/
|
||||
$purge_urls = apply_filters( 'rt_nginx_helper_purge_urls', $purge_urls, true );
|
||||
|
||||
if ( is_array( $purge_urls ) && ! empty( $purge_urls ) ) {
|
||||
|
||||
foreach ( $purge_urls as $purge_url ) {
|
||||
|
||||
$purge_url = trim( $purge_url );
|
||||
|
||||
if ( strpos( $purge_url, '*' ) === false ) {
|
||||
|
||||
$purge_url = $_url_purge_base . $purge_url;
|
||||
$status = $this->delete_single_key( $purge_url );
|
||||
|
||||
if ( $status ) {
|
||||
$this->log( '- Purge URL | ' . $purge_url );
|
||||
} else {
|
||||
$this->log( '- Cache Not Found | ' . $purge_url, 'ERROR' );
|
||||
}
|
||||
} else {
|
||||
|
||||
$purge_url = $_url_purge_base . $purge_url;
|
||||
$status = $this->delete_keys_by_wildcard( $purge_url );
|
||||
|
||||
if ( $status ) {
|
||||
$this->log( '- Purge Wild Card URL | ' . $purge_url . ' | ' . $status . ' url purged' );
|
||||
} else {
|
||||
$this->log( '- Cache Not Found | ' . $purge_url, 'ERROR' );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Single Key Delete Example
|
||||
* e.g. $key can be nginx-cache:httpGETexample.com/
|
||||
*
|
||||
* @param string $key Key.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function delete_single_key( $key ) {
|
||||
|
||||
try {
|
||||
return $this->redis_object->del( $key );
|
||||
} catch ( Exception $e ) {
|
||||
$this->log( $e->getMessage(), 'ERROR' );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete Keys by wildcard.
|
||||
* e.g. $key can be nginx-cache:httpGETexample.com*
|
||||
*
|
||||
* Lua Script block to delete multiple keys using wildcard
|
||||
* Script will return count i.e. number of keys deleted
|
||||
* if return value is 0, that means no matches were found
|
||||
*
|
||||
* Call redis eval and return value from lua script
|
||||
*
|
||||
* @param string $pattern pattern.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function delete_keys_by_wildcard( $pattern ) {
|
||||
|
||||
// Lua Script.
|
||||
$lua = <<<LUA
|
||||
local k = 0
|
||||
for i, name in ipairs(redis.call('KEYS', KEYS[1]))
|
||||
do
|
||||
redis.call('DEL', name)
|
||||
k = k+1
|
||||
end
|
||||
return k
|
||||
LUA;
|
||||
|
||||
try {
|
||||
return $this->redis_object->eval( $lua, array( $pattern ), 1 );
|
||||
} catch ( Exception $e ) {
|
||||
$this->log( $e->getMessage(), 'ERROR' );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
268
wp/wp-content/plugins/nginx-helper/admin/class-predis-purger.php
Normal file
268
wp/wp-content/plugins/nginx-helper/admin/class-predis-purger.php
Normal file
@@ -0,0 +1,268 @@
|
||||
<?php
|
||||
/**
|
||||
* The admin-specific functionality of the plugin.
|
||||
*
|
||||
* @package nginx-helper
|
||||
*/
|
||||
|
||||
/**
|
||||
* Description of Predis_Purger
|
||||
*
|
||||
* @package nginx-helper
|
||||
* @subpackage nginx-helper/admin
|
||||
* @author rtCamp
|
||||
*/
|
||||
class Predis_Purger extends Purger {
|
||||
|
||||
/**
|
||||
* Predis api object.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @access public
|
||||
* @var string $redis_object Predis api object.
|
||||
*/
|
||||
public $redis_object;
|
||||
|
||||
/**
|
||||
* Initialize the class and set its properties.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
global $nginx_helper_admin;
|
||||
|
||||
if ( ! class_exists( 'Predis\Autoloader' ) ) {
|
||||
require_once NGINX_HELPER_BASEPATH . 'admin/predis.php';
|
||||
}
|
||||
|
||||
Predis\Autoloader::register();
|
||||
|
||||
// redis server parameter.
|
||||
$this->redis_object = new Predis\Client(
|
||||
array(
|
||||
'host' => $nginx_helper_admin->options['redis_hostname'],
|
||||
'port' => $nginx_helper_admin->options['redis_port'],
|
||||
)
|
||||
);
|
||||
|
||||
try {
|
||||
$this->redis_object->connect();
|
||||
} catch ( Exception $e ) {
|
||||
$this->log( $e->getMessage(), 'ERROR' );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Purge all.
|
||||
*/
|
||||
public function purge_all() {
|
||||
|
||||
global $nginx_helper_admin;
|
||||
|
||||
$prefix = trim( $nginx_helper_admin->options['redis_prefix'] );
|
||||
|
||||
$this->log( '* * * * *' );
|
||||
|
||||
// If Purge Cache link click from network admin then purge all.
|
||||
if ( is_network_admin() ) {
|
||||
|
||||
$this->delete_keys_by_wildcard( $prefix . '*' );
|
||||
$this->log( '* Purged Everything! * ' );
|
||||
|
||||
} else { // Else purge only site specific cache.
|
||||
|
||||
$parse = wp_parse_url( get_home_url() );
|
||||
$parse['path'] = empty( $parse['path'] ) ? '/' : $parse['path'];
|
||||
$this->delete_keys_by_wildcard( $prefix . $parse['scheme'] . 'GET' . $parse['host'] . $parse['path'] . '*' );
|
||||
$this->log( '* ' . get_home_url() . ' Purged! * ' );
|
||||
|
||||
}
|
||||
|
||||
$this->log( '* * * * *' );
|
||||
|
||||
/**
|
||||
* Fire an action after the Redis cache has been purged.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
do_action( 'rt_nginx_helper_after_redis_purge_all' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Purge url.
|
||||
*
|
||||
* @param string $url URL.
|
||||
* @param bool $feed Feed or not.
|
||||
*/
|
||||
public function purge_url( $url, $feed = true ) {
|
||||
|
||||
global $nginx_helper_admin;
|
||||
|
||||
/**
|
||||
* Filters the URL to be purged.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*
|
||||
* @param string $url URL to be purged.
|
||||
*/
|
||||
$url = apply_filters( 'rt_nginx_helper_purge_url', $url );
|
||||
|
||||
$this->log( '- Purging URL | ' . $url );
|
||||
|
||||
$parse = wp_parse_url( $url );
|
||||
|
||||
if ( ! isset( $parse['path'] ) ) {
|
||||
$parse['path'] = '';
|
||||
}
|
||||
|
||||
$prefix = $nginx_helper_admin->options['redis_prefix'];
|
||||
$_url_purge_base = $prefix . $parse['scheme'] . 'GET' . $parse['host'] . $parse['path'];
|
||||
|
||||
/**
|
||||
* To delete device type caches such as `<URL>--mobile`, `<URL>--desktop`, `<URL>--lowend`, etc.
|
||||
* This would need $url above to be changed with this filter `rt_nginx_helper_purge_url` by cache key that Nginx sets while generating cache.
|
||||
*
|
||||
* For example: If page is accessed from desktop, then cache will be generated by appending `--desktop` to current URL.
|
||||
* Add this filter in separate plugin or simply in theme's function.php file:
|
||||
* ```
|
||||
* add_filter( 'rt_nginx_helper_purge_url', function( $url ) {
|
||||
* $url = $url . '--*';
|
||||
* return $url;
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* Regardless of what key / suffix is being to store `$device_type` cache , it will be deleted.
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
if ( strpos( $_url_purge_base, '*' ) === false ) {
|
||||
|
||||
$status = $this->delete_single_key( $_url_purge_base );
|
||||
|
||||
if ( $status ) {
|
||||
$this->log( '- Purge URL | ' . $_url_purge_base );
|
||||
} else {
|
||||
$this->log( '- Cache Not Found | ' . $_url_purge_base, 'ERROR' );
|
||||
}
|
||||
} else {
|
||||
|
||||
$status = $this->delete_keys_by_wildcard( $_url_purge_base );
|
||||
|
||||
if ( $status ) {
|
||||
$this->log( '- Purge Wild Card URL | ' . $_url_purge_base . ' | ' . $status . ' url purged' );
|
||||
} else {
|
||||
$this->log( '- Cache Not Found | ' . $_url_purge_base, 'ERROR' );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom purge urls.
|
||||
*/
|
||||
public function custom_purge_urls() {
|
||||
|
||||
global $nginx_helper_admin;
|
||||
|
||||
$parse = wp_parse_url( home_url() );
|
||||
$prefix = $nginx_helper_admin->options['redis_prefix'];
|
||||
$_url_purge_base = $prefix . $parse['scheme'] . 'GET' . $parse['host'];
|
||||
|
||||
$purge_urls = isset( $nginx_helper_admin->options['purge_url'] ) && ! empty( $nginx_helper_admin->options['purge_url'] ) ?
|
||||
explode( "\r\n", $nginx_helper_admin->options['purge_url'] ) : array();
|
||||
|
||||
/**
|
||||
* Allow plugins/themes to modify/extend urls.
|
||||
*
|
||||
* @param array $purge_urls URLs which needs to be purged.
|
||||
* @param bool $wildcard If wildcard in url is allowed or not. default true.
|
||||
*/
|
||||
$purge_urls = apply_filters( 'rt_nginx_helper_purge_urls', $purge_urls, true );
|
||||
|
||||
if ( is_array( $purge_urls ) && ! empty( $purge_urls ) ) {
|
||||
|
||||
foreach ( $purge_urls as $purge_url ) {
|
||||
|
||||
$purge_url = trim( $purge_url );
|
||||
|
||||
if ( strpos( $purge_url, '*' ) === false ) {
|
||||
|
||||
$purge_url = $_url_purge_base . $purge_url;
|
||||
$status = $this->delete_single_key( $purge_url );
|
||||
if ( $status ) {
|
||||
$this->log( '- Purge URL | ' . $purge_url );
|
||||
} else {
|
||||
$this->log( '- Not Found | ' . $purge_url, 'ERROR' );
|
||||
}
|
||||
} else {
|
||||
|
||||
$purge_url = $_url_purge_base . $purge_url;
|
||||
$status = $this->delete_keys_by_wildcard( $purge_url );
|
||||
|
||||
if ( $status ) {
|
||||
$this->log( '- Purge Wild Card URL | ' . $purge_url . ' | ' . $status . ' url purged' );
|
||||
} else {
|
||||
$this->log( '- Not Found | ' . $purge_url, 'ERROR' );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Single Key Delete Example
|
||||
* e.g. $key can be nginx-cache:httpGETexample.com/
|
||||
*
|
||||
* @param string $key Key to delete cache.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function delete_single_key( $key ) {
|
||||
|
||||
try {
|
||||
return $this->redis_object->executeRaw( array( 'DEL', $key ) );
|
||||
} catch ( Exception $e ) {
|
||||
$this->log( $e->getMessage(), 'ERROR' );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete Keys by wildcard.
|
||||
* e.g. $key can be nginx-cache:httpGETexample.com*
|
||||
*
|
||||
* Lua Script block to delete multiple keys using wildcard
|
||||
* Script will return count i.e. number of keys deleted
|
||||
* if return value is 0, that means no matches were found
|
||||
*
|
||||
* Call redis eval and return value from lua script
|
||||
*
|
||||
* @param string $pattern Pattern.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function delete_keys_by_wildcard( $pattern ) {
|
||||
|
||||
// Lua Script.
|
||||
$lua = <<<LUA
|
||||
local k = 0
|
||||
for i, name in ipairs(redis.call('KEYS', KEYS[1]))
|
||||
do
|
||||
redis.call('DEL', name)
|
||||
k = k+1
|
||||
end
|
||||
return k
|
||||
LUA;
|
||||
|
||||
try {
|
||||
return $this->redis_object->eval( $lua, 1, $pattern );
|
||||
} catch ( Exception $e ) {
|
||||
$this->log( $e->getMessage(), 'ERROR' );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
1262
wp/wp-content/plugins/nginx-helper/admin/class-purger.php
Normal file
1262
wp/wp-content/plugins/nginx-helper/admin/class-purger.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,105 @@
|
||||
/**
|
||||
* All of the CSS for your admin-specific functionality should be
|
||||
* included in this file.
|
||||
*/
|
||||
|
||||
.clearfix {
|
||||
*zoom: 1;
|
||||
}
|
||||
.clearfix:before,
|
||||
.clearfix:after {
|
||||
content: " ";
|
||||
display: table;
|
||||
}
|
||||
.clearfix:after {
|
||||
clear: both;
|
||||
}
|
||||
h4 {
|
||||
margin: 0;
|
||||
}
|
||||
.form-table th,
|
||||
.form-wrap label {
|
||||
vertical-align: middle;
|
||||
}
|
||||
table.rtnginx-table {
|
||||
border-bottom: 1px solid #EEE;
|
||||
}
|
||||
table.rtnginx-table:last-child {
|
||||
border-bottom: 0;
|
||||
}
|
||||
.rtnginx-table p.error {
|
||||
color: red;
|
||||
}
|
||||
pre#map {
|
||||
background: #e5e5e5 none;
|
||||
border-radius: 10px;
|
||||
padding: 10px;
|
||||
}
|
||||
.wrap h2.rt_option_title {
|
||||
background: url(../icons/nginx-icon-32x32.png) 0 6px no-repeat rgba(0, 0, 0, 0);
|
||||
padding-left: 40px;
|
||||
}
|
||||
#poststuff h2 {
|
||||
padding: 0 0 0 10px;
|
||||
margin-top: 0;
|
||||
}
|
||||
form#purgeall .button-primary {
|
||||
margin-bottom: 20px;
|
||||
box-shadow: inset 0 -2px rgba(0, 0, 0, 0.14);
|
||||
padding: 15px 30px;
|
||||
font-size: 1rem;
|
||||
border: 0;
|
||||
border-radius: 5px;
|
||||
color: #FFF;
|
||||
background: #DD3D36;
|
||||
height: auto;
|
||||
}
|
||||
form#purgeall .button-primary:hover,
|
||||
form#purgeall .button-primary:focus {
|
||||
background: #d52c24;
|
||||
}
|
||||
.nh-aligncenter {
|
||||
display: block;
|
||||
text-align: center;
|
||||
line-height: 2;
|
||||
}
|
||||
#latest_news .inside ul,
|
||||
#useful-links .inside ul {
|
||||
margin: 0 0 0 12px;
|
||||
}
|
||||
#latest_news .inside ul li,
|
||||
#useful-links .inside ul li {
|
||||
list-style: square;
|
||||
padding: 0 0 7px;
|
||||
}
|
||||
#social .inside a {
|
||||
background-color: #666;
|
||||
color: #FFF;
|
||||
display: inline-block;
|
||||
height: 30px;
|
||||
font-size: 1.25rem;
|
||||
line-height: 30px;
|
||||
margin: 10px 20px 0 0;
|
||||
overflow: hidden;
|
||||
padding: 0;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
width: 30px;
|
||||
-webkit-border-radius: 1000px;
|
||||
-moz-border-radius: 1000px;
|
||||
border-radius: 1000px;
|
||||
}
|
||||
|
||||
#social .inside .nginx-helper-facebook:hover {
|
||||
background-color: #537BBD;
|
||||
}
|
||||
#social .inside .nginx-helper-twitter:hover {
|
||||
background-color: #40BFF5;
|
||||
}
|
||||
|
||||
.rt-purge_url { width: 100%; }
|
||||
|
||||
.enable-logging-message {
|
||||
font-size: 13px;
|
||||
margin-left: 23px;
|
||||
}
|
||||
34
wp/wp-content/plugins/nginx-helper/admin/icons/config.json
Normal file
34
wp/wp-content/plugins/nginx-helper/admin/icons/config.json
Normal file
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "nginx-fontello",
|
||||
"css_prefix_text": "nginx-helper-",
|
||||
"css_use_suffix": false,
|
||||
"hinting": true,
|
||||
"units_per_em": 1000,
|
||||
"ascent": 850,
|
||||
"glyphs": [
|
||||
{
|
||||
"uid": "72b1277834cba5b7944b0a6cac7ddb0d",
|
||||
"css": "rss",
|
||||
"code": 59395,
|
||||
"src": "fontawesome"
|
||||
},
|
||||
{
|
||||
"uid": "627abcdb627cb1789e009c08e2678ef9",
|
||||
"css": "twitter",
|
||||
"code": 59394,
|
||||
"src": "fontawesome"
|
||||
},
|
||||
{
|
||||
"uid": "bc50457410acf467b8b5721240768742",
|
||||
"css": "facebook",
|
||||
"code": 59393,
|
||||
"src": "entypo"
|
||||
},
|
||||
{
|
||||
"uid": "b945f4ac2439565661e8e4878e35d379",
|
||||
"css": "gplus",
|
||||
"code": 59392,
|
||||
"src": "entypo"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
@font-face {
|
||||
font-family: 'nginx-fontello';
|
||||
src: url('../font/nginx-fontello.eot?7388141');
|
||||
src: url('../font/nginx-fontello.eot?7388141#iefix') format('embedded-opentype'),
|
||||
url('../font/nginx-fontello.woff?7388141') format('woff'),
|
||||
url('../font/nginx-fontello.ttf?7388141') format('truetype'),
|
||||
url('../font/nginx-fontello.svg?7388141#nginx-fontello') format('svg');
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
/* Chrome hack: SVG is rendered more smooth in Windozze. 100% magic, uncomment if you need it. */
|
||||
/* Note, that will break hinting! In other OS-es font will be not as sharp as it could be */
|
||||
/* // phpcs:ignore Squiz.PHP.CommentedOutCode.Found
|
||||
@media screen and (-webkit-min-device-pixel-ratio:0) {
|
||||
@font-face {
|
||||
font-family: 'nginx-fontello';
|
||||
src: url('../font/nginx-fontello.svg?7388141#nginx-fontello') format('svg');
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
[class^="nginx-helper-"]:before, [class*=" nginx-helper-"]:before {
|
||||
font-family: "nginx-fontello";
|
||||
font-style: normal;
|
||||
font-weight: normal;
|
||||
speak: none;
|
||||
|
||||
display: inline-block;
|
||||
text-decoration: inherit;
|
||||
width: 1em;
|
||||
margin-right: .2em;
|
||||
text-align: center;
|
||||
/* opacity: .8; */
|
||||
|
||||
/* For safety - reset parent styles, that can break glyph codes*/
|
||||
font-variant: normal;
|
||||
text-transform: none;
|
||||
|
||||
/* fix buttons height, for twitter bootstrap */
|
||||
line-height: 1em;
|
||||
|
||||
/* Animation center compensation - margins should be symmetric */
|
||||
/* remove if not needed */
|
||||
margin-left: .2em;
|
||||
|
||||
/* you can be more comfortable with increased icons size */
|
||||
/* font-size: 120%; */
|
||||
|
||||
/* Uncomment for 3D effect */
|
||||
/* text-shadow: 1px 1px 1px rgba(127, 127, 127, 0.3); */
|
||||
}
|
||||
|
||||
.nginx-helper-twitter:before { content: '\e802'; } /* '' */
|
||||
.nginx-helper-facebook:before { content: '\e801'; } /* '' */
|
||||
Binary file not shown.
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg xmlns="http://www.w3.org/2000/svg">
|
||||
<metadata>Copyright (C) 2013 by original authors @ fontello.com</metadata>
|
||||
<defs>
|
||||
<font id="nginx-fontello" horiz-adv-x="1000" >
|
||||
<font-face font-family="nginx-fontello" font-weight="400" font-stretch="normal" units-per-em="1000" ascent="850" descent="-150" />
|
||||
<missing-glyph horiz-adv-x="1000" />
|
||||
<glyph glyph-name="rss" unicode="" d="m214 100q0-45-31-76t-76-31t-76 31t-31 76t31 76t76 31t76-31t31-76z m286-69q1-15-9-26q-11-12-27-12h-75q-14 0-24 9t-11 23q-12 128-103 219t-219 103q-14 1-23 11t-9 24v75q0 16 12 26q9 10 24 10h3q89-7 170-45t145-101q63-63 101-145t45-171z m286-1q1-15-10-26q-10-11-26-11h-80q-14 0-25 10t-11 23q-6 120-56 228t-129 188t-188 129t-227 57q-14 0-24 11t-10 24v80q0 15 11 26q10 10 25 10h1q147-8 280-67t238-164q104-104 164-238t67-280z" horiz-adv-x="785.7" />
|
||||
<glyph glyph-name="twitter" unicode="" d="m904 622q-37-54-90-93q0-8 0-23q0-73-21-145t-64-139t-103-117t-144-82t-181-30q-151 0-276 81q19-3 43-3q126 0 224 77q-59 2-105 36t-64 89q19-2 34-2q24 0 48 6q-63 13-104 62t-41 115v2q38-21 82-23q-37 25-59 64t-22 86q0 49 25 91q68-83 164-133t208-55q-5 21-5 41q0 75 53 127t127 53q79 0 132-57q61 12 114 44q-20-64-79-100q52 6 104 28z" horiz-adv-x="928.6" />
|
||||
<glyph glyph-name="facebook" unicode="" d="m500 644l-142 0q-14 0-25-15t-11-37l0-102l178 0l0-148l-178 0l0-442l-170 0l0 442l-152 0l0 148l152 0l0 86q0 94 59 159t147 65l142 0l0-156z" horiz-adv-x="500" />
|
||||
<glyph glyph-name="gplus" unicode="" d="m48 572q0 58 25 102t56 65t69 34t56 15t26 2l230 0l0-4q0-22-78-36q-28 0-38-6q40-20 54-56t14-96q0-102-68-158q-38-38-38-54q0-18 50-64q104-90 104-178q0-140-116-194q-68-34-150-34l-4 0l-4 2q-2-2-4-2q-24 0-54 5t-75 21t-74 57t-29 103q0 60 32 101t83 57t88 22t71 6l2 0q-16 22-24 47t-8 39l2 14l-14 0q-64 0-110 30q-74 44-74 160z m370-452q-4 52-43 84t-103 32l-16 0q-64-2-114-46q-46-42-42-94t53-80t119-24q68 4 109 40t37 88z m-60 500q-30 108-122 108q-12 0-20-2q-40-12-58-62q-16-50-2-106q14-52 47-85t71-33q12 0 18 2q42 12 63 65t3 113z m388-174l150 0l0-94l-150 0l0-150l-94 0l0 150l-150 0l0 94l150 0l0 150l94 0l0-150z" horiz-adv-x="896" />
|
||||
</font>
|
||||
</defs>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.2 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 3.9 KiB |
8
wp/wp-content/plugins/nginx-helper/admin/index.php
Normal file
8
wp/wp-content/plugins/nginx-helper/admin/index.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Silence is golden.
|
||||
*
|
||||
* @package nginx-helper
|
||||
*/
|
||||
|
||||
// Silence.
|
||||
@@ -0,0 +1,117 @@
|
||||
/**
|
||||
* File to add JavaScript for nginx-helper.
|
||||
*
|
||||
* @package nginx-helper
|
||||
*/
|
||||
|
||||
(function ($) {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* All of the code for your admin-specific JavaScript source
|
||||
* should reside in this file.
|
||||
*
|
||||
* Note that this assume you're going to use jQuery, so it prepares
|
||||
* the $ function reference to be used within the scope of this
|
||||
* function.
|
||||
*
|
||||
* From here, you're able to define handlers for when the DOM is
|
||||
* ready:
|
||||
*
|
||||
* $(function() {
|
||||
*
|
||||
* });
|
||||
*
|
||||
* Or when the window is loaded:
|
||||
*
|
||||
* $( window ).load(function() {
|
||||
*
|
||||
* });
|
||||
*
|
||||
* ...and so on.
|
||||
*
|
||||
* Remember that ideally, we should not attach any more than a single DOM-ready or window-load handler
|
||||
* for any particular page. Though other scripts in WordPress core, other plugins, and other themes may
|
||||
* be doing this, we should try to minimize doing that in our own work.
|
||||
*/
|
||||
$(
|
||||
function () {
|
||||
|
||||
var news_section = jQuery( '#latest_news' );
|
||||
|
||||
if ( news_section.length > 0 ) {
|
||||
|
||||
var args = {
|
||||
'action': 'rt_get_feeds'
|
||||
};
|
||||
|
||||
jQuery.get(
|
||||
ajaxurl,
|
||||
args,
|
||||
function( data ) {
|
||||
/**
|
||||
* Received markup is safe and escaped appropriately.
|
||||
*
|
||||
* File: admin/class-nginx-helper-admin.php
|
||||
* Method: nginx_helper_get_feeds();
|
||||
*/
|
||||
|
||||
// phpcs:ignore -- WordPressVIPMinimum.JS.HTMLExecutingFunctions.append
|
||||
news_section.find( '.inside' ).empty().append( data );
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
jQuery( "form#purgeall a" ).click(
|
||||
function (e) {
|
||||
|
||||
if ( confirm( nginx_helper.purge_confirm_string ) === true ) {
|
||||
// Continue submitting form.
|
||||
} else {
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* Show OR Hide options on option checkbox
|
||||
*
|
||||
* @param {type} selector Selector of Checkbox and PostBox
|
||||
*/
|
||||
function nginx_show_option( selector ) {
|
||||
|
||||
jQuery( '#' + selector ).on(
|
||||
'change',
|
||||
function () {
|
||||
|
||||
if ( jQuery( this ).is( ':checked' ) ) {
|
||||
|
||||
jQuery( '.' + selector ).show();
|
||||
|
||||
if ( 'cache_method_redis' === selector ) {
|
||||
jQuery( '.cache_method_fastcgi' ).hide();
|
||||
} else if ( selector === 'cache_method_fastcgi' ) {
|
||||
jQuery( '.cache_method_redis' ).hide();
|
||||
}
|
||||
|
||||
} else {
|
||||
jQuery( '.' + selector ).hide();
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/* Function call with parameter */
|
||||
nginx_show_option( 'cache_method_fastcgi' );
|
||||
nginx_show_option( 'cache_method_redis' );
|
||||
nginx_show_option( 'enable_map' );
|
||||
nginx_show_option( 'enable_log' );
|
||||
nginx_show_option( 'enable_purge' );
|
||||
|
||||
}
|
||||
);
|
||||
})( jQuery );
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* Provide a admin area view for the plugin
|
||||
*
|
||||
* This file is used to markup the admin-facing aspects of the plugin.
|
||||
*
|
||||
* @link http://example.com
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @package nginx-helper
|
||||
* @subpackage nginx-helper/admin/partials
|
||||
*/
|
||||
|
||||
global $pagenow;
|
||||
?>
|
||||
|
||||
<!-- This file should primarily consist of HTML with a little bit of PHP. -->
|
||||
|
||||
<div class="wrap rt-nginx-wrapper">
|
||||
<h2 class="rt_option_title">
|
||||
<?php esc_html_e( 'Nginx Settings', 'nginx-helper' ); ?>
|
||||
</h2>
|
||||
<div id="poststuff">
|
||||
<div id="post-body" class="metabox-holder columns-2">
|
||||
<div id="post-body-content">
|
||||
<?php
|
||||
/* Show settinhs tabs */
|
||||
$current_tab = ( isset( $_GET['tab'] ) ? wp_strip_all_tags( $_GET['tab'] ) : '' );
|
||||
$current_setting_tab = ( ! empty( $current_tab ) ) ? $current_tab : 'general';
|
||||
|
||||
echo '<h2 class="nav-tab-wrapper">';
|
||||
foreach ( $this->settings_tabs as $setting_tab => $setting_name ) {
|
||||
|
||||
$class = ( $setting_tab === $current_setting_tab ) ? ' nav-tab-active' : '';
|
||||
printf(
|
||||
'<a class="%s" href="%s">%s</a>',
|
||||
esc_attr( 'nav-tab' . $class ),
|
||||
esc_url( '?page=nginx&tab=' . $setting_name['menu_slug'] ),
|
||||
esc_html( $setting_name['menu_title'] )
|
||||
);
|
||||
}
|
||||
echo '</h2>';
|
||||
|
||||
switch ( $current_setting_tab ) {
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
?>
|
||||
</div> <!-- End of #post-body-content -->
|
||||
<div id="postbox-container-1" class="postbox-container">
|
||||
<?php
|
||||
require plugin_dir_path( __FILE__ ) . 'nginx-helper-sidebar-display.php';
|
||||
?>
|
||||
</div> <!-- End of #postbox-container-1 -->
|
||||
</div> <!-- End of #post-body -->
|
||||
</div> <!-- End of #poststuff -->
|
||||
</div> <!-- End of .wrap .rt-nginx-wrapper -->
|
||||
@@ -0,0 +1,822 @@
|
||||
<?php
|
||||
/**
|
||||
* Display general options of the plugin.
|
||||
*
|
||||
* This file is used to markup the admin-facing aspects of the plugin.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @package nginx-helper
|
||||
* @subpackage nginx-helper/admin/partials
|
||||
*/
|
||||
|
||||
global $nginx_helper_admin;
|
||||
|
||||
$error_log_filesize = false;
|
||||
|
||||
$args = array(
|
||||
'enable_purge',
|
||||
'enable_stamp',
|
||||
'purge_method',
|
||||
'is_submit',
|
||||
'redis_hostname',
|
||||
'redis_port',
|
||||
'redis_prefix',
|
||||
'purge_homepage_on_edit',
|
||||
'purge_homepage_on_del',
|
||||
'purge_url',
|
||||
'log_level',
|
||||
'log_filesize',
|
||||
'smart_http_expire_save',
|
||||
'cache_method',
|
||||
'enable_map',
|
||||
'enable_log',
|
||||
'purge_archive_on_edit',
|
||||
'purge_archive_on_del',
|
||||
'purge_archive_on_new_comment',
|
||||
'purge_archive_on_deleted_comment',
|
||||
'purge_page_on_mod',
|
||||
'purge_page_on_new_comment',
|
||||
'purge_page_on_deleted_comment',
|
||||
'purge_feeds',
|
||||
'smart_http_expire_form_nonce',
|
||||
);
|
||||
|
||||
$all_inputs = array();
|
||||
|
||||
foreach ( $args as $val ) {
|
||||
if ( isset( $_POST[ $val ] ) ) {
|
||||
$all_inputs[ $val ] = wp_strip_all_tags( $_POST[ $val ] );
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $all_inputs['smart_http_expire_save'] ) && wp_verify_nonce( $all_inputs['smart_http_expire_form_nonce'], 'smart-http-expire-form-nonce' ) ) {
|
||||
unset( $all_inputs['smart_http_expire_save'] );
|
||||
unset( $all_inputs['is_submit'] );
|
||||
|
||||
$nginx_settings = wp_parse_args(
|
||||
$all_inputs,
|
||||
$nginx_helper_admin->nginx_helper_default_settings()
|
||||
);
|
||||
|
||||
$site_options = get_site_option( 'rt_wp_nginx_helper_options', array() );
|
||||
|
||||
foreach ( $nginx_helper_admin->nginx_helper_default_settings() as $default_setting_field => $default_setting_value ) {
|
||||
|
||||
// Uncheck checkbox fields whose default value is `1` but user has unchecked.
|
||||
if ( 1 === $default_setting_value && isset( $site_options[ $default_setting_field ] ) && empty( $all_inputs[ $default_setting_field ] ) ) {
|
||||
|
||||
$nginx_settings[ $default_setting_field ] = 0;
|
||||
|
||||
}
|
||||
|
||||
// Populate the setting field with default value when it is empty.
|
||||
if ( '' === $nginx_settings[ $default_setting_field ] ) {
|
||||
|
||||
$nginx_settings[ $default_setting_field ] = $default_setting_value;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ( ( ! is_numeric( $nginx_settings['log_filesize'] ) ) || ( empty( $nginx_settings['log_filesize'] ) ) ) {
|
||||
$error_log_filesize = __( 'Log file size must be a number.', 'nginx-helper' );
|
||||
unset( $nginx_settings['log_filesize'] );
|
||||
}
|
||||
|
||||
if ( $nginx_settings['enable_map'] ) {
|
||||
$nginx_helper_admin->update_map();
|
||||
}
|
||||
|
||||
update_site_option( 'rt_wp_nginx_helper_options', $nginx_settings );
|
||||
|
||||
echo '<div class="updated"><p>' . esc_html__( 'Settings saved.', 'nginx-helper' ) . '</p></div>';
|
||||
|
||||
}
|
||||
|
||||
$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();
|
||||
|
||||
/**
|
||||
* Get setting url for single multiple with subdomain OR multiple with subdirectory site.
|
||||
*/
|
||||
$nginx_setting_link = '#';
|
||||
if ( is_multisite() ) {
|
||||
if ( SUBDOMAIN_INSTALL === false ) {
|
||||
$nginx_setting_link = 'https://easyengine.io/wordpress-nginx/tutorials/multisite/subdirectories/fastcgi-cache-with-purging/';
|
||||
} else {
|
||||
$nginx_setting_link = 'https://easyengine.io/wordpress-nginx/tutorials/multisite/subdomains/fastcgi-cache-with-purging/';
|
||||
}
|
||||
} else {
|
||||
$nginx_setting_link = 'https://easyengine.io/wordpress-nginx/tutorials/single-site/fastcgi-cache-with-purging/';
|
||||
}
|
||||
?>
|
||||
|
||||
<!-- Forms containing nginx helper settings options. -->
|
||||
<form id="post_form" method="post" action="#" name="smart_http_expire_form" class="clearfix">
|
||||
<div class="postbox">
|
||||
<h3 class="hndle">
|
||||
<span><?php esc_html_e( 'Purging Options', 'nginx-helper' ); ?></span>
|
||||
</h3>
|
||||
<div class="inside">
|
||||
<table class="form-table">
|
||||
<tr valign="top">
|
||||
<td>
|
||||
<input type="checkbox" value="1" id="enable_purge" name="enable_purge" <?php checked( $nginx_helper_settings['enable_purge'], 1 ); ?> />
|
||||
<label for="enable_purge"><?php esc_html_e( 'Enable Purge', 'nginx-helper' ); ?></label>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div> <!-- End of .inside -->
|
||||
</div>
|
||||
|
||||
<?php if ( ! ( ! is_network_admin() && is_multisite() ) ) { ?>
|
||||
<div class="postbox enable_purge"<?php echo ( empty( $nginx_helper_settings['enable_purge'] ) ) ? ' style="display: none;"' : ''; ?>>
|
||||
<h3 class="hndle">
|
||||
<span><?php esc_html_e( 'Caching Method', 'nginx-helper' ); ?></span>
|
||||
</h3>
|
||||
<div class="inside">
|
||||
<input type="hidden" name="is_submit" value="1" />
|
||||
<table class="form-table">
|
||||
<tr valign="top">
|
||||
<td>
|
||||
<input type="radio" value="enable_fastcgi" id="cache_method_fastcgi" name="cache_method" <?php echo checked( $nginx_helper_settings['cache_method'], 'enable_fastcgi' ); ?> />
|
||||
<label for="cache_method_fastcgi">
|
||||
<?php
|
||||
printf(
|
||||
'%s (<a target="_blank" href="%s" title="%s">%s</a>)',
|
||||
esc_html__( 'nginx Fastcgi cache', 'nginx-helper' ),
|
||||
esc_url( $nginx_setting_link ),
|
||||
esc_attr__( 'External settings for nginx', 'nginx-helper' ),
|
||||
esc_html__( 'requires external settings for nginx', 'nginx-helper' )
|
||||
);
|
||||
?>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td>
|
||||
<input type="radio" value="enable_redis" id="cache_method_redis" name="cache_method" <?php echo checked( $nginx_helper_settings['cache_method'], 'enable_redis' ); ?> />
|
||||
<label for="cache_method_redis">
|
||||
<?php printf( esc_html__( 'Redis cache', 'nginx-helper' ) ); ?>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div> <!-- End of .inside -->
|
||||
</div>
|
||||
<div class="enable_purge">
|
||||
<div class="postbox cache_method_fastcgi" <?php echo ( ! empty( $nginx_helper_settings['enable_purge'] ) && 'enable_fastcgi' === $nginx_helper_settings['cache_method'] ) ? '' : 'style="display: none;"'; ?> >
|
||||
<h3 class="hndle">
|
||||
<span><?php esc_html_e( 'Purge Method', 'nginx-helper' ); ?></span>
|
||||
</h3>
|
||||
<div class="inside">
|
||||
<table class="form-table rtnginx-table">
|
||||
<tr valign="top">
|
||||
<td>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text">
|
||||
<span>
|
||||
|
||||
<?php esc_html_e( 'when a post/page/custom post is published.', 'nginx-helper' ); ?>
|
||||
</span>
|
||||
</legend>
|
||||
<label for="purge_method_get_request">
|
||||
<input type="radio" value="get_request" id="purge_method_get_request" name="purge_method" <?php checked( $nginx_helper_settings['purge_method'], 'get_request' ); ?>>
|
||||
|
||||
<?php
|
||||
echo wp_kses(
|
||||
sprintf(
|
||||
'%1$s <strong>PURGE/url</strong> %2$s',
|
||||
esc_html__( 'Using a GET request to', 'nginx-helper' ),
|
||||
esc_html__( '(Default option)', 'nginx-helper' )
|
||||
),
|
||||
array( 'strong' => array() )
|
||||
);
|
||||
?>
|
||||
<br />
|
||||
<small>
|
||||
<?php
|
||||
echo wp_kses(
|
||||
sprintf(
|
||||
// translators: %s Nginx cache purge module link.
|
||||
__( 'Uses the %s module.', 'nginx-helper' ),
|
||||
'<strong><a href="https://github.com/FRiCKLE/ngx_cache_purge">ngx_cache_purge</a></strong>'
|
||||
),
|
||||
array(
|
||||
'strong' => array(),
|
||||
'a' => array(
|
||||
'href' => array(),
|
||||
),
|
||||
)
|
||||
);
|
||||
?>
|
||||
</small>
|
||||
</label>
|
||||
<br />
|
||||
<label for="purge_method_unlink_files">
|
||||
<input type="radio" value="unlink_files" id="purge_method_unlink_files" name="purge_method" <?php checked( $nginx_helper_settings['purge_method'], 'unlink_files' ); ?>>
|
||||
|
||||
<?php
|
||||
esc_html_e( 'Delete local server cache files', 'nginx-helper' );
|
||||
?>
|
||||
<br />
|
||||
<small>
|
||||
<?php
|
||||
echo wp_kses(
|
||||
__( 'Checks for matching cache file in <strong>RT_WP_NGINX_HELPER_CACHE_PATH</strong>. Does not require any other modules. Requires that the cache be stored on the same server as WordPress. You must also be using the default nginx cache options (levels=1:2) and (fastcgi_cache_key "$scheme$request_method$host$request_uri").', 'nginx-helper' ),
|
||||
array( 'strong' => array() )
|
||||
);
|
||||
?>
|
||||
</small>
|
||||
</label>
|
||||
<br />
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div> <!-- End of .inside -->
|
||||
</div>
|
||||
<div class="postbox cache_method_redis"<?php echo ( ! empty( $nginx_helper_settings['enable_purge'] ) && 'enable_redis' === $nginx_helper_settings['cache_method'] ) ? '' : ' style="display: none;"'; ?>>
|
||||
<h3 class="hndle">
|
||||
<span><?php esc_html_e( 'Redis Settings', 'nginx-helper' ); ?></span>
|
||||
</h3>
|
||||
<div class="inside">
|
||||
<table class="form-table rtnginx-table">
|
||||
<tr>
|
||||
<th><label for="redis_hostname"><?php esc_html_e( 'Hostname', 'nginx-helper' ); ?></label></th>
|
||||
<td>
|
||||
<input id="redis_hostname" class="medium-text" type="text" name="redis_hostname" value="<?php echo esc_attr( $nginx_helper_settings['redis_hostname'] ); ?>" <?php echo ( $nginx_helper_settings['redis_enabled_by_constant'] ) ? 'readonly="readonly"' : ''; ?> />
|
||||
<?php
|
||||
if ( $nginx_helper_settings['redis_enabled_by_constant'] ) {
|
||||
|
||||
echo '<p class="description">';
|
||||
esc_html_e( 'Overridden by constant variables.', 'nginx-helper' );
|
||||
echo '</p>';
|
||||
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><label for="redis_port"><?php esc_html_e( 'Port', 'nginx-helper' ); ?></label></th>
|
||||
<td>
|
||||
<input id="redis_port" class="medium-text" type="text" name="redis_port" value="<?php echo esc_attr( $nginx_helper_settings['redis_port'] ); ?>" <?php echo ( $nginx_helper_settings['redis_enabled_by_constant'] ) ? 'readonly="readonly"' : ''; ?> />
|
||||
<?php
|
||||
if ( $nginx_helper_settings['redis_enabled_by_constant'] ) {
|
||||
|
||||
echo '<p class="description">';
|
||||
esc_html_e( 'Overridden by constant variables.', 'nginx-helper' );
|
||||
echo '</p>';
|
||||
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><label for="redis_prefix"><?php esc_html_e( 'Prefix', 'nginx-helper' ); ?></label></th>
|
||||
<td>
|
||||
<input id="redis_prefix" class="medium-text" type="text" name="redis_prefix" value="<?php echo esc_attr( $nginx_helper_settings['redis_prefix'] ); ?>" <?php echo ( $nginx_helper_settings['redis_enabled_by_constant'] ) ? 'readonly="readonly"' : ''; ?> />
|
||||
<?php
|
||||
if ( $nginx_helper_settings['redis_enabled_by_constant'] ) {
|
||||
|
||||
echo '<p class="description">';
|
||||
esc_html_e( 'Overridden by constant variables.', 'nginx-helper' );
|
||||
echo '</p>';
|
||||
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div> <!-- End of .inside -->
|
||||
</div>
|
||||
</div>
|
||||
<div class="postbox enable_purge"<?php echo ( empty( $nginx_helper_settings['enable_purge'] ) ) ? ' style="display: none;"' : ''; ?>>
|
||||
<h3 class="hndle">
|
||||
<span><?php esc_html_e( 'Purging Conditions', 'nginx-helper' ); ?></span>
|
||||
</h3>
|
||||
<div class="inside">
|
||||
<table class="form-table rtnginx-table">
|
||||
<tr valign="top">
|
||||
<th scope="row"><h4><?php esc_html_e( 'Purge Homepage:', 'nginx-helper' ); ?></h4></th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text">
|
||||
<span>
|
||||
|
||||
<?php
|
||||
esc_html_e( 'when a post/page/custom post is modified or added.', 'nginx-helper' );
|
||||
?>
|
||||
</span>
|
||||
</legend>
|
||||
<label for="purge_homepage_on_edit">
|
||||
<input type="checkbox" value="1" id="purge_homepage_on_edit" name="purge_homepage_on_edit" <?php checked( $nginx_helper_settings['purge_homepage_on_edit'], 1 ); ?> />
|
||||
|
||||
<?php
|
||||
echo wp_kses(
|
||||
__( 'when a <strong>post</strong> (or page/custom post) is <strong>modified</strong> or <strong>added</strong>.', 'nginx-helper' ),
|
||||
array( 'strong' => array() )
|
||||
);
|
||||
?>
|
||||
</label>
|
||||
<br />
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text">
|
||||
<span>
|
||||
|
||||
<?php
|
||||
esc_html_e( 'when an existing post/page/custom post is modified.', 'nginx-helper' );
|
||||
?>
|
||||
</span>
|
||||
</legend>
|
||||
<label for="purge_homepage_on_del">
|
||||
<input type="checkbox" value="1" id="purge_homepage_on_del" name="purge_homepage_on_del" <?php checked( $nginx_helper_settings['purge_homepage_on_del'], 1 ); ?> />
|
||||
|
||||
<?php
|
||||
echo wp_kses(
|
||||
__( 'when a <strong>published post</strong> (or page/custom post) is <strong>trashed</strong>', 'nginx-helper' ),
|
||||
array( 'strong' => array() )
|
||||
);
|
||||
?>
|
||||
</label>
|
||||
<br />
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table class="form-table rtnginx-table">
|
||||
<tr valign="top">
|
||||
<th scope="row">
|
||||
<h4>
|
||||
<?php esc_html_e( 'Purge Post/Page/Custom Post Type:', 'nginx-helper' ); ?>
|
||||
</h4>
|
||||
</th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text">
|
||||
<span>
|
||||
<?php
|
||||
esc_html_e( 'when a post/page/custom post is published.', 'nginx-helper' );
|
||||
?>
|
||||
</span>
|
||||
</legend>
|
||||
<label for="purge_page_on_mod">
|
||||
<input type="checkbox" value="1" id="purge_page_on_mod" name="purge_page_on_mod" <?php checked( $nginx_helper_settings['purge_page_on_mod'], 1 ); ?>>
|
||||
|
||||
<?php
|
||||
echo wp_kses(
|
||||
__( 'when a <strong>post</strong> is <strong>published</strong>.', 'nginx-helper' ),
|
||||
array( 'strong' => array() )
|
||||
);
|
||||
?>
|
||||
</label>
|
||||
<br />
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text">
|
||||
<span>
|
||||
|
||||
<?php
|
||||
esc_html_e( 'when a comment is approved/published.', 'nginx-helper' );
|
||||
?>
|
||||
</span>
|
||||
</legend>
|
||||
<label for="purge_page_on_new_comment">
|
||||
<input type="checkbox" value="1" id="purge_page_on_new_comment" name="purge_page_on_new_comment" <?php checked( $nginx_helper_settings['purge_page_on_new_comment'], 1 ); ?>>
|
||||
|
||||
<?php
|
||||
echo wp_kses(
|
||||
__( 'when a <strong>comment</strong> is <strong>approved/published</strong>.', 'nginx-helper' ),
|
||||
array( 'strong' => array() )
|
||||
);
|
||||
?>
|
||||
</label>
|
||||
<br />
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text">
|
||||
<span>
|
||||
|
||||
<?php
|
||||
esc_html_e( 'when a comment is unapproved/deleted.', 'nginx-helper' );
|
||||
?>
|
||||
</span>
|
||||
</legend>
|
||||
<label for="purge_page_on_deleted_comment">
|
||||
<input type="checkbox" value="1" id="purge_page_on_deleted_comment" name="purge_page_on_deleted_comment" <?php checked( $nginx_helper_settings['purge_page_on_deleted_comment'], 1 ); ?>>
|
||||
|
||||
<?php
|
||||
echo wp_kses(
|
||||
__( 'when a <strong>comment</strong> is <strong>unapproved/deleted</strong>.', 'nginx-helper' ),
|
||||
array( 'strong' => array() )
|
||||
);
|
||||
?>
|
||||
</label>
|
||||
<br />
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table class="form-table rtnginx-table">
|
||||
<tr valign="top">
|
||||
<th scope="row">
|
||||
<h4>
|
||||
<?php esc_html_e( 'Purge Archives:', 'nginx-helper' ); ?>
|
||||
</h4>
|
||||
<small><?php esc_html_e( '(date, category, tag, author, custom taxonomies)', 'nginx-helper' ); ?></small>
|
||||
</th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text">
|
||||
<span>
|
||||
|
||||
<?php
|
||||
esc_html_e( 'when an post/page/custom post is modified or added', 'nginx-helper' );
|
||||
?>
|
||||
</span>
|
||||
</legend>
|
||||
<label for="purge_archive_on_edit">
|
||||
<input type="checkbox" value="1" id="purge_archive_on_edit" name="purge_archive_on_edit" <?php checked( $nginx_helper_settings['purge_archive_on_edit'], 1 ); ?> />
|
||||
|
||||
<?php
|
||||
echo wp_kses(
|
||||
__( 'when a <strong>post</strong> (or page/custom post) is <strong>modified</strong> or <strong>added</strong>.', 'nginx-helper' ),
|
||||
array( 'strong' => array() )
|
||||
);
|
||||
?>
|
||||
</label>
|
||||
<br />
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text">
|
||||
<span>
|
||||
|
||||
<?php
|
||||
esc_html_e( 'when an existing post/page/custom post is trashed.', 'nginx-helper' );
|
||||
?>
|
||||
</span>
|
||||
</legend>
|
||||
<label for="purge_archive_on_del">
|
||||
<input type="checkbox" value="1" id="purge_archive_on_del" name="purge_archive_on_del"<?php checked( $nginx_helper_settings['purge_archive_on_del'], 1 ); ?> />
|
||||
|
||||
<?php
|
||||
echo wp_kses(
|
||||
__( 'when a <strong>published post</strong> (or page/custom post) is <strong>trashed</strong>.', 'nginx-helper' ),
|
||||
array( 'strong' => array() )
|
||||
);
|
||||
?>
|
||||
</label>
|
||||
<br />
|
||||
</fieldset>
|
||||
<br />
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text">
|
||||
<span>
|
||||
|
||||
<?php
|
||||
esc_html_e( 'when a comment is approved/published.', 'nginx-helper' );
|
||||
?>
|
||||
</span>
|
||||
</legend>
|
||||
<label for="purge_archive_on_new_comment">
|
||||
<input type="checkbox" value="1" id="purge_archive_on_new_comment" name="purge_archive_on_new_comment" <?php checked( $nginx_helper_settings['purge_archive_on_new_comment'], 1 ); ?> />
|
||||
|
||||
<?php
|
||||
echo wp_kses(
|
||||
__( 'when a <strong>comment</strong> is <strong>approved/published</strong>.', 'nginx-helper' ),
|
||||
array( 'strong' => array() )
|
||||
);
|
||||
?>
|
||||
</label>
|
||||
<br />
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text">
|
||||
<span>
|
||||
|
||||
<?php
|
||||
esc_html_e( 'when a comment is unapproved/deleted.', 'nginx-helper' );
|
||||
?>
|
||||
</span>
|
||||
</legend>
|
||||
<label for="purge_archive_on_deleted_comment">
|
||||
<input type="checkbox" value="1" id="purge_archive_on_deleted_comment" name="purge_archive_on_deleted_comment" <?php checked( $nginx_helper_settings['purge_archive_on_deleted_comment'], 1 ); ?> />
|
||||
|
||||
<?php
|
||||
echo wp_kses(
|
||||
__( 'when a <strong>comment</strong> is <strong>unapproved/deleted</strong>.', 'nginx-helper' ),
|
||||
array( 'strong' => array() )
|
||||
);
|
||||
?>
|
||||
</label>
|
||||
<br />
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table class="form-table rtnginx-table">
|
||||
<tr valign="top">
|
||||
<th scope="row">
|
||||
<h4>
|
||||
<?php esc_html_e( 'Purge Feeds:', 'nginx-helper' ); ?>
|
||||
</h4>
|
||||
</th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text">
|
||||
<span>
|
||||
|
||||
<?php
|
||||
esc_html_e( 'purge feeds', 'nginx-helper' );
|
||||
?>
|
||||
</span>
|
||||
</legend>
|
||||
<label for="purge_feeds">
|
||||
<input type="checkbox" value="1" id="purge_feeds" name="purge_feeds" <?php checked( $nginx_helper_settings['purge_feeds'], 1 ); ?> />
|
||||
|
||||
<?php
|
||||
echo wp_kses(
|
||||
__( 'purge <strong>feeds</strong> along with <strong>posts</strong> & <strong>pages</strong>.', 'nginx-helper' ),
|
||||
array( 'strong' => array() )
|
||||
);
|
||||
?>
|
||||
</label>
|
||||
<br />
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table class="form-table rtnginx-table">
|
||||
<tr valign="top">
|
||||
<th scope="row">
|
||||
<h4><?php esc_html_e( 'Custom Purge URL:', 'nginx-helper' ); ?></h4>
|
||||
</th>
|
||||
<td>
|
||||
<textarea rows="5"class="rt-purge_url" id="purge_url" name="purge_url"><?php echo esc_textarea( $nginx_helper_settings['purge_url'] ); ?></textarea>
|
||||
<p class="description">
|
||||
<?php
|
||||
esc_html_e( 'Add one URL per line. URL should not contain domain name.', 'nginx-helper' );
|
||||
echo '<br>';
|
||||
echo wp_kses(
|
||||
__( 'Eg: To purge http://example.com/sample-page/ add <strong>/sample-page/</strong> in above textarea.', 'nginx-helper' ),
|
||||
array( 'strong' => array() )
|
||||
);
|
||||
echo '<br>';
|
||||
esc_html_e( "'*' will only work with redis cache server.", 'nginx-helper' );
|
||||
?>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div> <!-- End of .inside -->
|
||||
</div>
|
||||
<div class="postbox">
|
||||
<h3 class="hndle">
|
||||
<span><?php esc_html_e( 'Debug Options', 'nginx-helper' ); ?></span>
|
||||
</h3>
|
||||
<div class="inside">
|
||||
<input type="hidden" name="is_submit" value="1" />
|
||||
<table class="form-table">
|
||||
<?php if ( is_network_admin() ) { ?>
|
||||
<tr valign="top">
|
||||
<td>
|
||||
<input type="checkbox" value="1" id="enable_map" name="enable_map" <?php checked( $nginx_helper_settings['enable_map'], 1 ); ?> />
|
||||
<label for="enable_map">
|
||||
<?php esc_html_e( 'Enable Nginx Map.', 'nginx-helper' ); ?>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
<tr valign="top">
|
||||
<td>
|
||||
<?php
|
||||
$is_checkbox_enabled = false;
|
||||
if ( 1 === (int) $nginx_helper_settings['enable_log'] ) {
|
||||
$is_checkbox_enabled = true;
|
||||
}
|
||||
?>
|
||||
<input
|
||||
type="checkbox" value="1" id="enable_log" name="enable_log"
|
||||
<?php checked( $nginx_helper_admin->is_nginx_log_enabled(), true ); ?>
|
||||
<?php echo esc_attr( $is_checkbox_enabled ? '' : ' disabled ' ); ?>
|
||||
/>
|
||||
<label for="enable_log">
|
||||
<?php esc_html_e( 'Enable Logging', 'nginx-helper' ); ?>
|
||||
<?php
|
||||
if ( ! $is_checkbox_enabled ) {
|
||||
|
||||
$setting_message_detail = [
|
||||
'status' => __( 'disable', 'nginx-helper' ),
|
||||
'value' => 'false',
|
||||
];
|
||||
|
||||
if ( ! $nginx_helper_admin->is_nginx_log_enabled() ) {
|
||||
$setting_message_detail = [
|
||||
'status' => __( 'enable', 'nginx-helper' ),
|
||||
'value' => 'true',
|
||||
];
|
||||
}
|
||||
|
||||
printf(
|
||||
'<p class="enable-logging-message">(<b>%1$s:</b> %2$s %3$s %4$s <b>NGINX_HELPER_LOG</b> constant %5$s <b>%6$s</b> %7$s <b>wp-config.php</b>)</p>',
|
||||
esc_html__( 'NOTE', 'nginx-helper' ),
|
||||
esc_html__( 'To', 'nginx-helper' ),
|
||||
esc_html( $setting_message_detail['status'] ),
|
||||
esc_html__( 'the logging feature, you must define', 'nginx-helper' ),
|
||||
esc_html__( 'as', 'nginx-helper' ),
|
||||
esc_html( $setting_message_detail['value'] ),
|
||||
esc_html__( 'in your', 'nginx-helper' )
|
||||
);
|
||||
}
|
||||
?>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td>
|
||||
<input type="checkbox" value="1" id="enable_stamp" name="enable_stamp" <?php checked( $nginx_helper_settings['enable_stamp'], 1 ); ?> />
|
||||
<label for="enable_stamp">
|
||||
<?php esc_html_e( 'Enable Nginx Timestamp in HTML', 'nginx-helper' ); ?>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div> <!-- End of .inside -->
|
||||
</div>
|
||||
<?php
|
||||
} // End of if.
|
||||
|
||||
if ( is_network_admin() ) {
|
||||
?>
|
||||
<div class="postbox enable_map"<?php echo ( empty( $nginx_helper_settings['enable_map'] ) ) ? ' style="display: none;"' : ''; ?>>
|
||||
<h3 class="hndle">
|
||||
<span><?php esc_html_e( 'Nginx Map', 'nginx-helper' ); ?></span>
|
||||
</h3>
|
||||
<div class="inside">
|
||||
<?php
|
||||
if ( ! is_writable( $log_path . 'map.conf' ) ) {
|
||||
?>
|
||||
<span class="error fade" style="display: block">
|
||||
<p>
|
||||
<?php
|
||||
esc_html_e( 'Can\'t write on map file.', 'nginx-helper' );
|
||||
echo '<br /><br />';
|
||||
echo wp_kses(
|
||||
sprintf(
|
||||
// translators: %s file url.
|
||||
__( 'Check you have write permission on <strong>%s</strong>', 'nginx-helper' ),
|
||||
esc_url( $log_path . 'map.conf' )
|
||||
),
|
||||
array( 'strong' => array() )
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</span>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<table class="form-table rtnginx-table">
|
||||
<tr>
|
||||
<th>
|
||||
<?php
|
||||
printf(
|
||||
'%1$s<br /><small>%2$s</small>',
|
||||
esc_html__( 'Nginx Map path to include in nginx settings', 'nginx-helper' ),
|
||||
esc_html__( '(recommended)', 'nginx-helper' )
|
||||
);
|
||||
?>
|
||||
</th>
|
||||
<td>
|
||||
<pre><?php echo esc_url( $log_path . 'map.conf' ); ?></pre>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>
|
||||
<?php
|
||||
printf(
|
||||
'%1$s<br />%2$s<br /><small>%3$s</small>',
|
||||
esc_html__( 'Or,', 'nginx-helper' ),
|
||||
esc_html__( 'Text to manually copy and paste in nginx settings', 'nginx-helper' ),
|
||||
esc_html__( '(if your network is small and new sites are not added frequently)', 'nginx-helper' )
|
||||
);
|
||||
?>
|
||||
</th>
|
||||
<td>
|
||||
<pre id="map">
|
||||
<?php echo esc_html( $nginx_helper_admin->get_map() ); ?>
|
||||
</pre>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div> <!-- End of .inside -->
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<div class="postbox enable_log"<?php echo ( ! $nginx_helper_admin->is_nginx_log_enabled() ) ? ' style="display: none;"' : ''; ?>>
|
||||
<h3 class="hndle">
|
||||
<span><?php esc_html_e( 'Logging Options', 'nginx-helper' ); ?></span>
|
||||
</h3>
|
||||
<div class="inside">
|
||||
<?php
|
||||
if ( ! is_dir( $log_path ) ) {
|
||||
mkdir( $log_path );
|
||||
}
|
||||
if ( is_writable( $log_path ) && ! file_exists( $log_path . 'nginx.log' ) ) {
|
||||
$log = fopen( $log_path . 'nginx.log', 'w' );
|
||||
fclose( $log );
|
||||
}
|
||||
if ( ! is_writable( $log_path . 'nginx.log' ) ) {
|
||||
?>
|
||||
<span class="error fade" style="display : block">
|
||||
<p>
|
||||
<?php
|
||||
esc_html_e( 'Can\'t write on log file.', 'nginx-helper' );
|
||||
echo '<br /><br />';
|
||||
echo wp_kses(
|
||||
sprintf(
|
||||
// translators: %s file url.
|
||||
__( 'Check you have write permission on <strong>%s</strong>', 'nginx-helper' ),
|
||||
esc_url( $log_path . 'nginx.log' )
|
||||
),
|
||||
array( 'strong' => array() )
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</span>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
<table class="form-table rtnginx-table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>
|
||||
<label for="rt_wp_nginx_helper_logs_path">
|
||||
<?php esc_html_e( 'Logs path', 'nginx-helper' ); ?>
|
||||
</label>
|
||||
</th>
|
||||
<td>
|
||||
<code>
|
||||
<?php echo esc_url( $log_path . 'nginx.log' ); ?>
|
||||
</code>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>
|
||||
<label for="rt_wp_nginx_helper_logs_link">
|
||||
<?php esc_html_e( 'View Log', 'nginx-helper' ); ?>
|
||||
</label>
|
||||
</th>
|
||||
<td>
|
||||
<a target="_blank" href="<?php echo esc_url( $log_url . 'nginx.log' ); ?>">
|
||||
<?php esc_html_e( 'Log', 'nginx-helper' ); ?>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>
|
||||
<label for="rt_wp_nginx_helper_log_level">
|
||||
<?php esc_html_e( 'Log level', 'nginx-helper' ); ?>
|
||||
</label>
|
||||
</th>
|
||||
<td>
|
||||
<select name="log_level">
|
||||
<option value="NONE" <?php selected( $nginx_helper_settings['log_level'], 'NONE' ); ?>> <?php esc_html_e( 'None', 'nginx-helper' ); ?> </option>
|
||||
<option value="INFO" <?php selected( $nginx_helper_settings['log_level'], 'INFO' ); ?>> <?php esc_html_e( 'Info', 'nginx-helper' ); ?> </option>
|
||||
<option value="WARNING" <?php selected( $nginx_helper_settings['log_level'], 'WARNING' ); ?>> <?php esc_html_e( 'Warning', 'nginx-helper' ); ?> </option>
|
||||
<option value="ERROR" <?php selected( $nginx_helper_settings['log_level'], 'ERROR' ); ?>> <?php esc_html_e( 'Error', 'nginx-helper' ); ?> </option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>
|
||||
<label for="log_filesize">
|
||||
<?php esc_html_e( 'Max log file size', 'nginx-helper' ); ?>
|
||||
</label>
|
||||
</th>
|
||||
<td>
|
||||
<input id="log_filesize" class="small-text" type="text" name="log_filesize" value="<?php echo esc_attr( $nginx_helper_settings['log_filesize'] ); ?>" />
|
||||
<?php
|
||||
esc_html_e( 'Mb', 'nginx-helper' );
|
||||
if ( $error_log_filesize ) {
|
||||
?>
|
||||
<p class="error fade" style="display: block;">
|
||||
<?php echo esc_html( $error_log_filesize ); ?>
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div> <!-- End of .inside -->
|
||||
</div>
|
||||
<input type="hidden" name="smart_http_expire_form_nonce" value="<?php echo esc_attr( wp_create_nonce( 'smart-http-expire-form-nonce' ) ); ?>" />
|
||||
<?php
|
||||
submit_button( __( 'Save All Changes', 'nginx-helper' ), 'primary large', 'smart_http_expire_save', true );
|
||||
?>
|
||||
</form><!-- End of #post_form -->
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/**
|
||||
* Display sidebar.
|
||||
*
|
||||
* This file is used to markup the admin-facing aspects of the plugin.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @package nginx-helper
|
||||
* @subpackage nginx-helper/admin/partials
|
||||
*/
|
||||
|
||||
$purge_url = add_query_arg(
|
||||
array(
|
||||
'nginx_helper_action' => 'purge',
|
||||
'nginx_helper_urls' => 'all',
|
||||
)
|
||||
);
|
||||
$nonced_url = wp_nonce_url( $purge_url, 'nginx_helper-purge_all' );
|
||||
?>
|
||||
|
||||
<!-- This file should primarily consist of HTML with a little bit of PHP. -->
|
||||
|
||||
<form id="purgeall" action="" method="post" class="clearfix">
|
||||
<a href="<?php echo esc_url( $nonced_url ); ?>" class="button-primary">
|
||||
<?php esc_html_e( 'Purge Entire Cache', 'nginx-helper' ); ?>
|
||||
</a>
|
||||
</form>
|
||||
<div class="postbox" id="support">
|
||||
<h3 class="hndle">
|
||||
<span><?php esc_html_e( 'Need Help?', 'nginx-helper' ); ?></span>
|
||||
</h3>
|
||||
<div class="inside">
|
||||
<p>
|
||||
<?php
|
||||
printf(
|
||||
'%s <a href=\'%s\'>%s</a>.',
|
||||
esc_html__( 'Please use our', 'nginx-helper' ),
|
||||
esc_url( 'http://rtcamp.com/support/forum/wordpress-nginx/' ),
|
||||
esc_html__( 'free support forum', 'nginx-helper' )
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="postbox" id="social">
|
||||
<h3 class="hndle">
|
||||
<span>
|
||||
<?php esc_html_e( 'Getting Social is Good', 'nginx-helper' ); ?>
|
||||
</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>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="postbox" id="useful-links">
|
||||
<h3 class="hndle">
|
||||
<span><?php esc_html_e( 'Useful Links', 'nginx-helper' ); ?></span>
|
||||
</h3>
|
||||
<div class="inside">
|
||||
<ul role="list">
|
||||
<li role="listitem">
|
||||
<a href="https://rtcamp.com/wordpress-nginx/" title="<?php esc_attr_e( 'WordPress-Nginx Solutions', 'nginx-helper' ); ?>"><?php esc_html_e( 'WordPress-Nginx Solutions', 'nginx-helper' ); ?></a>
|
||||
</li>
|
||||
<li role="listitem">
|
||||
<a href="https://rtcamp.com/services/wordPress-themes-design-development/" title="<?php esc_attr_e( 'WordPress Theme Devleopment', 'nginx-helper' ); ?>"><?php esc_html_e( 'WordPress Theme Devleopment', 'nginx-helper' ); ?></a>
|
||||
</li>
|
||||
<li role="listitem">
|
||||
<a href="http://rtcamp.com/services/wordpress-plugins/" title="<?php esc_attr_e( 'WordPress Plugin Development', 'nginx-helper' ); ?>"><?php esc_html_e( 'WordPress Plugin Development', 'nginx-helper' ); ?></a>
|
||||
</li>
|
||||
<li role="listitem">
|
||||
<a href="http://rtcamp.com/services/custom-wordpress-solutions/" title="<?php esc_attr_e( 'WordPress Consultancy', 'nginx-helper' ); ?>"><?php esc_html_e( 'WordPress Consultancy', 'nginx-helper' ); ?></a>
|
||||
</li>
|
||||
<li role="listitem">
|
||||
<a href="https://rtcamp.com/easyengine/" title="<?php esc_attr_e( 'easyengine (ee)', 'nginx-helper' ); ?>"><?php esc_html_e( 'easyengine (ee)', 'nginx-helper' ); ?></a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="postbox" id="latest_news">
|
||||
<div title="<?php esc_attr_e( 'Click to toggle', 'nginx-helper' ); ?>" class="handlediv"><br /></div>
|
||||
<h3 class="hndle"><span><?php esc_html_e( 'Latest News', 'nginx-helper' ); ?></span></h3>
|
||||
<div class="inside"><img src ="<?php echo esc_url( admin_url() ); ?>/images/wpspin_light.gif" /><?php esc_html_e( 'Loading...', 'nginx-helper' ); ?></div>
|
||||
</div>
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* Display support options of the plugin.
|
||||
*
|
||||
* This file is used to markup the admin-facing aspects of the plugin.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @package nginx-helper
|
||||
* @subpackage nginx-helper/admin/partials
|
||||
*/
|
||||
|
||||
?>
|
||||
|
||||
<!-- This file should primarily consist of HTML with a little bit of PHP. -->
|
||||
<div class="postbox">
|
||||
<h3 class="hndle">
|
||||
<span><?php esc_html_e( 'Support Forums', 'nginx-helper' ); ?></span>
|
||||
</h3>
|
||||
<div class="inside">
|
||||
<table class="form-table">
|
||||
<tr valign="top">
|
||||
<th>
|
||||
<?php esc_html_e( 'Free Support', 'nginx-helper' ); ?>
|
||||
</th>
|
||||
<td>
|
||||
<a href="https://community.easyengine.io/c/wordpress-nginx/" title="<?php esc_attr_e( 'Free Support Forum', 'nginx-helper' ); ?>" target="_blank">
|
||||
<?php esc_html_e( 'Link to forum', 'nginx-helper' ); ?>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<th>
|
||||
<?php esc_html_e( 'Premium Support', 'nginx-helper' ); ?>
|
||||
</th>
|
||||
<td>
|
||||
<a href="https://easyengine.io/contact/" title="<?php esc_attr_e( 'Premium Support Forum', 'nginx-helper' ); ?>" target="_blank">
|
||||
<?php esc_html_e( 'Link to forum', 'nginx-helper' ); ?>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
15203
wp/wp-content/plugins/nginx-helper/admin/predis.php
Normal file
15203
wp/wp-content/plugins/nginx-helper/admin/predis.php
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user