Issues (71)

auto-maintenance-mode.php (14 issues)

1
<?php
2
/*
3
Plugin Name: Auto Maintenance Mode
4
Version: 1.0.2
5
Plugin URI: https://github.com/pothi/auto-maintenance-mode
6
Author: pothi
7
Author URI: https://www.tinywp.in
8
Description: A plugin to enable maintenance mode automatically upon lack of activity on development / staging / test sites.
9
Text Domain: auto-maintenance-mode
10
Domain Path: /languages
11
*/
12
13
// disable executing this script directly
14
if(!defined('ABSPATH')) exit;
15
16
if(!class_exists('AUTO_MAINTENANCE_MODE'))
17
{
18
    class AUTO_MAINTENANCE_MODE
19
    {
20
        var $plugin_version = '1.0.3';
21
        var $plugin_url;
22
        var $plugin_path;
23
        function __construct()
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
24
        {
25
            define('AUTO_MAINTENANCE_MODE_VERSION', $this->plugin_version);
26
            define('AUTO_MAINTENANCE_MODE_SITE_URL',site_url());
27
            define('AUTO_MAINTENANCE_MODE_URL', $this->plugin_url());
28
            define('AUTO_MAINTENANCE_MODE_PATH', $this->plugin_path());
29
            $this->plugin_includes();
30
        }
31
        function plugin_includes()
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
32
        {
33
            add_action('plugins_loaded', array($this, 'plugins_loaded_handler'));
34
            add_action('template_redirect', array($this, 'amm_template_redirect'));
35
36
            // clear transient on logout and create upon login
37
            add_action('wp_login', array($this, 'amm_create_transient'));
38
            add_action('init', array($this, 'amm_create_transient'));
39
            add_action('wp_logout', array($this, 'amm_clear_transient'));
40
        }
41
        function amm_create_transient() {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
42
            if( is_user_logged_in() ) {
43
                if ( false === ( $tmp_value = get_transient( 'amm_is_any_user_logged_in' ) ) ) {
0 ignored issues
show
The assignment to $tmp_value is dead and can be removed.
Loading history...
44
                    $value = true;
45
                    set_transient( 'amm_is_any_user_logged_in', $value, 60*60 );
46
                }
47
            }
48
        }
49
        function amm_clear_transient() {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
50
            delete_transient('amm_is_any_user_logged_in');
51
        }
52
        function plugins_loaded_handler()
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
53
        {
54
            load_plugin_textdomain('auto-maintenance-mode', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/'); 
55
        }
56
        function plugin_url()
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
57
        {
58
            if($this->plugin_url) return $this->plugin_url;
59
            return $this->plugin_url = plugins_url( basename( plugin_dir_path(__FILE__) ), basename( __FILE__ ) );
60
        }
61
        function plugin_path(){     
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
62
            if ( $this->plugin_path ) return $this->plugin_path;        
63
            return $this->plugin_path = untrailingslashit( plugin_dir_path( __FILE__ ) );
64
        }
65
        function is_valid_page() {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
66
            return in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php'));
67
        }
68
        function amm_template_redirect()
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
69
        {
70
            if(is_user_logged_in()){
71
                //do not display maintenance page
72
                // $this->amm_create_transient_on_login();
73
            }
74
            else
75
            {
76
                if( !is_admin() && !$this->is_valid_page()){  //show maintenance page
77
                    if ( false === ( $tmp_value = get_transient( 'amm_is_any_user_logged_in' ) ) ) {
0 ignored issues
show
The assignment to $tmp_value is dead and can be removed.
Loading history...
78
                        $this->load_amm_page();
79
                    }
80
                }
81
            }
82
        }
83
        function load_amm_page()
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
84
        {
85
            header('HTTP/1.0 503 Service Unavailable');
86
?>
87
<!DOCTYPE html>
88
<html lang="<?php echo get_bloginfo('language'); ?>">
89
<head>
90
    <meta charset="<?php echo get_bloginfo('charset'); ?>" />
91
    <meta name="viewport" content="width=device-width, initial-width=1">
92
    <title><?php echo $name; ?> &#8250; Auto Maintenance Mode</title>
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $name seems to be never defined.
Loading history...
93
    <style>
94
        * { margin: 0;  padding: 0; }
95
        body { font-family: Georgia, Arial, Helvetica, Sans Serif; font-size: 65.5%; }
96
        a { color: #08658F; }
97
        a:hover { color: #0092BF; }
98
        #header { color: #333; padding: 1.5em; text-align: center; font-size: 1.2em; border-bottom: 1px solid #08658F; }
99
        #content { font-size: 150%; width:80%; margin:0 auto; padding: 5% 0; text-align: center; }
100
        #content p { font-size: 1em; padding: .8em 0; }
101
        h1, h2 { color: #08658F; }
102
        h1 { font-size: 300%; padding: .5em 0; }
103
    </style>
104
</head>
105
<body>
106
    <div id="header">
107
        <h2><?php echo get_bloginfo('name'); ?></h2>
108
    </div>  
109
    <div id="content">
110
        <h1><?php _e('Auto Maintenance Mode', 'auto-maintenance-mode')?></h1>
111
        <!-- <p><?php echo $link_text;?></p> -->
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $link_text seems to be never defined.
Loading history...
112
        <p><?php _e('Maintenance mode is enabled automatically, due to lack of activity from logged-in users!', 'auto-maintenance-mode')?></p>
113
        <p><?php _e('To disable the maintenance mode, please ', 'auto-maintenance-mode')?><strong><a href="<?php echo wp_login_url()?>"><?php _e('login now', 'auto-maintenance-mode'); ?></a></strong><?php _e(' or visit this page or any page of this site using a browser where you have already logged-in.', 'auto-maintenance-mode')?></p>
114
        <p><?php _e('Sorry for the inconvenience.', 'auto-maintenance-mode')?></p>
115
    </div>
116
</body>
117
</html>
118
<?php
119
            exit();
120
        }
121
    }
122
    $GLOBALS['auto_maintenance_mode'] = new AUTO_MAINTENANCE_MODE();
123
}
124