| 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 |
$this->step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : key( $default_steps ); |
| 74 |
|
| 75 |
include_once 'setup-wizard/view-page-setup-wizard.php'; |
| 76 |
|
| 77 |
exit; |
| 78 |
} |
| 79 |
|
| 80 |
public function save_data() { |
| 81 |
if( empty( $_POST['wppb_setup_wizard_nonce'] ) ) |
| 82 |
return; |
| 83 |
|
| 84 |
check_admin_referer( 'wppb-setup-wizard-nonce', 'wppb_setup_wizard_nonce' ); |
| 85 |
|
| 86 |
$default_steps = $this->get_default_steps(); |
| 87 |
|
| 88 |
reset( $default_steps ); |
| 89 |
|
| 90 |
$this->steps = apply_filters( 'wppb_setup_wizard_steps', $default_steps ); |
| 91 |
$this->step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : key( $default_steps ); |
| 92 |
|
| 93 |
// save data |
| 94 |
if( $this->step === 'user-pages' ) { |
| 95 |
|
| 96 |
if( !empty( $_POST['wppb_user_pages'] ) ) { |
| 97 |
|
| 98 |
$pages = array( |
| 99 |
'register' => array( |
| 100 |
'title' => 'Register', |
| 101 |
'option' => 'register_page', |
| 102 |
'content' => '[wppb-register]', |
| 103 |
), |
| 104 |
'login' => array( |
| 105 |
'title' => 'Login', |
| 106 |
'option' => 'login_page', |
| 107 |
'content' => '[wppb-login]', |
| 108 |
), |
| 109 |
'edit_profile' => array( |
| 110 |
'title' => 'Edit Profile', |
| 111 |
'option' => 'edit_profile_page', |
| 112 |
'content' => '[wppb-edit-profile]', |
| 113 |
), |
| 114 |
'reset_password' => array( |
| 115 |
'title' => 'Password Reset', |
| 116 |
'option' => 'lost_password_page', |
| 117 |
'content' => '[wppb-recover-password]', |
| 118 |
), |
| 119 |
); |
| 120 |
|
| 121 |
|
| 122 |
foreach( $_POST['wppb_user_pages'] as $page_slug => $value ) { /* phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized */ |
| 123 |
if( $value == 1 ){ |
| 124 |
$this->create_page( $pages[$page_slug]['option'], $pages[$page_slug]['title'], $pages[$page_slug]['content'] ); |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
update_option( 'wppb_user_pages', $this->user_pages ); |
| 129 |
|
| 130 |
} |
| 131 |
|
| 132 |
} elseif( $this->step === 'general' ) { |
| 133 |
|
| 134 |
$general_settings = get_option( 'wppb_general_settings', array() ); |
| 135 |
|
| 136 |
// Form Design |
| 137 |
if ( isset( $_POST['wppb_general_settings'] ) && !empty( $_POST['wppb_general_settings']['formsDesign'] ) ) |
| 138 |
$general_settings['formsDesign'] = sanitize_text_field( $_POST['wppb_general_settings']['formsDesign'] ); |
| 139 |
else $general_settings['formsDesign'] = 'default'; |
| 140 |
|
| 141 |
// Automatically Log-in |
| 142 |
if( isset( $_POST['automaticallyLogIn'] ) ) |
| 143 |
$general_settings['automaticallyLogIn'] = sanitize_text_field( $_POST['automaticallyLogIn'] ); |
| 144 |
else |
| 145 |
unset( $general_settings['automaticallyLogIn'] ); |
| 146 |
|
| 147 |
// Hide Admin Bar For Subscriber Role |
| 148 |
if( isset( $_POST['hide_admin_bar_for_subscriber'] ) ) { |
| 149 |
|
| 150 |
if ( empty( $general_settings['hide_admin_bar_for'] ) && !is_array( $general_settings['hide_admin_bar_for'] ) ) { |
| 151 |
$general_settings['hide_admin_bar_for'] = array(); |
| 152 |
} |
| 153 |
|
| 154 |
if ( empty( $general_settings['hide_admin_bar_for'] ) || !in_array( 'Subscriber', $general_settings['hide_admin_bar_for'] ) ) |
| 155 |
$general_settings['hide_admin_bar_for'][] = 'Subscriber'; |
| 156 |
|
| 157 |
} elseif ( !empty( $general_settings['hide_admin_bar_for'] ) && in_array( 'Subscriber', $general_settings['hide_admin_bar_for'] ) ) { |
| 158 |
|
| 159 |
$subscriber_key = array_search('Subscriber', $general_settings['hide_admin_bar_for']); |
| 160 |
unset( $general_settings['hide_admin_bar_for'][$subscriber_key] ); |
| 161 |
|
| 162 |
} |
| 163 |
|
| 164 |
// Email Confirmation After Registration |
| 165 |
if( isset( $_POST['emailConfirmation'] ) ) |
| 166 |
$general_settings['emailConfirmation'] = sanitize_text_field( $_POST['emailConfirmation'] ); |
| 167 |
else |
| 168 |
unset( $general_settings['emailConfirmation'] ); |
| 169 |
|
| 170 |
// Admin Approval |
| 171 |
if( isset( $_POST['adminApproval'] ) ) |
| 172 |
$general_settings['adminApproval'] = sanitize_text_field( $_POST['adminApproval'] ); |
| 173 |
else |
| 174 |
unset( $general_settings['adminApproval'] ); |
| 175 |
|
| 176 |
if( !empty( $general_settings ) ) |
| 177 |
update_option( 'wppb_general_settings', $general_settings ); |
| 178 |
|
| 179 |
} elseif( $this->step === 'addons' ) { |
| 180 |
$pro_addons = get_option( 'wppb_module_settings', 'not_found' ); |
| 181 |
|
| 182 |
// User Listing Addon |
| 183 |
if( isset( $_POST['wppb_userListing'] ) ) |
| 184 |
$pro_addons['wppb_userListing'] = 'show'; |
| 185 |
else $pro_addons['wppb_userListing'] = 'hide'; |
| 186 |
|
| 187 |
// Custom Redirects Addon |
| 188 |
if( isset( $_POST['wppb_customRedirect'] ) ) |
| 189 |
$pro_addons['wppb_customRedirect'] = 'show'; |
| 190 |
else $pro_addons['wppb_customRedirect'] = 'hide'; |
| 191 |
|
| 192 |
update_option( 'wppb_module_settings', $pro_addons ); |
| 193 |
|
| 194 |
|
| 195 |
$basic_addons = get_option( 'wppb_advanced_add_ons_settings', array() ); |
| 196 |
|
| 197 |
// Multi Step Form Addon |
| 198 |
if( isset( $_POST['multi-step-forms'] ) ) |
| 199 |
$basic_addons['multi-step-forms'] = true; |
| 200 |
else $basic_addons['multi-step-forms'] = false; |
| 201 |
|
| 202 |
// Social Connect Addon |
| 203 |
if( isset( $_POST['social-connect'] ) ) |
| 204 |
$basic_addons['social-connect'] = true; |
| 205 |
else $basic_addons['social-connect'] = false; |
| 206 |
|
| 207 |
update_option( 'wppb_advanced_add_ons_settings', $basic_addons ); |
| 208 |
|
| 209 |
} |
| 210 |
|
| 211 |
// step completion for setup |
| 212 |
$steps_completion = $this->get_completed_progress_steps(); |
| 213 |
|
| 214 |
if( !empty( $this->step ) ){ |
| 215 |
if( empty( $steps_completion ) ){ |
| 216 |
|
| 217 |
$steps_completion = array( |
| 218 |
$this->step => 1, |
| 219 |
); |
| 220 |
|
| 221 |
} else { |
| 222 |
|
| 223 |
$steps_completion[$this->step] = 1; |
| 224 |
|
| 225 |
} |
| 226 |
} |
| 227 |
|
| 228 |
update_option( 'wppb_setup_wizard_steps', $steps_completion ); |
| 229 |
|
| 230 |
// redirect to the next step at the end |
| 231 |
wp_safe_redirect( esc_url_raw( $this->get_next_step_link() ) ); |
| 232 |
exit; |
| 233 |
} |
| 234 |
|
| 235 |
public static function get_completed_progress_steps() { |
| 236 |
return get_option( 'wppb_setup_wizard_steps', false ); |
| 237 |
} |
| 238 |
|
| 239 |
private function get_next_step_link( $step = '' ) { |
| 240 |
if( !$step ) |
| 241 |
$step = $this->step; |
| 242 |
|
| 243 |
$keys = array_keys( $this->steps ); |
| 244 |
|
| 245 |
if( end( $keys ) === $step ) |
| 246 |
return admin_url(); |
| 247 |
|
| 248 |
$step_index = array_search( $step, $keys, true ); |
| 249 |
|
| 250 |
if( $step_index === false ) |
| 251 |
return ''; |
| 252 |
|
| 253 |
return add_query_arg( 'step', $keys[$step_index + 1] ); |
| 254 |
} |
| 255 |
|
| 256 |
private function create_page( $option, $title, $content = '' ) { |
| 257 |
if( empty( $this->user_pages ) ) |
| 258 |
$this->user_pages = get_option( 'wppb_user_pages', array() ); |
| 259 |
|
| 260 |
//try to find an existing page with the shortcode |
| 261 |
if( empty( $this->user_pages[$option] ) || $this->user_pages[$option] == '-1' ) { |
| 262 |
|
| 263 |
if( !empty( $content ) ){ |
| 264 |
global $wpdb; |
| 265 |
|
| 266 |
$shortcode = str_replace( array( '<!-- wp:shortcode -->', '<!-- /wp:shortcode -->' ), '', $content ); |
| 267 |
$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 . '%' ) ); |
| 268 |
|
| 269 |
if( !empty( $existing_page ) ) { |
| 270 |
$this->user_pages[$option] = $existing_page; |
| 271 |
|
| 272 |
return $existing_page; |
| 273 |
} |
| 274 |
} |
| 275 |
|
| 276 |
$page = array( |
| 277 |
'post_type' => 'page', |
| 278 |
'post_status' => 'publish', |
| 279 |
'post_title' => $title, |
| 280 |
'post_content' => $content |
| 281 |
); |
| 282 |
|
| 283 |
$page_id = wp_insert_post( $page ); |
| 284 |
$this->general_settings[$option] = $page_id; |
| 285 |
} |
| 286 |
} |
| 287 |
|
| 288 |
public function set_existing_user_pages() { |
| 289 |
if( empty( $_GET['subpage'] ) || $_GET['subpage'] != 'wppb-setup' ) |
| 290 |
return; |
| 291 |
|
| 292 |
$user_pages = get_option( 'wppb_user_pages', array() ); |
| 293 |
|
| 294 |
$pages = array( |
| 295 |
'register' => array( |
| 296 |
'title' => 'Register', |
| 297 |
'option' => 'register_page', |
| 298 |
'content' => '[wppb-register]', |
| 299 |
), |
| 300 |
'login' => array( |
| 301 |
'title' => 'Login', |
| 302 |
'option' => 'login_page', |
| 303 |
'content' => '[wppb-login]', |
| 304 |
), |
| 305 |
'edit_profile' => array( |
| 306 |
'title' => 'Edit Profile', |
| 307 |
'option' => 'edit_profile_page', |
| 308 |
'content' => '[wppb-edit-profile]', |
| 309 |
), |
| 310 |
'reset_password' => array( |
| 311 |
'title' => 'Password Reset', |
| 312 |
'option' => 'lost_password_page', |
| 313 |
'content' => '[wppb-recover-password]', |
| 314 |
), |
| 315 |
); |
| 316 |
|
| 317 |
global $wpdb; |
| 318 |
foreach ( $pages as $page ) { |
| 319 |
if( empty( $user_pages[$page['option']] ) && !empty( $page['content'] ) ){ |
| 320 |
$shortcode = str_replace( array( '<!-- wp:shortcode -->', '<!-- /wp:shortcode -->' ), '', $page['content'] ); |
| 321 |
$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 . '%' ) ); |
| 322 |
|
| 323 |
if( !empty( $existing_page ) ) { |
| 324 |
$user_pages[$page['option']] = $existing_page; |
| 325 |
} |
| 326 |
} |
| 327 |
} |
| 328 |
|
| 329 |
if ( !empty( $user_pages ) ) |
| 330 |
update_option( 'wppb_user_pages', $user_pages ); |
| 331 |
} |
| 332 |
|
| 333 |
public static function get_progress_steps() { |
| 334 |
$progress_steps = array( |
| 335 |
'user-pages' => array( |
| 336 |
'label' => __( 'Create user pages for registration, login, edit profile and password reset.', 'profile-builder' ), |
| 337 |
'url' => admin_url( 'admin.php?page=profile-builder-dashboard&subpage=wppb-setup' ), |
| 338 |
), |
| 339 |
'general' => array( |
| 340 |
'label' => __( 'Choose a design and optimize the login and registration flow for your users.', 'profile-builder' ), |
| 341 |
'url' => admin_url( 'admin.php?page=profile-builder-dashboard&subpage=wppb-setup&step=general' ), |
| 342 |
), |
| 343 |
'addons' => array( |
| 344 |
'label' => __( 'Learn about and enable addons for extra functionality.', 'profile-builder' ), |
| 345 |
'url' => admin_url( 'admin.php?page=profile-builder-dashboard&subpage=wppb-setup&step=addons' ), |
| 346 |
), |
| 347 |
'extra_form_field' => array( |
| 348 |
'label' => __( 'Add extra fields to the registration and edit profile forms.', 'profile-builder' ), |
| 349 |
'url' => admin_url( 'admin.php?page=manage-fields#manage-fields' ), |
| 350 |
), |
| 351 |
'restrict_content' => array( |
| 352 |
'label' => __( 'Restrict your content based on the user role.', 'profile-builder' ), |
| 353 |
'url' => admin_url( 'admin.php?page=profile-builder-content_restriction' ), |
| 354 |
), |
| 355 |
'extra_user_roles' => array( |
| 356 |
'label' => __( 'Create new user roles with the Role Editor.', 'profile-builder' ), |
| 357 |
'url' => 'edit.php?post_type=wppb-roles-editor', |
| 358 |
), |
| 359 |
); |
| 360 |
|
| 361 |
return $progress_steps; |
| 362 |
} |
| 363 |
|
| 364 |
public static function output_progress_steps() { |
| 365 |
$steps = self::get_progress_steps(); |
| 366 |
$steps_completion = self::get_completed_progress_steps(); |
| 367 |
|
| 368 |
// User Pages and General Settings Completion |
| 369 |
if( !isset( $steps_completion['user-pages'] ) && self::website_has_plugin_pages() ){ |
| 370 |
$steps_completion['user-pages'] = 1; |
| 371 |
$steps_completion['general'] = 1; |
| 372 |
} |
| 373 |
|
| 374 |
// Addons Completion |
| 375 |
if( !isset( $steps_completion['addons'] ) && self::website_has_active_addons() ) |
| 376 |
$steps_completion['addons'] = 1; |
| 377 |
|
| 378 |
// Extra Form Field Completion |
| 379 |
if( !isset( $steps_completion['extra_form_field'] ) && self::website_edited_form_fields() ) |
| 380 |
$steps_completion['extra_form_field'] = 1; |
| 381 |
|
| 382 |
// Restrict Content Completion |
| 383 |
if( !isset( $steps_completion['restrict_content'] ) && self::website_has_restricted_content() ) |
| 384 |
$steps_completion['restrict_content'] = 1; |
| 385 |
|
| 386 |
// User Roles Completion |
| 387 |
if( !isset( $steps_completion['extra_user_roles'] ) && self::website_has_extra_user_roles() ) |
| 388 |
$steps_completion['extra_user_roles'] = 1; |
| 389 |
|
| 390 |
update_option( 'wppb_setup_wizard_steps', $steps_completion ); |
| 391 |
|
| 392 |
$current_step = is_array( $steps_completion ) ? count( $steps_completion ) : 0; |
| 393 |
$total_steps = count( $steps ); |
| 394 |
|
| 395 |
ob_start(); ?> |
| 396 |
|
| 397 |
<div class="wppb-setup-progress"> |
| 398 |
<h3><?php esc_html_e( 'Progress Review', 'profile-builder' ); ?></h3> |
| 399 |
<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> |
| 400 |
|
| 401 |
<div class="wppb-setup-progress__bar"> |
| 402 |
<?php foreach( $steps as $slug => $step ) : ?> |
| 403 |
<div class="item <?php echo isset( $steps_completion[$slug] ) && $steps_completion[$slug] == 1 ? 'completed' : ''; ?>"></div> |
| 404 |
<?php endforeach; ?> |
| 405 |
</div> |
| 406 |
|
| 407 |
<div class="wppb-setup-progress__steps"> |
| 408 |
<?php foreach( $steps as $slug => $step ) : ?> |
| 409 |
<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'] ) : '' ?>"> |
| 410 |
<?php echo esc_html( $step['label'] ); ?> |
| 411 |
</a> |
| 412 |
<?php endforeach; ?> |
| 413 |
</div> |
| 414 |
</div> |
| 415 |
|
| 416 |
<?php |
| 417 |
$output = ob_get_clean(); |
| 418 |
|
| 419 |
echo $output; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 420 |
} |
| 421 |
|
| 422 |
public static function website_has_plugin_pages() { |
| 423 |
global $wpdb; |
| 424 |
|
| 425 |
$shortcodes = array( '[wppb-register]', '[wppb-login]', '[wppb-edit-profile]', '[wppb-recover-password]' ); |
| 426 |
|
| 427 |
foreach ( $shortcodes as $shortcode ) { |
| 428 |
$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 . '%' ) ); |
| 429 |
|
| 430 |
if( !empty( $existing_page ) ) |
| 431 |
return true; |
| 432 |
} |
| 433 |
|
| 434 |
return false; |
| 435 |
} |
| 436 |
|
| 437 |
public static function website_has_active_addons() { |
| 438 |
$free_addons = get_option( 'wppb_free_add_ons_settings', array() ); |
| 439 |
$pro_addons = get_option( 'wppb_module_settings', 'not_found' ); |
| 440 |
$basic_addons = get_option( 'wppb_advanced_add_ons_settings', array() ); |
| 441 |
|
| 442 |
$all_addons = array_merge( $free_addons, $pro_addons, $basic_addons ); |
| 443 |
|
| 444 |
foreach ( $all_addons as $addon => $value ) { |
| 445 |
if( $value === true || $value === 'show' ) |
| 446 |
return true; |
| 447 |
} |
| 448 |
|
| 449 |
return false; |
| 450 |
} |
| 451 |
|
| 452 |
public static function website_edited_form_fields() { |
| 453 |
$default_fields = array( |
| 454 |
'Default - Name (Heading)', |
| 455 |
'Default - Contact Info (Heading)', |
| 456 |
'Default - About Yourself (Heading)', |
| 457 |
'Default - Username', |
| 458 |
'Default - First Name', |
| 459 |
'Default - Last Name', |
| 460 |
'Default - Nickname', |
| 461 |
'Default - E-mail', |
| 462 |
'Default - Website', |
| 463 |
'Default - Password', |
| 464 |
'Default - Repeat Password', |
| 465 |
'Default - Biographical Info', |
| 466 |
'Default - Display name publicly as', |
| 467 |
); |
| 468 |
|
| 469 |
$wppb_manage_fields = get_option ( 'wppb_manage_fields', 'not_set' ); |
| 470 |
|
| 471 |
|
| 472 |
if ( empty( $wppb_manage_fields ) || count( $default_fields ) !== count( $wppb_manage_fields ) ) |
| 473 |
return true; |
| 474 |
|
| 475 |
foreach ( $wppb_manage_fields as $field ) { |
| 476 |
if ( !in_array( $field['field'], $default_fields ) ) |
| 477 |
return true; |
| 478 |
} |
| 479 |
|
| 480 |
return false; |
| 481 |
} |
| 482 |
|
| 483 |
public static function website_has_restricted_content() { |
| 484 |
$args = [ |
| 485 |
'posts_per_page' => '1', |
| 486 |
'post_type' => array( 'post', 'page' ), |
| 487 |
'meta_query' => [ |
| 488 |
[ |
| 489 |
'key' => 'wppb-content-restrict-user-role', |
| 490 |
'compare' => 'EXISTS' |
| 491 |
] |
| 492 |
], |
| 493 |
]; |
| 494 |
|
| 495 |
$result = new WP_Query( $args ); |
| 496 |
|
| 497 |
if( $result->have_posts() ) |
| 498 |
return true; |
| 499 |
|
| 500 |
// Logged in meta |
| 501 |
$args = [ |
| 502 |
'posts_per_page' => '1', |
| 503 |
'post_type' => array( 'post', 'page' ), |
| 504 |
'meta_query' => [ |
| 505 |
[ |
| 506 |
'key' => 'wppb-content-restrict-user-status', |
| 507 |
'compare' => 'EXISTS' |
| 508 |
] |
| 509 |
], |
| 510 |
]; |
| 511 |
|
| 512 |
$result = new WP_Query( $args ); |
| 513 |
|
| 514 |
if( $result->have_posts() ) |
| 515 |
return true; |
| 516 |
|
| 517 |
return false; |
| 518 |
} |
| 519 |
|
| 520 |
public static function website_has_extra_user_roles() { |
| 521 |
global $wp_roles; |
| 522 |
|
| 523 |
$user_roles = $wp_roles->roles; |
| 524 |
$default_roles = array( 'administrator', 'editor', 'author', 'contributor', 'subscriber' ); |
| 525 |
|
| 526 |
foreach ( $user_roles as $slug => $details ) { |
| 527 |
if ( !in_array( $slug, $default_roles ) ) |
| 528 |
return true; |
| 529 |
} |
| 530 |
|
| 531 |
return false; |
| 532 |
} |
| 533 |
|
| 534 |
|
| 535 |
public function dismiss_setup_wizard_newsletter_subscribe() { |
| 536 |
$user_id = get_current_user_id(); |
| 537 |
|
| 538 |
if( !empty( $user_id ) ) |
| 539 |
update_user_meta( $user_id, 'wppb_setup_wizard_newsletter', 1 ); |
| 540 |
|
| 541 |
wp_die(); |
| 542 |
} |
| 543 |
|
| 544 |
} |
| 545 |
|
| 546 |
new WPPB_Setup_Wizard(); |
| 547 |
|