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