function run() { $c = Dispatcher::config(); $this->api = new Extension_CloudFlare_Api(array('email' => $c->get_string(array('cloudflare', 'email')), 'key' => $c->get_string(array('cloudflare', 'key')), 'zone_id' => $c->get_string(array('cloudflare', 'zone_id')), 'timelimit_api_request' => $c->get_integer(array('cloudflare', 'timelimit.api_request')))); $this->_config = $c; add_filter('w3tc_dashboard_actions', array($this, 'w3tc_dashboard_actions')); $widget = new Extension_CloudFlare_Widget(); $widget->init(); // modify settings page add_filter('w3tc_settings_general_anchors', array($this, 'w3tc_settings_general_anchors')); add_action('w3tc_settings_general_boxarea_cloudflare', array($this, 'w3tc_settings_general_boxarea_cloudflare')); add_action('wp_ajax_w3tc_cloudflare_api_request', array($this, 'action_cloudflare_api_request')); // modify main menu add_action('w3tc_extension_page_cloudflare', array('\\W3TC\\Extension_CloudFlare_Page', 'w3tc_extension_page_cloudflare')); add_filter('w3tc_admin_bar_menu', array($this, 'w3tc_admin_bar_menu')); // dashboard add_action('admin_print_scripts-toplevel_page_w3tc_dashboard', array($this, 'admin_print_scripts_w3tc_dashboard')); add_filter('w3tc_admin_actions', array($this, 'w3tc_admin_actions')); // own settings page add_action('admin_print_scripts-performance_page_w3tc_extensions', array('\\W3TC\\Extension_CloudFlare_Page', 'admin_print_scripts_w3tc_extensions')); add_action('w3tc_ajax', array('\\W3TC\\Extension_CloudFlare_Popup', 'w3tc_ajax')); // add check to comments page add_filter('comment_row_actions', array($this, 'comment_row_actions'), 10, 2); add_action('admin_print_styles-edit-comments.php', array($this, 'admin_print_styles_edit_comments')); add_action('admin_print_scripts-edit-comments.php', array($this, 'admin_print_scripts_edit_comments')); add_action('wp_ajax_w3tc_cloudflare_ip_check', array($this, 'w3tc_cloudflare_ip_check')); // add notices about api health if (Util_Admin::is_w3tc_admin_page()) { add_action('admin_notices', array($this, 'admin_notices')); add_action('network_admin_notices', array($this, 'admin_notices')); } $this->check_ip_versions(); }
/** * Runs plugin */ function run() { // attach w3tc-bundled extensions add_filter('w3tc_extensions', array('\\W3TC\\Extension_CloudFlare_Plugin_Admin', 'w3tc_extensions'), 10, 2); add_filter('w3tc_extensions', array('\\W3TC\\Extension_FeedBurner_Plugin_Admin', 'w3tc_extensions'), 10, 2); add_filter('w3tc_extensions', array('\\W3TC\\Extension_FragmentCache_Plugin_Admin', 'w3tc_extensions'), 10, 2); add_filter('w3tc_extensions', array('\\W3TC\\Extension_Genesis_Plugin_Admin', 'w3tc_extensions'), 10, 2); add_filter('w3tc_extensions_hooks', array('\\W3TC\\Extension_Genesis_Plugin_Admin', 'w3tc_extensions_hooks')); add_filter('w3tc_notes_genesis_theme', array('\\W3TC\\Extension_Genesis_Plugin_Admin', 'w3tc_notes_genesis_theme')); add_filter('w3tc_extensions', array('\\W3TC\\Extension_NewRelic_Plugin_Admin', 'w3tc_extensions'), 10, 2); add_filter('w3tc_extensions', array('\\W3TC\\Extension_WordPressSeo_Plugin_Admin', 'w3tc_extensions'), 10, 2); add_filter('w3tc_extensions_hooks', array('\\W3TC\\Extension_WordPressSeo_Plugin_Admin', 'w3tc_extensions_hooks')); add_action('w3tc_notes_wordpress_seo', array('\\W3TC\\Extension_WordPressSeo_Plugin_Admin', 'w3tc_notes_wordpress_seo')); add_filter('w3tc_extensions', array('\\W3TC\\Extension_Wpml_Plugin_Admin', 'w3tc_extensions'), 10, 2); add_filter('w3tc_extensions', array('\\W3TC\\Extension_Amp_Plugin_Admin', 'w3tc_extensions'), 10, 2); add_filter('w3tc_extensions_hooks', array('\\W3TC\\Extension_Wpml_Plugin_Admin', 'w3tc_extensions_hooks')); add_action('w3tc_notes_wpml', array('\\W3TC\\Extension_Wpml_Plugin_Admin', 'w3tc_notes_wpml')); add_action('admin_init', array($this, 'admin_init'), 1); add_filter('pre_update_option_active_plugins', array($this, 'pre_update_option_active_plugins')); add_filter('w3tc_admin_menu', array($this, 'w3tc_admin_menu'), 10000); add_action('w3tc_settings_page-w3tc_extensions', array($this, 'w3tc_settings_page_w3tc_extensions')); if (Util_Admin::is_w3tc_admin_page()) { if (isset($_GET['extension']) && isset($_GET['action'])) { if (in_array($_GET['action'], array('activate', 'deactivate'))) { add_action('init', array($this, 'change_extension_status')); } } elseif (isset($_POST['checked'])) { add_action('admin_init', array($this, 'change_extensions_status')); } } }
/** * Runs plugin */ function run() { if (Util_Admin::is_w3tc_admin_page()) { add_action('admin_head', array($this, 'admin_head')); add_action('w3tc_message_action_generic_support_us', array($this, 'w3tc_message_action_generic_support_us')); add_action('w3tc_ajax_generic_support_us', array($this, 'w3tc_ajax_generic_support_us')); add_action('w3tc_message_action_generic_edge', array($this, 'w3tc_message_action_generic_edge')); add_action('w3tc_ajax_generic_edge', array($this, 'w3tc_ajax_generic_edge')); } }
/** * Setup notices actions */ function admin_init() { $capability = apply_filters('w3tc_capability_admin_notices', 'manage_options'); if (current_user_can($capability)) { if (is_admin() && Util_Admin::is_w3tc_admin_page()) { /** * Only admin can see W3TC notices and errors */ if (!Util_Environment::is_wpmu()) { add_action('admin_notices', array($this, 'admin_notices'), 1, 1); } add_action('network_admin_notices', array($this, 'admin_notices'), 1, 1); } } }
function run() { add_filter('w3tc_compatibility_test', array($this, 'verify_compatibility')); add_action('w3tc_config_save', array($this, 'w3tc_config_save'), 10, 1); add_filter('w3tc_admin_actions', array($this, 'w3tc_admin_actions')); add_filter('w3tc_admin_menu', array($this, 'w3tc_admin_menu')); add_filter('w3tc_extension_plugin_links_newrelic', array($this, 'w3tc_extension_plugin_links')); add_action('w3tc_settings_page-w3tc_monitoring', array($this, 'w3tc_settings_page_w3tc_monitoring')); add_action('admin_init_w3tc_general', array('\\W3TC\\Extension_NewRelic_GeneralPage', 'admin_init_w3tc_general')); add_action('w3tc_ajax', array('\\W3TC\\Extension_NewRelic_Popup', 'w3tc_ajax')); if (Util_Admin::is_w3tc_admin_page()) { add_action('admin_notices', array($this, 'admin_notices')); add_action('network_admin_notices', array($this, 'admin_notices')); } add_action('admin_init_w3tc_dashboard', array('\\W3TC\\Extension_NewRelic_Widget', 'admin_init_w3tc_dashboard')); add_action('w3tc_ajax', array('\\W3TC\\Extension_NewRelic_Widget', 'w3tc_ajax')); add_filter('w3tc_notes', array($this, 'w3tc_notes')); }
/** * Admin notices action * * @return void */ function admin_notices() { $cookie_domain = Util_Admin::get_cookie_domain(); $error_messages = array('fancy_permalinks_disabled_pgcache' => sprintf(__('Fancy permalinks are disabled. Please %s it first, then re-attempt to enabling enhanced disk mode.', 'w3-total-cache'), Util_Ui::button_link('enable', 'options-permalink.php')), 'fancy_permalinks_disabled_browsercache' => sprintf(__('Fancy permalinks are disabled. Please %s it first, then re-attempt to enabling the \'Do not process 404 errors for static objects with WordPress\'.', 'w3-total-cache'), Util_Ui::button_link('enable', 'options-permalink.php')), 'support_request' => __('Failed to send support request.', 'w3-total-cache'), 'support_request_type' => __('Please select request type.', 'w3-total-cache'), 'support_request_url' => __('Please enter the address of the site in the site <acronym title="Uniform Resource Locator">URL</acronym> field.', 'w3-total-cache'), 'support_request_name' => __('Please enter your name in the Name field', 'w3-total-cache'), 'support_request_email' => __('Please enter valid email address in the E-Mail field.', 'w3-total-cache'), 'support_request_phone' => __('Please enter your phone in the phone field.', 'w3-total-cache'), 'support_request_subject' => __('Please enter subject in the subject field.', 'w3-total-cache'), 'support_request_description' => __('Please describe the issue in the issue description field.', 'w3-total-cache'), 'support_request_wp_login' => __('Please enter an administrator login. Create a temporary one just for this support case if needed.', 'w3-total-cache'), 'support_request_wp_password' => __('Please enter WP Admin password, be sure it\'s spelled correctly.', 'w3-total-cache'), 'support_request_ftp_host' => __('Please enter <acronym title="Secure Shell">SSH</acronym> or <acronym title="File Transfer Protocol">FTP</acronym> host for the site.', 'w3-total-cache'), 'support_request_ftp_login' => __('Please enter <acronym title="Secure Shell">SSH</acronym> or <acronym title="File Transfer Protocol">FTP</acronym> login for the server. Create a temporary one just for this support case if needed.', 'w3-total-cache'), 'support_request_ftp_password' => __('Please enter <acronym title="Secure Shell">SSH</acronym> or <acronym title="File Transfer Protocol">FTP</acronym> password for the <acronym title="File Transfer Protocol">FTP</acronym> account.', 'w3-total-cache'), 'support_request' => __('Unable to send the support request.', 'w3-total-cache'), 'config_import_no_file' => __('Please select config file.', 'w3-total-cache'), 'config_import_upload' => __('Unable to upload config file.', 'w3-total-cache'), 'config_import_import' => __('Configuration file could not be imported.', 'w3-total-cache'), 'config_reset' => sprintf(__('Default settings could not be restored. Please run <strong>chmod 777 %s</strong> to make the configuration file write-able, then try again.', 'w3-total-cache'), W3TC_CONFIG_DIR), 'cdn_purge_attachment' => __('Unable to purge attachment.', 'w3-total-cache'), 'pgcache_purge_post' => __('Unable to purge post.', 'w3-total-cache'), 'enable_cookie_domain' => sprintf(__('<strong>%swp-config.php</strong> could not be written, please edit config and add:<br /><strong style="color:#f00;">define(\'COOKIE_DOMAIN\', \'%s\');</strong> before <strong style="color:#f00;">require_once(ABSPATH . \'wp-settings.php\');</strong>.', 'w3-total-cache'), ABSPATH, addslashes($cookie_domain)), 'disable_cookie_domain' => sprintf(__('<strong>%swp-config.php</strong> could not be written, please edit config and add:<br /><strong style="color:#f00;">define(\'COOKIE_DOMAIN\', false);</strong> before <strong style="color:#f00;">require_once(ABSPATH . \'wp-settings.php\');</strong>.', 'w3-total-cache'), ABSPATH), 'pull_zone' => __('Pull Zone could not be automatically created.', 'w3-total-cache')); $note_messages = array('config_save' => __('Plugin configuration successfully updated.', 'w3-total-cache'), 'flush_all' => __('All caches successfully emptied.', 'w3-total-cache'), 'flush_memcached' => __('Memcached cache(s) successfully emptied.', 'w3-total-cache'), 'flush_opcode' => __('Opcode cache(s) successfully emptied.', 'w3-total-cache'), 'flush_file' => __('Disk cache(s) successfully emptied.', 'w3-total-cache'), 'flush_pgcache' => __('Page cache successfully emptied.', 'w3-total-cache'), 'flush_dbcache' => __('Database cache successfully emptied.', 'w3-total-cache'), 'flush_objectcache' => __('Object cache successfully emptied.', 'w3-total-cache'), 'flush_fragmentcache' => __('Fragment cache successfully emptied.', 'w3-total-cache'), 'flush_minify' => __('Minify cache successfully emptied.', 'w3-total-cache'), 'flush_browser_cache' => __('Media Query string has been successfully updated.', 'w3-total-cache'), 'flush_varnish' => __('Varnish servers successfully purged.', 'w3-total-cache'), 'flush_cdn' => __('CDN was successfully purged.', 'w3-total-cache'), 'support_request' => __('The support request has been successfully sent.', 'w3-total-cache'), 'config_import' => __('Settings successfully imported.', 'w3-total-cache'), 'config_reset' => __('Settings successfully restored.', 'w3-total-cache'), 'preview_enable' => __('Preview mode was successfully enabled', 'w3-total-cache'), 'preview_disable' => __('Preview mode was successfully disabled', 'w3-total-cache'), 'preview_deploy' => __('Preview settings successfully deployed. Preview mode remains enabled until it\'s disabled. Continue testing new settings or disable preview mode if done.', 'w3-total-cache'), 'cdn_purge_attachment' => __('Attachment successfully purged.', 'w3-total-cache'), 'pgcache_purge_post' => __('Post successfully purged.', 'w3-total-cache'), 'new_relic_save' => __('New relic settings have been updated.', 'w3-total-cache'), 'add_in_removed' => __('The add-in has been removed.', 'w3-total-cache'), 'enabled_edge' => __('Edge mode has been enabled.', 'w3-total-cache'), 'disabled_edge' => __('Edge mode has been disabled.', 'w3-total-cache'), 'pull_zone' => __('Pull Zone was automatically created.', 'w3-total-cache')); $errors = array(); $notes = array(); $environment_error_present = false; $error = Util_Request::get_string('w3tc_error'); if (isset($error_messages[$error])) { $errors[$error] = $error_messages[$error]; } $note = Util_Request::get_string('w3tc_note'); if (isset($note_messages[$note])) { $notes[$note] = $note_messages[$note]; } // print errors happened during last request execution, // when we decided to redirect with error message instead of // printing it directly (to avoid reexecution on refresh) if (!is_null($this->w3tc_message)) { $v = $this->w3tc_message; if (isset($v['errors']) && is_array($v['errors'])) { foreach ($v['errors'] as $error) { if (isset($error_messages[$error])) { $errors[] = $error_messages[$error]; } else { $errors[] = $error; } } } if (isset($v['notes']) && is_array($v['notes'])) { foreach ($v['notes'] as $note) { if (isset($note_messages[$note])) { $notes[] = $note_messages[$note]; } else { $notes[] = $note; } } } } /* * Filesystem environment fix, if needed */ try { global $pagenow; if ($pagenow == 'plugins.php' || Util_Admin::is_w3tc_admin_page()) { $environment = Dispatcher::component('Root_Environment'); $environment->fix_in_wpadmin($this->_config); if (isset($_REQUEST['upgrade'])) { $notes[] = __('Required files and directories have been automatically created', 'w3-total-cache'); } } } catch (Util_Environment_Exceptions $exs) { $r = Util_Activation::parse_environment_exceptions($exs); $n = 1; foreach ($r['before_errors'] as $e) { $errors['generic_env_' . $n] = $e; $n++; } if (strlen($r['required_changes']) > 0) { $changes_style = 'border: 1px solid black; ' . 'background: white; ' . 'margin: 10px 30px 10px 30px; ' . 'padding: 10px; display: none'; $ftp_style = 'border: 1px solid black; background: white; ' . 'margin: 10px 30px 10px 30px; ' . 'padding: 10px; display: none'; $ftp_form = str_replace('class="wrap"', '', $exs->credentials_form()); $ftp_form = str_replace('<form ', '<form name="w3tc_ftp_form" ', $ftp_form); $ftp_form = str_replace('<fieldset>', '', $ftp_form); $ftp_form = str_replace('</fieldset>', '', $ftp_form); $ftp_form = str_replace('id="upgrade" class="button"', 'id="upgrade" class="button w3tc-button-save"', $ftp_form); $error = '<strong>W3 Total Cache Error:</strong> ' . 'Files and directories could not be automatically ' . 'created to complete the installation. ' . '<table>' . '<tr>' . '<td>Please execute commands manually</td>' . '<td>' . Util_Ui::button('View required changes', '', 'w3tc-show-required-changes') . '</td>' . '</tr>' . '<tr>' . '<td>or use FTP form to allow ' . '<strong>W3 Total Cache</strong> make it automatically.' . '</td>' . '<td>' . Util_Ui::button('Update via FTP', '', 'w3tc-show-ftp-form') . '</td>' . '</tr></table>' . '<div class="w3tc-required-changes" style="' . $changes_style . '">' . $r['required_changes'] . '</div>' . '<div class="w3tc-ftp-form" style="' . $ftp_style . '">' . $ftp_form . '</div>'; $environment_error_present = true; $errors['generic_ftp'] = $error; } foreach ($r['later_errors'] as $e) { $errors['generic_env_' . $n] = $e; $n++; } } $errors = apply_filters('w3tc_errors', $errors); $notes = apply_filters('w3tc_notes', $notes); /** * Show messages */ foreach ($notes as $key => $note) { echo sprintf('<div class="updated w3tc_note" id="%s"><p>%s</p></div>', $key, $note); } foreach ($errors as $key => $error) { echo sprintf('<div class="error w3tc_error" id="%s"><p>%s</p></div>', $key, $error); } }
/** * Options page * * @return void */ function options() { $this->_page = Util_Request::get_string('page'); if (!Util_Admin::is_w3tc_admin_page()) { $this->_page = 'w3tc_dashboard'; } /* * Hidden pages */ if (isset($_REQUEST['w3tc_dbcluster_config'])) { $options_dbcache = new DbCache_Page(); $options_dbcache->dbcluster_config(); } /** * Show tab */ switch ($this->_page) { case 'w3tc_dashboard': $options_dashboard = new Generic_Page_Dashboard(); $options_dashboard->options(); break; case 'w3tc_general': $options_general = new Generic_Page_General(); $options_general->options(); break; case 'w3tc_pgcache': $options_pgcache = new PgCache_Page(); $options_pgcache->options(); break; case 'w3tc_minify': $options_minify = new Minify_Page(); $options_minify->options(); break; case 'w3tc_dbcache': $options_dbcache = new DbCache_Page(); $options_dbcache->options(); break; case 'w3tc_objectcache': $options_objectcache = new ObjectCache_Page(); $options_objectcache->options(); break; case 'w3tc_browsercache': $options_browsercache = new BrowserCache_Page(); $options_browsercache->options(); break; case 'w3tc_mobile': $options_mobile = new Mobile_Page_UserAgentGroups(); $options_mobile->options(); break; case 'w3tc_referrer': $options_referrer = new Mobile_Page_ReferrerGroups(); $options_referrer->options(); break; case 'w3tc_cdn': $options_cdn = new Cdn_Page(); $options_cdn->options(); break; case 'w3tc_faq': $options_faq = new Generic_Page_Faq(); $options_faq->options(); break; case 'w3tc_support': $options_support = new Support_Page(); $options_support->options(); break; case 'w3tc_install': $options_install = new Generic_Page_Install(); $options_install->options(); break; case 'w3tc_about': $options_about = new Generic_Page_About(); $options_about->options(); break; default: // placeholder to make it the only way to show pages // with the time $view = new Base_Page_Settings(); $view->options(); do_action("w3tc_settings_page-{$this->_page}"); $view->render_footer(); break; } }