Skip to content

Commit 2f07a64

Browse files
authored
release: fixes
* Fix maintenance mode issue for previously logged users #321 * Allow comments into exclude textarea so that you can comment on the IP addresses for location, props @joostdekeijzer * Fix PHP notice errors on specific scenarios #324 * Fix Otter for saving subscriber entry
2 parents dc41144 + c81d8c5 commit 2f07a64

File tree

4 files changed

+87
-27
lines changed

4 files changed

+87
-27
lines changed

composer.lock

Lines changed: 9 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

includes/classes/wp-maintenance-mode.php

Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ private function __construct() {
6969
add_action( 'wp_ajax_wpmm_add_subscriber', array( $this, 'add_subscriber' ) );
7070
add_action( 'wp_ajax_nopriv_wpmm_send_contact', array( $this, 'send_contact' ) );
7171
add_action( 'wp_ajax_wpmm_send_contact', array( $this, 'send_contact' ) );
72+
add_action( 'otter_form_after_submit', array( $this, 'otter_add_subscriber' ) );
7273

7374
if ( isset( $this->plugin_settings['design']['page_id'] ) && get_option( 'wpmm_new_look' ) && get_post_status( $this->plugin_settings['design']['page_id'] ) === 'private' ) {
7475
wp_publish_post( $this->plugin_settings['design']['page_id'] );
@@ -78,7 +79,7 @@ private function __construct() {
7879
add_filter(
7980
'pre_option_page_on_front',
8081
function ( $value ) {
81-
if ( ! is_user_logged_in() && isset( $this->plugin_settings['design']['page_id'] ) && get_option( 'wpmm_new_look' ) ) {
82+
if ( ( ! $this->check_user_role() && ! $this->check_exclude() ) && isset( $this->plugin_settings['design']['page_id'] ) && get_option( 'wpmm_new_look' ) ) {
8283
$page_id = $this->plugin_settings['design']['page_id'];
8384

8485
if ( ! function_exists( 'is_plugin_active' ) ) {
@@ -650,7 +651,7 @@ public function init() {
650651
! $this->check_search_bots() &&
651652
! ( defined( 'WP_CLI' ) && WP_CLI )
652653
) {
653-
if ( get_option( 'wpmm_new_look' ) ) {
654+
if ( isset( $this->plugin_settings['design']['page_id'] ) && get_option( 'wpmm_new_look' ) ) {
654655
include_once wpmm_get_template_path( 'maintenance.php', true );
655656
return;
656657
}
@@ -861,6 +862,10 @@ public function check_exclude() {
861862
$request_uri = isset( $_SERVER['REQUEST_URI'] ) ? rawurldecode( $_SERVER['REQUEST_URI'] ) : '';
862863
$request_uri = wp_sanitize_redirect( $request_uri );
863864
foreach ( $excluded_list as $item ) {
865+
if ( false !== strpos( $item, '#' ) ) {
866+
$item = trim( substr( $item, 0, strpos( $item, '#' ) ) );
867+
}
868+
864869
if ( empty( $item ) ) { // just to be sure :-)
865870
continue;
866871
}
@@ -997,11 +1002,11 @@ public function use_maintenance_template( $template ) {
9971002
}
9981003

9991004
$current_template = get_post_meta( $post->ID, '_wp_page_template', true );
1000-
if ( 'templates/wpmm-page-template.php' !== $current_template ) {
1005+
if ( ! empty( $current_template ) && 'templates/wpmm-page-template.php' !== $current_template ) {
10011006
return $template;
10021007
}
10031008

1004-
$file = WPMM_VIEWS_PATH . '/wpmm-page-template.php';
1009+
$file = WPMM_VIEWS_PATH . 'wpmm-page-template.php';
10051010
if ( file_exists( $file ) ) {
10061011
return $file;
10071012
}
@@ -1216,18 +1221,8 @@ public function add_subscriber() {
12161221
) {
12171222
throw new Exception( __( 'Security check.', 'wp-maintenance-mode' ) );
12181223
}
1219-
// save
1220-
$exists = $wpdb->get_row( $wpdb->prepare( "SELECT id_subscriber FROM {$wpdb->prefix}wpmm_subscribers WHERE email = %s", $email ), ARRAY_A );
1221-
if ( empty( $exists ) ) {
1222-
$wpdb->insert(
1223-
$wpdb->prefix . 'wpmm_subscribers',
1224-
array(
1225-
'email' => $email,
1226-
'insert_date' => date( 'Y-m-d H:i:s' ),
1227-
),
1228-
array( '%s', '%s' )
1229-
);
1230-
}
1224+
// save.
1225+
$this->insert_subscriber( $email );
12311226

12321227
wp_send_json_success( __( 'You successfully subscribed. Thanks!', 'wp-maintenance-mode' ) );
12331228
} catch ( Exception $ex ) {
@@ -1293,6 +1288,59 @@ public function send_contact() {
12931288
}
12941289
}
12951290

1291+
/**
1292+
* Save subscriber into database.
1293+
*
1294+
* @param Form_Data_Request $form_data The form data.
1295+
* @return void
1296+
*/
1297+
public function otter_add_subscriber( $form_data ) {
1298+
if ( $form_data ) {
1299+
$input_data = $form_data->get_payload_field( 'formInputsData' );
1300+
$input_data = array_map(
1301+
function( $input_field ) {
1302+
if ( isset( $input_field['type'] ) && 'email' === $input_field['type'] ) {
1303+
return $input_field['value'];
1304+
}
1305+
return false;
1306+
},
1307+
$input_data
1308+
);
1309+
$input_data = array_filter( $input_data );
1310+
if ( ! empty( $input_data ) ) {
1311+
foreach ( $input_data as $email ) {
1312+
$this->insert_subscriber( $email );
1313+
}
1314+
}
1315+
}
1316+
}
1317+
1318+
/**
1319+
* Save subscriber into database.
1320+
*
1321+
* @param string $email Email address.
1322+
* @global object $wpdb
1323+
*
1324+
* @return void
1325+
*/
1326+
public function insert_subscriber( $email = '' ) {
1327+
global $wpdb;
1328+
if ( ! empty( $email ) ) {
1329+
// phpcs:ignore WordPress.DB.DirectDatabaseQuery
1330+
$exists = $wpdb->get_row( $wpdb->prepare( "SELECT id_subscriber FROM {$wpdb->prefix}wpmm_subscribers WHERE email = %s", $email ), ARRAY_A );
1331+
if ( empty( $exists ) ) {
1332+
// phpcs:ignore WordPress.DB.DirectDatabaseQuery
1333+
$wpdb->insert(
1334+
$wpdb->prefix . 'wpmm_subscribers',
1335+
array(
1336+
'email' => sanitize_email( $email ),
1337+
'insert_date' => date( 'Y-m-d H:i:s' ),
1338+
),
1339+
array( '%s', '%s' )
1340+
);
1341+
}
1342+
}
1343+
}
12961344
}
12971345

12981346
}

views/maintenance.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,28 @@
5454
if ( ! empty( $text ) ) {
5555
$allowed_html = wp_kses_allowed_html( 'post' );
5656

57-
$allowed_html['form'] = array(
57+
$allowed_html['form'] = array(
5858
'id' => array(),
5959
'class' => array(),
6060
'action' => array(),
6161
'method' => array(),
6262
);
63-
$allowed_html['input'] = array(
63+
$allowed_html['input'] = array(
6464
'type' => array(),
6565
'id' => array(),
6666
'name' => array(),
6767
'value' => array(),
6868
'class' => array(),
6969
'placeholder' => array(),
7070
);
71+
$allowed_html['iframe'] = array(
72+
'src' => array(),
73+
'height' => array(),
74+
'width' => array(),
75+
'frameborder' => array(),
76+
'allowfullscreen' => array(),
77+
'data-*' => true,
78+
);
7179
?>
7280
<!-- Text -->
7381
<h2><?php echo wp_kses( $text, $allowed_html ); ?></h2>

views/settings.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
defined( 'ABSPATH' ) || exit;
99

1010
$is_old_version = version_compare( $GLOBALS['wp_version'], '5.8', '<' );
11+
if ( ! isset( $this->plugin_settings['design']['page_id'] ) ) {
12+
$this->plugin_settings['design']['page_id'] = 0;
13+
}
1114
?>
1215
<div class="wrap">
1316
<h2 class="wpmm-title"><?php echo esc_html( get_admin_page_title() ); ?>
@@ -203,7 +206,7 @@
203206
$exclude_list = ! empty( $this->plugin_settings['general']['exclude'] ) && is_array( $this->plugin_settings['general']['exclude'] ) ? $this->plugin_settings['general']['exclude'] : array();
204207
?>
205208
<textarea rows="7" name="options[general][exclude]" style="width: 625px;"><?php echo esc_textarea( implode( "\n", $exclude_list ) ); ?></textarea>
206-
<p class="description"><?php esc_html_e( 'Exclude feed, pages, archives or IPs from maintenance mode. Add one slug / IP per line!', 'wp-maintenance-mode' ); ?></p>
209+
<p class="description"><?php esc_html_e( 'Exclude feed, pages, archives or IPs from maintenance mode. Add one slug / IP per line! Comments start with # and can be appended at the end of a line.', 'wp-maintenance-mode' ); ?></p>
207210
</td>
208211
</tr>
209212
<tr valign="top">

0 commit comments

Comments
 (0)