| 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
|
|||||||
| 24 | {
|
||||||
| 25 | define('AUTO_MAINTENANCE_MODE_VERSION', $this->plugin_version);
|
||||||
| 26 | define('AUTO_MAINTENANCE_MODE_SITE_URL',site_url());
|
||||||
|
0 ignored issues
–
show
The function
site_url was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 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
|
|||||||
| 32 | {
|
||||||
| 33 | add_action('plugins_loaded', array($this, 'plugins_loaded_handler'));
|
||||||
|
0 ignored issues
–
show
The function
add_action was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 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
|
|||||||
| 42 | if( is_user_logged_in() ) {
|
||||||
|
0 ignored issues
–
show
The function
is_user_logged_in was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 43 | if ( false === ( $tmp_value = get_transient( 'amm_is_any_user_logged_in' ) ) ) {
|
||||||
|
0 ignored issues
–
show
The function
get_transient was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 44 | $value = true; |
||||||
| 45 | set_transient( 'amm_is_any_user_logged_in', $value, 60*60 ); |
||||||
|
0 ignored issues
–
show
The function
set_transient was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 46 | } |
||||||
| 47 | } |
||||||
| 48 | } |
||||||
| 49 | function amm_clear_transient() {
|
||||||
|
0 ignored issues
–
show
|
|||||||
| 50 | delete_transient('amm_is_any_user_logged_in');
|
||||||
|
0 ignored issues
–
show
The function
delete_transient was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 51 | } |
||||||
| 52 | function plugins_loaded_handler() |
||||||
|
0 ignored issues
–
show
|
|||||||
| 53 | {
|
||||||
| 54 | load_plugin_textdomain('auto-maintenance-mode', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/');
|
||||||
|
0 ignored issues
–
show
The function
plugin_basename was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
The function
load_plugin_textdomain was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 55 | } |
||||||
| 56 | function plugin_url() |
||||||
|
0 ignored issues
–
show
|
|||||||
| 57 | {
|
||||||
| 58 | if($this->plugin_url) return $this->plugin_url; |
||||||
| 59 | return $this->plugin_url = plugins_url( basename( plugin_dir_path(__FILE__) ), basename( __FILE__ ) ); |
||||||
|
0 ignored issues
–
show
The function
plugin_dir_path was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
The function
plugins_url was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 60 | } |
||||||
| 61 | function plugin_path(){
|
||||||
|
0 ignored issues
–
show
|
|||||||
| 62 | if ( $this->plugin_path ) return $this->plugin_path; |
||||||
| 63 | return $this->plugin_path = untrailingslashit( plugin_dir_path( __FILE__ ) ); |
||||||
|
0 ignored issues
–
show
The function
untrailingslashit was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
The function
plugin_dir_path was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 64 | } |
||||||
| 65 | function is_valid_page() {
|
||||||
|
0 ignored issues
–
show
|
|||||||
| 66 | return in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php'));
|
||||||
| 67 | } |
||||||
| 68 | function amm_template_redirect() |
||||||
|
0 ignored issues
–
show
|
|||||||
| 69 | {
|
||||||
| 70 | if(is_user_logged_in()){
|
||||||
|
0 ignored issues
–
show
The function
is_user_logged_in was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 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
|
||||||
|
0 ignored issues
–
show
The function
is_admin was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 77 | if ( false === ( $tmp_value = get_transient( 'amm_is_any_user_logged_in' ) ) ) {
|
||||||
|
0 ignored issues
–
show
The function
get_transient was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 78 | $this->load_amm_page(); |
||||||
| 79 | } |
||||||
| 80 | } |
||||||
| 81 | } |
||||||
| 82 | } |
||||||
| 83 | function load_amm_page() |
||||||
|
0 ignored issues
–
show
|
|||||||
| 84 | {
|
||||||
| 85 | header('HTTP/1.0 503 Service Unavailable');
|
||||||
| 86 | ?> |
||||||
| 87 | <!DOCTYPE html> |
||||||
| 88 | <html lang="<?php echo get_bloginfo('language'); ?>">
|
||||||
|
0 ignored issues
–
show
The function
get_bloginfo was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 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; ?> › Auto Maintenance Mode</title> |
||||||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||||
| 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>
|
||||||
|
0 ignored issues
–
show
The function
_e was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 111 | <!-- <p><?php echo $link_text;?></p> --> |
||||||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||||
| 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>
|
||||||
|
0 ignored issues
–
show
The function
wp_login_url was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 114 | <p><?php _e('Sorry for the inconvenience.', 'auto-maintenance-mode')?></p>
|
||||||
| 115 | </div> |
||||||
| 116 | </body> |
||||||
| 117 | </html> |
||||||
| 118 | <?php |
||||||
| 119 | exit(); |
||||||
|
0 ignored issues
–
show
|
|||||||
| 120 | } |
||||||
| 121 | } |
||||||
| 122 | $GLOBALS['auto_maintenance_mode'] = new AUTO_MAINTENANCE_MODE(); |
||||||
| 123 | } |
||||||
| 124 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.