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 = '' . __( 'Settings', 'nginx-helper' ) . ''; 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 ); } ?>
' . esc_html__( 'Purge initiated', 'nginx-helper' ) . '