| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
class UsersWP_Admin_Setup_Wizard { |
| 8 |
|
| 9 |
private $step = ''; |
| 10 |
|
| 11 |
private $steps = array(); |
| 12 |
|
| 13 |
public function __construct() { |
| 14 |
|
| 15 |
add_action( 'admin_init', array( $this, 'remove_deprecated_functions' ) ); |
| 16 |
add_action( 'admin_menu', array( $this, 'admin_menus' ) ); |
| 17 |
add_action( 'current_screen', array( $this, 'setup_wizard' ) ); |
| 18 |
add_action( 'uwp_wizard_content_general_settings', array( $this, 'content_general_settings' ) ); |
| 19 |
add_action( 'uwp_wizard_content_use_userswp', array( $this, 'content_use_userswp' ) ); |
| 20 |
add_action( 'uwp_wizard_content_menus', array( $this, 'content_menus' ) ); |
| 21 |
add_action( 'uwp_wizard_content_dummy_users', array( $this, 'content_dummy_users' ) ); |
| 22 |
add_action( 'admin_notices', array( $this, 'setup_wizard_notice' ) ); |
| 23 |
add_action( 'wp_loaded', array( $this, 'hide_wizard_notices' ) ); |
| 24 |
|
| 25 |
} |
| 26 |
|
| 27 |
public function remove_deprecated_functions() { |
| 28 |
// removes deprecated warnings from page |
| 29 |
remove_action('admin_print_styles', 'print_emoji_styles'); |
| 30 |
remove_action( 'admin_head', 'wp_admin_bar_header' ); |
| 31 |
} |
| 32 |
|
| 33 |
public function setup_wizard_notice() { |
| 34 |
|
| 35 |
$show_notice = get_option( "uwp_setup_wizard_notice" ); |
| 36 |
|
| 37 |
if ( isset( $show_notice ) && 1 == $show_notice ) { |
| 38 |
?> |
| 39 |
<div id="message" class="updated notice-alt uwp-message"> |
| 40 |
<p><?php esc_html_e( '<strong>Welcome to UsersWP</strong> – You‘re almost ready to start your site. :)', 'userswp' ); ?></p> |
| 41 |
<p class="submit"> |
| 42 |
<a href="<?php echo esc_url( admin_url( 'admin.php?page=uwp-setup' ) ); ?>" |
| 43 |
class="button-primary"><?php esc_html_e( 'Run the Setup Wizard', 'userswp' ); ?></a> |
| 44 |
<a class="button-secondary skip" |
| 45 |
href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'uwp-hide-notice', 'install' ), 'uwp_hide_notices_nonce', '_uwp_notice_nonce' ) ); ?>"><?php esc_html_e( 'Skip setup', 'userswp' ); ?></a> |
| 46 |
</p> |
| 47 |
</div> |
| 48 |
<?php |
| 49 |
} |
| 50 |
|
| 51 |
} |
| 52 |
|
| 53 |
public function hide_wizard_notices() { |
| 54 |
|
| 55 |
if ( isset( $_GET['uwp-hide-notice'] ) && isset( $_GET['_uwp_notice_nonce'] ) ) { |
| 56 |
|
| 57 |
if ( ! wp_verify_nonce( $_GET['_uwp_notice_nonce'], 'uwp_hide_notices_nonce' ) ) { |
| 58 |
wp_die( esc_html__( 'Action failed. Please refresh the page and retry.', 'userswp' ) ); |
| 59 |
} |
| 60 |
|
| 61 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 62 |
wp_die( esc_html__( 'Cheatin’ huh?', 'userswp' ) ); |
| 63 |
} |
| 64 |
|
| 65 |
delete_option( 'uwp_setup_wizard_notice' ); |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
public function admin_menus() { |
| 70 |
add_dashboard_page( '', '', 'manage_options', 'uwp-setup', '' ); |
| 71 |
} |
| 72 |
|
| 73 |
public function setup_wizard() { |
| 74 |
|
| 75 |
if ( empty( $_GET['page'] ) || 'uwp-setup' !== $_GET['page'] ) { |
| 76 |
return; |
| 77 |
} |
| 78 |
|
| 79 |
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
| 80 |
|
| 81 |
$default_steps = array( |
| 82 |
'introduction' => array( |
| 83 |
'name' => __( 'Introduction', 'userswp' ), |
| 84 |
'view' => array( $this, 'setup_introduction' ), |
| 85 |
'handler' => '', |
| 86 |
), |
| 87 |
'content' => array( |
| 88 |
'name' => __( 'Content', 'userswp' ), |
| 89 |
'view' => array( $this, 'setup_content' ), |
| 90 |
'handler' => array( $this, 'setup_content_save' ), |
| 91 |
), |
| 92 |
'recommend' => array( |
| 93 |
'name' => __( 'Recommend', 'userswp' ), |
| 94 |
'view' => array( $this, 'setup_recommend' ), |
| 95 |
'handler' => array( $this, 'setup_recommend_save' ), |
| 96 |
), |
| 97 |
'next_steps' => array( |
| 98 |
'name' => __( 'Ready!', 'userswp' ), |
| 99 |
'view' => array( $this, 'setup_ready' ), |
| 100 |
'handler' => '', |
| 101 |
), |
| 102 |
); |
| 103 |
|
| 104 |
$this->steps = apply_filters( 'uwp_setup_wizard_steps', $default_steps ); |
| 105 |
$this->step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : current( array_keys( $this->steps ) ); |
| 106 |
|
| 107 |
wp_enqueue_style( 'wp-admin' ); |
| 108 |
$obj = WP_Font_Awesome_Settings::instance(); |
| 109 |
$obj->enqueue_style(); |
| 110 |
$obj->enqueue_scripts(); |
| 111 |
wp_enqueue_style( 'uwp-setup-wizard-style', USERSWP_PLUGIN_URL . 'admin/assets/css/setup-wizard' . $suffix . '.css', array( |
| 112 |
'dashicons', |
| 113 |
'install', |
| 114 |
'thickbox' |
| 115 |
), '', '' ); |
| 116 |
|
| 117 |
$required_scripts = array( |
| 118 |
'jquery', |
| 119 |
'jquery-ui-tooltip', |
| 120 |
'thickbox', |
| 121 |
'jquery-ui-progressbar' |
| 122 |
); |
| 123 |
|
| 124 |
wp_register_script( 'uwp-setup', USERSWP_PLUGIN_URL . 'admin/assets/js/setup-wizard' . $suffix . '.js', $required_scripts, USERSWP_VERSION ); |
| 125 |
|
| 126 |
wp_localize_script( 'uwp-setup', 'uwp_wizard_obj', array( |
| 127 |
'ajaxurl' => admin_url( 'admin-ajax.php' ) |
| 128 |
) ); |
| 129 |
|
| 130 |
if ( ! empty( $_POST['save_step'] ) && isset( $this->steps[ $this->step ]['handler'] ) ) { |
| 131 |
call_user_func( $this->steps[ $this->step ]['handler'], $this ); |
| 132 |
} |
| 133 |
|
| 134 |
ob_start(); |
| 135 |
|
| 136 |
$this->setup_wizard_header(); |
| 137 |
$this->setup_wizard_steps(); |
| 138 |
$this->setup_wizard_content(); |
| 139 |
$this->setup_wizard_footer(); |
| 140 |
exit; |
| 141 |
} |
| 142 |
|
| 143 |
public function setup_wizard_header() { |
| 144 |
?> |
| 145 |
<!DOCTYPE html> |
| 146 |
<html <?php language_attributes(); ?>> |
| 147 |
<head> |
| 148 |
<meta name="viewport" content="width=device-width"/> |
| 149 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> |
| 150 |
<title><?php esc_html_e( 'Userswp › Setup Wizard', 'userswp' ); ?></title> |
| 151 |
<?php do_action( 'admin_print_styles' ); ?> |
| 152 |
<?php wp_print_scripts( 'uwp-setup' ); ?> |
| 153 |
<?php do_action( 'admin_head' ); ?> |
| 154 |
</head> |
| 155 |
<body class="uwp-setup wp-core-ui"> |
| 156 |
<h1 id="uwp-logo"> |
| 157 |
<a href="https://userswp.io/"><span class="dashicons dashicons-groups"></span> |
| 158 |
<span><span class="text-secondary">Users</span><span class="text-primary">WP</span></span> |
| 159 |
</a> |
| 160 |
</h1> |
| 161 |
<?php |
| 162 |
} |
| 163 |
|
| 164 |
public function setup_wizard_steps() { |
| 165 |
|
| 166 |
$ouput_steps = $this->steps; |
| 167 |
|
| 168 |
array_shift( $ouput_steps ); |
| 169 |
?> |
| 170 |
<ol class="uwp-setup-steps"> |
| 171 |
<?php foreach ( $ouput_steps as $step_key => $step ) : ?> |
| 172 |
<li class="<?php |
| 173 |
if ( $step_key === $this->step ) { |
| 174 |
echo 'active'; |
| 175 |
} elseif ( array_search( $this->step, array_keys( $this->steps ) ) > array_search( $step_key, array_keys( $this->steps ) ) ) { |
| 176 |
echo 'done'; |
| 177 |
} |
| 178 |
?>"> |
| 179 |
<?php echo esc_html( $step['name'] ); ?> |
| 180 |
</li> |
| 181 |
<?php endforeach; ?> |
| 182 |
</ol> |
| 183 |
<?php |
| 184 |
} |
| 185 |
|
| 186 |
public function setup_wizard_content() { |
| 187 |
echo '<div class="uwp-setup-content">'; |
| 188 |
call_user_func( $this->steps[ $this->step ]['view'], $this ); |
| 189 |
echo '</div>'; |
| 190 |
} |
| 191 |
|
| 192 |
public function setup_wizard_footer() { |
| 193 |
if ( 'next_steps' === $this->step ) : ?> |
| 194 |
<p class="uwp-return-to-dashboard-wrap"> |
| 195 |
<a class="uwp-return-to-dashboard" href="<?php echo esc_url( admin_url() ); ?>"> |
| 196 |
<?php esc_html_e( 'Return to the WordPress Dashboard', 'userswp' ); ?> |
| 197 |
</a> |
| 198 |
</p> |
| 199 |
<?php endif; ?> |
| 200 |
</body> |
| 201 |
</html> |
| 202 |
<?php |
| 203 |
} |
| 204 |
|
| 205 |
public function setup_introduction() { |
| 206 |
?> |
| 207 |
<h2><?php esc_html_e( 'Thank you for choosing UsersWP!', 'userswp' ); ?></h2> |
| 208 |
<p><?php esc_html_e( 'This quick setup wizard will help you configure the basic settings. It\'s completely optional and shouldn\'t take longer than two minutes.', 'userswp' ); ?></p> |
| 209 |
<p><?php esc_html_e( 'No time right now? If you don\'t want to go through the wizard, you can skip and return to the WordPress dashboard. Come back anytime if you change your mind!', 'userswp' ); ?></p> |
| 210 |
|
| 211 |
<p class="uwp-setup-actions step"> |
| 212 |
<a href="<?php echo esc_url( admin_url() ); ?>" |
| 213 |
class="button button-large"><?php esc_html_e( 'Not right now', 'userswp' ); ?></a> |
| 214 |
<a href="<?php echo esc_url( $this->get_next_step_link() ); ?>" |
| 215 |
class="button-primary button button-large button-next"><?php esc_html_e( "Let's go!", 'userswp' ); ?></a> |
| 216 |
</p> |
| 217 |
<?php |
| 218 |
} |
| 219 |
|
| 220 |
public function get_next_step_link( $step = '' ) { |
| 221 |
if ( ! $step ) { |
| 222 |
$step = $this->step; |
| 223 |
} |
| 224 |
|
| 225 |
$keys = array_keys( $this->steps ); |
| 226 |
if ( end( $keys ) === $step ) { |
| 227 |
return admin_url(); |
| 228 |
} |
| 229 |
|
| 230 |
$step_index = array_search( $step, $keys ); |
| 231 |
if ( false === $step_index ) { |
| 232 |
return ''; |
| 233 |
} |
| 234 |
|
| 235 |
return add_query_arg( 'step', $keys[ $step_index + 1 ] ); |
| 236 |
} |
| 237 |
|
| 238 |
public function setup_content() { |
| 239 |
|
| 240 |
$wizard_content = array(); |
| 241 |
|
| 242 |
if ( is_multisite() ) { |
| 243 |
$reg = get_site_option( 'registration' ); |
| 244 |
|
| 245 |
if ( $reg == 'none' ) { |
| 246 |
$wizard_content['general_settings'] = __( "General Settings", "userswp" ); |
| 247 |
} |
| 248 |
|
| 249 |
} else { |
| 250 |
if ( ! get_option( 'users_can_register' ) ) { |
| 251 |
$wizard_content['general_settings'] = __( "General Settings", "userswp" ); |
| 252 |
} |
| 253 |
} |
| 254 |
|
| 255 |
$wizard_content['use_userswp'] = __( "How will you use UsersWP", "userswp" ); |
| 256 |
$wizard_content['menus'] = __( "Menus", "userswp" ); |
| 257 |
$wizard_content['dummy_users'] = __( "Dummy Users", "userswp" ); |
| 258 |
|
| 259 |
$wizard_content = apply_filters( 'uwp_wizard_content', $wizard_content ); |
| 260 |
?> |
| 261 |
<div class="uwp-wizard-content-parts"> |
| 262 |
<ul> |
| 263 |
<?php |
| 264 |
foreach ( $wizard_content as $slug => $title ) { |
| 265 |
echo '<li class="uwp-sub-menu-tab"><a href="#' . esc_attr( $slug ) . '">' . esc_attr( $title ) . '</a></li>' . " \n"; |
| 266 |
} |
| 267 |
?> |
| 268 |
</ul> |
| 269 |
</div> |
| 270 |
<form method="post"> |
| 271 |
<?php |
| 272 |
foreach ( $wizard_content as $slug => $title ) { |
| 273 |
echo '<h2 class="uwp-settings-title "><a id="' . esc_attr( $slug ) . '"></a>' . esc_attr( $title ) . '</h2>' . " \n"; // line break adds a nice spacing |
| 274 |
do_action( "uwp_wizard_content_{$slug}" ); |
| 275 |
} |
| 276 |
?> |
| 277 |
<p class="uwp-setup-actions step"> |
| 278 |
<a href="<?php echo esc_url( $this->get_next_step_link() ); ?>" |
| 279 |
class="button button-large button-next"><?php esc_html_e( 'Skip this step', 'userswp' ); ?></a> |
| 280 |
<input type="submit" class="button-primary button button-large button-next" |
| 281 |
value="<?php esc_attr_e( 'Continue', 'userswp' ); ?>" name="save_step"/> |
| 282 |
<?php wp_nonce_field( 'uwp-setup' ); ?> |
| 283 |
</p> |
| 284 |
</form> |
| 285 |
<?php |
| 286 |
} |
| 287 |
|
| 288 |
public function content_general_settings() { |
| 289 |
|
| 290 |
if ( is_multisite() ) { |
| 291 |
|
| 292 |
$reg = get_site_option( 'registration' ); |
| 293 |
|
| 294 |
if ( $reg == 'none' ) { |
| 295 |
?> |
| 296 |
<table class="form-table"> |
| 297 |
<tbody> |
| 298 |
<tr> |
| 299 |
<td> |
| 300 |
<p class="description-tooltip danger" style="color: red;"><i |
| 301 |
class="fas fa-exclamation-circle"></i> |
| 302 |
<strong><?php esc_html_e( 'Heads Up!', 'userswp' ); ?></strong> <?php esc_html_e( ' User registration is currently not allowed.', 'userswp' ); ?> |
| 303 |
</p> |
| 304 |
<label><input class="uwp-general-seetings" name="registration" type="radio" |
| 305 |
id="registration1" |
| 306 |
value="none"<?php checked( $reg, 'none' ); ?> /> <?php esc_html_e( 'Registration is disabled', 'userswp' ); ?> |
| 307 |
</label><br/> |
| 308 |
<label><input class="uwp-general-seetings" name="registration" type="radio" |
| 309 |
id="registration2" |
| 310 |
value="user"<?php checked( $reg, 'user' ); ?> /> <?php esc_html_e( 'User accounts may be registered', 'userswp' ); ?> |
| 311 |
</label><br/> |
| 312 |
<label><input class="uwp-general-seetings" name="registration" type="radio" |
| 313 |
id="registration3" |
| 314 |
value="blog"<?php checked( $reg, 'blog' ); ?> /> <?php esc_html_e( 'Logged in users may register new sites', 'userswp' ); ?> |
| 315 |
</label><br/> |
| 316 |
<label><input class="uwp-general-seetings" name="registration" type="radio" |
| 317 |
id="registration4" |
| 318 |
value="all"<?php checked( $reg, 'all' ); ?> /> <?php esc_html_e( 'Both sites and user accounts can be registered', 'userswp' ); ?> |
| 319 |
</label> |
| 320 |
</td> |
| 321 |
<td></td> |
| 322 |
</tr> |
| 323 |
</tbody> |
| 324 |
</table> |
| 325 |
<?php |
| 326 |
} |
| 327 |
} else { |
| 328 |
if ( ! get_option( 'users_can_register' ) ) { |
| 329 |
?> |
| 330 |
<table class="form-table"> |
| 331 |
<tbody> |
| 332 |
<tr> |
| 333 |
<td> |
| 334 |
<p class="description-tooltip danger" style="color: red;"><i |
| 335 |
class="fas fa-exclamation-circle"></i> |
| 336 |
<strong><?php esc_html_e( 'Heads Up!', 'userswp' ); ?></strong> <?php esc_html_e( ' User registration is currently not allowed.', 'userswp' ); ?> |
| 337 |
</p> |
| 338 |
<input type="checkbox" name="users_can_register" class="uwp-general-seetings" value="1"> |
| 339 |
<strong><?php esc_html_e( " Anyone can register", "userswp" ); ?></strong> |
| 340 |
</td> |
| 341 |
<td></td> |
| 342 |
</tr> |
| 343 |
</tbody> |
| 344 |
</table> |
| 345 |
<?php |
| 346 |
} |
| 347 |
} |
| 348 |
} |
| 349 |
|
| 350 |
public function content_use_userswp() { |
| 351 |
?> |
| 352 |
<table class="form-table uwp-dummy-table"> |
| 353 |
<tbody> |
| 354 |
<tr> |
| 355 |
<td> |
| 356 |
<input type="checkbox" name="login_register_page" class="use-uwp-pages" value="1" checked> |
| 357 |
<strong><?php esc_html_e( "Login/Register", "userswp" ); ?></strong></td> |
| 358 |
<td></td> |
| 359 |
</tr> |
| 360 |
<tr> |
| 361 |
<td> |
| 362 |
<input type="checkbox" name="user_profiles_page" class="use-uwp-pages" value="1" checked> |
| 363 |
<strong><?php esc_html_e( "User Profiles", "userswp" ); ?></strong></td> |
| 364 |
<td></td> |
| 365 |
</tr> |
| 366 |
<tr> |
| 367 |
<td> |
| 368 |
<input type="checkbox" name="member_directory_page" class="use-uwp-pages" value="1" checked> |
| 369 |
<strong><?php esc_html_e( "Members Directory", "userswp" ); ?></strong></td> |
| 370 |
<td></td> |
| 371 |
</tr> |
| 372 |
</tbody> |
| 373 |
</table> |
| 374 |
<?php |
| 375 |
} |
| 376 |
|
| 377 |
public function content_menus() { |
| 378 |
?> |
| 379 |
<table class="form-table uwp-dummy-table"> |
| 380 |
<tbody> |
| 381 |
<tr> |
| 382 |
<td> |
| 383 |
<strong><?php esc_html_e( "Select the theme main menu", "userswp" ); ?></strong> |
| 384 |
</td> |
| 385 |
<td style="width: 20%"> |
| 386 |
<strong><?php esc_html_e( "Action", "userswp" ); ?></strong> |
| 387 |
</td> |
| 388 |
</tr> |
| 389 |
<tr> |
| 390 |
<td> |
| 391 |
<?php |
| 392 |
$set_menus = get_nav_menu_locations(); |
| 393 |
$set_menus = array_filter( $set_menus ); |
| 394 |
|
| 395 |
if ( ! empty( $set_menus ) ) { |
| 396 |
|
| 397 |
echo "<select id='uwp_wizard_menu_id' data-type='add' class='uwp-select'>"; |
| 398 |
|
| 399 |
foreach ( $set_menus as $menu_location => $menu_id ) { |
| 400 |
$selected = false; |
| 401 |
|
| 402 |
if ( strpos( strtolower( $menu_location ), 'primary' ) !== false || strpos( strtolower( $menu_location ), 'main' ) !== false ) { |
| 403 |
$selected = true; |
| 404 |
} |
| 405 |
|
| 406 |
$menu_item = wp_get_nav_menus( $menu_id )[0]; |
| 407 |
|
| 408 |
?> |
| 409 |
<option value="<?php echo esc_attr( $menu_id ); ?>" <?php selected( $selected, true ); ?>> |
| 410 |
<?php echo esc_html( $menu_item->name ); |
| 411 |
if ( $selected ) { |
| 412 |
echo ' ' . esc_html__( '( Auto detected )', 'userswp' ); |
| 413 |
} ?> |
| 414 |
</option> |
| 415 |
<?php |
| 416 |
} |
| 417 |
|
| 418 |
echo "</select>"; |
| 419 |
|
| 420 |
} else { |
| 421 |
$menus = get_registered_nav_menus(); |
| 422 |
|
| 423 |
if ( ! empty( $menus ) ) { |
| 424 |
|
| 425 |
echo "<select id='uwp_wizard_menu_location' data-type='create' class='uwp-select'>"; |
| 426 |
|
| 427 |
foreach ( $menus as $menu_slug => $menu_name ) { |
| 428 |
$selected = false; |
| 429 |
|
| 430 |
if ( strpos( strtolower( $menu_slug ), 'primary' ) !== false || strpos( strtolower( $menu_slug ), 'main' ) !== false ) { |
| 431 |
$selected = true; |
| 432 |
} |
| 433 |
?> |
| 434 |
<option value="<?php echo esc_attr( $menu_slug ); ?>" <?php selected( $selected, true ); ?>> |
| 435 |
<?php esc_html_e( 'Create new menu in:', 'userswp' ); |
| 436 |
echo ' ' . esc_html__( $menu_name ); |
| 437 |
if ( $selected ) { |
| 438 |
echo ' ' . esc_html__( '( Auto detected )', 'userswp' ); |
| 439 |
} ?> |
| 440 |
</option> |
| 441 |
<?php |
| 442 |
} |
| 443 |
echo "</select>"; |
| 444 |
} |
| 445 |
} |
| 446 |
?> |
| 447 |
<div class="notice inline notice-success notice-alt uwp-wizard-menu uwp-wizard-menu-result"></div> |
| 448 |
</td> |
| 449 |
<td> |
| 450 |
<input type="button" value="<?php esc_attr_e( "Insert menu items", "userswp" ); ?>" |
| 451 |
class="button-primary uwp_dummy_button" |
| 452 |
onclick="uwp_wizard_setup_menu('<?php echo esc_attr( wp_create_nonce( "uwp-wizard-setup-menu" ) ); ?>'); return false;"> |
| 453 |
</td> |
| 454 |
</tr> |
| 455 |
</tbody> |
| 456 |
</table> |
| 457 |
<?php |
| 458 |
|
| 459 |
} |
| 460 |
|
| 461 |
public function content_dummy_users() { |
| 462 |
|
| 463 |
$get_dummy_user_passowrd = $this->get_dummy_user_passowrd(); |
| 464 |
$dummy_users = get_users( array( |
| 465 |
'meta_key' => 'uwp_dummy_user', |
| 466 |
'meta_value' => '1', |
| 467 |
'fields' => array( 'ID' ) |
| 468 |
) ); |
| 469 |
$total_dummy_users = ! empty( $dummy_users ) ? count( $dummy_users ) : 0; |
| 470 |
?> |
| 471 |
<table class="form-table uwp-dummy-table"> |
| 472 |
<tbody> |
| 473 |
<tr> |
| 474 |
<td> |
| 475 |
<p><?php echo wp_sprintf( __( 'Dummy Users for Testing. Password for all dummy users: <strong>%s</strong>', 'userswp' ), $get_dummy_user_passowrd ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></p> |
| 476 |
</td> |
| 477 |
<td style="width: 20%"> |
| 478 |
<input style="display: <?php echo ( $total_dummy_users > 0 ) ? 'block' : 'none'; ?>" type="button" |
| 479 |
value="<?php esc_attr_e( 'Remove', 'userswp' ); ?>" |
| 480 |
class="button-primary button uwp_diagnosis_button uwp_dummy_users_button uwp_remove_dummy_users_button" |
| 481 |
onclick="uwp_wizard_setup_dummy_users('<?php echo esc_attr( wp_create_nonce( "uwp_process_diagnosis" ) ); ?>','remove_dummy_users'); return false;"/> |
| 482 |
<input style="display: <?php echo ( $total_dummy_users > 0 ) ? 'none' : 'block'; ?>" type="button" |
| 483 |
value="<?php esc_attr_e( "Create Users", "userswp" ); ?>" |
| 484 |
class="button-primary button uwp_diagnosis_button uwp_dummy_users_button uwp_add_dummy_users_button" |
| 485 |
onclick="uwp_wizard_setup_dummy_users('<?php echo esc_attr( wp_create_nonce( "uwp_process_diagnosis" ) ); ?>','add_dummy_users'); return false;"> |
| 486 |
</td> |
| 487 |
</tr> |
| 488 |
<tr> |
| 489 |
<td colspan="2" class="has-pbar"> |
| 490 |
<div id="uwp_diagnose_pb_add_dummy_users" class="uwp-pb-wrapper"> |
| 491 |
<div class="progressBar" style="display: none;"> |
| 492 |
<div></div> |
| 493 |
</div> |
| 494 |
</div> |
| 495 |
<div id="uwp_diagnose_add_dummy_users"></div> |
| 496 |
<div id="uwp_diagnose_pb_remove_dummy_users" class="uwp-pb-wrapper"> |
| 497 |
<div class="progressBar" style="display: none;"> |
| 498 |
<div></div> |
| 499 |
</div> |
| 500 |
</div> |
| 501 |
<div id="uwp_diagnose_remove_dummy_users"></div> |
| 502 |
</td> |
| 503 |
</tr> |
| 504 |
</tbody> |
| 505 |
</table> |
| 506 |
<?php |
| 507 |
} |
| 508 |
|
| 509 |
public function get_dummy_user_passowrd() { |
| 510 |
return substr( hash( 'SHA256', AUTH_KEY . site_url() ), 0, 15 ); |
| 511 |
} |
| 512 |
|
| 513 |
public function setup_content_save() { |
| 514 |
check_admin_referer( 'uwp-setup' ); |
| 515 |
|
| 516 |
if ( ! empty( $_REQUEST['step'] ) && 'content' === $_REQUEST['step'] ) { |
| 517 |
$this->save_content_step_data(); |
| 518 |
} |
| 519 |
|
| 520 |
wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); |
| 521 |
exit; |
| 522 |
} |
| 523 |
|
| 524 |
public function save_content_step_data() { |
| 525 |
|
| 526 |
$login_register_page = ! empty( $_POST['login_register_page'] ) ? absint( $_POST['login_register_page'] ) : ''; |
| 527 |
$user_profiles_page = ! empty( $_POST['user_profiles_page'] ) ? absint( $_POST['user_profiles_page'] ) : ''; |
| 528 |
$member_directory_page = ! empty( $_POST['member_directory_page'] ) ? absint( $_POST['member_directory_page'] ) : ''; |
| 529 |
|
| 530 |
if ( is_multisite() ) { |
| 531 |
if ( isset( $_POST['registration'] ) && ! empty( $_POST['registration'] ) ) { |
| 532 |
update_site_option( 'registration', esc_attr( $_POST['registration'] ) ); |
| 533 |
} |
| 534 |
} else { |
| 535 |
if ( isset( $_POST['users_can_register'] ) && 1 == absint( $_POST['users_can_register'] ) ) { |
| 536 |
update_option( 'users_can_register', 1 ); |
| 537 |
} |
| 538 |
} |
| 539 |
|
| 540 |
$login_page = uwp_get_page_id( 'login_page' ); |
| 541 |
$register_page = uwp_get_page_id( 'register_page' ); |
| 542 |
$change_page = uwp_get_page_id( 'change_page' ); |
| 543 |
$forgot_page = uwp_get_page_id( 'forgot_page' ); |
| 544 |
$reset_page = uwp_get_page_id( 'reset_page' ); |
| 545 |
$profile_page = uwp_get_page_id( 'profile_page' ); |
| 546 |
$account_page = uwp_get_page_id( 'account_page' ); |
| 547 |
$users_page = uwp_get_page_id( 'users_page' ); |
| 548 |
$user_list_item_page = uwp_get_page_id( 'user_list_item_page' ); |
| 549 |
|
| 550 |
$login_pages = array( $login_page, $register_page, $change_page, $forgot_page, $reset_page ); |
| 551 |
|
| 552 |
if ( ! empty( $login_pages ) && count( $login_pages ) > 0 ) { |
| 553 |
$login_page_status = 'draft'; |
| 554 |
foreach ( $login_pages as $login_page_id ) { |
| 555 |
|
| 556 |
if ( ! empty( $login_register_page ) ) { |
| 557 |
$login_page_status = 'publish'; |
| 558 |
} |
| 559 |
|
| 560 |
wp_update_post( array( |
| 561 |
'ID' => $login_page_id, |
| 562 |
'post_status' => $login_page_status |
| 563 |
) ); |
| 564 |
|
| 565 |
} |
| 566 |
} |
| 567 |
|
| 568 |
$profile_pages = array( $profile_page, $account_page ); |
| 569 |
|
| 570 |
if ( ! empty( $profile_pages ) && count( $profile_pages ) > 0 ) { |
| 571 |
$profile_page_status = 'draft'; |
| 572 |
foreach ( $profile_pages as $profile_page_id ) { |
| 573 |
|
| 574 |
if ( ! empty( $user_profiles_page ) ) { |
| 575 |
$profile_page_status = 'publish'; |
| 576 |
} |
| 577 |
|
| 578 |
wp_update_post( array( |
| 579 |
'ID' => $profile_page_id, |
| 580 |
'post_status' => $profile_page_status |
| 581 |
) ); |
| 582 |
|
| 583 |
} |
| 584 |
} |
| 585 |
|
| 586 |
$users_pages = array( $users_page, $user_list_item_page ); |
| 587 |
|
| 588 |
if ( ! empty( $users_pages ) && count( $users_pages ) > 0 ) { |
| 589 |
$user_page_status = 'draft'; |
| 590 |
foreach ( $users_pages as $user_page_id ) { |
| 591 |
|
| 592 |
if ( ! empty( $member_directory_page ) ) { |
| 593 |
$user_page_status = 'publish'; |
| 594 |
} |
| 595 |
|
| 596 |
wp_update_post( array( |
| 597 |
'ID' => $user_page_id, |
| 598 |
'post_status' => $user_page_status |
| 599 |
) ); |
| 600 |
|
| 601 |
} |
| 602 |
} |
| 603 |
|
| 604 |
} |
| 605 |
|
| 606 |
public function setup_recommend() { |
| 607 |
?> |
| 608 |
<form method="post"> |
| 609 |
<div class="uwp-wizard-recommend"> |
| 610 |
<h2 class="uwp-settings-title "><?php esc_html_e( "Recommended Plugins", "userswp" ); ?></h2> |
| 611 |
<p><?php esc_html_e( "Below are a few recommended plugins that will help you with your site.", "userswp" ); ?></p> |
| 612 |
<?php |
| 613 |
include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); |
| 614 |
|
| 615 |
$recommend_wp_plugins = self::get_recommend_wp_plugins(); |
| 616 |
|
| 617 |
if ( ! empty( $recommend_wp_plugins ) ) { |
| 618 |
echo "<ul>"; |
| 619 |
|
| 620 |
$installed_text = '<i class="fas fa-check-circle" aria-hidden="true"></i> ' . esc_html__( 'Installed', 'userswp' ); |
| 621 |
$installing_text = '<i class="fas fa-sync fa-spin" aria-hidden="true"></i> ' . esc_html__( 'Installing', 'userswp' ); |
| 622 |
|
| 623 |
echo "<input type='hidden' id='uwp-installing-text' value='" . esc_attr( $installing_text ) . "' >"; |
| 624 |
echo "<input type='hidden' id='uwp-installed-text' value='" . esc_attr( $installed_text ) . "' >"; |
| 625 |
|
| 626 |
foreach ( $recommend_wp_plugins as $plugin ) { |
| 627 |
$status = install_plugin_install_status( array( "slug" => $plugin['slug'], "version" => "" ) ); |
| 628 |
|
| 629 |
$plugin_status = isset( $status['status'] ) ? $status['status'] : ''; |
| 630 |
$url = isset( $status['url'] ) ? $status['url'] : ''; |
| 631 |
|
| 632 |
if ( $plugin_status == 'install' ) { |
| 633 |
$checked = "checked"; |
| 634 |
$disabled = ""; |
| 635 |
$checkbox_class = "class='uwp_install_plugins'"; |
| 636 |
} else { |
| 637 |
$checked = "checked"; |
| 638 |
$disabled = "disabled"; |
| 639 |
$checkbox_class = ""; |
| 640 |
} |
| 641 |
|
| 642 |
$uwp_html_tip = '<span class="uwp-help-tip dashicons dashicons-editor-help" title="' . esc_attr( $plugin['desc'] ) . '"></span>'; |
| 643 |
echo "<li class='" . esc_attr( $plugin['slug'] ) . "'>"; |
| 644 |
echo "<input type='checkbox' id='" . esc_attr( $plugin['slug'] ) . "' $checked $disabled $checkbox_class />" . $plugin['name'] . " " . $uwp_html_tip; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 645 |
echo " | <a href='" . esc_url( admin_url( "plugin-install.php?uwp_wizard_recommend=true&tab=plugin-information&plugin=" . $plugin['slug'] . '&TB_iframe=true&width=772&height=407' ) ) . "' class='thickbox'>" . esc_html__( 'More info', 'userswp' ) . "</a>"; |
| 646 |
if ( $plugin_status == 'install' && $url ) { |
| 647 |
echo " | <span class='uwp-plugin-status' >( " . esc_html__( 'Tick to install', 'userswp' ) . " )</span>"; |
| 648 |
} else { |
| 649 |
if ( ! empty( $plugin_status ) ) { |
| 650 |
$plugin_status = $installed_text; |
| 651 |
} |
| 652 |
echo " | <span class='uwp-plugin-status'>" . $plugin_status . "</span>"; |
| 653 |
} |
| 654 |
echo "</li>"; |
| 655 |
|
| 656 |
} |
| 657 |
echo "</ul>"; |
| 658 |
} |
| 659 |
?> |
| 660 |
</div> |
| 661 |
<p class="uwp-setup-actions step"> |
| 662 |
<?php wp_nonce_field( 'uwp-setup' ); ?> |
| 663 |
<a href="<?php echo esc_url( $this->get_next_step_link() ); ?>" |
| 664 |
class="button button-large button-next"><?php esc_html_e( 'Skip this step', 'userswp' ); ?></a> |
| 665 |
<input type="submit" class="button-primary button button-large button-next uwp-continue-recommend" |
| 666 |
value="<?php esc_attr_e( 'Continue', 'userswp' ); ?>" name="save_step"/> |
| 667 |
<input type="submit" class="button-primary button button-large button-next uwp-install-recommend" |
| 668 |
value="<?php esc_attr_e( 'Install', 'userswp' ); ?>" name="install_recommend" |
| 669 |
onclick="uwp_wizard_install_plugins('<?php echo esc_attr( wp_create_nonce( 'updates' ) ); ?>');return false;"/> |
| 670 |
</p> |
| 671 |
</form> |
| 672 |
<?php |
| 673 |
} |
| 674 |
|
| 675 |
public static function get_recommend_wp_plugins() { |
| 676 |
|
| 677 |
$plugins = array( |
| 678 |
'ayecode-connect' => array( |
| 679 |
'url' => 'https://wordpress.org/plugins/ayecode-connect/', |
| 680 |
'slug' => 'ayecode-connect', |
| 681 |
'name' => 'AyeCode Connect', |
| 682 |
'desc' => __( 'Allows you to install any purchased AyeCode Ltd product add-ons without a zip file. It also installs and activates licences automatically, so there is no need to copy/paste licenses.', 'userswp' ), |
| 683 |
), |
| 684 |
'userswp-social-login' => array( |
| 685 |
'url' => 'https://wordpress.org/plugins/userswp-social-login/', |
| 686 |
'slug' => 'userswp-social-login', |
| 687 |
'name' => __( 'UsersWP – Social Login', 'userswp' ), |
| 688 |
'desc' => __( 'This plugin lets your user to register and login with popular sites like Facebook, Google, Twitter, LinkedIn, Instagram, Yahoo, WordPress, vkontakte etc.', 'userswp' ), |
| 689 |
), |
| 690 |
'userswp-recaptcha' => array( |
| 691 |
'url' => 'https://wordpress.org/plugins/userswp-recaptcha/', |
| 692 |
'slug' => 'userswp-recaptcha', |
| 693 |
'name' => __( 'UsersWP – ReCaptcha', 'userswp' ), |
| 694 |
'desc' => __( 'This plugin allows you to implement a super security captcha into forms like registration, login forms etc.', 'userswp' ), |
| 695 |
), |
| 696 |
); |
| 697 |
|
| 698 |
return $plugins; |
| 699 |
} |
| 700 |
|
| 701 |
public function setup_recommend_save() { |
| 702 |
check_admin_referer( 'uwp-setup' ); |
| 703 |
wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); |
| 704 |
exit; |
| 705 |
} |
| 706 |
|
| 707 |
public function setup_ready() { |
| 708 |
$this->setup_ready_actions(); |
| 709 |
?> |
| 710 |
<h2><?php esc_html_e( 'Awesome, you are ready to go!', 'userswp' ); ?></h2> |
| 711 |
<div class="uwp-message"> |
| 712 |
<p><?php esc_html_e( 'Thank you for using UsersWP :)', 'userswp' ); ?></p> |
| 713 |
</div> |
| 714 |
<div class="uwp-setup-next-steps-last"> |
| 715 |
<h2><?php esc_html_e( 'Learn more', 'userswp' ); ?></h2> |
| 716 |
<ul> |
| 717 |
<li class="uwp-getting-started"> |
| 718 |
<a href="https://userswp.io/documentation/?utm_source=setupwizard&utm_medium=product&utm_content=getting-started&utm_campaign=userswpplugin" |
| 719 |
target="_blank"><?php esc_html_e( 'Getting started guide', 'userswp' ); ?></a> |
| 720 |
</li> |
| 721 |
<li class="uwp-newsletter"> |
| 722 |
<a href="https://userswp.io/newsletter-signup/?utm_source=setupwizard&utm_medium=product&utm_content=newsletter&utm_campaign=userswpplugin" |
| 723 |
target="_blank"><?php esc_html_e( 'Get Userswp advice in your inbox', 'userswp' ); ?></a> |
| 724 |
</li> |
| 725 |
<li class="uwp-get-help"> |
| 726 |
<a href="https://userswp.io/support/?utm_source=setupwizard&utm_medium=product&utm_content=docs&utm_campaign=userswpplugin" |
| 727 |
target="_blank"><?php esc_html_e( 'Have questions? Get help.', 'userswp' ); ?></a> |
| 728 |
</li> |
| 729 |
</ul> |
| 730 |
</div> |
| 731 |
<?php |
| 732 |
} |
| 733 |
|
| 734 |
private function setup_ready_actions() { |
| 735 |
delete_option( 'uwp_setup_wizard_notice' ); |
| 736 |
} |
| 737 |
|
| 738 |
} |
| 739 |
|
| 740 |
new UsersWP_Admin_Setup_Wizard(); |