@@ -69,6 +69,7 @@ private function __construct() {
69
69
add_action ( 'wp_ajax_wpmm_add_subscriber ' , array ( $ this , 'add_subscriber ' ) );
70
70
add_action ( 'wp_ajax_nopriv_wpmm_send_contact ' , array ( $ this , 'send_contact ' ) );
71
71
add_action ( 'wp_ajax_wpmm_send_contact ' , array ( $ this , 'send_contact ' ) );
72
+ add_action ( 'otter_form_after_submit ' , array ( $ this , 'otter_add_subscriber ' ) );
72
73
73
74
if ( isset ( $ this ->plugin_settings ['design ' ]['page_id ' ] ) && get_option ( 'wpmm_new_look ' ) && get_post_status ( $ this ->plugin_settings ['design ' ]['page_id ' ] ) === 'private ' ) {
74
75
wp_publish_post ( $ this ->plugin_settings ['design ' ]['page_id ' ] );
@@ -78,7 +79,7 @@ private function __construct() {
78
79
add_filter (
79
80
'pre_option_page_on_front ' ,
80
81
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 ' ) ) {
82
83
$ page_id = $ this ->plugin_settings ['design ' ]['page_id ' ];
83
84
84
85
if ( ! function_exists ( 'is_plugin_active ' ) ) {
@@ -650,7 +651,7 @@ public function init() {
650
651
! $ this ->check_search_bots () &&
651
652
! ( defined ( 'WP_CLI ' ) && WP_CLI )
652
653
) {
653
- if ( get_option ( 'wpmm_new_look ' ) ) {
654
+ if ( isset ( $ this -> plugin_settings [ ' design ' ][ ' page_id ' ] ) && get_option ( 'wpmm_new_look ' ) ) {
654
655
include_once wpmm_get_template_path ( 'maintenance.php ' , true );
655
656
return ;
656
657
}
@@ -861,6 +862,10 @@ public function check_exclude() {
861
862
$ request_uri = isset ( $ _SERVER ['REQUEST_URI ' ] ) ? rawurldecode ( $ _SERVER ['REQUEST_URI ' ] ) : '' ;
862
863
$ request_uri = wp_sanitize_redirect ( $ request_uri );
863
864
foreach ( $ excluded_list as $ item ) {
865
+ if ( false !== strpos ( $ item , '# ' ) ) {
866
+ $ item = trim ( substr ( $ item , 0 , strpos ( $ item , '# ' ) ) );
867
+ }
868
+
864
869
if ( empty ( $ item ) ) { // just to be sure :-)
865
870
continue ;
866
871
}
@@ -997,11 +1002,11 @@ public function use_maintenance_template( $template ) {
997
1002
}
998
1003
999
1004
$ 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 ) {
1001
1006
return $ template ;
1002
1007
}
1003
1008
1004
- $ file = WPMM_VIEWS_PATH . '/ wpmm-page-template.php ' ;
1009
+ $ file = WPMM_VIEWS_PATH . 'wpmm-page-template.php ' ;
1005
1010
if ( file_exists ( $ file ) ) {
1006
1011
return $ file ;
1007
1012
}
@@ -1216,18 +1221,8 @@ public function add_subscriber() {
1216
1221
) {
1217
1222
throw new Exception ( __ ( 'Security check. ' , 'wp-maintenance-mode ' ) );
1218
1223
}
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 );
1231
1226
1232
1227
wp_send_json_success ( __ ( 'You successfully subscribed. Thanks! ' , 'wp-maintenance-mode ' ) );
1233
1228
} catch ( Exception $ ex ) {
@@ -1293,6 +1288,59 @@ public function send_contact() {
1293
1288
}
1294
1289
}
1295
1290
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
+ }
1296
1344
}
1297
1345
1298
1346
}
0 commit comments