WordPress.org

Plugin Directory

Changeset 1758718


Ignore:
Timestamp:
11/04/17 18:07:15 (2 weeks ago)
Author:
themattroyal
Message:

Plugin refactor. Version 2 release

Location:
woocommerce-maintenance-mode/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • woocommerce-maintenance-mode/trunk/LICENSE

    r929613 r1758718  
    1 GNU GENERAL PUBLIC LICENSE 
     1                    GNU GENERAL PUBLIC LICENSE 
    22                       Version 3, 29 June 2007 
    33 
    4  Copyright (C) 2007 Free Software Foundation, Inc. {http://fsf.org/} 
     4 Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> 
    55 Everyone is permitted to copy and distribute verbatim copies 
    66 of this license document, but changing it is not allowed. 
     
    632632the "copyright" line and a pointer to where the full notice is found. 
    633633 
    634     {one line to give the program's name and a brief idea of what it does.} 
    635     Copyright (C) {year}  {name of author} 
     634    <one line to give the program's name and a brief idea of what it does.> 
     635    Copyright (C) <year>  <name of author> 
    636636 
    637637    This program is free software: you can redistribute it and/or modify 
     
    646646 
    647647    You should have received a copy of the GNU General Public License 
    648     along with this program.  If not, see {http://www.gnu.org/licenses/}. 
     648    along with this program.  If not, see <http://www.gnu.org/licenses/>. 
    649649 
    650650Also add information on how to contact you by electronic and paper mail. 
     
    653653notice like this when it starts in an interactive mode: 
    654654 
    655     WooCommerce-Email-Validation-PRO  Copyright (C) 2013  Hugh Lashbrooke 
     655    <program>  Copyright (C) <year>  <name of author> 
    656656    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 
    657657    This is free software, and you are welcome to redistribute it 
     
    665665if any, to sign a "copyright disclaimer" for the program, if necessary. 
    666666For more information on this, and how to apply and follow the GNU GPL, see 
    667 {http://www.gnu.org/licenses/}. 
     667<http://www.gnu.org/licenses/>. 
    668668 
    669669  The GNU General Public License does not permit incorporating your program 
     
    672672the library.  If this is what you want to do, use the GNU Lesser General 
    673673Public License instead of this License.  But first, please read 
    674 {http://www.gnu.org/philosophy/why-not-lgpl.html}. 
     674<http://www.gnu.org/philosophy/why-not-lgpl.html>. 
  • woocommerce-maintenance-mode/trunk/readme.txt

    r1170994 r1758718  
    1 === WooCommerce Maintenance Mode === 
     1=== WooCommerce Maintenance Mode (Free) === 
    22Contributors: themattroyal 
    33Donate link: http://mattroyal.co.za/donate 
    4 Tags: woocommerce, maintenance, shop, store, notice, alert, redirect, lightbox 
     4Tags: woocommerce, maintenance, woocommerce maintenance, shop, store, notice, alert, redirect, lightbox, popup, alert, notification, modal, disable shop, disable ecommerce 
    55Requires at least: 3.8 
    6 Tested up to: 4.2 
    7 Stable tag: 1.4 
     6Tested up to: 4.8.2 
     7Stable tag: 2.0.0 
    88 
    99Store messages or redirects on all WooCommerce pages for non admins. Other pages/posts unaffected. Ideal for store maintenance or store wide notices. 
     
    1111== Description == 
    1212 
    13 Easily choose between displaying a message or specifying an existing page or external URL to redirect users. This will be applied to all users that are not-logged in and are without shop editing capabilities.This will only affect WooCommerce store pages and no other pages or posts on your website.  
     13Easily choose between redirecting users or displaying notifications with the option to disable e-commerce functionality whilst still allowing product visibility. You can set your notifications to occur site wide or only on WooCommerce pages, thus not affecting any other part of your website. 
    1414 
    15 Easily select from your websites existing pages to pull in content for your messages or as a destination for your redirects. Alternatively use the Maintenance WYSIWYG field to create your own custom messages (just like on a page or post).  
     15Logged in admins will not be redirected or see the notifications set in the backend, so you can continue working, testing and managing your store seemllessly without your users ever being aware you are working on it and without it interfearing with your work flow. 
    1616 
    17 Set an end date that will automatically resume your store to normal view and enjoy the flexibility of being able to adjust the frequency at which to display your store messages or redirects to your users.  
     17**For Premium Users:** 
     18 
     19You can set an end date that will automatically disable redirects or notications to resume your store to its normal view, just in case you forget. You can also enjoy the flexibility of being able to adjust the frequency at which to display your store notifications or redirects to your users. 
     20 
     21You will also be able to create your custom messages with a WYSIWYG editor(just like on a page or post), making use of lightbox popup modals and be able to use any shortcodes including some bundled with the premium version for your convenience. 
     22 
    1823 
    1924Requires WordPress 3.0 + and WooCommerce 2.0 +. 
     
    2429**Features** 
    2530 
    26 * Set end date 
    27 * Control frequency of messages/redirects  
    28 * Control how message is displayed 
    29 * Countdown Timer 
     31* Redirect users 
     32* Show notifications/messages 
     33* Control colour scheme of notification area to match you theme/website 
     34* Set for all pages or only WooCommerce pages 
     35* Disable e-commerce functionality but still display products 
     36 
     37* Use shortcodes anywhere you display messaging - Premium only 
     38* Lightbox Popup option - Premium only 
     39* Auto disable with end date - Premium only 
     40* Control frequency of messages - Premium only 
     41* Countdown Timer with various display options (& other handy bundled shortcodes) - Premium only 
    3042 
    3143== Usage == 
    3244 
    33 * Go to 'Settings' > WooMaintenance 
    34 * Switch 'Activation' mode ON 
    35 * Select your end date 
    36 * Specify your message intervals 
    37 * Select your display option or redirect 
    38 * Select your page for redirect or message or 
    39 * Add URL for external redirect or use editor to create your message 
    40  
    41 **Please Note - NB!!** 
    42  
    43 * If the chosen 'Display Option' is set to 'Redirect', the 'External Redirect URL' field must be empty to redirect to an 'Existing Page' option as seen below it. If you specify a URL in the field it will ignore the 'Existing Page' option. 
    44 * If the chosen 'Display Option' is set to 'Lightbox' or 'On Page', the Store Message WYSIWYG textarea must be empty to use content from the 'Existing Page' option above. If Store Message WYSIWYG textarea has any content whatsoever, it will ignore the existing page option. 
     45* Go to 'WooCommerce' > Maintenance Mode 
     46* Specify your mode (redirect or notification type) 
     47* Specify the display (all pages or WooCommerce pages only) 
     48* Once these settings have been saved, the appropriate tab will then be added to the screen to further manage your options 
     49* Add a URL for redirect or add your message content, set your colour scheme and save. 
     50* Preview your settings and once your satisfied, make sure your activation is switched on (under general settings). 
    4551 
    4652 
     
    5763= The plugin isn't working?! = 
    5864 
    59 When previewing your lightbox popup, in-page message or testing your redirect you MUST remember to logout and then view it or use a secondary browser that is not logged into your Dashboard to view it. One of the conditions for the plugin to display or redirect on WooCommerce pages is that the user is NOT logged in, but its easy to forget this when working or testing things on your site. (I have done it plenty.) 
     65The premise of maintenance mode is to have your visitors see one thing and someone logged in as an admin to see the real state of the website so make sure you are logged out or alternatively, ig you are logged in you can use the built in preview button or tab. 
    6066 
    61 Also remember to either use the 0 value for cookie settings within your plugin whilst testing or use the delete all cookies button and then test again. Often it is not working because the cookie has already been set previously and you have just forgotten about it :) 
     67If the activation is not toggled on, you will see your settings applied to the site in preview mode but this will not be live so none of your website visitors or you will see this. 
    6268 
    6369= I have a question, I need help = 
     
    7480 
    7581== Changelog == 
     82 
     83= 2.0.0 = 
     84* 2017-10-20 
     85* Ovehaul of plugin, re-written with OOP (object oriented programming). Some features have been removed and some improved upon. Not compatible with previous version. Any previous settings will likely be lost. It is now also located under the main WooCommerce menu. 
    7686 
    7787= 1.4 = 
     
    102112== Upgrade Notice == 
    103113 
     114= 2.0.0 = 
     115* 2017-10-20 
     116* Ovehaul of plugin, re-written with OOP (object oriented programming). Some features have been removed and some improved upon. Not compatible with previous version. Any previous settings will likely be lost. It is now also located under the main WooCommerce menu. 
     117 
    104118= 1.4 = 
    105119* 2015-06-30 
  • woocommerce-maintenance-mode/trunk/woocommerce-maintenance-mode.php

    r1170994 r1758718  
    11<?php 
    22/* 
    3    Plugin Name: WooCommerce Maintenance Mode 
    4    Version: 1.4 
    5    Description: Add a message or redirect on Woocommerce pages only, not affecting any other parts of your website. Logged in admins will not see anything. 
    6    Plugin URI: http://www.mattroyal.co.za/plugins/woocommerce-maintenance-mode/ 
    7    Author: Matt Royal 
    8    Author URI: http://www.mattroyal.co.za/ 
    9    Requires at least: 3.8 
    10    Tested up to: 4.2 
    11    Text Domain: woocommerce-maintenance-mode 
    12    License: GPLv3 
    13   */ 
     3 * Plugin Name: WooCommerce Maintenance Mode (Free Version) 
     4 * Version: 2.0.0 
     5 * Plugin URI: http://www.mattroyal.co.za/plugins/woocommerce-maintenance-mode/ 
     6 * Description: Show notifications or redirect users with the option to disable e-commerce functionality but still allow product visibility. You can set this site wide or on WooCommerce pages only thus not affecting any other parts of your website. Logged in admins will not see anything so you can continue working, testing and managing your store seemllessly without your users even being aware and you can specify a date to automatically disable the redirect/notification so you never forget. 
     7 * Author: Matt Royal 
     8 * Author URI: http://www.mattroyal.co.za/ 
     9 * Requires at least: 3.8 
     10 * Tested up to: 4.8.2 
     11 * 
     12 * Text Domain: woocommerce-maintenance-mode 
     13 * Domain Path: /lang/ 
     14 * 
     15 * @package WordPress 
     16 * @author Matt Royal 
     17 * @since 2.0.0 
     18 */ 
    1419 
    1520if ( ! defined( 'ABSPATH' ) ) exit; 
    1621 
    17 // Check if WooCommerce is active 
    18 if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { 
    19      
    20     function woocommerce_maintmode_i18n_init() { 
    21         $pluginDir = dirname(plugin_basename(__FILE__)); 
    22         load_plugin_textdomain('woocommerce-maintenance-mode', false, $pluginDir . '/lang/'); 
    23     } 
    24      
    25     woocommerce_maintmode_i18n_init(); 
    26      
    27      
    28     // Add Settings Page Link 
    29     function woocommerce_maintmode_settings_link( $links ) { 
    30         $settings_link = '<a href="options-general.php?page=woocommerce_maintmode_plugin_options">Settings</a>'; 
    31         array_push( $links, $settings_link ); 
    32         return $links; 
    33     } 
    34      
    35     $plugin = plugin_basename( __FILE__ ); 
    36      
    37     add_filter( "plugin_action_links_$plugin", 'woocommerce_maintmode_settings_link' ); 
    38      
    39      
    40     // include plugin settings page/options 
    41     require_once ( "admin/admin.php" ); 
    42      
    43      
    44     // Display admin notice when activated 
    45     $options = get_option('woo_maint'); 
    46          
    47     if ( $options['activation'] == 1 ) { 
    48          
    49         function woocommerce_maintmode_admin_notice() { 
     22if ( class_exists( 'WooCommerce_Maintenance_Mode' ) ) { 
    5023             
    51             global $current_user ; 
    52             $user_id = $current_user->ID; 
    53              
    54             if ( ! get_user_meta($user_id, 'woocommerce_maintmode_ignore_notice') ) { 
    55                 echo '<div class="error"><p>'; 
    56                 printf(__('WooCommerce Maintenance/Message mode is Active! | <a href="options-general.php?page=woocommerce_maintmode_plugin_options">Turn Off</a> | <a href="admin.php?page=w3tc_dashboard&w3tc_note=flush_all">Flush Cache (W3 Total Cache)</a><br /> 
    57                             Please make sure you are logged out and you have cleared all cookies before testing!!<!-- | <a href="%1$s">Hide Notice</a> -->'), '?woocommerce_maintmode_nag_ignore=0'); 
    58                 echo "</p></div>"; 
    59             } 
    60         } 
    61          
    62         add_action('admin_notices', 'woocommerce_maintmode_admin_notice'); 
    63          
    64             // Allow admin notice to be dismissed  
    65             function woocommerce_maintmode_nag_ignore() { 
    66              
    67             global $current_user; 
    68             $user_id = $current_user->ID; 
    69              
    70             if ( isset($_GET['woocommerce_maintmode_nag_ignore']) && '0' == $_GET['woocommerce_maintmode_nag_ignore'] ) { 
    71                  add_user_meta($user_id, 'woocommerce_maintmode_ignore_notice', 'true', true); 
    72             } 
    73         } 
    74          
    75         // add_action('admin_init', 'woocommerce_maintmode_nag_ignore'); 
    76              
    77     } 
    78      
    79          
    80     // Register and Enqueue Theme Scripts 
    81     function woocommerce_maintmode_scripts() { 
    82          
    83         global $woocommerce; 
    84         $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; 
    85              
    86         wp_enqueue_script( 'prettyPhoto', $woocommerce->plugin_url() . '/assets/js/prettyPhoto/jquery.prettyPhoto' . $suffix . '.js', array( 'jquery' ), '3.1.5', true ); 
    87          
    88         wp_register_style( 'woo_maint_prettyPhotocss', plugins_url( 'assets/prettyPhoto/css/prettyPhoto.css' , __FILE__ ), '', '', 'all' ); 
    89         wp_enqueue_style( 'woo_maint_prettyPhotocss' );  
     24    exit( __( '<p>I am sad to see you reverting to the free version, please think about sending me some feedback so I can help or make improvements <a href="http://mattroyal.co.za/contact-me/" target="_blank">(click here to mail me)</a>. If you really still want to, please first deactivate and delete the premium version of WooCommerce Maintenance Mode plugin first.</p>', 'woocommerce-maintenance-mode') ); 
     25} 
    9026 
    91         wp_register_script( 'woo_maint_cookiesjs', plugins_url( 'assets/jquery.cookie.js' , __FILE__ ),array('jquery'), '1.0', false ); 
    92         wp_enqueue_script( 'woo_maint_cookiesjs' );  
    93          
    94     } 
    95      
    96     function woocommerce_maintmode_countdown_scripts() {     
    97          
    98         wp_register_script( 'woo_maint_pluginjs', plugins_url( 'assets/countdown/jquery.plugin.min.js' , __FILE__ ),array('jquery'), false, false ); 
    99         wp_enqueue_script( 'woo_maint_pluginjs' );   
    100          
    101         wp_register_script( 'woo_maint_countdownjs', plugins_url( 'assets/countdown/jquery.countdown.min.js' , __FILE__ ),array('jquery'), '2.0', false ); 
    102         wp_enqueue_script( 'woo_maint_countdownjs' ); 
    103          
    104     } 
    105      
    106     // only add scripts to site if active 
    107     function woocommerce_maintmode_scripts_init(){ 
    108          
    109         $options = get_option('woo_maint'); 
    110          
    111         if ( ($options['activation'] == 1) /* && ! current_user_can( 'manage_woocommerce' ) */ ) { 
    112             add_action( 'wp_enqueue_scripts', 'woocommerce_maintmode_scripts' ); 
    113         } 
    114          
    115         if ( ($options['activation'] == 1) /* && ! current_user_can( 'manage_woocommerce' ) */ && ($options['countdown'] == 1) ) { 
    116             add_action( 'wp_enqueue_scripts', 'woocommerce_maintmode_countdown_scripts' ); 
    117         } 
    118     } 
    119      
    120     add_action( 'init', 'woocommerce_maintmode_scripts_init' ); 
    121      
    122     // Place some stuff into the websites pages 
    123     function woocommerce_maintmode_header() { 
    124          
    125         // check to see if users capabilities are less than woocommerce shop manager and only dispaly on Woocommerce pages 
    126         if( is_woocommerce() or is_shop() or is_product_category() or is_product() or is_cart() or is_checkout() or is_account_page() /* && ! current_user_can( 'manage_woocommerce' ) */ ) { 
    127              
    128             // Get some settings 
    129             $options = get_option('woo_maint'); 
    130             $options['end_date']; 
    131              
    132             // Set Default Time Zone based on WordPress settings 
    133             $wp_gmt_offset = get_option('gmt_offset'); 
    134             $wp_timezone = get_option('timezone_string'); 
    135             date_default_timezone_set($wp_timezone); 
    136              
    137             // Today's date time stamp 
    138             $today_date = date("Y-m-d");  
    139             $today_string = strtotime($today_date); 
    140          
    141             // End date time stamp 
    142             $timer_date = $options['end_date']; 
    143             $end_string = strtotime($timer_date); 
    144             $end_date = date("Y-m-d", $end_string);  
    145          
    146             // Difference between the two strings 
    147             $time_diff_string = $end_string - $today_string; 
    148             $time_diff = floor($time_diff_string/(60*60*24)); 
    149              
    150              
    151             // For countdown timer 
    152             $date_array = explode("-", $end_date); 
    153              
    154             $output .= ' 
    155              
    156             <style type="text/css"> 
    157              
    158                 .woo_maint_page { 
    159                     border: 3px dashed #999;  
    160                     margin: 20px 0 50px;  
    161                     padding: 20px;  
    162                     text-align: center; 
    163                 } 
    164                  
    165                 #defaultCountdown { 
    166                     height: auto; 
    167                     margin: 20px 0; 
    168                     } 
    169                      
    170                 .countdown-section { 
    171                     display:block; 
    172                     width:23%; 
    173                     float: left; 
    174                 } 
    175                                  
    176             </style> 
    177              
    178             <script> 
    179              
    180                 jQuery(document).ready(function(){ 
    181                      
    182                    var check_cookie = jQuery.cookie("lightbox_cookie"); 
    183                     if(check_cookie == null){ 
    184                          
    185                     jQuery.cookie("lightbox_cookie", "woo_maintmode_on", { expires: '.$options['cookie_expire'].', path: "/" });'; 
    186                      
    187                     if ( $time_diff >= 0 ) { 
    188                         $output .= 'jQuery(".royal-prettyPhoto").prettyPhoto({ 
    189                                         theme: "pp_default", 
    190                                         social_tools: "" 
    191                                     }).trigger("click");'; 
    192                     } 
    193                      
    194                    $output .= '}     
    195                     
    196                     jQuery(function () { 
    197                         var austDay = new Date(); 
    198                         austDay = new Date('.$date_array[0].', '.$date_array[1].' - 1, '.$date_array[2].'); 
    199                         jQuery("#defaultCountdown").countdown({until: austDay}); 
    200                     });          
    201                                     
    202                 }); 
    203                  
    204             </script>'; 
    205                      
    206             echo $output; 
    207              
    208             // Check if lightbox / page or content   
    209             if ( $options['position'] == 'Lightbox' /* && ! current_user_can( 'manage_woocommerce' ) */ ) { 
    210                  
    211                 if( $options['countdown'] == 1 ) { 
    212                      
    213                     $countdown = '<div id="defaultCountdown"></div>'; 
     27require_once( 'includes/class-woomaint.php' ); 
     28require_once( 'includes/class-woomaint-settings.php' ); 
     29require_once( 'includes/lib/class-woomaint-admin-api.php' ); 
     30require_once( 'includes/lib/class-maintmode-conditions.php' ); 
     31require_once( 'includes/lib/class-woomaint-store-notice.php' ); 
     32require_once( 'includes/lib/class-woomaint-store-redirect.php' ); 
    21433 
    215                 } else { 
    216                      
    217                     $countdown = ''; 
    218                 } 
    219                  
    220                 // Check if internal or external page 
    221                     if ( $options['message'] == '' ) { 
    222                         $page_id = $options['redirect_page']; 
    223                          
    224                         // ...and get + display message in pages 
    225                         $page = $page_id; 
    226                         $page_data = get_post( $page ); 
    227                         $page_content = $page_data->post_content; 
    228                          
    229                         //$title = $page_data->post_title; 
    230                          
    231                         $content = ' 
    232                         <a class="royal-prettyPhoto" href="#woo_maint_lightbox" style="display: none;">Inline</a> 
    233                         <div id="woo_maint_lightbox" style="display: none;">'.$page_content.''.$countdown.'</div>'; 
    234                      
    235                         echo $content; 
    236                      
    237                     } else { 
    238                  
    239                         $content = ' 
    240                             <a class="royal-prettyPhoto" href="#woo_maint_lightbox" style="display: none;">Inline</a> 
    241                             <div id="woo_maint_lightbox" style="display: none;">'.$options['message'].''.$countdown.'</div>'; 
    242                          
    243                         echo $content; 
    244                      
    245                     } 
    246              
    247             }  
    248          
    249         } 
    250      
    251     } 
    252      
    253     // Initialize fuction to add stuff to header 
    254     function woocommerce_maintmode_header_init(){ 
    255          
    256         $options = get_option('woo_maint'); 
    257          
    258         if ( ($options['activation'] == 1) && ($options['position'] == 'Page' or $options['position'] == 'Lightbox') /* && ! current_user_can( 'manage_woocommerce' ) */ ) { 
    259             add_filter('wp_head', 'woocommerce_maintmode_header'); 
    260         } 
    261     } 
    262      
    263     add_action( 'init', 'woocommerce_maintmode_header_init' ); 
    264      
    265              
    266      
    267     // Redirect Function 
    268     function woocommerce_maintmode_redirect(){ 
    269          
    270         // Check if redirect option set 
    271         $options = get_option('woo_maint'); 
    272         $options['end_date']; 
    273              
    274         // Set Default Time Zone based on WordPress settings 
    275         $wp_gmt_offset = get_option('gmt_offset'); 
    276         $wp_timezone = get_option('timezone_string'); 
    277         date_default_timezone_set($wp_timezone); 
    278          
    279         // Today's date time stamp 
    280         $today_date = date("Y-m-d");  
    281         $today_string = strtotime($today_date); 
    282      
    283         // End date time stamp 
    284         $timer_date = $options['end_date']; 
    285         $end_string = strtotime($timer_date); 
    286         $end_date = date("Y-m-d", $end_string);  
    287      
    288         // Difference between the two strings 
    289         $time_diff_string = $end_string - $today_string; 
    290         $time_diff = floor($time_diff_string/(60*60*24)); 
    291          
    292         // Check if internal or external page 
    293         if ( $options['redirect_url'] == '' ) { 
    294             $page_url = get_permalink( $options['redirect_page'] ); 
    295             $redirection = $page_url; 
    296         } else { 
    297             $redirection = $options['redirect_url']; 
    298         } 
    299          
    300         // Conditions to validate against before redirecting the user 
    301         if ( ( $options['position'] == 'Redirect' && $time_diff >= 0 ) && (is_woocommerce() or is_shop() or is_product_category() or is_product() or is_cart() or is_checkout() or is_account_page() ) /* && ! current_user_can( 'manage_woocommerce' ) */ ) { 
    302              
    303             // Check if cookie is set for the user 
    304             if ( ! isset( $_COOKIE['redirect_cookie'] ) ) { 
    305                  
    306                 $days = $options['cookie_expire']; 
    307                 $cookie = 'woo_maintmode_on'; 
    308                  
    309                 // Set the cookie for the user 
    310                 setcookie('redirect_cookie',$cookie,time() + (86400 * $days), '/'); // 86400 = 1 day 
    311                      
    312                 // ...and Redirect user 
    313                 wp_redirect( $redirection, 302 ); exit(); 
    314             }  
    315         } 
    316          
    317     } 
    318      
    319     add_action( 'wp', 'woocommerce_maintmode_redirect' ); 
    320      
    321      
    322     // Add to just Woocommerce pages 
    323     function woocommerce_maintmode_page() { 
     34/** 
     35 * Returns the main instance of WooCommerce_Maintenance_Mode to prevent the need to use globals. 
     36 * 
     37 * @since  2.0.0 
     38 * @return object WooCommerce_Maintenance_Mode 
     39 */ 
     40function WooCommerce_Maintenance_Mode () { 
     41    $instance = WooCommerce_Maintenance_Mode::instance( __FILE__, '2.0.0' ); 
    32442 
    325         global $post; 
    326          
    327         // Check if redirect option set 
    328         $options = get_option('woo_maint'); 
    329         $options['end_date']; 
    330              
    331         // Set Default Time Zone based on WordPress settings 
    332         $wp_gmt_offset = get_option('gmt_offset'); 
    333         $wp_timezone = get_option('timezone_string'); 
    334         date_default_timezone_set($wp_timezone); 
    335          
    336         // Today's date time stamp 
    337         $today_date = date("Y-m-d");  
    338         $today_string = strtotime($today_date); 
    339      
    340         // End date time stamp 
    341         $timer_date = $options['end_date']; 
    342         $end_string = strtotime($timer_date); 
    343         $end_date = date("Y-m-d", $end_string);  
    344      
    345         // Difference between the two strings 
    346         $time_diff_string = $end_string - $today_string; 
    347         $time_diff = floor($time_diff_string/(60*60*24)); 
    348      
    349         // Conditions to validate against before redirecting the user 
    350         if ( ( $options['position'] == 'Page' && $time_diff >= 0 ) && (is_woocommerce() or is_shop() or is_product_category() or is_product() or is_cart() or is_checkout() or is_account_page() ) /* && ! current_user_can( 'manage_woocommerce' ) */ ) { 
    351              
    352             // Check if cookie is set for the user 
    353             if ( ! isset( $_COOKIE['page_cookie'] ) ) { 
    354                  
    355                 $days = $options['cookie_expire']; 
    356                 $cookie = 'woo_maintmode_on'; 
    357                  
    358                 // Set the cookie for the user 
    359                 setcookie('page_cookie',$cookie,time() + (86400 * $days), '/'); // 86400 = 1 day 
    360                  
    361                     $options = get_option('woo_maint'); 
    362                      
    363                     if ($options['countdown'] == 1) { 
    364                         $countdown = '<p><div id="defaultCountdown"></div></p>'; 
    365                     } else { 
    366                         $countdown = ''; 
    367                     } 
    368                  
    369                     // Check if internal or external page 
    370                     if ( $options['message'] == '' ) { 
    371                         $page_id = $options['redirect_page']; 
    372                          
    373                         // ...and get + display message in pages 
    374                         $page = $page_id; 
    375                         $page_data = get_post( $page ); 
    376                         $page_content = $page_data->post_content; 
    377                         //$title = $page_data->post_title; 
    378                          
    379                         $content.= '<div class="woo_maint_page">'; 
    380                         $content.= '<p>'.$page_content.''.$countdown.'</p>'; 
    381                         $content.= '</div>'; 
    382                              
    383                         echo $content; 
    384                  
    385                     } else { 
    386                          
    387                         $content.= '<div class="woo_maint_page">'; 
    388                         $content.= '<p>'.$options['message'].''.$countdown.'</p>'; 
    389                         $content.= '</div>'; 
    390                              
    391                         echo $content; 
    392                     } 
    393                  
    394                 //add_filter ('the_content', 'woocommerce_maintmode_page_message'); Use: function woocommerce_maintmode_page_message($content){} 
    395             }  
    396         } 
    397             
     43    if ( is_null( $instance->settings ) ) { 
     44        $instance->settings = WooCommerce_Maintenance_Mode_Settings::instance( $instance ); 
    39845    } 
    39946 
    400     add_action( 'woocommerce_before_main_content', 'woocommerce_maintmode_page'); 
    401     add_action( 'woocommerce_before_single_product', 'woocommerce_maintmode_page'); 
    402     add_action( 'woocommerce_before_cart', 'woocommerce_maintmode_page'); 
    403     add_action( 'woocommerce_before_my_account', 'woocommerce_maintmode_page'); 
    404     add_action( 'woocommerce_checkout_before_customer_details', 'woocommerce_maintmode_page'); 
    405      
    406      
    407     //add_action( 'wp', 'woocommerce_maintmode_page' ); 
    408      
    409 } else { 
    410      
    411     // If Woocommerce is not activated then admin error message  
    412     function woocommerce_maintmode_activate_admin_notice() { 
    413          
    414         global $current_user ; 
    415         $user_id = $current_user->ID; 
    416          
    417         if ( ! get_user_meta($user_id, 'woocommerce_maintmode_activate_ignore_notice') ) { 
    418             echo '<div class="error"><p>'; 
    419             printf(__('WooCommerce Plugin is not installed or activated. <!-- <a href="%1$s">Hide Notice</a> -->'), '?woocommerce_maintmode_activate_nag_ignore=0'); 
    420             echo "</p></div>"; 
    421         } 
    422     } 
    423      
    424     add_action('admin_notices', 'woocommerce_maintmode_activate_admin_notice'); 
    425      
    426     // Allow activation notice to be dismissed  
    427     function woocommerce_maintmode_activate_nag_ignore() { 
    428          
    429         global $current_user; 
    430         $user_id = $current_user->ID; 
    431          
    432         if ( isset($_GET['woocommerce_maintmode__activate_nag_ignore']) && '0' == $_GET['woocommerce_maintmode__activate_nag_ignore'] ) { 
    433              add_user_meta($user_id, 'woocommerce_maintmode__activate_ignore_notice', 'true', true); 
    434         } 
    435     } 
    436      
    437     // add_action('admin_init', 'woocommerce_maintmode_activate_nag_ignore'); 
    438  
    439 } 
    440 // Remove Existing Cookies Set By The Plugin     
    441 function woocommerce_maintmode_delete_cookies(){ 
    442      
    443     if(isset( $_GET['woo_maint_delete_cookies'] ) ) { 
    444          
    445         if ( isset( $_COOKIE['lightbox_cookie'] ) ) { 
    446            
    447             $expiry = time() - 60; 
    448    
    449             unset( $_COOKIE['lightbox_cookie'] ); 
    450             setcookie('lightbox_cookie', '', $expiry, '/'); 
    451              
    452              
    453          } 
    454           
    455          if ( isset( $_COOKIE['page_cookie'] ) ) { 
    456    
    457             $expiry = time() - 60; 
    458    
    459             unset( $_COOKIE['page_cookie'] ); 
    460             setcookie('page_cookie', '', $expiry, '/'); 
    461              
    462              
    463          } 
    464           
    465          if ( isset( $_COOKIE['redirect_cookie'] ) ) { 
    466    
    467             $expiry = time() - 60; 
    468    
    469             unset( $_COOKIE['redirect_cookie'] ); 
    470             setcookie('redirect_cookie', '', $expiry, '/'); 
    471              
    472              
    473          } 
    474                   
    475             echo '<div class="updated"><p>'; 
    476             printf(__('All Cookies Set By This Plugin Have Been Deleted'), ''); 
    477             echo "</p></div>"; 
    478     } 
    479      
     47    return $instance; 
    48048} 
    48149 
    482 add_action('admin_init','woocommerce_maintmode_delete_cookies'); 
     50WooCommerce_Maintenance_Mode(); 
Note: See TracChangeset for help on using the changeset viewer.