init(); add_filter('w3tc_extensions', array($this, 'extension'), 10, 2); } private function init() { $this->_config = w3_instance('W3_Config'); add_filter('w3tc_save_options', array($this, 'save_settings'),10,3); add_filter('w3tc_general_anchors', array($this, 'general_settings_anchors')); add_filter('w3tc_errors', array($this, 'register_error')); add_filter('w3tc_dashboard_actions', array($this, 'dashboard_actions')); add_action('w3tc_general_boxarea_cloudflare',array($this, 'general_settings_box')); w3_require_once(W3TC_LIB_W3_DIR . '/Request.php'); $page = W3_Request::get_string('page'); if ($page && strpos($page, 'w3tc_') !== false) { /** * Only admin can see W3TC notices and errors */ add_action('admin_notices', array( $this, 'admin_notices' )); add_action('network_admin_notices', array( $this, 'admin_notices' )); } add_action('wp_ajax_w3tc_cloudflare_api_request', array($this, 'action_cloudflare_api_request')); w3_require_once(W3TC_CORE_EXTENSION_DIR . '/CloudFlare/CloudFlareAPI.php'); $this->cloudflareAPI = new CloudFlareAPI(); if (w3tc_get_extension_config('cloudflare', 'enabled', $this->_config, false)) { $this->check_ip_versions(); } add_filter('w3tc_setting_label', array($this, 'setting_label')); add_filter('w3tc_custom_module_settings', array($this, 'set_settings_class')); add_filter("w3tc_extension_plugin_links-cloudflare", array($this, 'extension_settings_link')); } function extension_settings_link($links) { $links = array(); $links[] = ''. __('Settings').''; return $links; } function set_settings_class($modules) { $modules['cloudflare'] = array($this, 'load_settings_class'); return $modules; } function load_settings_class() { w3_require_once(W3TC_CORE_EXTENSION_DIR . '/CloudFlare/CloudFlareSettings.php'); return new CloudFlareSettings(); } /** * @param $extensions * @param W3_Config $config * @return mixed */ function extension($extensions, $config) { global $current_user; $message = array(); $message[] = 'CloudFlare'; $cloudflare_signup_email = ''; $cloudflare_signup_user = ''; if (is_a($current_user, 'WP_User')) { if ($current_user->user_email) { $cloudflare_signup_email = $current_user->user_email; } if ($current_user->user_login && $current_user->user_login != 'admin') { $cloudflare_signup_user = $current_user->user_login; } } $extensions['cloudflare'] = array ( 'name' => 'CloudFlare', 'author' => 'W3 EDGE', 'description' => sprintf( __('CloudFlare protects and accelerates websites. Sign up now for free to get started, or if you have an account simply log in to obtain your API key from the account page to enter it on the General Settings box that appears after plugin activation. Contact the CloudFlare support team with any questions.', 'w3-total-cache'), 'https://www.cloudflare.com/sign-up.html?affiliate=w3edge&seed_domain=' . w3_get_host() . '&email=' . htmlspecialchars($cloudflare_signup_email) . '&username=' . htmlspecialchars($cloudflare_signup_user) ), 'author uri' => 'http://www.w3-edge.com/', 'extension uri' => 'http://www.w3-edge.com/', 'extension id' => 'cloudflare', 'version' => '1.0', 'enabled' => true, 'requirements' => implode(', ', $message), 'path' => 'w3-total-cache/extensions/CloudFlare.php' ); return $extensions; } public function register_error($errors) { if ($error = $this->cloudflareAPI->check_lasterror()) { $errors[] = $error; }elseif(W3_Request::get_string('w3tc_error')) { $errors[] = __('Unable to make CloudFlare API request.', 'w3-total-cache'); } return $errors; } public function register_notifications($notes) { $notes['flush_all_except_cf'] = __('All caches except CloudFlare successfully emptied.', 'w3-total-cache'); $notes['cloudflare_api_request'] = __('Unable to make CloudFlare API request.', 'w3-total-cache'); return $notes; } public function dashboard_actions($actions) { $cloudflare_enabled = true; if ($cloudflare_enabled && w3tc_get_extension_config('cloudflare','email') && w3tc_get_extension_config('cloudflare','key')) { $can_empty_cloudflare = true; } else { $can_empty_cloudflare = false; } $modules = w3_instance('W3_ModuleStatus'); $can_empty_memcache = $modules->can_empty_memcache(); $can_empty_opcode = $modules->can_empty_opcode(); $can_empty_file = $modules->can_empty_file(); $can_empty_varnish = $modules->can_empty_varnish(); $actions[] = ' or ' . __('at once', 'w3-total-cache'); return $actions; } /** * Check if last check has expired. If so update CloudFlare ips */ function check_ip_versions() { $checked = get_transient('w3tc_cloudflare_ip_check'); if (false === $checked) { try { $this->cloudflareAPI->update_ip_ranges(); } catch (Exception $ex) {} set_transient('w3tc_cloudflare_ip_check', time(), 3600*24); } } function admin_notices() { $plugins = get_plugins(); if (array_key_exists('cloudflare/cloudflare.php', $plugins) && $this->_config->get_boolean('notes.cloudflare_plugin')) { w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/other.php'); echo sprintf('
%s %s