plugin install

This commit is contained in:
Tony Volpe
2024-06-18 17:29:05 -04:00
parent e1aaedd1ae
commit 41f50eacc4
5880 changed files with 1057631 additions and 39681 deletions

View File

@@ -0,0 +1,63 @@
<?php
/**
* Fired during plugin activation.
*
* This class defines all code necessary to run during the plugin's activation.
*
* @since 2.0.0
* @link https://rtcamp.com/nginx-helper/
*
* @package nginx-helper
* @subpackage nginx-helper/includes
*
* @author rtCamp
*/
/**
* Class Nginx_Helper_Activator
*/
class Nginx_Helper_Activator {
/**
* Create log directory. Add capability of nginx helper.
* Schedule event to check log file size daily.
*
* @since 2.0.0
*
* @global Nginx_Helper_Admin $nginx_helper_admin
*/
public static function activate() {
global $nginx_helper_admin;
$path = $nginx_helper_admin->functional_asset_path();
if ( ! is_dir( $path ) ) {
mkdir( $path );
}
if ( ! current_user_can( 'activate_plugins' ) ) {
return;
}
$role = get_role( 'administrator' );
if ( empty( $role ) ) {
update_site_option(
'rt_wp_nginx_helper_init_check',
__( 'Sorry, you need to be an administrator to use Nginx Helper', 'nginx-helper' )
);
return;
}
$role->add_cap( 'Nginx Helper | Config' );
$role->add_cap( 'Nginx Helper | Purge cache' );
wp_schedule_event( time(), 'daily', 'rt_wp_nginx_helper_check_log_file_size_daily' );
}
}

View File

@@ -0,0 +1,38 @@
<?php
/**
* Contains Nginx_Helper_Deactivator class.
*
* @package nginx-helper
*/
/**
* Fired during plugin deactivation.
*
* This class defines all code necessary to run during the plugin's deactivation.
*
* @since 2.0.0
* @link https://rtcamp.com/nginx-helper/
*
* @package nginx-helper
* @subpackage nginx-helper/includes
*
* @author rtCamp
*/
class Nginx_Helper_Deactivator {
/**
* Schedule event to check log file size daily. Remove nginx helper capability.
*
* @since 2.0.0
*/
public static function deactivate() {
wp_clear_scheduled_hook( 'rt_wp_nginx_helper_check_log_file_size_daily' );
$role = get_role( 'administrator' );
$role->remove_cap( 'Nginx Helper | Config' );
$role->remove_cap( 'Nginx Helper | Purge cache' );
}
}

View File

@@ -0,0 +1,63 @@
<?php
/**
* Define the internationalization functionality
*
* Loads and defines the internationalization files for this plugin
* so that it is ready for translation.
*
* @link https://rtcamp.com/nginx-helper/
* @since 2.0.0
*
* @package nginx-helper
* @subpackage nginx-helper/includes
*/
/**
* Define the internationalization functionality.
*
* Loads and defines the internationalization files for this plugin
* so that it is ready for translation.
*
* @since 2.0.0
* @package nginx-helper
* @subpackage nginx-helper/includes
* @author rtCamp
*/
class Nginx_Helper_i18n {
/**
* The domain specified for this plugin.
*
* @since 2.0.0
* @access private
* @var string $domain The domain identifier for this plugin.
*/
private $domain;
/**
* Load the plugin text domain for translation.
*
* @since 2.0.0
*/
public function load_plugin_textdomain() {
load_plugin_textdomain(
$this->domain,
false,
dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/'
);
}
/**
* Set the domain equal to that of the specified domain.
*
* @since 2.0.0
*
* @param string $domain The domain that represents the locale of this plugin.
*/
public function set_domain( $domain ) {
$this->domain = $domain;
}
}

View File

@@ -0,0 +1,139 @@
<?php
/**
* Register all actions and filters for the plugin
*
* @link https://rtcamp.com/nginx-helper/
* @since 2.0.0
*
* @package nginx-helper
* @subpackage nginx-helper/includes
*/
/**
* Register all actions and filters for the plugin.
*
* Maintain a list of all hooks that are registered throughout
* the plugin, and register them with the WordPress API. Call the
* run function to execute the list of actions and filters.
*
* @package nginx-helper
*
* @subpackage nginx-helper/includes
*
* @author rtCamp
*/
class Nginx_Helper_Loader {
/**
* The array of actions registered with WordPress.
*
* @since 2.0.0
*
* @access protected
*
* @var array $actions The actions registered with WordPress to fire when the plugin loads.
*/
protected $actions;
/**
* The array of filters registered with WordPress.
*
* @since 2.0.0
*
* @access protected
*
* @var array $filters The filters registered with WordPress to fire when the plugin loads.
*/
protected $filters;
/**
* Initialize the collections used to maintain the actions and filters.
*
* @since 2.0.0
*/
public function __construct() {
$this->actions = array();
$this->filters = array();
}
/**
* Add a new action to the collection to be registered with WordPress.
*
* @since 2.0.0
*
* @param string $hook The name of the WordPress action that is being registered.
* @param object $component A reference to the instance of the object on which the action is defined.
* @param string $callback The name of the function definition on the $component.
* @param int $priority The priority at which the function should be fired.
* @param int $accepted_args The number of arguments that should be passed to the $callback.
*/
public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
$this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
}
/**
* Add a new filter to the collection to be registered with WordPress.
*
* @since 2.0.0
*
* @param string $hook The name of the WordPress filter that is being registered.
* @param object $component A reference to the instance of the object on which the filter is defined.
* @param string $callback The name of the function definition on the $component.
* @param int $priority The priority at which the function should be fired.
* @param int $accepted_args The number of arguments that should be passed to the $callback.
*/
public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
$this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
}
/**
* A utility function that is used to register the actions and hooks into a single
* collection.
*
* @since 2.0.0
*
* @access private
*
* @param array $hooks The collection of hooks that is being registered (that is, actions or filters).
* @param string $hook The name of the WordPress filter that is being registered.
* @param object $component A reference to the instance of the object on which the filter is defined.
* @param string $callback The name of the function definition on the $component.
* @param int $priority The priority at which the function should be fired.
* @param int $accepted_args The number of arguments that should be passed to the $callback.
*
* @return array The collection of actions and filters registered with WordPress.
*/
private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
$hooks[] = array(
'hook' => $hook,
'component' => $component,
'callback' => $callback,
'priority' => $priority,
'accepted_args' => $accepted_args,
);
return $hooks;
}
/**
* Register the filters and actions with WordPress.
*
* @since 2.0.0
*/
public function run() {
foreach ( $this->filters as $hook ) {
add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
}
foreach ( $this->actions as $hook ) {
add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
}
}
}

View File

@@ -0,0 +1,320 @@
<?php
/**
* The file that defines the core plugin class
*
* A class definition that includes attributes and functions used across both the
* public-facing side of the site and the admin area.
*
* @link https://rtcamp.com/nginx-helper/
* @since 2.0.0
*
* @package nginx-helper
* @subpackage nginx-helper/includes
*/
/**
* The core plugin class.
*
* This is used to define internationalization, admin-specific hooks, and
* public-facing site hooks.
*
* Also maintains the unique identifier of this plugin as well as the current
* version of the plugin.
*
* @since 2.0.0
* @package nginx-helper
* @subpackage nginx-helper/includes
* @author rtCamp
*/
class Nginx_Helper {
/**
* The loader that's responsible for maintaining and registering all hooks that power
* the plugin.
*
* @since 2.0.0
* @access protected
* @var Nginx_Helper_Loader $loader Maintains and registers all hooks for the plugin.
*/
protected $loader;
/**
* The unique identifier of this plugin.
*
* @since 2.0.0
* @access protected
* @var string $plugin_name The string used to uniquely identify this plugin.
*/
protected $plugin_name;
/**
* The current version of the plugin.
*
* @since 2.0.0
* @access protected
* @var string $version The current version of the plugin.
*/
protected $version;
/**
* Minimum WordPress Version Required.
*
* @since 2.0.0
* @access public
* @var string $minium_wp
*/
protected $minimum_wp;
/**
* Define the core functionality of the plugin.
*
* Set the plugin name and the plugin version that can be used throughout the plugin.
* Load the dependencies, define the locale, and set the hooks for the admin area and
* the public-facing side of the site.
*
* @since 2.0.0
*/
public function __construct() {
$this->plugin_name = 'nginx-helper';
$this->version = '2.2.5';
$this->minimum_wp = '3.0';
if ( ! $this->required_wp_version() ) {
return;
}
if ( ! defined( 'RT_WP_NGINX_HELPER_CACHE_PATH' ) ) {
define( 'RT_WP_NGINX_HELPER_CACHE_PATH', '/var/run/nginx-cache' );
}
$this->load_dependencies();
$this->set_locale();
$this->define_admin_hooks();
}
/**
* Load the required dependencies for this plugin.
*
* Include the following files that make up the plugin:
*
* - Nginx_Helper_Loader. Orchestrates the hooks of the plugin.
* - Nginx_Helper_i18n. Defines internationalization functionality.
* - Nginx_Helper_Admin. Defines all hooks for the admin area.
*
* Create an instance of the loader which will be used to register the hooks
* with WordPress.
*
* @since 2.0.0
* @access private
*/
private function load_dependencies() {
/**
* The class responsible for orchestrating the actions and filters of the
* core plugin.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-nginx-helper-loader.php';
/**
* The class responsible for defining internationalization functionality
* of the plugin.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-nginx-helper-i18n.php';
/**
* The class responsible for defining all actions that required for purging urls.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-purger.php';
/**
* The class responsible for defining all actions that occur in the admin area.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-nginx-helper-admin.php';
/**
* The class responsible for defining all actions that occur in the public-facing
* side of the site.
*/
$this->loader = new Nginx_Helper_Loader();
}
/**
* Define the locale for this plugin for internationalization.
*
* Uses the Nginx_Helper_i18n class in order to set the domain and to register the hook
* with WordPress.
*
* @since 2.0.0
* @access private
*/
private function set_locale() {
$plugin_i18n = new Nginx_Helper_i18n();
$plugin_i18n->set_domain( $this->get_plugin_name() );
$this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
}
/**
* Register all of the hooks related to the admin area functionality of the plugin.
*
* @since 2.0.0
* @access private
*/
private function define_admin_hooks() {
global $nginx_helper_admin, $nginx_purger;
$nginx_helper_admin = new Nginx_Helper_Admin( $this->get_plugin_name(), $this->get_version() );
// Defines global variables.
if ( ! empty( $nginx_helper_admin->options['cache_method'] ) && 'enable_redis' === $nginx_helper_admin->options['cache_method'] ) {
if ( class_exists( 'Redis' ) ) { // Use PHP5-Redis extension if installed.
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-phpredis-purger.php';
$nginx_purger = new PhpRedis_Purger();
} else {
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-predis-purger.php';
$nginx_purger = new Predis_Purger();
}
} else {
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-fastcgi-purger.php';
$nginx_purger = new FastCGI_Purger();
}
$this->loader->add_action( 'admin_enqueue_scripts', $nginx_helper_admin, 'enqueue_styles' );
$this->loader->add_action( 'admin_enqueue_scripts', $nginx_helper_admin, 'enqueue_scripts' );
if ( is_multisite() ) {
$this->loader->add_action( 'network_admin_menu', $nginx_helper_admin, 'nginx_helper_admin_menu' );
$this->loader->add_filter( 'network_admin_plugin_action_links_' . NGINX_HELPER_BASENAME, $nginx_helper_admin, 'nginx_helper_settings_link' );
} else {
$this->loader->add_action( 'admin_menu', $nginx_helper_admin, 'nginx_helper_admin_menu' );
$this->loader->add_filter( 'plugin_action_links_' . NGINX_HELPER_BASENAME, $nginx_helper_admin, 'nginx_helper_settings_link' );
}
if ( ! empty( $nginx_helper_admin->options['enable_purge'] ) ) {
$this->loader->add_action( 'admin_bar_menu', $nginx_helper_admin, 'nginx_helper_toolbar_purge_link', 100 );
}
$this->loader->add_action( 'wp_ajax_rt_get_feeds', $nginx_helper_admin, 'nginx_helper_get_feeds' );
$this->loader->add_action( 'shutdown', $nginx_helper_admin, 'add_timestamps', 99999 );
$this->loader->add_action( 'add_init', $nginx_helper_admin, 'update_map' );
// Add actions to purge.
$this->loader->add_action( 'wp_insert_comment', $nginx_purger, 'purge_post_on_comment', 200, 2 );
$this->loader->add_action( 'transition_comment_status', $nginx_purger, 'purge_post_on_comment_change', 200, 3 );
$this->loader->add_action( 'transition_post_status', $nginx_helper_admin, 'set_future_post_option_on_future_status', 20, 3 );
$this->loader->add_action( 'delete_post', $nginx_helper_admin, 'unset_future_post_option_on_delete', 20, 1 );
$this->loader->add_action( 'rt_wp_nginx_helper_check_log_file_size_daily', $nginx_purger, 'check_and_truncate_log_file', 100, 1 );
$this->loader->add_action( 'edit_attachment', $nginx_purger, 'purge_image_on_edit', 100, 1 );
$this->loader->add_action( 'wpmu_new_blog', $nginx_helper_admin, 'update_new_blog_options', 10, 1 );
$this->loader->add_action( 'transition_post_status', $nginx_purger, 'purge_on_post_moved_to_trash', 20, 3 );
$this->loader->add_action( 'edit_term', $nginx_purger, 'purge_on_term_taxonomy_edited', 20, 3 );
$this->loader->add_action( 'delete_term', $nginx_purger, 'purge_on_term_taxonomy_edited', 20, 3 );
$this->loader->add_action( 'check_ajax_referer', $nginx_purger, 'purge_on_check_ajax_referer', 20 );
$this->loader->add_action( 'admin_bar_init', $nginx_helper_admin, 'purge_all' );
// expose action to allow other plugins to purge the cache.
$this->loader->add_action( 'rt_nginx_helper_purge_all', $nginx_purger, 'purge_all' );
}
/**
* Run the loader to execute all of the hooks with WordPress.
*
* @since 2.0.0
*/
public function run() {
$this->loader->run();
}
/**
* The name of the plugin used to uniquely identify it within the context of
* WordPress and to define internationalization functionality.
*
* @since 2.0.0
* @return string The name of the plugin.
*/
public function get_plugin_name() {
return $this->plugin_name;
}
/**
* The reference to the class that orchestrates the hooks with the plugin.
*
* @since 2.0.0
*
* @return Nginx_Helper_Loader Orchestrates the hooks of the plugin.
*/
public function get_loader() {
return $this->loader;
}
/**
* Retrieve the version number of the plugin.
*
* @since 2.0.0
* @return string The version number of the plugin.
*/
public function get_version() {
return $this->version;
}
/**
* Check wp version.
*
* @since 2.0.0
*
* @global string $wp_version
*
* @return boolean
*/
public function required_wp_version() {
global $wp_version;
$wp_ok = version_compare( $wp_version, $this->minimum_wp, '>=' );
if ( false === $wp_ok ) {
add_action( 'admin_notices', array( &$this, 'display_notices' ) );
add_action( 'network_admin_notices', array( &$this, 'display_notices' ) );
return false;
}
return true;
}
/**
* Dispay plugin notices.
*/
public function display_notices() {
?>
<div id="message" class="error">
<p>
<strong>
<?php
printf(
/* translators: %s is Minimum WP version. */
esc_html__( 'Sorry, Nginx Helper requires WordPress %s or higher', 'nginx-helper' ),
esc_html( $this->minimum_wp )
);
?>
</strong>
</p>
</div>
<?php
}
}

View File

@@ -0,0 +1,8 @@
<?php
/**
* Silence is golden.
*
* @package nginx-helper
*/
// Silence.