Plugin Directory

Changeset 3369189


Ignore:
Timestamp:
09/28/2025 12:32:05 PM (6 months ago)
Author:
fugudesign
Message:

Update to version 1.6.3 from GitHub

Location:
maintenance-switch
Files:
12 edited
1 copied

Legend:

Unmodified
Added
Removed
  • maintenance-switch/tags/1.6.3/includes/class-maintenance-switch.php

    r3369156 r3369189  
    1515
    1616// If this file is called directly, abort.
    17 if ( ! defined( 'WPINC' ) ) {
     17if (!defined('WPINC')) {
    1818    die;
    1919}
     
    3333 * @author     Fugu <info@fugu.fr>
    3434 */
    35 class Maintenance_Switch {
     35class Maintenance_Switch
     36{
    3637
    3738    /**
     
    108109     * @since    1.0.0
    109110     */
    110     public function __construct() {
     111    public function __construct()
     112    {
    111113
    112114        $this->plugin_name = MS_SLUG;
    113115        $this->version = PLUGIN_VERSION;
    114         $this->default_settings = json_decode( MS_DEFAULT_SETTINGS, true );
     116        $this->default_settings = json_decode(MS_DEFAULT_SETTINGS, true);
    115117        $this->current_theme = wp_get_theme();
    116118
     
    137139     * @access   private
    138140     */
    139     private function load_dependencies() {
     141    private function load_dependencies()
     142    {
    140143
    141144        /**
     
    143146         * core plugin.
    144147         */
    145         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-maintenance-switch-loader.php';
     148        require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-maintenance-switch-loader.php';
    146149
    147150        /**
     
    149152         * of the plugin.
    150153         */
    151         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-maintenance-switch-i18n.php';
     154        require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-maintenance-switch-i18n.php';
    152155
    153156        /**
    154157         * The class responsible for defining all actions that occur in the admin area.
    155158         */
    156         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-maintenance-switch-admin.php';
     159        require_once plugin_dir_path(dirname(__FILE__)) . 'admin/class-maintenance-switch-admin.php';
    157160
    158161        /**
     
    160163         * side of the site.
    161164         */
    162         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-maintenance-switch-public.php';
     165        require_once plugin_dir_path(dirname(__FILE__)) . 'public/class-maintenance-switch-public.php';
    163166
    164167        $this->loader = new Maintenance_Switch_Loader();
     
    175178     * @access   private
    176179     */
    177     private function set_locale() {
     180    private function set_locale()
     181    {
    178182
    179183        $plugin_i18n = new Maintenance_Switch_i18n();
    180         $plugin_i18n->set_domain( $this->plugin_name );
    181 
    182         $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
     184        $plugin_i18n->set_domain($this->plugin_name);
     185
     186        $this->loader->add_action('plugins_loaded', $plugin_i18n, 'load_plugin_textdomain');
    183187
    184188    }
     
    191195     * @access   private
    192196     */
    193     private function define_admin_hooks() {
    194 
    195         $plugin_admin = new Maintenance_Switch_Admin( $this );
     197    private function define_admin_hooks()
     198    {
     199
     200        $plugin_admin = new Maintenance_Switch_Admin($this);
    196201
    197202        $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_styles');
    198203        $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts');
    199        
     204
    200205        // Add AJAX variables to admin footer
    201206        $this->loader->add_action('admin_footer', $plugin_admin, 'add_ajax_script_variables');      // Add the options page and menu item.
    202         $this->loader->add_action( 'admin_menu', $plugin_admin, 'add_plugin_admin_menu' );
     207        $this->loader->add_action('admin_menu', $plugin_admin, 'add_plugin_admin_menu');
    203208
    204209        // Execute actions on settings option updated
    205         $this->loader->add_action( 'update_option_maintenance_switch_settings', $this, 'admin_action_update' );
     210        $this->loader->add_action('update_option_maintenance_switch_settings', $this, 'admin_action_update');
    206211
    207212        // Add an action link pointing to the options page.
    208         $plugin_basename = plugin_basename( plugin_dir_path( __DIR__ ) . $this->plugin_name . '.php' );
    209         $this->loader->add_filter( 'plugin_action_links_' . $plugin_basename, $plugin_admin, 'add_action_links' );
     213        $plugin_basename = plugin_basename(plugin_dir_path(__DIR__) . $this->plugin_name . '.php');
     214        $this->loader->add_filter('plugin_action_links_' . $plugin_basename, $plugin_admin, 'add_action_links');
    210215
    211216        // Add an action for the switch button
     
    213218
    214219        // Add an action to init in admin
    215         $this->loader->add_action( 'wp_loaded', $this, 'admin_init' );
     220        $this->loader->add_action('wp_loaded', $this, 'admin_init');
    216221
    217222        // Add callback action for ajax request
    218         $this->loader->add_action( 'wp_ajax_toggle_status', $this, 'toggle_status_callback' );
     223        $this->loader->add_action('wp_ajax_toggle_status', $this, 'toggle_status_callback');
    219224
    220225        // Admin notices
    221         $this->loader->add_action( 'admin_notices', $this, 'display_admin_notices' );
     226        $this->loader->add_action('admin_notices', $this, 'display_admin_notices');
    222227    }
    223228
     
    229234     * @access   private
    230235     */
    231     private function define_public_hooks() {
    232 
    233         $plugin_public = new Maintenance_Switch_Public( $this->plugin_name, $this->version );
    234 
    235         $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
    236         $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
    237 
    238         $this->loader->add_action( 'wp_head', $plugin_public,'set_ajaxurl' );
     236    private function define_public_hooks()
     237    {
     238
     239        $plugin_public = new Maintenance_Switch_Public($this->plugin_name, $this->version);
     240
     241        $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_styles');
     242        $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_scripts');
     243
     244        $this->loader->add_action('wp_head', $plugin_public, 'set_ajaxurl');
    239245    }
    240246
     
    244250     * @since    1.3.3
    245251     */
    246     public function admin_action_update() {
    247 
    248         $this->init_files( true );
     252    public function admin_action_update()
     253    {
     254
     255        $this->init_files(true);
    249256    }
    250257
     
    254261     * @since    1.3.3
    255262     */
    256     public function admin_action_request() {
     263    public function admin_action_request()
     264    {
    257265
    258266        $action = isset($_REQUEST['action']) ? sanitize_key($_REQUEST['action']) : '';
    259         if ( !empty( $action ) ) {
    260 
    261             switch( $action ) {
     267        if (!empty($action)) {
     268
     269            switch ($action) {
    262270
    263271                case 'restore_settings':
    264272
    265                     if ( $this->restore_default_settings() )
    266                         $this->notice( 'success', __( 'Default settings successfuly restored.', MS_SLUG ) );
     273                    if ($this->restore_default_settings())
     274                        $this->notice('success', __('Default settings successfuly restored.', MS_SLUG));
    267275                    else
    268                         $this->notice( 'error', __( 'Default settings was not restored.', MS_SLUG ) );
     276                        $this->notice('error', __('Default settings was not restored.', MS_SLUG));
    269277                    break;
    270278
    271279                case 'restore_html':
    272280
    273                     if ( $this->restore_html_setting() ) {
    274                         $this->notice( 'success', __( 'HTML code successfuly restored.', MS_SLUG ) );
     281                    if ($this->restore_html_setting()) {
     282                        $this->notice('success', __('HTML code successfuly restored.', MS_SLUG));
    275283                    } else {
    276                         $this->notice( 'error', __( 'HTML code could was not restored.', MS_SLUG ) );
     284                        $this->notice('error', __('HTML code could was not restored.', MS_SLUG));
    277285                    }
    278286                    break;
     
    280288                case 'create_theme_file':
    281289
    282                     if ( $this->create_theme_file() ) {
    283                         $this->notice( 'success', __( 'The theme file was created successfuly.', MS_SLUG ) );
     290                    if ($this->create_theme_file()) {
     291                        $this->notice('success', __('The theme file was created successfuly.', MS_SLUG));
    284292                    } else {
    285                         $this->notice( 'error', __( 'The theme file was not created.', MS_SLUG ) );
     293                        $this->notice('error', __('The theme file was not created.', MS_SLUG));
    286294                    }
    287295                    break;
     
    289297                case 'delete_theme_file':
    290298
    291                     if ( $this->delete_theme_file() ) {
    292                         $this->notice( 'success', __( 'The theme file was deleted successfuly', MS_SLUG ) );
     299                    if ($this->delete_theme_file()) {
     300                        $this->notice('success', __('The theme file was deleted successfuly', MS_SLUG));
    293301                    } else {
    294                         $this->notice( 'error', __( 'The theme file was not deleted.', MS_SLUG ) );
     302                        $this->notice('error', __('The theme file was not deleted.', MS_SLUG));
    295303                    }
    296304                    break;
     
    306314     * @since    1.3.3
    307315     */
    308      public function notice( $type, $notice ) {
    309 
    310          if ( !empty( $type ) && !empty( $notice ) )
    311             $this->notices[] = sprintf( '<div class="notice notice-%s is-dismissible"><p>%s</p></div>', $type, $notice );
    312      }
    313 
    314      /**
     316    public function notice($type, $notice)
     317    {
     318
     319        if (!empty($type) && !empty($notice))
     320            $this->notices[] = sprintf('<div class="notice notice-%s is-dismissible"><p>%s</p></div>', $type, $notice);
     321    }
     322
     323    /**
    315324     * Display admin notices stored in object
    316325     *
    317326     * @since    1.3.3
    318327     */
    319     public function display_admin_notices() {
    320 
    321         if ( !empty( $this->notices ) ) {
    322             foreach( $this->notices as $key => $notice ) {
     328    public function display_admin_notices()
     329    {
     330
     331        if (!empty($this->notices)) {
     332            foreach ($this->notices as $key => $notice) {
    323333                echo $notice;
    324334            }
     
    331341     * @since    1.1.1
    332342     */
    333     public function admin_init() {
     343    public function admin_init()
     344    {
    334345
    335346        $this->init_settings();
     
    343354     * @since    1.3.1
    344355     */
    345     public function init_settings() {
     356    public function init_settings()
     357    {
    346358
    347359        // Define if settings mode needs to be migrated from old to new system
     
    349361
    350362        // Get and delete previous settings values
    351         if ( $this->version_before( '1.3.3' ) ) {
     363        if ($this->version_before('1.3.3')) {
    352364
    353365            // Get previous settins in an array
    354366            $previous_version_settings = array(
    355                 'ms_page_html'      => get_option( 'ms_page_html' ),
    356                 'ms_switch_roles'   => get_option( 'ms_switch_roles' ),
    357                 'ms_allowed_roles'  => get_option( 'ms_allowed_roles' ),
    358                 'ms_allowed_ips'    => get_option( 'ms_allowed_ips' ),
    359                 'ms_use_theme'      => get_option( 'ms_use_theme' )
     367                'ms_page_html' => get_option('ms_page_html'),
     368                'ms_switch_roles' => get_option('ms_switch_roles'),
     369                'ms_allowed_roles' => get_option('ms_allowed_roles'),
     370                'ms_allowed_ips' => get_option('ms_allowed_ips'),
     371                'ms_use_theme' => get_option('ms_use_theme')
    360372            );
    361             $ms_status = (int) get_option( 'ms_status' );
     373            $ms_status = (int) get_option('ms_status');
    362374
    363375            // Remove old invalid settings
    364             delete_option( 'ms_maintenance_page_html' );
    365             delete_option( 'ms_allowed_ip' );
     376            delete_option('ms_maintenance_page_html');
     377            delete_option('ms_allowed_ip');
    366378
    367379            // Get and remove previous settings version
    368             if ( $previous_version_settings['ms_page_html'] !== false ) { $migrate = true; delete_option( 'ms_page_html' ); }
    369             if ( $previous_version_settings['ms_switch_roles'] !== false ) { $migrate = true; delete_option( 'ms_switch_roles' ); }
    370             if ( $previous_version_settings['ms_allowed_roles'] !== false ) { $migrate = true; delete_option( 'ms_allowed_roles' ); }
    371             if ( $previous_version_settings['ms_allowed_ips'] !== false ) { $migrate = true; delete_option( 'ms_allowed_ips' ); }
    372             if ( $previous_version_settings['ms_use_theme'] !== false ) { $migrate = true; delete_option( 'ms_use_theme' ); }
    373             if ( $ms_status !== false ) { $migrate = true; delete_option( 'ms_status' ); }
    374 
    375             if ( !$migrate ) return false;
     380            if ($previous_version_settings['ms_page_html'] !== false) {
     381                $migrate = true;
     382                delete_option('ms_page_html');
     383            }
     384            if ($previous_version_settings['ms_switch_roles'] !== false) {
     385                $migrate = true;
     386                delete_option('ms_switch_roles');
     387            }
     388            if ($previous_version_settings['ms_allowed_roles'] !== false) {
     389                $migrate = true;
     390                delete_option('ms_allowed_roles');
     391            }
     392            if ($previous_version_settings['ms_allowed_ips'] !== false) {
     393                $migrate = true;
     394                delete_option('ms_allowed_ips');
     395            }
     396            if ($previous_version_settings['ms_use_theme'] !== false) {
     397                $migrate = true;
     398                delete_option('ms_use_theme');
     399            }
     400            if ($ms_status !== false) {
     401                $migrate = true;
     402                delete_option('ms_status');
     403            }
     404
     405            if (!$migrate)
     406                return false;
    376407        }
    377408
    378409        // Initialize options
    379         $this->init_options( $migrate ? $previous_version_settings : array(), $migrate ? $ms_status : null );
     410        $this->init_options($migrate ? $previous_version_settings : array(), $migrate ? $ms_status : null);
    380411
    381412        // Create the plugin core maintenance files
     
    392423     * @var      int        $status     the status wanted
    393424     */
    394     public function init_options( $options = array(), $status = null ) {
     425    public function init_options($options = array(), $status = null)
     426    {
    395427
    396428        // Get defaults settings
     
    401433
    402434        // Merging database options with defaults options
    403         if ( empty($settings) )
    404             $settings = wp_parse_args( $defaults, $settings );
     435        if (empty($settings))
     436            $settings = wp_parse_args($defaults, $settings);
    405437
    406438        // Merging options param with defaults options
    407         if ( !empty( $options ) )
    408             $settings = wp_parse_args( $options, $settings );
     439        if (!empty($options))
     440            $settings = wp_parse_args($options, $settings);
    409441
    410442        // Save settings
    411         update_option( 'maintenance_switch_settings', $settings );
     443        update_option('maintenance_switch_settings', $settings);
    412444
    413445        // Set the status param
    414         if ( $status !== null )
    415             $status = update_option( 'maintenance_switch_status', $status );
     446        if ($status !== null)
     447            $status = update_option('maintenance_switch_status', $status);
    416448
    417449        // Get the status of maintenance
     
    419451
    420452        // Save the plugin version in the database
    421         update_option( 'maintenance_switch_version', $this->version );
     453        update_option('maintenance_switch_version', $this->version);
    422454    }
    423455
     
    428460     * @var      integer    $status     the status to set, or just sync with file if null
    429461     */
    430     public function sync_status( $status_wanted=null ) {
     462    public function sync_status($status_wanted = null)
     463    {
    431464
    432465        // get the status in the database if no status in param
    433         if ( $status_wanted === null )
     466        if ($status_wanted === null)
    434467            $status = $this->get_the_status();
    435468        else
     
    437470
    438471        // try to create the file according to the status value
    439         switch ( $status ) {
     472        switch ($status) {
    440473
    441474            case 1:
    442475
    443                 if ( $this->create_dot_file() ) {
    444                     $response = array( 'success' => true );
     476                if ($this->create_dot_file()) {
     477                    $response = array('success' => true);
    445478                    // if status called, update in db
    446                     if ( $status_wanted !== null ) $this->set_the_status( $status );
     479                    if ($status_wanted !== null)
     480                        $this->set_the_status($status);
    447481                } else {
    448                     $response = array( 'success' => false );
     482                    $response = array('success' => false);
    449483                }
    450484
     
    453487            case 0:
    454488
    455                 if ( $this->_delete_file( MS_DOT_FILE_ACTIVE, true ) ) {
    456                     $response = array( 'success' => true );
     489                if ($this->_delete_file(MS_DOT_FILE_ACTIVE, true)) {
     490                    $response = array('success' => true);
    457491                    // if status called, update in db
    458                     if ( $status_wanted !== null ) $this->set_the_status( $status );
     492                    if ($status_wanted !== null)
     493                        $this->set_the_status($status);
    459494                } else {
    460                     $response = array( 'success' => false );
     495                    $response = array('success' => false);
    461496                }
    462497
     
    476511     * @return   boolean    true
    477512     */
    478     public function init_files( $override=false ) {
     513    public function init_files($override = false)
     514    {
    479515
    480516        // create the php file from template
    481         if ( $override || ! file_exists( MS_PHP_FILE_ACTIVE ) ) {
     517        if ($override || !file_exists(MS_PHP_FILE_ACTIVE)) {
    482518            $this->create_php_file();
    483519        }
    484520
    485         if ( $this->get_the_status() == 1 )
     521        if ($this->get_the_status() == 1)
    486522            $this->create_dot_file();
    487523
     
    494530     * @since    1.3.1
    495531     */
    496     public function version_before( $version ) {
     532    public function version_before($version)
     533    {
    497534        // get the version in db
    498535        $previous_version = $this->get_the_version();
    499536
    500         if ( empty( $previous_version ) )
     537        if (empty($previous_version))
    501538            return false;
    502539
    503540        // test if the db version is anterior to called version
    504         if ( $this->numeric_version( $previous_version ) < $this->numeric_version( $version ) )
     541        if ($this->numeric_version($previous_version) < $this->numeric_version($version))
    505542            return true;
    506543
     
    513550     * @since    1.3.1
    514551     */
    515     public function numeric_version( $version ) {
    516 
    517         $version = str_replace( '.', '', $version );
     552    public function numeric_version($version)
     553    {
     554
     555        $version = str_replace('.', '', $version);
    518556        return (int) $version;
    519557    }
     
    524562     * @since    1.3.0
    525563     */
    526     public function get_current_theme() {
     564    public function get_current_theme()
     565    {
    527566
    528567        return $this->current_theme;
     
    534573     * @since    1.3.0
    535574     */
    536     public function get_the_status() {
    537 
    538         $status = get_option( 'maintenance_switch_status' );
    539         if ( !$status ) {
    540             $status = update_option( 'maintenance_switch_status', MS_DEFAULT_STATUS );
     575    public function get_the_status()
     576    {
     577
     578        $status = get_option('maintenance_switch_status');
     579        if (!$status) {
     580            $status = update_option('maintenance_switch_status', MS_DEFAULT_STATUS);
    541581            return MS_DEFAULT_STATUS;
    542582        }
     
    551591     * @return   boolean        true if the status was changed, false if not
    552592     */
    553     public function set_the_status( $status ) {
    554 
    555         if ( isset( $status ) ) {
    556             return update_option( 'maintenance_switch_status', $status );
     593    public function set_the_status($status)
     594    {
     595
     596        if (isset($status)) {
     597            return update_option('maintenance_switch_status', $status);
    557598        }
    558599        return false;
     
    565606     * @return   string         the version of the plugin saved in db
    566607     */
    567     public function get_the_version() {
    568 
    569         return get_option( 'maintenance_switch_version' );
     608    public function get_the_version()
     609    {
     610
     611        return get_option('maintenance_switch_version');
    570612    }
    571613
     
    576618     * @return   misc       the option value or false if option not exists
    577619     */
    578     public function get_the_settings() {
    579 
    580         return get_option( 'maintenance_switch_settings' );
     620    public function get_the_settings()
     621    {
     622
     623        return get_option('maintenance_switch_settings');
    581624    }
    582625
     
    586629     * @since    1.3.0
    587630     */
    588     public function restore_default_settings() {
     631    public function restore_default_settings()
     632    {
    589633
    590634        $settings = $this->default_settings;
    591         return update_option( 'maintenance_switch_settings', $settings );
     635        return update_option('maintenance_switch_settings', $settings);
    592636    }
    593637
     
    597641     * @since    1.3.0
    598642     */
    599     public function restore_html_setting() {
     643    public function restore_html_setting()
     644    {
    600645
    601646        $settings = $this->get_the_settings();
    602647        $settings['ms_page_html'] = $this->default_settings['ms_page_html'];
    603         return update_option( 'maintenance_switch_settings', $settings );
     648        return update_option('maintenance_switch_settings', $settings);
    604649    }
    605650
     
    610655     * @return   string    The theme file with absolute url
    611656     */
    612     public function get_theme_file_url() {
     657    public function get_theme_file_url()
     658    {
    613659
    614660        return $this->current_theme->get_stylesheet_directory_uri() . '/' . MS_THEME_FILENAME;
     
    621667     * @return   string    The theme file with absolute path
    622668     */
    623     public function get_theme_file_path() {
     669    public function get_theme_file_path()
     670    {
    624671
    625672        return $this->current_theme->get_stylesheet_directory() . '/' . MS_THEME_FILENAME;
     
    632679     * @return   boolean    true if the file exists in theme, false if not
    633680     */
    634     public function theme_file_exists() {
     681    public function theme_file_exists()
     682    {
    635683
    636684        $theme_file = $this->get_theme_file_path();
    637         return file_exists( $theme_file );
     685        return file_exists($theme_file);
    638686    }
    639687
     
    644692     * @return   boolean    True if the file was created in theme, false if not of if it already exists
    645693     */
    646     public function create_theme_file() {
     694    public function create_theme_file()
     695    {
    647696
    648697        $theme_file = $this->get_theme_file_path();
    649         if ( ! $this->theme_file_exists() ) {
    650             return $this->_create_file( $theme_file, $this->default_settings['ms_page_html'] );
     698        if (!$this->theme_file_exists()) {
     699            return $this->_create_file($theme_file, $this->default_settings['ms_page_html']);
    651700        }
    652701        return false;
     
    659708     * @return   boolean    True if the file was deleted in theme, false if not of if not exists
    660709     */
    661     public function delete_theme_file() {
     710    public function delete_theme_file()
     711    {
    662712
    663713        $theme_file = $this->get_theme_file_path();
    664         if ( $this->theme_file_exists() ) {
    665             return $this->_delete_file( $theme_file );
     714        if ($this->theme_file_exists()) {
     715            return $this->_delete_file($theme_file);
    666716        }
    667717        return false;
     
    676726     * @return   misc    The setting value
    677727     */
    678     public function get_setting( $setting_name, $default_value = false ) {
     728    public function get_setting($setting_name, $default_value = false)
     729    {
    679730
    680731        $settings = $this->get_the_settings();
    681732
    682         if ( isset( $settings[ $setting_name ] ) ) {
    683             return $settings[ $setting_name ];
     733        if (isset($settings[$setting_name])) {
     734            return $settings[$setting_name];
    684735        }
    685736
     
    695746     * @return   boolean    True if the setting was updated, false if not of if is not set
    696747     */
    697     public function update_setting( $setting_name, $setting_value ) {
     748    public function update_setting($setting_name, $setting_value)
     749    {
    698750
    699751        $settings = $this->get_the_settings();
    700752
    701         if ( isset( $settings[$setting_name] ) )
     753        if (isset($settings[$setting_name]))
    702754            $settings[$setting_name] = $setting_value;
    703755        else
     
    712764     * @since    1.0.0
    713765     */
    714     public function run() {
     766    public function run()
     767    {
    715768
    716769        $this->loader->run();
     
    724777     * @return    string    The name of the plugin.
    725778     */
    726     public function get_plugin_name() {
     779    public function get_plugin_name()
     780    {
    727781
    728782        return $this->plugin_name;
     
    735789     * @return    Maintenance_Switch_Loader    Orchestrates the hooks of the plugin.
    736790     */
    737     public function get_loader() {
     791    public function get_loader()
     792    {
    738793
    739794        return $this->loader;
     
    746801     * @return    string    The version number of the plugin.
    747802     */
    748     public function get_version() {
     803    public function get_version()
     804    {
    749805
    750806        return $this->version;
     
    757813     * @return    string    The status of the maintenance mode.
    758814     */
    759     public function get_status() {
     815    public function get_status()
     816    {
    760817
    761818        return $this->status;
     
    768825     * @return    string    The default settings.
    769826     */
    770     public function get_default_settings() {
     827    public function get_default_settings()
     828    {
    771829
    772830        return $this->default_settings;
     
    779837     * @return    boolean    True if the user can switch, false if not
    780838     */
    781     public function current_user_can_switch() {
     839    public function current_user_can_switch()
     840    {
    782841
    783842        global $current_user;
    784843        $user_can = false;
    785844
    786         $switch_roles = (array) $this->get_setting( 'ms_switch_roles' );
    787 
    788         foreach( $current_user->roles as $role ) {
    789             if ( in_array( $role, $switch_roles ) )
     845        $switch_roles = (array) $this->get_setting('ms_switch_roles');
     846
     847        foreach ($current_user->roles as $role) {
     848            if (in_array($role, $switch_roles))
    790849                $user_can = true;
    791850        }
     
    799858     * @return   array    List of all users logins
    800859     */
    801     public function get_allowed_users() {
    802 
    803         $allowed_roles = (array) $this->get_setting( 'ms_allowed_roles' );
    804         $users = $this->get_users_by_role( $allowed_roles );
     860    public function get_allowed_users()
     861    {
     862
     863        $allowed_roles = (array) $this->get_setting('ms_allowed_roles');
     864        $users = $this->get_users_by_role($allowed_roles);
    805865        $allowed_users = array();
    806         foreach ( $users as $user ) {
     866        foreach ($users as $user) {
    807867            $allowed_users[] = $user->user_login;
    808868        }
     
    816876     * @return   string    List of all ips comma separated
    817877     */
    818     public function get_allowed_ips() {
    819 
    820         $allowed_ips = $this->get_setting( 'ms_allowed_ips' );
    821         $allowed_ips = explode( ',', $allowed_ips );
     878    public function get_allowed_ips()
     879    {
     880
     881        $allowed_ips = $this->get_setting('ms_allowed_ips');
     882        $allowed_ips = explode(',', $allowed_ips);
    822883        return $allowed_ips;
    823884    }
     
    830891     * @return   array    the user list
    831892     */
    832     public function get_users_by_role( $roles = array() ) {
    833 
    834         $users = array();
    835         foreach ($roles as $role) {
    836             if ( !empty( $role ) ) {
    837                 $users_query = new WP_User_Query( array(
    838                     'fields' => 'all_with_meta',
    839                     'role' => $role,
    840                     'orderby' => 'display_name'
    841                     ) );
    842                 $results = $users_query->get_results();
    843                 if ($results) $users = array_merge($users, $results);
    844             }
    845         }
    846         return $users;
     893    public function get_users_by_role($roles = array())
     894    {
     895
     896        $users = array();
     897        foreach ($roles as $role) {
     898            if (!empty($role)) {
     899                $users_query = new WP_User_Query(array(
     900                    'fields' => 'all_with_meta',
     901                    'role' => $role,
     902                    'orderby' => 'display_name'
     903                ));
     904                $results = $users_query->get_results();
     905                if ($results)
     906                    $users = array_merge($users, $results);
     907            }
     908        }
     909        return $users;
    847910    }
    848911
     
    853916     * @return   string    The current ip of the user
    854917     */
    855     public function get_user_ip() {
     918    public function get_user_ip()
     919    {
    856920        //Just get the headers if we can or else use the SERVER global
    857         if ( function_exists( 'apache_request_headers' ) ) {
     921        if (function_exists('apache_request_headers')) {
    858922            $headers = apache_request_headers();
    859923        } else {
    860             $headers = $_SERVER;
     924            $headers = array_map('sanitize_text_field', $_SERVER);
    861925        }
    862926        // Get the forwarded IP if it exists
    863         if ( array_key_exists( 'X-Forwarded-For', $headers ) && filter_var( $headers['X-Forwarded-For'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ) ) {
     927        if (array_key_exists('X-Forwarded-For', $headers) && filter_var($headers['X-Forwarded-For'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
    864928            $the_ip = $headers['X-Forwarded-For'];
    865         } elseif ( array_key_exists( 'HTTP_X_FORWARDED_FOR', $headers ) && filter_var( $headers['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ) ) {
     929        } elseif (array_key_exists('HTTP_X_FORWARDED_FOR', $headers) && filter_var($headers['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
    866930            $the_ip = $headers['HTTP_X_FORWARDED_FOR'];
    867931        } else {
    868             $the_ip = filter_var( $_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 );
     932            $the_ip = filter_var(sanitize_text_field($_SERVER['REMOTE_ADDR']), FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
    869933        }
    870934        return $the_ip;
     
    878942     * @return   boolean    True if the .maintenance file is core, false if was created by the plugin
    879943     */
    880     public function _check_core_file( $file ) {
    881 
    882         if ( file_exists( $file ) ) {
    883             $content = file_get_contents( $file );
    884             if ( preg_match( '/'.$this->plugin_name.'/i', $content) )
     944    public function _check_core_file($file)
     945    {
     946
     947        if (file_exists($file)) {
     948            $content = file_get_contents($file);
     949            if (preg_match('/' . $this->plugin_name . '/i', $content))
    885950                return false;
    886951            else
     
    898963     * @return   boolean    True if the file was deleted, false if not
    899964     */
    900     public function _delete_file( $file, $check_core=false ) {
    901 
    902         if ( file_exists( $file ) ) {
    903 
    904             if ( $check_core && $this->_check_core_file( $file ) )
     965    public function _delete_file($file, $check_core = false)
     966    {
     967
     968        if (file_exists($file)) {
     969
     970            if ($check_core && $this->_check_core_file($file))
    905971                return false;
    906972
    907             if ( unlink( $file ) )
     973            if (unlink($file))
    908974                return true;
    909975        }
     
    918984     * @var      string    $content     the content to put in the file
    919985     */
    920     public function _create_file( $file, $content ) {
    921 
    922         if ( file_exists( $file ) )
     986    public function _create_file($file, $content)
     987    {
     988
     989        if (file_exists($file))
    923990            return false;
    924991
    925         if ( ! file_put_contents( $file, $content ) )
     992        if (!file_put_contents($file, $content))
    926993            return false;
    927994
     
    9341001     * @since    1.0.0
    9351002     */
    936     public function create_php_file() {
     1003    public function create_php_file()
     1004    {
    9371005
    9381006        // get the template file content
    939         $content = file_get_contents( MS_PHP_FILE_TEMPLATE );
     1007        $content = file_get_contents(MS_PHP_FILE_TEMPLATE);
    9401008
    9411009        // get flags values
    942         $page_html = wp_specialchars_decode( $this->get_setting( 'ms_page_html' ), ENT_QUOTES );
    943         $use_theme_file = $this->get_setting( 'ms_use_theme' );
    944         $return503 = $this->get_setting( 'ms_error_503' );
     1010        $page_html = wp_specialchars_decode($this->get_setting('ms_page_html'), ENT_QUOTES);
     1011        $use_theme_file = $this->get_setting('ms_use_theme');
     1012        $return503 = $this->get_setting('ms_error_503');
    9451013        $theme = wp_get_theme();
    9461014        $theme_file = $theme->get_stylesheet_directory() . '/' . MS_THEME_FILENAME;
    9471015
    9481016        // apply flags replacements
    949         $content = str_replace( '{{MS_PLUGIN_SLUG}}' , $this->plugin_name, $content );
    950         $content = str_replace( '{{MS_USE_THEME_FILE}}' , $use_theme_file, $content );
    951         $content = str_replace( '{{MS_RETURN_503}}' , $return503, $content );
    952         $content = str_replace( '{{MS_THEME_FILE}}' , $theme_file, $content );
    953         $content = str_replace( '{{MS_PAGE_HTML}}' , $page_html, $content );
     1017        $content = str_replace('{{MS_PLUGIN_SLUG}}', $this->plugin_name, $content);
     1018        $content = str_replace('{{MS_USE_THEME_FILE}}', $use_theme_file, $content);
     1019        $content = str_replace('{{MS_RETURN_503}}', $return503, $content);
     1020        $content = str_replace('{{MS_THEME_FILE}}', $theme_file, $content);
     1021        $content = str_replace('{{MS_PAGE_HTML}}', $page_html, $content);
    9541022
    9551023        // delete the current file
    956         $this->_delete_file( MS_PHP_FILE_ACTIVE );
     1024        $this->_delete_file(MS_PHP_FILE_ACTIVE);
    9571025
    9581026        // try to create the file
    959         if ( ! $this->_create_file( MS_PHP_FILE_ACTIVE, $content ) ) {
     1027        if (!$this->_create_file(MS_PHP_FILE_ACTIVE, $content)) {
    9601028            return false;
    9611029        }
     
    9681036     * @since    1.0.0
    9691037     */
    970     public function create_dot_file() {
     1038    public function create_dot_file()
     1039    {
    9711040
    9721041        // get the template file content
    973         $content = file_get_contents( MS_DOT_FILE_TEMPLATE );
     1042        $content = file_get_contents(MS_DOT_FILE_TEMPLATE);
    9741043
    9751044        // get flags values
    976         $allowed_users = "'" . implode( "', '", $this->get_allowed_users() ) . "'";
    977         $allowed_ips = "'" . implode( "','", $this->get_allowed_ips() ) . "'";
    978         $login_url = str_replace( get_site_url(), '', wp_login_url() );
     1045        $allowed_users = "'" . implode("', '", $this->get_allowed_users()) . "'";
     1046        $allowed_ips = "'" . implode("','", $this->get_allowed_ips()) . "'";
     1047        $login_url = str_replace(get_site_url(), '', wp_login_url());
    9791048
    9801049        // apply flags replacements
    981         $content = str_replace( '{{MS_ALLOWED_USERS}}' , $allowed_users, $content );
    982         $content = str_replace( '{{MS_ALLOWED_IPS}}' , $allowed_ips, $content );
    983         $content = str_replace( '{{MS_PLUGIN_SLUG}}' , $this->plugin_name, $content );
    984         $content = str_replace( '{{MS_LOGIN_URL}}' , $login_url, $content );
     1050        $content = str_replace('{{MS_ALLOWED_USERS}}', $allowed_users, $content);
     1051        $content = str_replace('{{MS_ALLOWED_IPS}}', $allowed_ips, $content);
     1052        $content = str_replace('{{MS_PLUGIN_SLUG}}', $this->plugin_name, $content);
     1053        $content = str_replace('{{MS_LOGIN_URL}}', $login_url, $content);
    9851054
    9861055        // check if the core dot file exists or delete current file
    987         if ( $this->_check_core_file( MS_DOT_FILE_ACTIVE ) ) {
     1056        if ($this->_check_core_file(MS_DOT_FILE_ACTIVE)) {
    9881057            return false;
    9891058        } else {
    990             $this->_delete_file( MS_DOT_FILE_ACTIVE, true );
     1059            $this->_delete_file(MS_DOT_FILE_ACTIVE, true);
    9911060        }
    9921061
    9931062        // try to create the file
    994         if ( ! $this->_create_file( MS_DOT_FILE_ACTIVE, $content ) ) {
     1063        if (!$this->_create_file(MS_DOT_FILE_ACTIVE, $content)) {
    9951064            return false;
    9961065        }
     
    10031072     * @since    1.0.0
    10041073     */
    1005     public function toggle_status_callback() {
    1006        
     1074    public function toggle_status_callback()
     1075    {
     1076
    10071077        // Check nonce for security
    10081078        $nonce = isset($_POST['nonce']) ? sanitize_text_field(wp_unslash($_POST['nonce'])) : '';
     
    10231093        $new_status = (bool) $status == 1 ? 0 : 1;
    10241094        // sync status
    1025         $response = $this->sync_status( $new_status );
     1095        $response = $this->sync_status($new_status);
    10261096        // return json response
    1027         wp_send_json( $response );
     1097        wp_send_json($response);
    10281098        // this is required to terminate immediately and return a proper response
    10291099        wp_die();
     
    10361106     * @since    1.0.0
    10371107     */
    1038     public function add_switch_button( $wp_admin_bar ){
    1039 
    1040         if ( $this->current_user_can_switch() ) {
     1108    public function add_switch_button($wp_admin_bar)
     1109    {
     1110
     1111        if ($this->current_user_can_switch()) {
    10411112
    10421113            $args = array(
    10431114                'id' => 'ms-switch-button',
    1044                 'title' => '<span class="ab-icon dashicons-admin-tools"></span><span class="ab-label">' . __( 'Maintenance', $this->plugin_name ) . '</span>',
     1115                'title' => '<span class="ab-icon dashicons-admin-tools"></span><span class="ab-label">' . __('Maintenance', $this->plugin_name) . '</span>',
    10451116                'href' => '#',
    10461117                'meta' => array(
    1047                     'class' => 'toggle-button ' . ( $this->status ? 'active' : '' ),
     1118                    'class' => 'toggle-button ' . ($this->status ? 'active' : ''),
    10481119                )
    10491120            );
    10501121
    1051             $wp_admin_bar->add_node( $args );
     1122            $wp_admin_bar->add_node($args);
    10521123        }
    10531124    }
  • maintenance-switch/tags/1.6.3/maintenance-switch.php

    r3369181 r3369189  
    1717 * Plugin URI:        https://wordpress.org/plugins/maintenance-switch
    1818 * Description:       Customize easily and switch in one-click to (native) maintenance mode from your backend or frontend.
    19  * Version:           1.6.2
     19 * Version:           1.6.3
    2020 * Author:            Fugu
    2121 * Author URI:        http://www.fugu.fr
  • maintenance-switch/tags/1.6.3/preview.php

    r3369181 r3369189  
    22
    33// If this file is called directly, abort.
    4 if ( ! defined( 'WPINC' ) ) {
    5     die;
     4if (!defined('WPINC')) {
     5    die;
    66}
    77
    88// Security check: only allow admin users
    9 if ( ! current_user_can( 'manage_options' ) ) {
    10     wp_die( __( 'Insufficient permissions to access this page.' ) );
     9if (!current_user_can('manage_options')) {
     10    wp_die(__('Insufficient permissions to access this page.'));
    1111}
    1212
    1313// Security check: verify nonce
    14 if ( ! empty( $_POST['preview-code'] ) ) {
    15     if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( $_POST['_wpnonce'], 'maintenance_switch_preview' ) ) {
    16         wp_die( __( 'Security check failed.' ) );
    17     }
     14if (!empty($_POST['preview-code'])) {
     15    if (!isset($_POST['_wpnonce']) || !wp_verify_nonce(sanitize_text_field($_POST['_wpnonce']), 'maintenance_switch_preview')) {
     16        wp_die(__('Security check failed.'));
     17    }
    1818}
    1919
     
    3333header('Content-Type: text/html; charset=utf-8');
    3434
    35 
    3635if (!empty($_POST['preview-code'])) {
    37     echo wp_kses_post(wp_unslash($_POST['preview-code']));
     36    echo wp_kses_post(wp_unslash(sanitize_textarea_field($_POST['preview-code'])));
    3837}
  • maintenance-switch/tags/1.6.3/readme.txt

    r3369181 r3369189  
    55Requires at least: 3.5
    66Tested up to: 6.3
    7 Stable tag: 1.6.2
     7Stable tag: 1.6.3
    88Requires PHP: 7.4
    99License: GPLv2 or later
  • maintenance-switch/tags/1.6.3/templates/maintenance.php

    r3369156 r3369189  
    1010
    1111// If this file is called directly, abort.
    12 if ( ! defined( 'WPINC' ) ) {
     12if (!defined('WPINC')) {
    1313    die;
    1414}
    1515
    1616// Displaying this page during the maintenance mode
    17 $protocol = $_SERVER["SERVER_PROTOCOL"];
     17$protocol = isset($_SERVER['SERVER_PROTOCOL']) ? sanitize_text_field($_SERVER['SERVER_PROTOCOL']) : 'HTTP/1.0';
    1818
    1919if ('HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol)
     
    3434$use_theme = '{{MS_USE_THEME_FILE}}';
    3535
    36 if ($use_theme == '1' && file_exists($theme_file)) {
     36if ($use_theme == '1' && !empty($theme_file) && file_exists($theme_file) && strpos(realpath($theme_file), ABSPATH) === 0) {
    3737    require_once $theme_file;
    3838    die();
  • maintenance-switch/tags/1.6.3/uninstall.php

    r3369156 r3369189  
    22
    33// If this file is called directly, abort.
    4 if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
     4if (!defined('WP_UNINSTALL_PLUGIN')) {
    55    die;
    66}
     
    1313 *
    1414 * - This method should be static
    15  * - Check if the $_REQUEST content actually is the plugin name
    16  * - Run an admin referrer check to make sure it goes through authentication
    17  * - Verify the output of $_GET makes sense
     15 * - Check if the request content actually is the plugin name
     16 * - Run an admin referrer check to make sure it goes through authentication 
     17 * - Verify the output makes sense
    1818 * - Repeat with other user roles. Best directly by using the links/query string parameters.
    1919 * - Repeat things for multisite. Once for a single site in the network, once sitewide.
  • maintenance-switch/trunk/includes/class-maintenance-switch.php

    r3369156 r3369189  
    1515
    1616// If this file is called directly, abort.
    17 if ( ! defined( 'WPINC' ) ) {
     17if (!defined('WPINC')) {
    1818    die;
    1919}
     
    3333 * @author     Fugu <info@fugu.fr>
    3434 */
    35 class Maintenance_Switch {
     35class Maintenance_Switch
     36{
    3637
    3738    /**
     
    108109     * @since    1.0.0
    109110     */
    110     public function __construct() {
     111    public function __construct()
     112    {
    111113
    112114        $this->plugin_name = MS_SLUG;
    113115        $this->version = PLUGIN_VERSION;
    114         $this->default_settings = json_decode( MS_DEFAULT_SETTINGS, true );
     116        $this->default_settings = json_decode(MS_DEFAULT_SETTINGS, true);
    115117        $this->current_theme = wp_get_theme();
    116118
     
    137139     * @access   private
    138140     */
    139     private function load_dependencies() {
     141    private function load_dependencies()
     142    {
    140143
    141144        /**
     
    143146         * core plugin.
    144147         */
    145         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-maintenance-switch-loader.php';
     148        require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-maintenance-switch-loader.php';
    146149
    147150        /**
     
    149152         * of the plugin.
    150153         */
    151         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-maintenance-switch-i18n.php';
     154        require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-maintenance-switch-i18n.php';
    152155
    153156        /**
    154157         * The class responsible for defining all actions that occur in the admin area.
    155158         */
    156         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-maintenance-switch-admin.php';
     159        require_once plugin_dir_path(dirname(__FILE__)) . 'admin/class-maintenance-switch-admin.php';
    157160
    158161        /**
     
    160163         * side of the site.
    161164         */
    162         require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-maintenance-switch-public.php';
     165        require_once plugin_dir_path(dirname(__FILE__)) . 'public/class-maintenance-switch-public.php';
    163166
    164167        $this->loader = new Maintenance_Switch_Loader();
     
    175178     * @access   private
    176179     */
    177     private function set_locale() {
     180    private function set_locale()
     181    {
    178182
    179183        $plugin_i18n = new Maintenance_Switch_i18n();
    180         $plugin_i18n->set_domain( $this->plugin_name );
    181 
    182         $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
     184        $plugin_i18n->set_domain($this->plugin_name);
     185
     186        $this->loader->add_action('plugins_loaded', $plugin_i18n, 'load_plugin_textdomain');
    183187
    184188    }
     
    191195     * @access   private
    192196     */
    193     private function define_admin_hooks() {
    194 
    195         $plugin_admin = new Maintenance_Switch_Admin( $this );
     197    private function define_admin_hooks()
     198    {
     199
     200        $plugin_admin = new Maintenance_Switch_Admin($this);
    196201
    197202        $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_styles');
    198203        $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts');
    199        
     204
    200205        // Add AJAX variables to admin footer
    201206        $this->loader->add_action('admin_footer', $plugin_admin, 'add_ajax_script_variables');      // Add the options page and menu item.
    202         $this->loader->add_action( 'admin_menu', $plugin_admin, 'add_plugin_admin_menu' );
     207        $this->loader->add_action('admin_menu', $plugin_admin, 'add_plugin_admin_menu');
    203208
    204209        // Execute actions on settings option updated
    205         $this->loader->add_action( 'update_option_maintenance_switch_settings', $this, 'admin_action_update' );
     210        $this->loader->add_action('update_option_maintenance_switch_settings', $this, 'admin_action_update');
    206211
    207212        // Add an action link pointing to the options page.
    208         $plugin_basename = plugin_basename( plugin_dir_path( __DIR__ ) . $this->plugin_name . '.php' );
    209         $this->loader->add_filter( 'plugin_action_links_' . $plugin_basename, $plugin_admin, 'add_action_links' );
     213        $plugin_basename = plugin_basename(plugin_dir_path(__DIR__) . $this->plugin_name . '.php');
     214        $this->loader->add_filter('plugin_action_links_' . $plugin_basename, $plugin_admin, 'add_action_links');
    210215
    211216        // Add an action for the switch button
     
    213218
    214219        // Add an action to init in admin
    215         $this->loader->add_action( 'wp_loaded', $this, 'admin_init' );
     220        $this->loader->add_action('wp_loaded', $this, 'admin_init');
    216221
    217222        // Add callback action for ajax request
    218         $this->loader->add_action( 'wp_ajax_toggle_status', $this, 'toggle_status_callback' );
     223        $this->loader->add_action('wp_ajax_toggle_status', $this, 'toggle_status_callback');
    219224
    220225        // Admin notices
    221         $this->loader->add_action( 'admin_notices', $this, 'display_admin_notices' );
     226        $this->loader->add_action('admin_notices', $this, 'display_admin_notices');
    222227    }
    223228
     
    229234     * @access   private
    230235     */
    231     private function define_public_hooks() {
    232 
    233         $plugin_public = new Maintenance_Switch_Public( $this->plugin_name, $this->version );
    234 
    235         $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
    236         $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
    237 
    238         $this->loader->add_action( 'wp_head', $plugin_public,'set_ajaxurl' );
     236    private function define_public_hooks()
     237    {
     238
     239        $plugin_public = new Maintenance_Switch_Public($this->plugin_name, $this->version);
     240
     241        $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_styles');
     242        $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_scripts');
     243
     244        $this->loader->add_action('wp_head', $plugin_public, 'set_ajaxurl');
    239245    }
    240246
     
    244250     * @since    1.3.3
    245251     */
    246     public function admin_action_update() {
    247 
    248         $this->init_files( true );
     252    public function admin_action_update()
     253    {
     254
     255        $this->init_files(true);
    249256    }
    250257
     
    254261     * @since    1.3.3
    255262     */
    256     public function admin_action_request() {
     263    public function admin_action_request()
     264    {
    257265
    258266        $action = isset($_REQUEST['action']) ? sanitize_key($_REQUEST['action']) : '';
    259         if ( !empty( $action ) ) {
    260 
    261             switch( $action ) {
     267        if (!empty($action)) {
     268
     269            switch ($action) {
    262270
    263271                case 'restore_settings':
    264272
    265                     if ( $this->restore_default_settings() )
    266                         $this->notice( 'success', __( 'Default settings successfuly restored.', MS_SLUG ) );
     273                    if ($this->restore_default_settings())
     274                        $this->notice('success', __('Default settings successfuly restored.', MS_SLUG));
    267275                    else
    268                         $this->notice( 'error', __( 'Default settings was not restored.', MS_SLUG ) );
     276                        $this->notice('error', __('Default settings was not restored.', MS_SLUG));
    269277                    break;
    270278
    271279                case 'restore_html':
    272280
    273                     if ( $this->restore_html_setting() ) {
    274                         $this->notice( 'success', __( 'HTML code successfuly restored.', MS_SLUG ) );
     281                    if ($this->restore_html_setting()) {
     282                        $this->notice('success', __('HTML code successfuly restored.', MS_SLUG));
    275283                    } else {
    276                         $this->notice( 'error', __( 'HTML code could was not restored.', MS_SLUG ) );
     284                        $this->notice('error', __('HTML code could was not restored.', MS_SLUG));
    277285                    }
    278286                    break;
     
    280288                case 'create_theme_file':
    281289
    282                     if ( $this->create_theme_file() ) {
    283                         $this->notice( 'success', __( 'The theme file was created successfuly.', MS_SLUG ) );
     290                    if ($this->create_theme_file()) {
     291                        $this->notice('success', __('The theme file was created successfuly.', MS_SLUG));
    284292                    } else {
    285                         $this->notice( 'error', __( 'The theme file was not created.', MS_SLUG ) );
     293                        $this->notice('error', __('The theme file was not created.', MS_SLUG));
    286294                    }
    287295                    break;
     
    289297                case 'delete_theme_file':
    290298
    291                     if ( $this->delete_theme_file() ) {
    292                         $this->notice( 'success', __( 'The theme file was deleted successfuly', MS_SLUG ) );
     299                    if ($this->delete_theme_file()) {
     300                        $this->notice('success', __('The theme file was deleted successfuly', MS_SLUG));
    293301                    } else {
    294                         $this->notice( 'error', __( 'The theme file was not deleted.', MS_SLUG ) );
     302                        $this->notice('error', __('The theme file was not deleted.', MS_SLUG));
    295303                    }
    296304                    break;
     
    306314     * @since    1.3.3
    307315     */
    308      public function notice( $type, $notice ) {
    309 
    310          if ( !empty( $type ) && !empty( $notice ) )
    311             $this->notices[] = sprintf( '<div class="notice notice-%s is-dismissible"><p>%s</p></div>', $type, $notice );
    312      }
    313 
    314      /**
     316    public function notice($type, $notice)
     317    {
     318
     319        if (!empty($type) && !empty($notice))
     320            $this->notices[] = sprintf('<div class="notice notice-%s is-dismissible"><p>%s</p></div>', $type, $notice);
     321    }
     322
     323    /**
    315324     * Display admin notices stored in object
    316325     *
    317326     * @since    1.3.3
    318327     */
    319     public function display_admin_notices() {
    320 
    321         if ( !empty( $this->notices ) ) {
    322             foreach( $this->notices as $key => $notice ) {
     328    public function display_admin_notices()
     329    {
     330
     331        if (!empty($this->notices)) {
     332            foreach ($this->notices as $key => $notice) {
    323333                echo $notice;
    324334            }
     
    331341     * @since    1.1.1
    332342     */
    333     public function admin_init() {
     343    public function admin_init()
     344    {
    334345
    335346        $this->init_settings();
     
    343354     * @since    1.3.1
    344355     */
    345     public function init_settings() {
     356    public function init_settings()
     357    {
    346358
    347359        // Define if settings mode needs to be migrated from old to new system
     
    349361
    350362        // Get and delete previous settings values
    351         if ( $this->version_before( '1.3.3' ) ) {
     363        if ($this->version_before('1.3.3')) {
    352364
    353365            // Get previous settins in an array
    354366            $previous_version_settings = array(
    355                 'ms_page_html'      => get_option( 'ms_page_html' ),
    356                 'ms_switch_roles'   => get_option( 'ms_switch_roles' ),
    357                 'ms_allowed_roles'  => get_option( 'ms_allowed_roles' ),
    358                 'ms_allowed_ips'    => get_option( 'ms_allowed_ips' ),
    359                 'ms_use_theme'      => get_option( 'ms_use_theme' )
     367                'ms_page_html' => get_option('ms_page_html'),
     368                'ms_switch_roles' => get_option('ms_switch_roles'),
     369                'ms_allowed_roles' => get_option('ms_allowed_roles'),
     370                'ms_allowed_ips' => get_option('ms_allowed_ips'),
     371                'ms_use_theme' => get_option('ms_use_theme')
    360372            );
    361             $ms_status = (int) get_option( 'ms_status' );
     373            $ms_status = (int) get_option('ms_status');
    362374
    363375            // Remove old invalid settings
    364             delete_option( 'ms_maintenance_page_html' );
    365             delete_option( 'ms_allowed_ip' );
     376            delete_option('ms_maintenance_page_html');
     377            delete_option('ms_allowed_ip');
    366378
    367379            // Get and remove previous settings version
    368             if ( $previous_version_settings['ms_page_html'] !== false ) { $migrate = true; delete_option( 'ms_page_html' ); }
    369             if ( $previous_version_settings['ms_switch_roles'] !== false ) { $migrate = true; delete_option( 'ms_switch_roles' ); }
    370             if ( $previous_version_settings['ms_allowed_roles'] !== false ) { $migrate = true; delete_option( 'ms_allowed_roles' ); }
    371             if ( $previous_version_settings['ms_allowed_ips'] !== false ) { $migrate = true; delete_option( 'ms_allowed_ips' ); }
    372             if ( $previous_version_settings['ms_use_theme'] !== false ) { $migrate = true; delete_option( 'ms_use_theme' ); }
    373             if ( $ms_status !== false ) { $migrate = true; delete_option( 'ms_status' ); }
    374 
    375             if ( !$migrate ) return false;
     380            if ($previous_version_settings['ms_page_html'] !== false) {
     381                $migrate = true;
     382                delete_option('ms_page_html');
     383            }
     384            if ($previous_version_settings['ms_switch_roles'] !== false) {
     385                $migrate = true;
     386                delete_option('ms_switch_roles');
     387            }
     388            if ($previous_version_settings['ms_allowed_roles'] !== false) {
     389                $migrate = true;
     390                delete_option('ms_allowed_roles');
     391            }
     392            if ($previous_version_settings['ms_allowed_ips'] !== false) {
     393                $migrate = true;
     394                delete_option('ms_allowed_ips');
     395            }
     396            if ($previous_version_settings['ms_use_theme'] !== false) {
     397                $migrate = true;
     398                delete_option('ms_use_theme');
     399            }
     400            if ($ms_status !== false) {
     401                $migrate = true;
     402                delete_option('ms_status');
     403            }
     404
     405            if (!$migrate)
     406                return false;
    376407        }
    377408
    378409        // Initialize options
    379         $this->init_options( $migrate ? $previous_version_settings : array(), $migrate ? $ms_status : null );
     410        $this->init_options($migrate ? $previous_version_settings : array(), $migrate ? $ms_status : null);
    380411
    381412        // Create the plugin core maintenance files
     
    392423     * @var      int        $status     the status wanted
    393424     */
    394     public function init_options( $options = array(), $status = null ) {
     425    public function init_options($options = array(), $status = null)
     426    {
    395427
    396428        // Get defaults settings
     
    401433
    402434        // Merging database options with defaults options
    403         if ( empty($settings) )
    404             $settings = wp_parse_args( $defaults, $settings );
     435        if (empty($settings))
     436            $settings = wp_parse_args($defaults, $settings);
    405437
    406438        // Merging options param with defaults options
    407         if ( !empty( $options ) )
    408             $settings = wp_parse_args( $options, $settings );
     439        if (!empty($options))
     440            $settings = wp_parse_args($options, $settings);
    409441
    410442        // Save settings
    411         update_option( 'maintenance_switch_settings', $settings );
     443        update_option('maintenance_switch_settings', $settings);
    412444
    413445        // Set the status param
    414         if ( $status !== null )
    415             $status = update_option( 'maintenance_switch_status', $status );
     446        if ($status !== null)
     447            $status = update_option('maintenance_switch_status', $status);
    416448
    417449        // Get the status of maintenance
     
    419451
    420452        // Save the plugin version in the database
    421         update_option( 'maintenance_switch_version', $this->version );
     453        update_option('maintenance_switch_version', $this->version);
    422454    }
    423455
     
    428460     * @var      integer    $status     the status to set, or just sync with file if null
    429461     */
    430     public function sync_status( $status_wanted=null ) {
     462    public function sync_status($status_wanted = null)
     463    {
    431464
    432465        // get the status in the database if no status in param
    433         if ( $status_wanted === null )
     466        if ($status_wanted === null)
    434467            $status = $this->get_the_status();
    435468        else
     
    437470
    438471        // try to create the file according to the status value
    439         switch ( $status ) {
     472        switch ($status) {
    440473
    441474            case 1:
    442475
    443                 if ( $this->create_dot_file() ) {
    444                     $response = array( 'success' => true );
     476                if ($this->create_dot_file()) {
     477                    $response = array('success' => true);
    445478                    // if status called, update in db
    446                     if ( $status_wanted !== null ) $this->set_the_status( $status );
     479                    if ($status_wanted !== null)
     480                        $this->set_the_status($status);
    447481                } else {
    448                     $response = array( 'success' => false );
     482                    $response = array('success' => false);
    449483                }
    450484
     
    453487            case 0:
    454488
    455                 if ( $this->_delete_file( MS_DOT_FILE_ACTIVE, true ) ) {
    456                     $response = array( 'success' => true );
     489                if ($this->_delete_file(MS_DOT_FILE_ACTIVE, true)) {
     490                    $response = array('success' => true);
    457491                    // if status called, update in db
    458                     if ( $status_wanted !== null ) $this->set_the_status( $status );
     492                    if ($status_wanted !== null)
     493                        $this->set_the_status($status);
    459494                } else {
    460                     $response = array( 'success' => false );
     495                    $response = array('success' => false);
    461496                }
    462497
     
    476511     * @return   boolean    true
    477512     */
    478     public function init_files( $override=false ) {
     513    public function init_files($override = false)
     514    {
    479515
    480516        // create the php file from template
    481         if ( $override || ! file_exists( MS_PHP_FILE_ACTIVE ) ) {
     517        if ($override || !file_exists(MS_PHP_FILE_ACTIVE)) {
    482518            $this->create_php_file();
    483519        }
    484520
    485         if ( $this->get_the_status() == 1 )
     521        if ($this->get_the_status() == 1)
    486522            $this->create_dot_file();
    487523
     
    494530     * @since    1.3.1
    495531     */
    496     public function version_before( $version ) {
     532    public function version_before($version)
     533    {
    497534        // get the version in db
    498535        $previous_version = $this->get_the_version();
    499536
    500         if ( empty( $previous_version ) )
     537        if (empty($previous_version))
    501538            return false;
    502539
    503540        // test if the db version is anterior to called version
    504         if ( $this->numeric_version( $previous_version ) < $this->numeric_version( $version ) )
     541        if ($this->numeric_version($previous_version) < $this->numeric_version($version))
    505542            return true;
    506543
     
    513550     * @since    1.3.1
    514551     */
    515     public function numeric_version( $version ) {
    516 
    517         $version = str_replace( '.', '', $version );
     552    public function numeric_version($version)
     553    {
     554
     555        $version = str_replace('.', '', $version);
    518556        return (int) $version;
    519557    }
     
    524562     * @since    1.3.0
    525563     */
    526     public function get_current_theme() {
     564    public function get_current_theme()
     565    {
    527566
    528567        return $this->current_theme;
     
    534573     * @since    1.3.0
    535574     */
    536     public function get_the_status() {
    537 
    538         $status = get_option( 'maintenance_switch_status' );
    539         if ( !$status ) {
    540             $status = update_option( 'maintenance_switch_status', MS_DEFAULT_STATUS );
     575    public function get_the_status()
     576    {
     577
     578        $status = get_option('maintenance_switch_status');
     579        if (!$status) {
     580            $status = update_option('maintenance_switch_status', MS_DEFAULT_STATUS);
    541581            return MS_DEFAULT_STATUS;
    542582        }
     
    551591     * @return   boolean        true if the status was changed, false if not
    552592     */
    553     public function set_the_status( $status ) {
    554 
    555         if ( isset( $status ) ) {
    556             return update_option( 'maintenance_switch_status', $status );
     593    public function set_the_status($status)
     594    {
     595
     596        if (isset($status)) {
     597            return update_option('maintenance_switch_status', $status);
    557598        }
    558599        return false;
     
    565606     * @return   string         the version of the plugin saved in db
    566607     */
    567     public function get_the_version() {
    568 
    569         return get_option( 'maintenance_switch_version' );
     608    public function get_the_version()
     609    {
     610
     611        return get_option('maintenance_switch_version');
    570612    }
    571613
     
    576618     * @return   misc       the option value or false if option not exists
    577619     */
    578     public function get_the_settings() {
    579 
    580         return get_option( 'maintenance_switch_settings' );
     620    public function get_the_settings()
     621    {
     622
     623        return get_option('maintenance_switch_settings');
    581624    }
    582625
     
    586629     * @since    1.3.0
    587630     */
    588     public function restore_default_settings() {
     631    public function restore_default_settings()
     632    {
    589633
    590634        $settings = $this->default_settings;
    591         return update_option( 'maintenance_switch_settings', $settings );
     635        return update_option('maintenance_switch_settings', $settings);
    592636    }
    593637
     
    597641     * @since    1.3.0
    598642     */
    599     public function restore_html_setting() {
     643    public function restore_html_setting()
     644    {
    600645
    601646        $settings = $this->get_the_settings();
    602647        $settings['ms_page_html'] = $this->default_settings['ms_page_html'];
    603         return update_option( 'maintenance_switch_settings', $settings );
     648        return update_option('maintenance_switch_settings', $settings);
    604649    }
    605650
     
    610655     * @return   string    The theme file with absolute url
    611656     */
    612     public function get_theme_file_url() {
     657    public function get_theme_file_url()
     658    {
    613659
    614660        return $this->current_theme->get_stylesheet_directory_uri() . '/' . MS_THEME_FILENAME;
     
    621667     * @return   string    The theme file with absolute path
    622668     */
    623     public function get_theme_file_path() {
     669    public function get_theme_file_path()
     670    {
    624671
    625672        return $this->current_theme->get_stylesheet_directory() . '/' . MS_THEME_FILENAME;
     
    632679     * @return   boolean    true if the file exists in theme, false if not
    633680     */
    634     public function theme_file_exists() {
     681    public function theme_file_exists()
     682    {
    635683
    636684        $theme_file = $this->get_theme_file_path();
    637         return file_exists( $theme_file );
     685        return file_exists($theme_file);
    638686    }
    639687
     
    644692     * @return   boolean    True if the file was created in theme, false if not of if it already exists
    645693     */
    646     public function create_theme_file() {
     694    public function create_theme_file()
     695    {
    647696
    648697        $theme_file = $this->get_theme_file_path();
    649         if ( ! $this->theme_file_exists() ) {
    650             return $this->_create_file( $theme_file, $this->default_settings['ms_page_html'] );
     698        if (!$this->theme_file_exists()) {
     699            return $this->_create_file($theme_file, $this->default_settings['ms_page_html']);
    651700        }
    652701        return false;
     
    659708     * @return   boolean    True if the file was deleted in theme, false if not of if not exists
    660709     */
    661     public function delete_theme_file() {
     710    public function delete_theme_file()
     711    {
    662712
    663713        $theme_file = $this->get_theme_file_path();
    664         if ( $this->theme_file_exists() ) {
    665             return $this->_delete_file( $theme_file );
     714        if ($this->theme_file_exists()) {
     715            return $this->_delete_file($theme_file);
    666716        }
    667717        return false;
     
    676726     * @return   misc    The setting value
    677727     */
    678     public function get_setting( $setting_name, $default_value = false ) {
     728    public function get_setting($setting_name, $default_value = false)
     729    {
    679730
    680731        $settings = $this->get_the_settings();
    681732
    682         if ( isset( $settings[ $setting_name ] ) ) {
    683             return $settings[ $setting_name ];
     733        if (isset($settings[$setting_name])) {
     734            return $settings[$setting_name];
    684735        }
    685736
     
    695746     * @return   boolean    True if the setting was updated, false if not of if is not set
    696747     */
    697     public function update_setting( $setting_name, $setting_value ) {
     748    public function update_setting($setting_name, $setting_value)
     749    {
    698750
    699751        $settings = $this->get_the_settings();
    700752
    701         if ( isset( $settings[$setting_name] ) )
     753        if (isset($settings[$setting_name]))
    702754            $settings[$setting_name] = $setting_value;
    703755        else
     
    712764     * @since    1.0.0
    713765     */
    714     public function run() {
     766    public function run()
     767    {
    715768
    716769        $this->loader->run();
     
    724777     * @return    string    The name of the plugin.
    725778     */
    726     public function get_plugin_name() {
     779    public function get_plugin_name()
     780    {
    727781
    728782        return $this->plugin_name;
     
    735789     * @return    Maintenance_Switch_Loader    Orchestrates the hooks of the plugin.
    736790     */
    737     public function get_loader() {
     791    public function get_loader()
     792    {
    738793
    739794        return $this->loader;
     
    746801     * @return    string    The version number of the plugin.
    747802     */
    748     public function get_version() {
     803    public function get_version()
     804    {
    749805
    750806        return $this->version;
     
    757813     * @return    string    The status of the maintenance mode.
    758814     */
    759     public function get_status() {
     815    public function get_status()
     816    {
    760817
    761818        return $this->status;
     
    768825     * @return    string    The default settings.
    769826     */
    770     public function get_default_settings() {
     827    public function get_default_settings()
     828    {
    771829
    772830        return $this->default_settings;
     
    779837     * @return    boolean    True if the user can switch, false if not
    780838     */
    781     public function current_user_can_switch() {
     839    public function current_user_can_switch()
     840    {
    782841
    783842        global $current_user;
    784843        $user_can = false;
    785844
    786         $switch_roles = (array) $this->get_setting( 'ms_switch_roles' );
    787 
    788         foreach( $current_user->roles as $role ) {
    789             if ( in_array( $role, $switch_roles ) )
     845        $switch_roles = (array) $this->get_setting('ms_switch_roles');
     846
     847        foreach ($current_user->roles as $role) {
     848            if (in_array($role, $switch_roles))
    790849                $user_can = true;
    791850        }
     
    799858     * @return   array    List of all users logins
    800859     */
    801     public function get_allowed_users() {
    802 
    803         $allowed_roles = (array) $this->get_setting( 'ms_allowed_roles' );
    804         $users = $this->get_users_by_role( $allowed_roles );
     860    public function get_allowed_users()
     861    {
     862
     863        $allowed_roles = (array) $this->get_setting('ms_allowed_roles');
     864        $users = $this->get_users_by_role($allowed_roles);
    805865        $allowed_users = array();
    806         foreach ( $users as $user ) {
     866        foreach ($users as $user) {
    807867            $allowed_users[] = $user->user_login;
    808868        }
     
    816876     * @return   string    List of all ips comma separated
    817877     */
    818     public function get_allowed_ips() {
    819 
    820         $allowed_ips = $this->get_setting( 'ms_allowed_ips' );
    821         $allowed_ips = explode( ',', $allowed_ips );
     878    public function get_allowed_ips()
     879    {
     880
     881        $allowed_ips = $this->get_setting('ms_allowed_ips');
     882        $allowed_ips = explode(',', $allowed_ips);
    822883        return $allowed_ips;
    823884    }
     
    830891     * @return   array    the user list
    831892     */
    832     public function get_users_by_role( $roles = array() ) {
    833 
    834         $users = array();
    835         foreach ($roles as $role) {
    836             if ( !empty( $role ) ) {
    837                 $users_query = new WP_User_Query( array(
    838                     'fields' => 'all_with_meta',
    839                     'role' => $role,
    840                     'orderby' => 'display_name'
    841                     ) );
    842                 $results = $users_query->get_results();
    843                 if ($results) $users = array_merge($users, $results);
    844             }
    845         }
    846         return $users;
     893    public function get_users_by_role($roles = array())
     894    {
     895
     896        $users = array();
     897        foreach ($roles as $role) {
     898            if (!empty($role)) {
     899                $users_query = new WP_User_Query(array(
     900                    'fields' => 'all_with_meta',
     901                    'role' => $role,
     902                    'orderby' => 'display_name'
     903                ));
     904                $results = $users_query->get_results();
     905                if ($results)
     906                    $users = array_merge($users, $results);
     907            }
     908        }
     909        return $users;
    847910    }
    848911
     
    853916     * @return   string    The current ip of the user
    854917     */
    855     public function get_user_ip() {
     918    public function get_user_ip()
     919    {
    856920        //Just get the headers if we can or else use the SERVER global
    857         if ( function_exists( 'apache_request_headers' ) ) {
     921        if (function_exists('apache_request_headers')) {
    858922            $headers = apache_request_headers();
    859923        } else {
    860             $headers = $_SERVER;
     924            $headers = array_map('sanitize_text_field', $_SERVER);
    861925        }
    862926        // Get the forwarded IP if it exists
    863         if ( array_key_exists( 'X-Forwarded-For', $headers ) && filter_var( $headers['X-Forwarded-For'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ) ) {
     927        if (array_key_exists('X-Forwarded-For', $headers) && filter_var($headers['X-Forwarded-For'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
    864928            $the_ip = $headers['X-Forwarded-For'];
    865         } elseif ( array_key_exists( 'HTTP_X_FORWARDED_FOR', $headers ) && filter_var( $headers['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ) ) {
     929        } elseif (array_key_exists('HTTP_X_FORWARDED_FOR', $headers) && filter_var($headers['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
    866930            $the_ip = $headers['HTTP_X_FORWARDED_FOR'];
    867931        } else {
    868             $the_ip = filter_var( $_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 );
     932            $the_ip = filter_var(sanitize_text_field($_SERVER['REMOTE_ADDR']), FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
    869933        }
    870934        return $the_ip;
     
    878942     * @return   boolean    True if the .maintenance file is core, false if was created by the plugin
    879943     */
    880     public function _check_core_file( $file ) {
    881 
    882         if ( file_exists( $file ) ) {
    883             $content = file_get_contents( $file );
    884             if ( preg_match( '/'.$this->plugin_name.'/i', $content) )
     944    public function _check_core_file($file)
     945    {
     946
     947        if (file_exists($file)) {
     948            $content = file_get_contents($file);
     949            if (preg_match('/' . $this->plugin_name . '/i', $content))
    885950                return false;
    886951            else
     
    898963     * @return   boolean    True if the file was deleted, false if not
    899964     */
    900     public function _delete_file( $file, $check_core=false ) {
    901 
    902         if ( file_exists( $file ) ) {
    903 
    904             if ( $check_core && $this->_check_core_file( $file ) )
     965    public function _delete_file($file, $check_core = false)
     966    {
     967
     968        if (file_exists($file)) {
     969
     970            if ($check_core && $this->_check_core_file($file))
    905971                return false;
    906972
    907             if ( unlink( $file ) )
     973            if (unlink($file))
    908974                return true;
    909975        }
     
    918984     * @var      string    $content     the content to put in the file
    919985     */
    920     public function _create_file( $file, $content ) {
    921 
    922         if ( file_exists( $file ) )
     986    public function _create_file($file, $content)
     987    {
     988
     989        if (file_exists($file))
    923990            return false;
    924991
    925         if ( ! file_put_contents( $file, $content ) )
     992        if (!file_put_contents($file, $content))
    926993            return false;
    927994
     
    9341001     * @since    1.0.0
    9351002     */
    936     public function create_php_file() {
     1003    public function create_php_file()
     1004    {
    9371005
    9381006        // get the template file content
    939         $content = file_get_contents( MS_PHP_FILE_TEMPLATE );
     1007        $content = file_get_contents(MS_PHP_FILE_TEMPLATE);
    9401008
    9411009        // get flags values
    942         $page_html = wp_specialchars_decode( $this->get_setting( 'ms_page_html' ), ENT_QUOTES );
    943         $use_theme_file = $this->get_setting( 'ms_use_theme' );
    944         $return503 = $this->get_setting( 'ms_error_503' );
     1010        $page_html = wp_specialchars_decode($this->get_setting('ms_page_html'), ENT_QUOTES);
     1011        $use_theme_file = $this->get_setting('ms_use_theme');
     1012        $return503 = $this->get_setting('ms_error_503');
    9451013        $theme = wp_get_theme();
    9461014        $theme_file = $theme->get_stylesheet_directory() . '/' . MS_THEME_FILENAME;
    9471015
    9481016        // apply flags replacements
    949         $content = str_replace( '{{MS_PLUGIN_SLUG}}' , $this->plugin_name, $content );
    950         $content = str_replace( '{{MS_USE_THEME_FILE}}' , $use_theme_file, $content );
    951         $content = str_replace( '{{MS_RETURN_503}}' , $return503, $content );
    952         $content = str_replace( '{{MS_THEME_FILE}}' , $theme_file, $content );
    953         $content = str_replace( '{{MS_PAGE_HTML}}' , $page_html, $content );
     1017        $content = str_replace('{{MS_PLUGIN_SLUG}}', $this->plugin_name, $content);
     1018        $content = str_replace('{{MS_USE_THEME_FILE}}', $use_theme_file, $content);
     1019        $content = str_replace('{{MS_RETURN_503}}', $return503, $content);
     1020        $content = str_replace('{{MS_THEME_FILE}}', $theme_file, $content);
     1021        $content = str_replace('{{MS_PAGE_HTML}}', $page_html, $content);
    9541022
    9551023        // delete the current file
    956         $this->_delete_file( MS_PHP_FILE_ACTIVE );
     1024        $this->_delete_file(MS_PHP_FILE_ACTIVE);
    9571025
    9581026        // try to create the file
    959         if ( ! $this->_create_file( MS_PHP_FILE_ACTIVE, $content ) ) {
     1027        if (!$this->_create_file(MS_PHP_FILE_ACTIVE, $content)) {
    9601028            return false;
    9611029        }
     
    9681036     * @since    1.0.0
    9691037     */
    970     public function create_dot_file() {
     1038    public function create_dot_file()
     1039    {
    9711040
    9721041        // get the template file content
    973         $content = file_get_contents( MS_DOT_FILE_TEMPLATE );
     1042        $content = file_get_contents(MS_DOT_FILE_TEMPLATE);
    9741043
    9751044        // get flags values
    976         $allowed_users = "'" . implode( "', '", $this->get_allowed_users() ) . "'";
    977         $allowed_ips = "'" . implode( "','", $this->get_allowed_ips() ) . "'";
    978         $login_url = str_replace( get_site_url(), '', wp_login_url() );
     1045        $allowed_users = "'" . implode("', '", $this->get_allowed_users()) . "'";
     1046        $allowed_ips = "'" . implode("','", $this->get_allowed_ips()) . "'";
     1047        $login_url = str_replace(get_site_url(), '', wp_login_url());
    9791048
    9801049        // apply flags replacements
    981         $content = str_replace( '{{MS_ALLOWED_USERS}}' , $allowed_users, $content );
    982         $content = str_replace( '{{MS_ALLOWED_IPS}}' , $allowed_ips, $content );
    983         $content = str_replace( '{{MS_PLUGIN_SLUG}}' , $this->plugin_name, $content );
    984         $content = str_replace( '{{MS_LOGIN_URL}}' , $login_url, $content );
     1050        $content = str_replace('{{MS_ALLOWED_USERS}}', $allowed_users, $content);
     1051        $content = str_replace('{{MS_ALLOWED_IPS}}', $allowed_ips, $content);
     1052        $content = str_replace('{{MS_PLUGIN_SLUG}}', $this->plugin_name, $content);
     1053        $content = str_replace('{{MS_LOGIN_URL}}', $login_url, $content);
    9851054
    9861055        // check if the core dot file exists or delete current file
    987         if ( $this->_check_core_file( MS_DOT_FILE_ACTIVE ) ) {
     1056        if ($this->_check_core_file(MS_DOT_FILE_ACTIVE)) {
    9881057            return false;
    9891058        } else {
    990             $this->_delete_file( MS_DOT_FILE_ACTIVE, true );
     1059            $this->_delete_file(MS_DOT_FILE_ACTIVE, true);
    9911060        }
    9921061
    9931062        // try to create the file
    994         if ( ! $this->_create_file( MS_DOT_FILE_ACTIVE, $content ) ) {
     1063        if (!$this->_create_file(MS_DOT_FILE_ACTIVE, $content)) {
    9951064            return false;
    9961065        }
     
    10031072     * @since    1.0.0
    10041073     */
    1005     public function toggle_status_callback() {
    1006        
     1074    public function toggle_status_callback()
     1075    {
     1076
    10071077        // Check nonce for security
    10081078        $nonce = isset($_POST['nonce']) ? sanitize_text_field(wp_unslash($_POST['nonce'])) : '';
     
    10231093        $new_status = (bool) $status == 1 ? 0 : 1;
    10241094        // sync status
    1025         $response = $this->sync_status( $new_status );
     1095        $response = $this->sync_status($new_status);
    10261096        // return json response
    1027         wp_send_json( $response );
     1097        wp_send_json($response);
    10281098        // this is required to terminate immediately and return a proper response
    10291099        wp_die();
     
    10361106     * @since    1.0.0
    10371107     */
    1038     public function add_switch_button( $wp_admin_bar ){
    1039 
    1040         if ( $this->current_user_can_switch() ) {
     1108    public function add_switch_button($wp_admin_bar)
     1109    {
     1110
     1111        if ($this->current_user_can_switch()) {
    10411112
    10421113            $args = array(
    10431114                'id' => 'ms-switch-button',
    1044                 'title' => '<span class="ab-icon dashicons-admin-tools"></span><span class="ab-label">' . __( 'Maintenance', $this->plugin_name ) . '</span>',
     1115                'title' => '<span class="ab-icon dashicons-admin-tools"></span><span class="ab-label">' . __('Maintenance', $this->plugin_name) . '</span>',
    10451116                'href' => '#',
    10461117                'meta' => array(
    1047                     'class' => 'toggle-button ' . ( $this->status ? 'active' : '' ),
     1118                    'class' => 'toggle-button ' . ($this->status ? 'active' : ''),
    10481119                )
    10491120            );
    10501121
    1051             $wp_admin_bar->add_node( $args );
     1122            $wp_admin_bar->add_node($args);
    10521123        }
    10531124    }
  • maintenance-switch/trunk/maintenance-switch.php

    r3369181 r3369189  
    1717 * Plugin URI:        https://wordpress.org/plugins/maintenance-switch
    1818 * Description:       Customize easily and switch in one-click to (native) maintenance mode from your backend or frontend.
    19  * Version:           1.6.2
     19 * Version:           1.6.3
    2020 * Author:            Fugu
    2121 * Author URI:        http://www.fugu.fr
  • maintenance-switch/trunk/preview.php

    r3369181 r3369189  
    22
    33// If this file is called directly, abort.
    4 if ( ! defined( 'WPINC' ) ) {
    5     die;
     4if (!defined('WPINC')) {
     5    die;
    66}
    77
    88// Security check: only allow admin users
    9 if ( ! current_user_can( 'manage_options' ) ) {
    10     wp_die( __( 'Insufficient permissions to access this page.' ) );
     9if (!current_user_can('manage_options')) {
     10    wp_die(__('Insufficient permissions to access this page.'));
    1111}
    1212
    1313// Security check: verify nonce
    14 if ( ! empty( $_POST['preview-code'] ) ) {
    15     if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( $_POST['_wpnonce'], 'maintenance_switch_preview' ) ) {
    16         wp_die( __( 'Security check failed.' ) );
    17     }
     14if (!empty($_POST['preview-code'])) {
     15    if (!isset($_POST['_wpnonce']) || !wp_verify_nonce(sanitize_text_field($_POST['_wpnonce']), 'maintenance_switch_preview')) {
     16        wp_die(__('Security check failed.'));
     17    }
    1818}
    1919
     
    3333header('Content-Type: text/html; charset=utf-8');
    3434
    35 
    3635if (!empty($_POST['preview-code'])) {
    37     echo wp_kses_post(wp_unslash($_POST['preview-code']));
     36    echo wp_kses_post(wp_unslash(sanitize_textarea_field($_POST['preview-code'])));
    3837}
  • maintenance-switch/trunk/readme.txt

    r3369181 r3369189  
    55Requires at least: 3.5
    66Tested up to: 6.3
    7 Stable tag: 1.6.2
     7Stable tag: 1.6.3
    88Requires PHP: 7.4
    99License: GPLv2 or later
  • maintenance-switch/trunk/templates/maintenance.php

    r3369156 r3369189  
    1010
    1111// If this file is called directly, abort.
    12 if ( ! defined( 'WPINC' ) ) {
     12if (!defined('WPINC')) {
    1313    die;
    1414}
    1515
    1616// Displaying this page during the maintenance mode
    17 $protocol = $_SERVER["SERVER_PROTOCOL"];
     17$protocol = isset($_SERVER['SERVER_PROTOCOL']) ? sanitize_text_field($_SERVER['SERVER_PROTOCOL']) : 'HTTP/1.0';
    1818
    1919if ('HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol)
     
    3434$use_theme = '{{MS_USE_THEME_FILE}}';
    3535
    36 if ($use_theme == '1' && file_exists($theme_file)) {
     36if ($use_theme == '1' && !empty($theme_file) && file_exists($theme_file) && strpos(realpath($theme_file), ABSPATH) === 0) {
    3737    require_once $theme_file;
    3838    die();
  • maintenance-switch/trunk/uninstall.php

    r3369156 r3369189  
    22
    33// If this file is called directly, abort.
    4 if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
     4if (!defined('WP_UNINSTALL_PLUGIN')) {
    55    die;
    66}
     
    1313 *
    1414 * - This method should be static
    15  * - Check if the $_REQUEST content actually is the plugin name
    16  * - Run an admin referrer check to make sure it goes through authentication
    17  * - Verify the output of $_GET makes sense
     15 * - Check if the request content actually is the plugin name
     16 * - Run an admin referrer check to make sure it goes through authentication 
     17 * - Verify the output makes sense
    1818 * - Repeat with other user roles. Best directly by using the links/query string parameters.
    1919 * - Repeat things for multisite. Once for a single site in the network, once sitewide.
Note: See TracChangeset for help on using the changeset viewer.