PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 4.0.2
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v4.0.2
4.0.2 4.0.1 4.0.0 3.16.6 3.16.5 3.16.4 3.16.3 3.16.2 3.16.1 3.16.0 3.15.9 3.9.9 3.9.5 3.9.6 3.9.7 3.9.8 1.1.7 1.1.8 1.1.9 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 All 340 releases
profile-builder / admin / setup-wizard.php

setup-wizard.php in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 4.0.2, at admin/setup-wizard.php

693 lines 27.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) exit;
4
5 class WPPB_Setup_Wizard {
6 private $step = '';
7 private $steps = array();
8 public $general_settings = array();
9 public $user_pages = array();
10 public $content_restriction_settings = array();
11
12 public function __construct() {
13 if( apply_filters( 'wppb_run_setup_wizard', true ) && current_user_can( 'manage_options' ) ){
14 add_action( 'admin_menu', array( $this, 'add_page' ) );
15 add_action( 'admin_head', array( $this, 'hide_page_from_dashboard' ) );
16 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts_and_styles' ) );
17 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_wizard_forms_pointer' ) );
18 add_filter( 'wppb_output_dashboard_setup_wizard', array( $this, 'setup_wizard' ) );
19 add_action( 'admin_init', array( $this, 'redirect_to_setup' ) );
20 add_action( 'admin_init', array( $this, 'save_data' ) );
21 //add_action( 'admin_init', array( $this, 'set_existing_user_pages' ) );
22 add_action( 'wp_ajax_dismiss_setup_wizard_newsletter_subscribe', array( $this, 'dismiss_setup_wizard_newsletter_subscribe' ) );
23 }
24 }
25
26 public function add_page() {
27 add_dashboard_page( '', '', 'manage_options', 'wppb-setup', '' );
28 }
29
30 public function hide_page_from_dashboard() {
31 remove_submenu_page( 'index.php', 'wppb-setup' );
32 }
33
34 public function enqueue_scripts_and_styles() {
35 if( isset( $_GET['subpage'] ) && $_GET['subpage'] == 'wppb-setup' ) {
36 wp_enqueue_style( 'wppb-setup-wizard', WPPB_PLUGIN_URL . 'assets/css/style-setup-wizard.css', array(), PROFILE_BUILDER_VERSION );
37 wp_enqueue_script( 'wppb-wizard-js', WPPB_PLUGIN_URL . 'assets/js/setup-wizard.js', array( 'jquery', 'jquery-ui-core', 'jquery-ui-dialog' ), PROFILE_BUILDER_VERSION );
38 }
39 }
40
41 /**
42 * Native WP pointer on the Registration Forms list after the setup wizard.
43 *
44 * @param string $hook Current admin page hook.
45 */
46 public function enqueue_wizard_forms_pointer( $hook ) {
47 if ( $hook !== 'edit.php' ) {
48 return;
49 }
50
51 if ( empty( $_GET['post_type'] ) || sanitize_text_field( $_GET['post_type'] ) !== 'wppb-rf-cpt' ) {
52 return;
53 }
54
55 if ( empty( $_GET['wppb_wizard_hint'] ) || sanitize_text_field( $_GET['wppb_wizard_hint'] ) !== '1' ) {
56 return;
57 }
58
59 $pointer_id = 'wppb_setup_customize_form';
60 $dismissed = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
61
62 if ( in_array( $pointer_id, $dismissed, true ) ) {
63 return;
64 }
65
66 $defaults = get_option( 'wppb_default_form_ids', array() );
67 $form_id = ( is_array( $defaults ) && ! empty( $defaults['register'] ) ) ? absint( $defaults['register'] ) : 0;
68 $target = $form_id ? '#post-' . $form_id . ' .row-title' : '#the-list .row-title:first';
69
70 wp_enqueue_style( 'wp-pointer' );
71 wp_enqueue_script(
72 'wppb-setup-wizard-pointer',
73 WPPB_PLUGIN_URL . 'assets/js/setup-wizard-pointer.js',
74 array( 'jquery', 'wp-pointer' ),
75 PROFILE_BUILDER_VERSION,
76 true
77 );
78 wp_localize_script(
79 'wppb-setup-wizard-pointer',
80 'wppbSetupWizardPointer',
81 array(
82 'pointerId' => $pointer_id,
83 'target' => $target,
84 'content' => '<h3>' . esc_html__( 'Customize your registration form', 'profile-builder' ) . '</h3><p>' . esc_html__( 'Your registration form is ready. Click the form name to open the Form Builder and customize it.', 'profile-builder' ) . '</p>',
85 )
86 );
87 }
88
89 /**
90 * Registration Forms list, with a query flag that opens the post-wizard pointer.
91 *
92 * @return string
93 */
94 public static function get_setup_complete_url() {
95 return add_query_arg(
96 'wppb_wizard_hint',
97 '1',
98 admin_url( 'edit.php?post_type=wppb-rf-cpt' )
99 );
100 }
101
102 public function get_default_steps(){
103 $steps = array(
104 'user-pages' => __( 'User Pages', 'profile-builder' ),
105 'general' => __( 'User Flow', 'profile-builder' ),
106 );
107
108 if ( defined( 'WPPB_PAID_PLUGIN_DIR' ) ) {
109 $steps['addons'] = __( 'Add-Ons', 'profile-builder' );
110 }
111
112 $steps['next'] = __( 'Ready!', 'profile-builder' );
113
114 return $steps;
115 }
116
117 public function redirect_to_setup(){
118 $run_setup = get_transient( 'wppb_run_setup_wizard' );
119
120 if( $run_setup == true ){
121 delete_transient( 'wppb_run_setup_wizard' );
122 wp_safe_redirect( admin_url( 'admin.php?page=profile-builder-dashboard&subpage=wppb-setup' ) );
123 die();
124 }
125 }
126
127 public function setup_wizard() {
128 if( empty( $_GET['page'] ) || $_GET['page'] != 'profile-builder-dashboard' )
129 return;
130
131 if( empty( $_GET['subpage'] ) || $_GET['subpage'] != 'wppb-setup' )
132 return;
133
134 $this->general_settings = get_option( 'wppb_general_settings', array() );
135 $this->user_pages = get_option( 'wppb_user_pages', array() );
136 $this->content_restriction_settings = get_option( 'wppb_content_restriction_settings', array() );
137
138 $default_steps = $this->get_default_steps();
139
140 reset( $default_steps );
141
142 $this->steps = apply_filters( 'wppb_setup_wizard_steps', $default_steps );
143
144 $step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : key( $default_steps );
145 $valid_steps = array_keys( $this->steps );
146
147 if ( !in_array( $step, $valid_steps ) ) {
148 $step = 'user-pages'; // default
149 }
150
151 $this->step = $step;
152
153 include_once 'setup-wizard/view-page-setup-wizard.php';
154
155 exit;
156 }
157
158 public function save_data() {
159 if( empty( $_POST['wppb_setup_wizard_nonce'] ) )
160 return;
161
162 check_admin_referer( 'wppb-setup-wizard-nonce', 'wppb_setup_wizard_nonce' );
163
164 if( !current_user_can( 'manage_options' ) )
165 return;
166
167 $default_steps = $this->get_default_steps();
168
169 reset( $default_steps );
170
171 $this->steps = apply_filters( 'wppb_setup_wizard_steps', $default_steps );
172 $this->step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : key( $default_steps );
173
174 // save data
175 if( $this->step === 'user-pages' ) {
176
177 if( !empty( $_POST['wppb_user_pages'] ) ) {
178
179 $pages = array(
180 'register' => array(
181 'title' => 'Register',
182 'option' => 'register_page',
183 'content' => '[wppb-register]',
184 'block_content' => '<!-- wp:wppb/register /-->',
185 ),
186 'login' => array(
187 'title' => 'Login',
188 'option' => 'login_page',
189 'content' => '[wppb-login]',
190 'block_content' => '<!-- wp:wppb/login /-->',
191 ),
192 'edit_profile' => array(
193 'title' => 'Edit Profile',
194 'option' => 'edit_profile_page',
195 'content' => '[wppb-edit-profile]',
196 'block_content' => '<!-- wp:wppb/edit-profile /-->',
197 ),
198 'reset_password' => array(
199 'title' => 'Password Reset',
200 'option' => 'lost_password_page',
201 'content' => '[wppb-recover-password]',
202 'block_content' => '<!-- wp:wppb/recover-password /-->',
203 ),
204 );
205
206
207 foreach( $_POST['wppb_user_pages'] as $page_slug => $value ) { /* phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized */
208 if( $value == 1 ){
209 $this->create_page( $pages[$page_slug]['option'], $pages[$page_slug]['title'], $pages[$page_slug]['content'], $pages[$page_slug]['block_content'] );
210 }
211 }
212
213 update_option( 'wppb_user_pages', $this->user_pages );
214
215 }
216
217 } elseif( $this->step === 'general' ) {
218
219 $general_settings = get_option( 'wppb_general_settings', array() );
220
221 // Form Design
222 if ( isset( $_POST['wppb_general_settings'] ) && !empty( $_POST['wppb_general_settings']['formsDesign'] ) )
223 $general_settings['formsDesign'] = sanitize_text_field( $_POST['wppb_general_settings']['formsDesign'] );
224 else $general_settings['formsDesign'] = 'form-style-default';
225
226 // Automatically Log-in
227 if( isset( $_POST['automaticallyLogIn'] ) )
228 $general_settings['automaticallyLogIn'] = sanitize_text_field( $_POST['automaticallyLogIn'] );
229 else
230 unset( $general_settings['automaticallyLogIn'] );
231
232 // Hide Admin Bar For Subscriber Role
233 if( isset( $_POST['hide_admin_bar_for_subscriber'] ) ) {
234
235 if ( empty( $general_settings['hide_admin_bar_for'] ) && !is_array( $general_settings['hide_admin_bar_for'] ) ) {
236 $general_settings['hide_admin_bar_for'] = array();
237 }
238
239 if ( empty( $general_settings['hide_admin_bar_for'] ) || !in_array( 'Subscriber', $general_settings['hide_admin_bar_for'] ) )
240 $general_settings['hide_admin_bar_for'][] = 'Subscriber';
241
242 } elseif ( !empty( $general_settings['hide_admin_bar_for'] ) && in_array( 'Subscriber', $general_settings['hide_admin_bar_for'] ) ) {
243
244 $subscriber_key = array_search('Subscriber', $general_settings['hide_admin_bar_for']);
245 unset( $general_settings['hide_admin_bar_for'][$subscriber_key] );
246
247 }
248
249 // Email Confirmation After Registration
250 if( isset( $_POST['emailConfirmation'] ) )
251 $general_settings['emailConfirmation'] = sanitize_text_field( $_POST['emailConfirmation'] );
252 else
253 unset( $general_settings['emailConfirmation'] );
254
255 // Admin Approval
256 if( isset( $_POST['adminApproval'] ) )
257 $general_settings['adminApproval'] = sanitize_text_field( $_POST['adminApproval'] );
258 else
259 unset( $general_settings['adminApproval'] );
260
261 // Roles Editor
262 if ( isset( $_POST['rolesEditor'] ) )
263 $general_settings['rolesEditor'] = 'yes';
264 else
265 unset( $general_settings['rolesEditor'] );
266
267 if( !empty( $general_settings ) )
268 update_option( 'wppb_general_settings', $general_settings );
269
270 // Content Restriction
271 $content_restriction_settings = get_option( 'wppb_content_restriction_settings', array() );
272 if ( ! is_array( $content_restriction_settings ) ) {
273 $content_restriction_settings = array();
274 }
275
276 if ( isset( $_POST['contentRestriction'] ) )
277 $content_restriction_settings['contentRestriction'] = 'yes';
278 else
279 $content_restriction_settings['contentRestriction'] = 'no';
280
281 update_option( 'wppb_content_restriction_settings', $content_restriction_settings );
282
283 } elseif( $this->step === 'addons' && defined( 'WPPB_PAID_PLUGIN_DIR' ) ) {
284 $pro_addons = get_option( 'wppb_module_settings', 'not_found' );
285
286 // User Listing Addon
287 if( isset( $_POST['wppb_userListing'] ) )
288 $pro_addons['wppb_userListing'] = 'show';
289 else $pro_addons['wppb_userListing'] = 'hide';
290
291 // Custom Redirects Addon
292 if( isset( $_POST['wppb_customRedirect'] ) )
293 $pro_addons['wppb_customRedirect'] = 'show';
294 else $pro_addons['wppb_customRedirect'] = 'hide';
295
296 update_option( 'wppb_module_settings', $pro_addons );
297
298
299 $basic_addons = get_option( 'wppb_advanced_add_ons_settings', array() );
300
301 // Multi Step Form Addon
302 if( isset( $_POST['multi-step-forms'] ) )
303 $basic_addons['multi-step-forms'] = true;
304 else $basic_addons['multi-step-forms'] = false;
305
306 // Social Connect Addon
307 if( isset( $_POST['social-connect'] ) )
308 $basic_addons['social-connect'] = true;
309 else $basic_addons['social-connect'] = false;
310
311 update_option( 'wppb_advanced_add_ons_settings', $basic_addons );
312
313 }
314
315 // step completion for setup
316 $steps_completion = $this->get_completed_progress_steps();
317
318 if( !empty( $this->step ) ){
319 if( empty( $steps_completion ) ){
320
321 $steps_completion = array(
322 $this->step => 1,
323 );
324
325 } else {
326
327 $steps_completion[$this->step] = 1;
328
329 }
330 }
331
332 update_option( 'wppb_setup_wizard_steps', $steps_completion, false );
333
334 // redirect to the next step at the end
335 wp_safe_redirect( esc_url_raw( $this->get_next_step_link() ) );
336 exit;
337 }
338
339 public static function get_completed_progress_steps() {
340 $steps = get_option( 'wppb_setup_wizard_steps', array() );
341
342 return is_array( $steps ) ? $steps : array();
343 }
344
345 private function get_next_step_link( $step = '' ) {
346 if( !$step )
347 $step = $this->step;
348
349 $keys = array_keys( $this->steps );
350
351 if( end( $keys ) === $step )
352 return $this->get_setup_complete_url();
353
354 $step_index = array_search( $step, $keys, true );
355
356 if( $step_index === false )
357 return '';
358
359 return add_query_arg( 'step', $keys[$step_index + 1] );
360 }
361
362 /**
363 * Check if Gutenberg block editor is available and active
364 *
365 * @return bool
366 */
367 private function is_gutenberg_available() {
368 // use_block_editor_for_post_type() checks if block editor is available (WP 5.0+),
369 // respects Classic Editor plugin settings, and any filters
370 return function_exists( 'use_block_editor_for_post_type' ) && use_block_editor_for_post_type( 'page' );
371 }
372
373 private function create_page( $option, $title, $content = '', $block_content = '' ) {
374 if( empty( $this->user_pages ) )
375 $this->user_pages = get_option( 'wppb_user_pages', array() );
376
377 //try to find an existing page with the shortcode or block
378 if( empty( $this->user_pages[$option] ) || $this->user_pages[$option] == '-1' ) {
379
380 if( !empty( $content ) ){
381 global $wpdb;
382
383 // Clean shortcode for searching (remove wp:shortcode wrapper if present)
384 $shortcode = str_replace( array( '<!-- wp:shortcode -->', '<!-- /wp:shortcode -->' ), '', $content );
385
386 // Search for existing page with shortcode
387 $existing_page = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", '%' . $shortcode . '%' ) );
388
389 // If no shortcode page found, and we have block content, search for block
390 if( empty( $existing_page ) && !empty( $block_content ) ) {
391 $existing_page = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", '%' . $wpdb->esc_like( $block_content ) . '%' ) );
392 }
393
394 if( !empty( $existing_page ) ) {
395 $this->user_pages[$option] = $existing_page;
396
397 return $existing_page;
398 }
399 }
400
401 // Determine which content to use: blocks if available, otherwise shortcodes
402 $page_content = $content;
403 if( $this->is_gutenberg_available() && !empty( $block_content ) ) {
404 $page_content = $block_content;
405 }
406
407 $page = array(
408 'post_type' => 'page',
409 'post_status' => 'publish',
410 'post_title' => $title,
411 'post_content' => $page_content
412 );
413
414 $page_id = wp_insert_post( $page );
415 $this->user_pages[$option] = $page_id;
416 }
417 }
418
419 public function set_existing_user_pages() {
420
421 if( !current_user_can( 'manage_options' ) )
422 return;
423
424 $user_pages = get_option( 'wppb_user_pages', array() );
425
426 $pages = array(
427 'register' => array(
428 'title' => 'Register',
429 'option' => 'register_page',
430 'content' => '[wppb-register]',
431 'block_content' => '<!-- wp:wppb/register /-->',
432 ),
433 'login' => array(
434 'title' => 'Login',
435 'option' => 'login_page',
436 'content' => '[wppb-login]',
437 'block_content' => '<!-- wp:wppb/login /-->',
438 ),
439 'edit_profile' => array(
440 'title' => 'Edit Profile',
441 'option' => 'edit_profile_page',
442 'content' => '[wppb-edit-profile]',
443 'block_content' => '<!-- wp:wppb/edit-profile /-->',
444 ),
445 'reset_password' => array(
446 'title' => 'Password Reset',
447 'option' => 'lost_password_page',
448 'content' => '[wppb-recover-password]',
449 'block_content' => '<!-- wp:wppb/recover-password /-->',
450 ),
451 );
452
453 global $wpdb;
454 foreach ( $pages as $page ) {
455 if( empty( $user_pages[$page['option']] ) && !empty( $page['content'] ) ){
456 // Search for shortcode-based pages
457 $shortcode = str_replace( array( '<!-- wp:shortcode -->', '<!-- /wp:shortcode -->' ), '', $page['content'] );
458 $existing_page = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", '%' . $shortcode . '%' ) );
459
460 // If no shortcode page found, search for block-based pages
461 if( empty( $existing_page ) && !empty( $page['block_content'] ) ) {
462 $existing_page = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", '%' . $wpdb->esc_like( $page['block_content'] ) . '%' ) );
463 }
464
465 if( !empty( $existing_page ) ) {
466 $user_pages[$page['option']] = $existing_page;
467 }
468 }
469 }
470
471 if ( !empty( $user_pages ) )
472 update_option( 'wppb_user_pages', $user_pages );
473
474 $this->user_pages = get_option( 'wppb_user_pages', array() );
475
476 }
477
478 public static function get_progress_steps() {
479
480 $wppb_generalSettings = get_option( 'wppb_general_settings', 'not_found' );
481 $roles_editor_enabled = ( $wppb_generalSettings !== 'not_found' && isset( $wppb_generalSettings['rolesEditor'] ) && !empty( $wppb_generalSettings['rolesEditor'] ) && $wppb_generalSettings['rolesEditor'] === 'yes' );
482
483 if ( $roles_editor_enabled ) {
484 $roles_editor_url = admin_url( 'edit.php?post_type=wppb-roles-editor' );
485 } else {
486 // URL with nonce for activating Roles Editor
487 $roles_editor_url = wp_nonce_url( admin_url( 'admin.php?action=wppb_enable_roles_editor' ), 'wppb_enable_roles_editor_nonce', 'wppb_nonce' );
488 }
489
490 $progress_steps = array(
491 'user-pages' => array(
492 'label' => __( 'Create user pages for registration, login, edit profile and password reset.', 'profile-builder' ),
493 'url' => admin_url( 'admin.php?page=profile-builder-dashboard&subpage=wppb-setup' ),
494 ),
495 'general' => array(
496 'label' => __( 'Optimize the login and registration flow for your users', 'profile-builder' ),
497 'url' => admin_url( 'admin.php?page=profile-builder-dashboard&subpage=wppb-setup&step=general' ),
498 ),
499 'extra_form_field' => array(
500 'label' => __( 'Add extra fields to the registration and edit profile forms.', 'profile-builder' ),
501 'url' => admin_url( 'edit.php?post_type=wppb-rf-cpt' ),
502 ),
503 'restrict_content' => array(
504 'label' => __( 'Restrict your content based on the user role.', 'profile-builder' ),
505 'url' => admin_url( 'admin.php?page=profile-builder-content_restriction' ),
506 ),
507 'extra_user_roles' => array(
508 'label' => __( 'Create new user roles with the Role Editor.', 'profile-builder' ),
509 'url' => $roles_editor_url,
510 ),
511 );
512
513 return $progress_steps;
514 }
515
516 public static function output_progress_steps() {
517 $steps = self::get_progress_steps();
518 $steps_completion = self::get_completed_progress_steps();
519
520 // User Pages and General Settings Completion
521 if( !isset( $steps_completion['user-pages'] ) && self::website_has_plugin_pages() ){
522 $steps_completion['user-pages'] = 1;
523 $steps_completion['general'] = 1;
524 }
525
526 // Extra Form Field Completion
527 if( !isset( $steps_completion['extra_form_field'] ) && self::website_edited_form_fields() )
528 $steps_completion['extra_form_field'] = 1;
529
530 // Restrict Content Completion
531 if( !isset( $steps_completion['restrict_content'] ) && self::website_has_restricted_content() )
532 $steps_completion['restrict_content'] = 1;
533
534 // User Roles Completion
535 if( !isset( $steps_completion['extra_user_roles'] ) && self::website_has_extra_user_roles() )
536 $steps_completion['extra_user_roles'] = 1;
537
538 update_option( 'wppb_setup_wizard_steps', $steps_completion, false );
539
540 $current_step = count( array_intersect_key( $steps_completion, $steps ) );
541 $total_steps = count( $steps );
542
543 ob_start(); ?>
544
545 <div class="wppb-setup-progress">
546 <h3><?php esc_html_e( 'Progress Review', 'profile-builder' ); ?></h3>
547 <p><?php printf( esc_html__( 'Follow these steps to start registering users on your website. %1s out of %2s complete.', 'profile-builder' ), esc_html( $current_step ), esc_html( $total_steps ) ); ?></p>
548
549 <div class="wppb-setup-progress__bar">
550 <?php foreach( $steps as $slug => $step ) : ?>
551 <div class="item <?php echo isset( $steps_completion[$slug] ) && $steps_completion[$slug] == 1 ? 'completed' : ''; ?>"></div>
552 <?php endforeach; ?>
553 </div>
554
555 <div class="wppb-setup-progress__steps">
556 <?php foreach( $steps as $slug => $step ) : ?>
557 <a class="wppb-setup-progress__step <?php echo isset( $steps_completion[$slug] ) && $steps_completion[$slug] == 1 ? 'completed' : ''; ?>" href="<?php echo esc_url( $step['url'] ) ?>" target="<?php echo isset( $step['target'] ) ? esc_html( $step['target'] ) : '' ?>">
558 <?php echo esc_html( $step['label'] ); ?>
559 </a>
560 <?php endforeach; ?>
561 </div>
562 </div>
563
564 <?php
565 $output = ob_get_clean();
566
567 echo $output; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
568 }
569
570 public static function website_has_plugin_pages() {
571 global $wpdb;
572
573 // Check for both shortcode and block-based pages
574 $search_patterns = array(
575 '[wppb-register]',
576 '[wppb-login]',
577 '[wppb-edit-profile]',
578 '[wppb-recover-password]',
579 '<!-- wp:wppb/register',
580 '<!-- wp:wppb/login',
581 '<!-- wp:wppb/edit-profile',
582 '<!-- wp:wppb/recover-password',
583 );
584
585 foreach ( $search_patterns as $pattern ) {
586 $existing_page = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", '%' . $wpdb->esc_like( $pattern ) . '%' ) );
587
588 if( !empty( $existing_page ) )
589 return true;
590 }
591
592 return false;
593 }
594
595 public static function website_edited_form_fields() {
596 $default_fields = array(
597 'Default - Name (Heading)',
598 'Default - Contact Info (Heading)',
599 'Default - About Yourself (Heading)',
600 'Default - Username',
601 'Default - First Name',
602 'Default - Last Name',
603 'Default - Nickname',
604 'Default - E-mail',
605 'Default - Website',
606 'Default - Password',
607 'Default - Repeat Password',
608 'Default - Biographical Info',
609 'Default - Display name publicly as',
610 );
611
612 $wppb_manage_fields = get_option ( 'wppb_manage_fields', 'not_set' );
613
614
615 if ( empty( $wppb_manage_fields ) || count( $default_fields ) !== count( $wppb_manage_fields ) )
616 return true;
617
618 foreach ( $wppb_manage_fields as $field ) {
619 if ( !in_array( $field['field'], $default_fields ) )
620 return true;
621 }
622
623 return false;
624 }
625
626 public static function website_has_restricted_content() {
627 $args = [
628 'posts_per_page' => '1',
629 'post_type' => array( 'post', 'page' ),
630 'meta_query' => [
631 [
632 'key' => 'wppb-content-restrict-user-role',
633 'compare' => 'EXISTS'
634 ]
635 ],
636 ];
637
638 $result = new WP_Query( $args );
639
640 if( $result->have_posts() )
641 return true;
642
643 // Logged in meta
644 $args = [
645 'posts_per_page' => '1',
646 'post_type' => array( 'post', 'page' ),
647 'meta_query' => [
648 [
649 'key' => 'wppb-content-restrict-user-status',
650 'compare' => 'EXISTS'
651 ]
652 ],
653 ];
654
655 $result = new WP_Query( $args );
656
657 if( $result->have_posts() )
658 return true;
659
660 return false;
661 }
662
663 public static function website_has_extra_user_roles() {
664 global $wp_roles;
665
666 $user_roles = $wp_roles->roles;
667 $default_roles = array( 'administrator', 'editor', 'author', 'contributor', 'subscriber' );
668
669 foreach ( $user_roles as $slug => $details ) {
670 if ( !in_array( $slug, $default_roles ) )
671 return true;
672 }
673
674 return false;
675 }
676
677 public function dismiss_setup_wizard_newsletter_subscribe() {
678
679 check_ajax_referer( 'dismiss_setup_wizard_newsletter_subscribe', 'wppb_nonce' );
680
681 $user_id = get_current_user_id();
682
683 if( !empty( $user_id ) )
684 update_user_meta( $user_id, 'wppb_setup_wizard_newsletter', 1 );
685
686 wp_die();
687
688 }
689
690 }
691
692 new WPPB_Setup_Wizard();
693