From 45b6e6f84b3761e026b3e32f73c75d2b7c0be05e Mon Sep 17 00:00:00 2001 From: georgejipa Date: Tue, 2 Sep 2014 22:48:24 +0300 Subject: [PATCH] version 2.0.1 --- .../classes/wp-maintenance-mode-admin.php | 58 ++++++++++++++----- includes/classes/wp-maintenance-mode.php | 30 ++++------ readme.md | 2 +- readme.txt | 20 +++++-- views/maintenance.php | 52 ++++++++++------- views/settings.php | 50 ++++++++-------- wp-maintenance-mode.php | 2 +- 7 files changed, 125 insertions(+), 89 deletions(-) diff --git a/includes/classes/wp-maintenance-mode-admin.php b/includes/classes/wp-maintenance-mode-admin.php index 425c4464..085ffafd 100644 --- a/includes/classes/wp-maintenance-mode-admin.php +++ b/includes/classes/wp-maintenance-mode-admin.php @@ -26,7 +26,8 @@ private function __construct() { // Add an action link pointing to the options page $plugin_basename = plugin_basename(WPMM_PATH . $this->plugin_slug . '.php'); if (is_multisite() && is_plugin_active_for_network($plugin_basename)) { - add_filter('network_admin_plugin_action_links', array($this, 'add_settings_link')); + // settings link will point to admin_url of the main blog, not to network_admin_url + add_filter('network_admin_plugin_action_links_' . $plugin_basename, array($this, 'add_settings_link')); } else { add_filter('plugin_action_links_' . $plugin_basename, array($this, 'add_settings_link')); } @@ -201,29 +202,30 @@ public function save_plugin_settings() { } $_POST['options']['general']['notice'] = (int) $_POST['options']['general']['notice']; $_POST['options']['general']['author_link'] = (int) $_POST['options']['general']['author_link']; + + // delete cache everytime + $this->delete_cache(); break; case 'design': $custom_css = array(); - // CONTENT + // CONTENT & CUSTOM CSS $_POST['options']['design']['title'] = sanitize_text_field($_POST['options']['design']['title']); $_POST['options']['design']['heading'] = sanitize_text_field($_POST['options']['design']['heading']); + if (!empty($_POST['options']['design']['heading_color'])) { + $_POST['options']['design']['heading_color'] = sanitize_text_field($_POST['options']['design']['heading_color']); + $custom_css['heading_color'] = '.wrap h1 { color: ' . $_POST['options']['design']['heading_color'] . '; }'; + } $_POST['options']['design']['text'] = wp_kses_post($_POST['options']['design']['text']); + if (!empty($_POST['options']['design']['text_color'])) { + $_POST['options']['design']['text_color'] = sanitize_text_field($_POST['options']['design']['text_color']); + $custom_css['text_color'] = '.wrap h2 { color: ' . $_POST['options']['design']['text_color'] . '; }'; + } // BACKGROUND & CUSTOM CSS if (!empty($_POST['options']['design']['bg_type'])) { $_POST['options']['design']['bg_type'] = sanitize_text_field($_POST['options']['design']['bg_type']); - if (!empty($_POST['options']['design']['heading_color'])) { - $_POST['options']['design']['heading_color'] = sanitize_text_field($_POST['options']['design']['heading_color']); - $custom_css['heading_color'] = '.wrap h1 { color: ' . $_POST['options']['design']['heading_color'] . '; }'; - } - - if (!empty($_POST['options']['design']['text_color'])) { - $_POST['options']['design']['text_color'] = sanitize_text_field($_POST['options']['design']['text_color']); - $custom_css['text_color'] = '.wrap h2 { color: ' . $_POST['options']['design']['text_color'] . '; }'; - } - if ($_POST['options']['design']['bg_type'] == 'color' && !empty($_POST['options']['design']['bg_color'])) { $_POST['options']['design']['bg_color'] = sanitize_text_field($_POST['options']['design']['bg_color']); $custom_css['bg_color'] = 'body { background-color: ' . $_POST['options']['design']['bg_color'] . '; }'; @@ -241,6 +243,11 @@ public function save_plugin_settings() { } $_POST['options']['design']['custom_css'] = $custom_css; + + // delete cache when is activated + if (!empty($this->plugin_settings['general']['status']) && $this->plugin_settings['general']['status'] == 1) { + $this->delete_cache(); + } break; case 'modules': $custom_css = array(); @@ -248,7 +255,6 @@ public function save_plugin_settings() { // COUNTDOWN & CUSTOM CSS $_POST['options']['modules']['countdown_status'] = (int) $_POST['options']['modules']['countdown_status']; $_POST['options']['modules']['countdown_start'] = sanitize_text_field($_POST['options']['modules']['countdown_start']); - $_POST['options']['modules']['countdown_start'] = sanitize_text_field($_POST['options']['modules']['countdown_start']); $_POST['options']['modules']['countdown_details'] = array_map('trim', $_POST['options']['modules']['countdown_details']); $_POST['options']['modules']['countdown_details']['days'] = !empty($_POST['options']['modules']['countdown_details']['days']) && is_numeric($_POST['options']['modules']['countdown_details']['days']) ? $_POST['options']['modules']['countdown_details']['days'] : 0; $_POST['options']['modules']['countdown_details']['hours'] = !empty($_POST['options']['modules']['countdown_details']['hours']) && is_numeric($_POST['options']['modules']['countdown_details']['hours']) ? $_POST['options']['modules']['countdown_details']['hours'] : 1; @@ -281,14 +287,36 @@ public function save_plugin_settings() { $_POST['options']['modules']['contact_effects'] = sanitize_text_field($_POST['options']['modules']['contact_effects']); $_POST['options']['modules']['custom_css'] = $custom_css; + + // delete cache when is activated + if (!empty($this->plugin_settings['general']['status']) && $this->plugin_settings['general']['status'] == 1) { + $this->delete_cache(); + } break; } - $this->plugin_settings[$tab] = array_map('stripslashes_deep', $_POST['options'][$tab]); + $this->plugin_settings[$tab] = $_POST['options'][$tab]; update_option('wpmm_settings', $this->plugin_settings); } } + /** + * Delete cache if any cache plugin (wp_cache or w3tc) is activated + * + * @since 2.0.1 + */ + public function delete_cache() { + // Super Cache Plugin + if (function_exists('wp_cache_clear_cache')) { + wp_cache_clear_cache(get_current_blog_id()); + } + + // W3 Total Cache Plugin + if (function_exists('w3tc_pgcache_flush')) { + w3tc_pgcache_flush(); + } + } + /** * Add settings link * @@ -299,7 +327,7 @@ public function save_plugin_settings() { public function add_settings_link($links) { return array_merge( array( - 'settings' => '' . __('Settings', $this->plugin_slug) . '' + 'wpmm_settings' => '' . __('Settings', $this->plugin_slug) . '' ), $links ); } diff --git a/includes/classes/wp-maintenance-mode.php b/includes/classes/wp-maintenance-mode.php index c037486a..68ee4b33 100644 --- a/includes/classes/wp-maintenance-mode.php +++ b/includes/classes/wp-maintenance-mode.php @@ -3,7 +3,7 @@ class WP_Maintenance_Mode { - const VERSION = '2.0.0'; + const VERSION = '2.0.1'; protected $plugin_slug = 'wp-maintenance-mode'; protected $plugin_settings; @@ -391,19 +391,6 @@ public function load_plugin_textdomain() { * Initialize when plugin is activated */ public function init() { - /** - * DELETE CACHE IF ACTIVATED - */ - // Super Cache Plugin - if (function_exists('wp_cache_clear_cache')) { - wp_cache_clear_cache(get_current_blog_id()); - } - - // W3 Total Cache Plugin - if (function_exists('w3tc_pgcache_flush')) { - w3tc_pgcache_flush(); - } - /** * CHECKS */ @@ -421,8 +408,8 @@ public function init() { // HEADER STUFF $protocol = !empty($_SERVER['SERVER_PROTOCOL']) && in_array($_SERVER['SERVER_PROTOCOL'], array('HTTP/1.1', 'HTTP/1.0')) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0'; $charset = get_bloginfo('charset') ? get_bloginfo('charset') : 'UTF-8'; - $status_code = (int) apply_filters('wp_maintenance_mode_status_code', '503'); // this hook will be removed in the next versions - $status_code = (int) apply_filters('wpmm_status_code', '503'); + $status_code = (int) apply_filters('wp_maintenance_mode_status_code', 503); // this hook will be removed in the next versions + $status_code = (int) apply_filters('wpmm_status_code', 503); $backtime_seconds = $this->calculate_backtime(); $backtime = (int) apply_filters('wpmm_backtime', $backtime_seconds); @@ -447,7 +434,9 @@ public function init() { // CSS STUFF $body_classes = !empty($this->plugin_settings['design']['bg_type']) && $this->plugin_settings['design']['bg_type'] != 'color' ? 'background' : ''; - $custom_css = array_merge($this->plugin_settings['design']['custom_css'], $this->plugin_settings['modules']['custom_css']); + $custom_css_design = !empty($this->plugin_settings['design']['custom_css']) && is_array($this->plugin_settings['design']['custom_css']) ? $this->plugin_settings['design']['custom_css'] : array(); + $custom_css_modules = !empty($this->plugin_settings['modules']['custom_css']) && is_array($this->plugin_settings['modules']['custom_css']) ? $this->plugin_settings['modules']['custom_css'] : array(); + $custom_css = array_merge($custom_css_design, $custom_css_modules); // CONTENT $heading = !empty($this->plugin_settings['design']['heading']) ? $this->plugin_settings['design']['heading'] : ''; @@ -616,7 +605,8 @@ public function redirect() { } if (preg_match('#wp-admin/#', $_SERVER['REQUEST_URI'])) { - wp_redirect($this->plugin_settings['general']['redirection']); + $redirect_to = stripslashes($this->plugin_settings['general']['redirection']); + wp_redirect($redirect_to); } } @@ -635,7 +625,7 @@ public function add_subscriber() { if (empty($exists)) { $wpdb->insert( $wpdb->prefix . 'wpmm_subscribers', array( - 'email' => $_REQUEST['email'], + 'email' => sanitize_text_field($_REQUEST['email']), 'insert_date' => date('Y-m-d H:i:s') ), array('%s', '%s')); } @@ -673,7 +663,7 @@ public function send_contact() { $email_content = ob_get_contents(); ob_clean(); - $send_to = !empty($this->plugin_settings['modules']['contact_email']) ? $this->plugin_settings['modules']['contact_email'] : get_option('admin_email'); + $send_to = !empty($this->plugin_settings['modules']['contact_email']) ? stripslashes($this->plugin_settings['modules']['contact_email']) : get_option('admin_email'); $subject = __('Message via contact', $this->plugin_slug); add_filter('wp_mail_content_type', create_function('', 'return "text/html";')); diff --git a/readme.md b/readme.md index a52ae0cb..907efa20 100755 --- a/readme.md +++ b/readme.md @@ -86,7 +86,7 @@ We embedded a new css style on maintenance page. Same mechanism can be used for **Cache Plugin Support** -The plugin flush the cache on activate the maintenance mode form the plugins W3 Total Cache and WP Super Cache +WP Maintenance Mode can be unstable due the cache plugins, we recommend to deactivate any cache plugin when maintenance mode is active. ## Other Notes ### License diff --git a/readme.txt b/readme.txt index df7fdb33..487354c6 100644 --- a/readme.txt +++ b/readme.txt @@ -7,7 +7,7 @@ Author URI: http://designmodo.com/ Tags: maintenance, mode, admin, administration, unavailable, coming soon, multisite, landing page, under construction, contact form, subscribe, countdown Requires at least: 3.5 Tested up to: 3.9.2 -Stable tag: 2.0.0 +Stable tag: 2.0.1 License: GPL-2.0+ Adds a splash page to your site that lets visitors know your site is down for maintenance. It's perfect for a coming soon page. @@ -60,19 +60,29 @@ Please give us feedback, contribute and file technical bugs on [GitHub Repo](htt See [GitHub Repo] (https://github.com/Designmodocom/WP-Maintenance-Mode) FAQ. = Cache Plugin Support = -The plugin flush the cache on activate the maintenance mode form the plugins W3 Total Cache and WP Super Cache +WP Maintenance Mode can be unstable due the cache plugins, we recommend to deactivate any cache plugin when maintenance mode is active. == Changelog == -= 2.0.0 (02/09/2014) = += 2.0.1 (02/09/2014) = +* Reintroduced some deprecated actions from old version (but still available in next 4 releases, after that will be removed) and replaced with new ones: +- `wm_head` -> `wpmm_head` +- `wm_footer` -> `wpmm_footer` +* Multisite settings link fix +* WP_Maintenance_Mode: init (array checking for custom_css arrays, move delete cache part into a helper, etc.), add_subscriber, send_contact, redirect fixes & optimizations +* WP_Maintenance_Mode_Admin: save_plugin_settings fixes, delete_cache (new method) +* Settings & Maintenance views fixes +* Readme.txt changes + += 2.0.0 (01/09/2014) = * Changed design and functionality, new features * Changed multisite behaviour: now you can activate maintenance individually (each blog from the network has it's own maintenance settings) * Removed actions: `wm_header`, `wm_footer`, `wm_content` * Removed filters: `wm_header` * Removed [loginform] shortcode -* Some filters are depreciated (but still available in next 4 releases, after that will be removed) and replaced with new ones: +* Some filters are deprecated (but still available in next 4 releases, after that will be removed) and replaced with new ones: - `wm_heading` -> `wpmm_heading`, -- `wp_maintenance_mode_status_code` -> `wp_maintenance_mode_status_code` +- `wp_maintenance_mode_status_code` -> `wpmm_status_code` - `wm_title` -> `wpmm_meta_title` - `wm_meta_author` -> `wpmm_meta_author` - `wm_meta_description` -> `wpmm_meta_description` diff --git a/views/maintenance.php b/views/maintenance.php index 9e3c58a0..ce719d14 100644 --- a/views/maintenance.php +++ b/views/maintenance.php @@ -1,7 +1,7 @@ - <?php echo $title; ?> + <?php echo stripslashes($title); ?> - - - - + + + +
-

-

+

+

plugin_settings['modules']['countdown_status']) && $this->plugin_settings['modules']['countdown_status'] == 1) { @@ -39,7 +43,7 @@ plugin_settings['modules']['subscribe_status']) && $this->plugin_settings['modules']['subscribe_status'] == 1) { ?> - plugin_settings['modules']['subscribe_text'])) { ?>

plugin_settings['modules']['subscribe_text']; ?>

+ plugin_settings['modules']['subscribe_text'])) { ?>

plugin_settings['modules']['subscribe_text']); ?>