Skip to content

Commit 26079b7

Browse files
committed
fix php warning / code review #9
1 parent aa1145c commit 26079b7

7 files changed

Lines changed: 76 additions & 64 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog ##
22

3+
## 1.0.6 - 04 Mar 2020
4+
* Fixed [#9](https://github.com/BeAPI/beapi-maintenance-mode/issues/9) Fix PHP warnings
5+
* Code refactoring
6+
37
## 1.0.5 - 02 Apr 2019
48
* Add [#8](https://github.com/BeAPI/beapi-maintenance-mode/issues/8) : filter is maintenance mode helper for handle custom behaviour.
59

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ If you are a developer and the plugin is not installed, you could also just use
3838
# Requirements
3939

4040
- Tested up to 4.9.8
41-
- PHP 5.6+
41+
- PHP 7+
4242

4343
# Installation
4444

beapi-maintenance-mode.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
<?php
22
/*
3-
Plugin Name: BEAPI - Maintenance Mode
4-
Version: 1.0.5
5-
Plugin URI: https://github.com/BeAPI/beapi-maintenance-mode
6-
Description: Puts your WordPress site into maintenance mode.
7-
Author: Be API Technical team
8-
Author URI: https://beapi.fr
9-
Domain Path: languages
10-
Text Domain: beapi-maintenance-mode-mode
11-
Contributors: Maxime Culea, Nicolas Juen, Romain Lefort
3+
Plugin Name: BEAPI - Maintenance Mode
4+
Version: 1.0.6
5+
Plugin URI: https://github.com/BeAPI/beapi-maintenance-mode
6+
Description: Puts your WordPress site into maintenance mode.
7+
Author: Be API Technical team
8+
Author URI: https://beapi.fr
9+
Domain Path: languages
10+
Text Domain: beapi-maintenance-mode-mode
11+
Contributors: Maxime Culea, Nicolas Juen, Romain Lefort
1212
13-
----
13+
----
1414
15-
Copyright 2018 Be API Technical team (human@beapi.fr)
15+
Copyright 2018 Be API Technical team (human@beapi.fr)
1616
17-
This program is free software; you can redistribute it and/or modify
18-
it under the terms of the GNU General Public License as published by
19-
the Free Software Foundation; either version 2 of the License, or
20-
(at your option) any later version.
17+
This program is free software; you can redistribute it and/or modify
18+
it under the terms of the GNU General Public License as published by
19+
the Free Software Foundation; either version 2 of the License, or
20+
(at your option) any later version.
2121
22-
This program is distributed in the hope that it will be useful,
23-
but WITHOUT ANY WARRANTY; without even the implied warranty of
24-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25-
GNU General Public License for more details.
22+
This program is distributed in the hope that it will be useful,
23+
but WITHOUT ANY WARRANTY; without even the implied warranty of
24+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25+
GNU General Public License for more details.
2626
27-
You should have received a copy of the GNU General Public License
28-
along with this program; if not, write to the Free Software
29-
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27+
You should have received a copy of the GNU General Public License
28+
along with this program; if not, write to the Free Software
29+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
3030
*/
3131

3232
// don't load directly
@@ -42,11 +42,11 @@
4242
define( 'BEAPI_MAINTENANCE_MODE_URL', plugin_dir_url( __FILE__ ) );
4343
define( 'BEAPI_MAINTENANCE_MODE_DIR', plugin_dir_path( __FILE__ ) );
4444
define( 'BEAPI_MAINTENANCE_MODE_MAIN_FILE_DIR', __FILE__ );
45-
define( 'BEAPI_MAINTENANCE_MODE_PLUGIN_DIRNAME', basename( rtrim( dirname( __FILE__ ), '/' ) ) );
45+
define( 'BEAPI_MAINTENANCE_MODE_PLUGIN_DIRNAME', basename( rtrim( __DIR__, '/' ) ) );
4646

4747
// Check PHP min version
4848
if ( version_compare( PHP_VERSION, BEAPI_MAINTENANCE_MODE_MIN_PHP_VERSION, '<' ) ) {
49-
require_once( BEAPI_MAINTENANCE_MODE_DIR . 'compat.php' );
49+
require_once BEAPI_MAINTENANCE_MODE_DIR . 'compat.php';
5050

5151
// possibly display a notice, trigger error
5252
add_action( 'admin_init', array( 'BEAPI\Maintenance_Mode\Compatibility', 'admin_init' ) );

classes/helpers.php

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?php namespace BEAPI\Maintenance_Mode;
1+
<?php
2+
3+
namespace BEAPI\Maintenance_Mode;
24

35
class Helpers {
46

@@ -12,37 +14,37 @@ class Helpers {
1214
* - current ip is from whitelist
1315
* - it is multisite activation process
1416
*
17+
* @return bool
1518
* @author Maxime CULEA
1619
*
17-
* @return bool
1820
*/
1921
public static function is_maintenance_mode() {
2022
$is_maintenance_mode = ! is_user_logged_in() && ! self::is_allowed_ip() && ! self::is_ms_activate();
23+
2124
return apply_filters( 'beapi.maintenance_mode.is_maintenance_mode', $is_maintenance_mode );
2225
}
2326

2427
/**
2528
* Check if the current IP is in whitelist
2629
*
27-
* @author Maxime CULEA
30+
* @return bool
2831
* @since 1.0.0
2932
*
30-
* @return bool
33+
* @author Maxime CULEA
3134
*/
3235
public static function is_allowed_ip() {
3336
/**
3437
* Allow to add/remove custom ips
3538
*
3639
* @params array $whitelist_ips : Array of allowed ips
3740
*
38-
* @author Maxime CULEA
41+
* @return array
3942
* @since 1.0.0
4043
*
41-
* @return array
44+
* @author Maxime CULEA
4245
*/
4346
$whitelist_ips = apply_filters( 'beapi.maintenance_mode.whitelist_ips', [] );
44-
if ( empty( $whitelist_ips ) ) {
45-
// No whitelist, then everybody is allowed
47+
if ( empty( $whitelist_ips ) ) { // No whitelist, then everybody is allowed
4648
return true;
4749
}
4850

@@ -52,13 +54,13 @@ public static function is_allowed_ip() {
5254
// No current ip set to check against
5355
return false;
5456
}
55-
$current_ip = preg_replace_callback( '/(\d+)/', [ __SELF__, 'maintenance_replace_ip' ], $current_ip );
57+
$current_ip = preg_replace_callback( '/(\d+)/', [ __CLASS__, 'maintenance_replace_ip' ], $current_ip );
5658

5759
// Loop on each whitelist IP
5860
foreach ( $whitelist_ips as $allowed_ip ) {
59-
$allowed_ip = preg_replace_callback( '/(\d+)/', [ __SELF__, 'maintenance_replace_ip' ], $allowed_ip );
61+
$allowed_ip = preg_replace_callback( '/(\d+)/', [ __CLASS__, 'maintenance_replace_ip' ], $allowed_ip );
6062
// Not strict mode check because user ip and whitelist ips could not be the same type
61-
if ( $current_ip == $allowed_ip ) {
63+
if ( $current_ip === $allowed_ip ) {
6264
// We found a match into the whitelist
6365
return true;
6466
}
@@ -71,10 +73,10 @@ public static function is_allowed_ip() {
7173
/**
7274
* Check if during multisite process to avoid not maintenance mode or not
7375
*
74-
* @author Maxime CULEA
76+
* @return bool
7577
* @since 1.0.0
7678
*
77-
* @return bool
79+
* @author Maxime CULEA
7880
*/
7981
public static function is_ms_activate() {
8082
if ( empty( $_SERVER['SCRIPT_NAME'] ) ) {
@@ -89,38 +91,38 @@ public static function is_ms_activate() {
8991
*
9092
* @param $matches
9193
*
92-
* @author Nicolas Juen
94+
* @return string
9395
* @since 1.0.0
9496
*
95-
* @return string
97+
* @author Nicolas Juen
9698
*/
97-
private function maintenance_replace_ip( $matches ) {
98-
return sprintf( "%03d", $matches[1] );
99+
private static function maintenance_replace_ip( $matches ) {
100+
return sprintf( '%03d', $matches[1] );
99101
}
100102

101103
/**
102104
* Get the maintenance template path
103105
*
104-
* @author Maxime CULEA
106+
* @return string
105107
* @since 1.0.0
106108
*
107-
* @return string
109+
* @author Maxime CULEA
108110
*/
109-
static function get_template_path() {
111+
public static function get_template_path() {
110112
$default = BEAPI_MAINTENANCE_MODE_DIR . 'templates/maintenance.php';
111113

112114
/**
113115
* Filter maintenance template path to add a custom one
114116
*
115-
* @params string $whitelist_ips : The path to the custom template
117+
* @params string $default : The path to the custom template
116118
*
117-
* @author Maxime CULEA
119+
* @return array
118120
* @since 1.0.0
119121
*
120-
* @return array
122+
* @author Maxime CULEA
121123
*/
122124
$template = apply_filters( 'beapi.maintenance_mode.template.path', $default );
123-
if ( empty( $template ) || ! file_exists( $template ) ) {
125+
if ( empty( $template ) || ! is_file( $template ) ) {
124126
$template = $default;
125127
}
126128

classes/main.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?php namespace BEAPI\Maintenance_Mode;
1+
<?php
2+
3+
namespace BEAPI\Maintenance_Mode;
24

35
// don't load directly
46
if ( ! defined( 'ABSPATH' ) ) {
@@ -33,18 +35,18 @@ protected function init() {
3335
* Change the header if maintenance mode
3436
*
3537
* @param $status_header
36-
* @param $header
37-
* @param $text
38+
* @param $code
39+
* @param $description
3840
* @param $protocol
3941
*
40-
* @author Maxime CULEA
42+
* @return string
4143
* @since 1.0.0
4244
*
43-
* @return string
45+
* @author Maxime CULEA
4446
*/
45-
function maintenance_header( $status_header, $header, $text, $protocol ) {
47+
public function maintenance_header( $status_header, $code, $description, $protocol ) {
4648
if ( ! Helpers::is_maintenance_mode() ) {
47-
return $protocol;
49+
return $status_header;
4850
}
4951

5052
return "$protocol 503 Service Unavailable";
@@ -56,7 +58,7 @@ function maintenance_header( $status_header, $header, $text, $protocol ) {
5658
* @author Maxime CULEA
5759
* @since 1.0.0
5860
*/
59-
function maintenance_feed() {
61+
public function maintenance_feed() {
6062
if ( ! Helpers::is_maintenance_mode() ) {
6163
return;
6264
}
@@ -71,7 +73,7 @@ function maintenance_feed() {
7173
* @author Maxime CULEA
7274
* @since 1.0.0
7375
*/
74-
function maintenance_content() {
76+
public function maintenance_content() {
7577
if ( ! Helpers::is_maintenance_mode() ) {
7678
return;
7779
}
@@ -80,4 +82,4 @@ function maintenance_content() {
8082
$page = file_get_contents( Helpers::get_template_path() );
8183
die( $page );
8284
}
83-
}
85+
}

classes/singleton.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?php namespace BEAPI\Maintenance_Mode;
1+
<?php
2+
3+
namespace BEAPI\Maintenance_Mode;
24

35
trait Singleton {
46

@@ -30,7 +32,8 @@ final private function __construct() {
3032
* Implement this method in your child class
3133
* If you want to have actions send at construct
3234
*/
33-
protected function init() {}
35+
protected function init() {
36+
}
3437

3538
/**
3639
* prevent the instance from being cloned
@@ -45,5 +48,6 @@ final private function __clone() {
4548
*
4649
* @return void
4750
*/
48-
final private function __wakeup() {}
49-
}
51+
final private function __wakeup() {
52+
}
53+
}

templates/maintenance.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
}
3636
.denied p.icon {
3737
font-size: 30px;
38-
margin-bottom: 0px;
38+
margin-bottom: 0;
3939
}
4040
</style>
4141
</head>

0 commit comments

Comments
 (0)