Skip to content

Commit

Permalink
release: fixes
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
selul authored Sep 27, 2022
2 parents dc41144 + c81d8c5 commit 2f07a64
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 27 deletions.
17 changes: 9 additions & 8 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 64 additions & 16 deletions includes/classes/wp-maintenance-mode.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ private function __construct() {
add_action( 'wp_ajax_wpmm_add_subscriber', array( $this, 'add_subscriber' ) );
add_action( 'wp_ajax_nopriv_wpmm_send_contact', array( $this, 'send_contact' ) );
add_action( 'wp_ajax_wpmm_send_contact', array( $this, 'send_contact' ) );
add_action( 'otter_form_after_submit', array( $this, 'otter_add_subscriber' ) );

if ( isset( $this->plugin_settings['design']['page_id'] ) && get_option( 'wpmm_new_look' ) && get_post_status( $this->plugin_settings['design']['page_id'] ) === 'private' ) {
wp_publish_post( $this->plugin_settings['design']['page_id'] );
Expand All @@ -78,7 +79,7 @@ private function __construct() {
add_filter(
'pre_option_page_on_front',
function ( $value ) {
if ( ! is_user_logged_in() && isset( $this->plugin_settings['design']['page_id'] ) && get_option( 'wpmm_new_look' ) ) {
if ( ( ! $this->check_user_role() && ! $this->check_exclude() ) && isset( $this->plugin_settings['design']['page_id'] ) && get_option( 'wpmm_new_look' ) ) {
$page_id = $this->plugin_settings['design']['page_id'];

if ( ! function_exists( 'is_plugin_active' ) ) {
Expand Down Expand Up @@ -650,7 +651,7 @@ public function init() {
! $this->check_search_bots() &&
! ( defined( 'WP_CLI' ) && WP_CLI )
) {
if ( get_option( 'wpmm_new_look' ) ) {
if ( isset( $this->plugin_settings['design']['page_id'] ) && get_option( 'wpmm_new_look' ) ) {
include_once wpmm_get_template_path( 'maintenance.php', true );
return;
}
Expand Down Expand Up @@ -861,6 +862,10 @@ public function check_exclude() {
$request_uri = isset( $_SERVER['REQUEST_URI'] ) ? rawurldecode( $_SERVER['REQUEST_URI'] ) : '';
$request_uri = wp_sanitize_redirect( $request_uri );
foreach ( $excluded_list as $item ) {
if ( false !== strpos( $item, '#' ) ) {
$item = trim( substr( $item, 0, strpos( $item, '#' ) ) );
}

if ( empty( $item ) ) { // just to be sure :-)
continue;
}
Expand Down Expand Up @@ -997,11 +1002,11 @@ public function use_maintenance_template( $template ) {
}

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

$file = WPMM_VIEWS_PATH . '/wpmm-page-template.php';
$file = WPMM_VIEWS_PATH . 'wpmm-page-template.php';
if ( file_exists( $file ) ) {
return $file;
}
Expand Down Expand Up @@ -1216,18 +1221,8 @@ public function add_subscriber() {
) {
throw new Exception( __( 'Security check.', 'wp-maintenance-mode' ) );
}
// save
$exists = $wpdb->get_row( $wpdb->prepare( "SELECT id_subscriber FROM {$wpdb->prefix}wpmm_subscribers WHERE email = %s", $email ), ARRAY_A );
if ( empty( $exists ) ) {
$wpdb->insert(
$wpdb->prefix . 'wpmm_subscribers',
array(
'email' => $email,
'insert_date' => date( 'Y-m-d H:i:s' ),
),
array( '%s', '%s' )
);
}
// save.
$this->insert_subscriber( $email );

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

/**
* Save subscriber into database.
*
* @param Form_Data_Request $form_data The form data.
* @return void
*/
public function otter_add_subscriber( $form_data ) {
if ( $form_data ) {
$input_data = $form_data->get_payload_field( 'formInputsData' );
$input_data = array_map(
function( $input_field ) {
if ( isset( $input_field['type'] ) && 'email' === $input_field['type'] ) {
return $input_field['value'];
}
return false;
},
$input_data
);
$input_data = array_filter( $input_data );
if ( ! empty( $input_data ) ) {
foreach ( $input_data as $email ) {
$this->insert_subscriber( $email );
}
}
}
}

/**
* Save subscriber into database.
*
* @param string $email Email address.
* @global object $wpdb
*
* @return void
*/
public function insert_subscriber( $email = '' ) {
global $wpdb;
if ( ! empty( $email ) ) {
// phpcs:ignore WordPress.DB.DirectDatabaseQuery
$exists = $wpdb->get_row( $wpdb->prepare( "SELECT id_subscriber FROM {$wpdb->prefix}wpmm_subscribers WHERE email = %s", $email ), ARRAY_A );
if ( empty( $exists ) ) {
// phpcs:ignore WordPress.DB.DirectDatabaseQuery
$wpdb->insert(
$wpdb->prefix . 'wpmm_subscribers',
array(
'email' => sanitize_email( $email ),
'insert_date' => date( 'Y-m-d H:i:s' ),
),
array( '%s', '%s' )
);
}
}
}
}

}
12 changes: 10 additions & 2 deletions views/maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,28 @@
if ( ! empty( $text ) ) {
$allowed_html = wp_kses_allowed_html( 'post' );

$allowed_html['form'] = array(
$allowed_html['form'] = array(
'id' => array(),
'class' => array(),
'action' => array(),
'method' => array(),
);
$allowed_html['input'] = array(
$allowed_html['input'] = array(
'type' => array(),
'id' => array(),
'name' => array(),
'value' => array(),
'class' => array(),
'placeholder' => array(),
);
$allowed_html['iframe'] = array(
'src' => array(),
'height' => array(),
'width' => array(),
'frameborder' => array(),
'allowfullscreen' => array(),
'data-*' => true,
);
?>
<!-- Text -->
<h2><?php echo wp_kses( $text, $allowed_html ); ?></h2>
Expand Down
5 changes: 4 additions & 1 deletion views/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
defined( 'ABSPATH' ) || exit;

$is_old_version = version_compare( $GLOBALS['wp_version'], '5.8', '<' );
if ( ! isset( $this->plugin_settings['design']['page_id'] ) ) {
$this->plugin_settings['design']['page_id'] = 0;
}
?>
<div class="wrap">
<h2 class="wpmm-title"><?php echo esc_html( get_admin_page_title() ); ?>
Expand Down Expand Up @@ -203,7 +206,7 @@
$exclude_list = ! empty( $this->plugin_settings['general']['exclude'] ) && is_array( $this->plugin_settings['general']['exclude'] ) ? $this->plugin_settings['general']['exclude'] : array();
?>
<textarea rows="7" name="options[general][exclude]" style="width: 625px;"><?php echo esc_textarea( implode( "\n", $exclude_list ) ); ?></textarea>
<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>
<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>
</td>
</tr>
<tr valign="top">
Expand Down

0 comments on commit 2f07a64

Please sign in to comment.