| 1 |
<?php |
| 2 |
/** |
| 3 |
* As Setup Wizard Class |
| 4 |
* |
| 5 |
* Takes new users through some basic steps to setup their support. |
| 6 |
* |
| 7 |
* @package Awesome Support/Admin/AS_Admin_Setup_Wizard |
| 8 |
* @author AwesomeSupport <contact@getawesomesupport.com> |
| 9 |
* @license GPL-2.0+ |
| 10 |
* @link https://getawesomesupport.com |
| 11 |
* @copyright 2015-2018 AwesomeSupport |
| 12 |
*/ |
| 13 |
|
| 14 |
if ( ! defined( 'ABSPATH' ) ) { |
| 15 |
exit; |
| 16 |
} |
| 17 |
|
| 18 |
/** |
| 19 |
* AS_Admin_Setup_Wizard class. |
| 20 |
*/ |
| 21 |
class AS_Admin_Setup_Wizard { |
| 22 |
|
| 23 |
/** |
| 24 |
* Current step |
| 25 |
* |
| 26 |
* @var string |
| 27 |
*/ |
| 28 |
private $step = ''; |
| 29 |
|
| 30 |
/** |
| 31 |
* Steps for the setup wizard |
| 32 |
* |
| 33 |
* @var array |
| 34 |
*/ |
| 35 |
private $steps = array(); |
| 36 |
|
| 37 |
/** |
| 38 |
* Hook in tabs. |
| 39 |
*/ |
| 40 |
public function __construct() { |
| 41 |
// check if current user can manage wizard. |
| 42 |
add_action( 'admin_menu', array( $this, 'admin_menus' ) ); |
| 43 |
add_action( 'admin_init', array( $this, 'setup_wizard' ) ); |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Add admin menus/screens. |
| 48 |
*/ |
| 49 |
public function admin_menus() { |
| 50 |
add_dashboard_page( '', '', 'manage_options', 'as-setup', '' ); |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Show the setup wizard. |
| 55 |
*/ |
| 56 |
public function setup_wizard() { |
| 57 |
if ( empty( $_GET['page'] ) || 'as-setup' !== $_GET['page'] ) { // WPCS: CSRF ok, input var ok. |
| 58 |
return; |
| 59 |
} |
| 60 |
$default_steps = array( |
| 61 |
'product_setup' => array( |
| 62 |
'name' => __( 'Product Setup', 'awesome-support' ), |
| 63 |
'view' => array( $this, 'as_product_setup_setup' ), |
| 64 |
'handler' => array( $this, 'as_product_setup_setup_save' ), |
| 65 |
), |
| 66 |
'submit_ticket_page' => array( |
| 67 |
'name' => __( 'Submit ticket page', 'awesome-support' ), |
| 68 |
'view' => array( $this, 'as_setup_submit_ticket_page' ), |
| 69 |
'handler' => array( $this, 'as_setup_submit_ticket_page_save' ), |
| 70 |
), |
| 71 |
'my_ticket_page' => array( |
| 72 |
'name' => __( 'My ticket Page', 'awesome-support' ), |
| 73 |
'view' => array( $this, 'as_setup_my_ticket_page' ), |
| 74 |
'handler' => array( $this, 'as_setup_my_ticket_page_save' ), |
| 75 |
), |
| 76 |
'priorities' => array( |
| 77 |
'name' => __( 'Priorities', 'awesome-support' ), |
| 78 |
'view' => array( $this, 'as_setup_priorities' ), |
| 79 |
'handler' => array( $this, 'as_setup_priorities_save' ), |
| 80 |
), |
| 81 |
'departments' => array( |
| 82 |
'name' => __( 'Departments', 'awesome-support' ), |
| 83 |
'view' => array( $this, 'as_setup_departments' ), |
| 84 |
'handler' => array( $this, 'as_setup_departments_save' ), |
| 85 |
), |
| 86 |
'ticket_submit_user_roles' => array( |
| 87 |
'name' => __( 'Existing Users', 'awesome-support' ), |
| 88 |
'view' => array( $this, 'as_setup_ticket_submit_user_roles' ), |
| 89 |
'handler' => array( $this, 'as_setup_ticket_submit_user_roles_save' ), |
| 90 |
), |
| 91 |
'lets_go' => array( |
| 92 |
'name' => __( "Let's Go", 'awesome-support' ), |
| 93 |
'view' => array( $this, 'as_setup_lets_go' ), |
| 94 |
'handler' => array( $this, 'as_setup_lets_go_save' ), |
| 95 |
), |
| 96 |
); |
| 97 |
|
| 98 |
// Admin styles |
| 99 |
wp_enqueue_style( 'as-admin-style', WPAS_URL . 'assets/admin/css/admin.css', WPAS_VERSION ); |
| 100 |
wp_enqueue_style( 'admin-wizard-style', WPAS_URL . 'assets/admin/css/setup-wizard.css', WPAS_VERSION ); |
| 101 |
wp_register_script( 'as-admin-script', WPAS_URL . 'assets/admin/js/as-setup.js', array( 'jquery' ), '1.0.0' ); |
| 102 |
wp_register_script( 'as-setup', WPAS_URL . '/assets/admin/js/as-setup.js', array( 'jquery', 'wp-util' ), WPAS_VERSION ); |
| 103 |
|
| 104 |
$this->steps = apply_filters( 'as_setup_wizard_steps', $default_steps ); |
| 105 |
$this->step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : current( array_keys( $this->steps ) ); // WPCS: CSRF ok, input var ok. |
| 106 |
|
| 107 |
if ( ! empty( $_POST['save_step'] ) && isset( $this->steps[ $this->step ]['handler'] ) ) { |
| 108 |
call_user_func( $this->steps[ $this->step ]['handler'], $this ); |
| 109 |
} |
| 110 |
|
| 111 |
ob_start(); |
| 112 |
// call setup view functions here. |
| 113 |
$this->setup_wizard_header(); |
| 114 |
$this->setup_wizard_steps(); |
| 115 |
$this->setup_wizard_content(); |
| 116 |
$this->setup_wizard_footer(); |
| 117 |
exit; |
| 118 |
} |
| 119 |
|
| 120 |
/** |
| 121 |
* Setup Wizard Header. |
| 122 |
*/ |
| 123 |
public function setup_wizard_header() { |
| 124 |
?> |
| 125 |
<!DOCTYPE html> |
| 126 |
<html <?php language_attributes(); ?>> |
| 127 |
<head> |
| 128 |
<meta name="viewport" content="width=device-width" /> |
| 129 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| 130 |
<title><?php esc_html_e( 'Awesome Support › Setup Wizard', 'awesome-support' ); ?></title> |
| 131 |
<?php wp_print_scripts( 'as-setup' ); ?> |
| 132 |
<?php do_action( 'admin_print_styles' ); ?> |
| 133 |
<?php do_action( 'admin_head' ); ?> |
| 134 |
</head> |
| 135 |
<body class="as-setup wp-core-ui"> |
| 136 |
<div class="as-setup-wizard"> |
| 137 |
<h1 id="as-logo"><a href="https://getawesomesupport.com/">Awesome Support</a></h1> |
| 138 |
<?php |
| 139 |
} |
| 140 |
|
| 141 |
|
| 142 |
/** |
| 143 |
* Output the steps. |
| 144 |
*/ |
| 145 |
public function setup_wizard_steps() { |
| 146 |
$output_steps = $this->steps; |
| 147 |
?> |
| 148 |
<ol class="as-setup-steps"> |
| 149 |
<?php foreach ( $output_steps as $step_key => $step ) : ?> |
| 150 |
<?php |
| 151 |
/** |
| 152 |
* Determine step_class |
| 153 |
* On each steps done, add .done while .active |
| 154 |
* for the current step state. |
| 155 |
*/ |
| 156 |
if ( $step_key === $this->step ) { |
| 157 |
$step_class = 'active'; |
| 158 |
} elseif ( array_search( $this->step, array_keys( $this->steps ), true ) > array_search( $step_key, array_keys( $this->steps ), true ) ) { |
| 159 |
$step_class = 'done'; |
| 160 |
} else { |
| 161 |
$step_class = ''; |
| 162 |
} |
| 163 |
?> |
| 164 |
<li class="<?php echo esc_attr( $step_class ); ?>"><div class="hint"> |
| 165 |
<?php echo esc_html( $step['name'] ); ?> |
| 166 |
</div></li> |
| 167 |
<?php endforeach; ?> |
| 168 |
</ol> |
| 169 |
<?php |
| 170 |
} |
| 171 |
|
| 172 |
/** |
| 173 |
* Output the content for the current step. |
| 174 |
*/ |
| 175 |
public function setup_wizard_content() { |
| 176 |
echo '<div class="as-setup-content">'; |
| 177 |
/* |
| 178 |
printf( |
| 179 |
'<p class="sub-heading">%s</p>', |
| 180 |
__( 'Welcome to Awesome Support! This setup wizard will help you to quickly configure your new support system so that you can start processing customer requests right away. So lets get started with our first question!', 'awesome-support' ) |
| 181 |
); |
| 182 |
*/ |
| 183 |
if ( ! empty( $this->steps[ $this->step ]['view'] ) ) { |
| 184 |
call_user_func( $this->steps[ $this->step ]['view'], $this ); |
| 185 |
|
| 186 |
} |
| 187 |
echo '</div>'; |
| 188 |
} |
| 189 |
|
| 190 |
|
| 191 |
/** |
| 192 |
* Setup Wizard Footer. |
| 193 |
*/ |
| 194 |
public function setup_wizard_footer() { |
| 195 |
$about_us_link = add_query_arg( array( 'post_type' => 'ticket', 'page' => 'wpas-about' ), admin_url( 'edit.php' ) ) |
| 196 |
?> |
| 197 |
<?php if ( 'lets_go' !== $this->step ) : ?> |
| 198 |
<a class="not-now" href="<?php echo esc_url( $about_us_link ); ?>"><?php esc_html_e( 'Not right now', 'awesome-support' ); ?></a> |
| 199 |
<?php endif; ?> |
| 200 |
</div><!-- .setup-wizard --> |
| 201 |
</body> |
| 202 |
</html> |
| 203 |
<?php |
| 204 |
} |
| 205 |
|
| 206 |
/** |
| 207 |
* Awesome Support Multiple or single Product setup |
| 208 |
*/ |
| 209 |
public function as_product_setup_setup(){ |
| 210 |
$support_products = wpas_get_option( 'support_products' ); |
| 211 |
printf( |
| 212 |
'<p class="sub-heading">%s</p>', |
| 213 |
esc_html__( 'Welcome to Awesome Support! This setup wizard will help you to quickly configure your new support system so that you can start processing customer requests right away. So lets get started with our first question!', 'awesome-support' ) |
| 214 |
); |
| 215 |
?> |
| 216 |
<form method="post"> |
| 217 |
<p><b><?php esc_html_e( 'Would you like to turn on support for multiple products?', 'awesome-support' );?> </b></p> |
| 218 |
<p><?php esc_html_e( 'If you only offer support for one product you do not need to turn on multi-product support. But if you offer support for multiple products then you should respond YES to this question.', 'awesome-support' );?></p> |
| 219 |
<p><?php esc_html_e( 'Note: You can change your mind later by going to the TICKETS->SETTINGS->PRODUCTS MANAGEMENT tab.', 'awesome-support' );?></p> |
| 220 |
<label for="product_type_yes">Yes</label> |
| 221 |
<input type="radio" name="product_type" id='product_type_yes' value="yes" checked /> |
| 222 |
<label for="product_type_no">No</label> |
| 223 |
<input type="radio" name="product_type" id='product_type_no' value="no"/> |
| 224 |
<input type="submit" name="save_step" value="Continue"> |
| 225 |
<?php wp_nonce_field( 'as-setup' ); ?> |
| 226 |
</form> |
| 227 |
<?php |
| 228 |
} |
| 229 |
|
| 230 |
/** |
| 231 |
* Awesome Support Multiple or single Product setup on save |
| 232 |
*/ |
| 233 |
public function as_product_setup_setup_save(){ |
| 234 |
check_admin_referer( 'as-setup' ); |
| 235 |
$product_type = (isset( $_POST['product_type'] ) )? sanitize_text_field( wp_unslash( $_POST['product_type'] ) ): ''; |
| 236 |
|
| 237 |
// If the user needs multiple products we need to update the plugin options |
| 238 |
$options = maybe_unserialize( get_option( 'wpas_options' ) ); |
| 239 |
// If multiple product is selected, make product selection multiple. |
| 240 |
if( !empty( $product_type ) && 'yes' === $product_type ){ |
| 241 |
$options['support_products'] = '1'; |
| 242 |
} else{ |
| 243 |
$options['support_products'] = '0'; |
| 244 |
} |
| 245 |
update_option( 'wpas_options', serialize( $options ) ); |
| 246 |
wp_safe_redirect( esc_url_raw( $this->get_next_step_link() ) ); |
| 247 |
} |
| 248 |
|
| 249 |
/** |
| 250 |
* Awesome Support submit ticket page setup view. |
| 251 |
*/ |
| 252 |
public function as_setup_submit_ticket_page(){ |
| 253 |
?> |
| 254 |
<form method="post"> |
| 255 |
<p><b><?php esc_html_e( 'Which menu would you like to add the SUBMIT TICKET page to?', 'awesome-support' );?> </b></p> |
| 256 |
<p><?php esc_html_e( 'We have created a new page that users can access to submit tickets to your new support system. However, the page first needs to be added to one of your menus so that the user can easily access it.', 'awesome-support' );?> </p> |
| 257 |
|
| 258 |
<?php |
| 259 |
$menu_lists = wp_get_nav_menus(); |
| 260 |
if( !empty( $menu_lists )){ |
| 261 |
?> |
| 262 |
<p><?php esc_html_e( 'Note: If you change your mind later you can remove the page from your menu or add it to a new menu via APPEARANCE->MENUS.', 'awesome-support' );?></p> |
| 263 |
<?php |
| 264 |
echo '<select name="wpas_ticket_submit_manu">'; |
| 265 |
foreach ($menu_lists as $key => $menu ) { |
| 266 |
echo '<option value="' . esc_attr( $menu->term_id ) . '">' . esc_html( $menu->name ) . '</option>'; |
| 267 |
} |
| 268 |
echo '<select>'; |
| 269 |
echo '<input type="submit" name="save_step" value="Continue">'; |
| 270 |
wp_nonce_field( 'as-setup' ); |
| 271 |
} else{ |
| 272 |
if (!current_theme_supports('menus')) { |
| 273 |
$get_next_step_link = esc_url_raw( $this->get_next_step_link() ); |
| 274 |
$x_text = 'Oop! Your theme does not support navigation menus. No worry! Click <a class="not-menu-ignore" href="'. esc_url( $get_next_step_link ).'">'.__( 'Here', 'awesome-support' ).'</a> to continue'; |
| 275 |
|
| 276 |
// translators: %s is the text. |
| 277 |
$x_content = __( '%s.' , 'awesome-support' ); |
| 278 |
echo wp_kses_post( sprintf( $x_content, $x_text) ); |
| 279 |
} |
| 280 |
else |
| 281 |
{ |
| 282 |
$x_text = 'It looks like you have a brand new install of WordPress without any menus. So please setup at least one menu first. Click <a href="'. admin_url( 'nav-menus.php').'" class="contrast-link">Here</a> to setup your first menu'; |
| 283 |
|
| 284 |
// translators: %s is the text. |
| 285 |
$x_content = __( '%s.' , 'awesome-support' ); |
| 286 |
echo wp_kses_post( sprintf( $x_content, $x_text) ); |
| 287 |
} |
| 288 |
} |
| 289 |
?> |
| 290 |
</form> |
| 291 |
<?php |
| 292 |
} |
| 293 |
|
| 294 |
/** |
| 295 |
* Awesome Support submit ticket page setup on save. |
| 296 |
*/ |
| 297 |
public function as_setup_submit_ticket_page_save(){ |
| 298 |
check_admin_referer( 'as-setup' ); |
| 299 |
$ticket_submit = wpas_get_option( 'ticket_submit' ); |
| 300 |
$wpas_ticket_submit_manu = (isset( $_POST['wpas_ticket_submit_manu'] ) && !empty( $_POST['wpas_ticket_submit_manu'] ) )? intval( $_POST['wpas_ticket_submit_manu'] ): 0; |
| 301 |
if( !empty( $ticket_submit ) && !is_array( $ticket_submit ) ){ |
| 302 |
wp_update_nav_menu_item( $wpas_ticket_submit_manu , 0, array( |
| 303 |
'menu-item-db-id' => $ticket_submit, |
| 304 |
'menu-item-object-id' => $ticket_submit, |
| 305 |
'menu-item-object' => 'page', |
| 306 |
'menu-item-title' => wp_strip_all_tags( __( 'Submit Ticket', 'awesome-support' ) ), |
| 307 |
'menu-item-status' => 'publish', |
| 308 |
'menu-item-type' => 'post_type' |
| 309 |
) |
| 310 |
); |
| 311 |
} |
| 312 |
wp_safe_redirect( esc_url_raw( $this->get_next_step_link() ) ); |
| 313 |
} |
| 314 |
|
| 315 |
/** |
| 316 |
* Awesome Support my tickets page setup view. |
| 317 |
*/ |
| 318 |
public function as_setup_my_ticket_page(){ |
| 319 |
?> |
| 320 |
<form method="post"> |
| 321 |
<p><b><?php esc_html_e( 'Which menu would you like to add the MY TICKETS page to?', 'awesome-support' );?> </b></p> |
| 322 |
<p><?php esc_html_e( 'We have created a new page that users can access to view their existing tickets. This step allows you to add that page to one of your existing menus so users can easily access it.', 'awesome-support' );?></p> |
| 323 |
<?php |
| 324 |
$menu_lists = wp_get_nav_menus(); |
| 325 |
if( !empty( $menu_lists )){ |
| 326 |
?> |
| 327 |
<p><?php esc_html_e( 'Note: If you change your mind later you can remove the page from your menu or add it to a new menu via APPEARANCE->MENUS.', 'awesome-support' );?></p> |
| 328 |
<?php |
| 329 |
echo '<select name="wpas_ticket_list_menu">'; |
| 330 |
foreach ($menu_lists as $key => $menu ) { |
| 331 |
echo '<option value="' . esc_attr( $menu->term_id ) . '">' . esc_html( $menu->name ) . '</option>'; |
| 332 |
} |
| 333 |
echo '<select>'; |
| 334 |
echo '<input type="submit" name="save_step" value="Continue">'; |
| 335 |
wp_nonce_field( 'as-setup' ); |
| 336 |
} else{ |
| 337 |
if (!current_theme_supports('menus')) { |
| 338 |
$get_next_step_link = esc_url_raw( $this->get_next_step_link() ); |
| 339 |
$x_text = 'Oop! Your theme does not support navigation menus. No worry! Click <a class="not-menu-ignore" href="'. esc_url( $get_next_step_link ).'">'.__( 'Here', 'awesome-support' ).'</a> to continue'; |
| 340 |
|
| 341 |
// translators: %s is the text. |
| 342 |
$x_content = __( '%s.' , 'awesome-support' ); |
| 343 |
echo wp_kses_post( sprintf( $x_content, $x_text) ); |
| 344 |
} |
| 345 |
} |
| 346 |
?> |
| 347 |
</form> |
| 348 |
<?php |
| 349 |
} |
| 350 |
|
| 351 |
/** |
| 352 |
* Awesome Support my ticket page setup on save. |
| 353 |
*/ |
| 354 |
public function as_setup_my_ticket_page_save(){ |
| 355 |
check_admin_referer( 'as-setup' ); |
| 356 |
$ticket_list = wpas_get_option( 'ticket_list' ); |
| 357 |
$wpas_ticket_list_menu = (isset( $_POST['wpas_ticket_list_menu'] ) && !empty( $_POST['wpas_ticket_list_menu'] ) )? intval( $_POST['wpas_ticket_list_menu'] ): 0; |
| 358 |
if( !empty( $ticket_list ) && !is_array( $ticket_list ) ){ |
| 359 |
wp_update_nav_menu_item( $wpas_ticket_list_menu, 0, array( |
| 360 |
'menu-item-db-id' => $ticket_list, |
| 361 |
'menu-item-object-id' => $ticket_list, |
| 362 |
'menu-item-object' => 'page', |
| 363 |
'menu-item-title' => wp_strip_all_tags( __( 'My Tickets', 'awesome-support' ) ), |
| 364 |
'menu-item-status' => 'publish', |
| 365 |
'menu-item-type' => 'post_type' |
| 366 |
) |
| 367 |
); |
| 368 |
} |
| 369 |
wp_safe_redirect( esc_url_raw( $this->get_next_step_link() ) ); |
| 370 |
} |
| 371 |
|
| 372 |
/** |
| 373 |
* Awesome Support priorities setup view. |
| 374 |
*/ |
| 375 |
public function as_setup_priorities(){ |
| 376 |
$support_priority = wpas_get_option( 'support_priority' ); |
| 377 |
?> |
| 378 |
<form method="post"> |
| 379 |
<p><b><?php esc_html_e( 'Would you like to use the priority field in your tickets?', 'awesome-support' ); ?> </b></p> |
| 380 |
<p><?php esc_html_e( 'Turn this option on if you would like to assign priorities to your tickets.', 'awesome-support' ); ?> </p> |
| 381 |
<p><?php esc_html_e( 'After you have finished with the wizard you can configure your priority levels under TICKETS->PRIORITIES.', 'awesome-support' ); ?> </p> |
| 382 |
<p><?php esc_html_e( 'You can also tweak how priorities work by changing settings under the TICKETS->SETTINGS->FIELDS tab.', 'awesome-support' ); ?> </p> |
| 383 |
<label for='property_field_yes'>Yes</label> |
| 384 |
<input type="radio" name="property_field" id='property_field_yes' value="yes" checked /> |
| 385 |
<label for='property_field_no'>No</label> |
| 386 |
<input type="radio" name="property_field" id='property_field_no' value="no"/> |
| 387 |
<input type="submit" name="save_step" value="Continue"> |
| 388 |
<?php wp_nonce_field( 'as-setup' ); ?> |
| 389 |
</form> |
| 390 |
<?php |
| 391 |
} |
| 392 |
|
| 393 |
/** |
| 394 |
* Awesome Support priorities setup on save. |
| 395 |
*/ |
| 396 |
public function as_setup_priorities_save(){ |
| 397 |
check_admin_referer( 'as-setup' ); |
| 398 |
$property_field = (isset( $_POST['property_field'] ) )? sanitize_text_field( wp_unslash( $_POST['property_field'] ) ): ''; |
| 399 |
|
| 400 |
$raw_options = get_option( 'wpas_options', array() ); |
| 401 |
if ( is_serialized( $raw_options ) ) { |
| 402 |
$options = @unserialize( $raw_options, ['allowed_classes' => false] ); |
| 403 |
if ( ! is_array( $options ) ) { |
| 404 |
$options = array(); |
| 405 |
} |
| 406 |
} elseif ( is_array( $raw_options ) ) { |
| 407 |
$options = $raw_options; |
| 408 |
} else { |
| 409 |
$options = array(); |
| 410 |
} |
| 411 |
|
| 412 |
if ( ! empty( $options ) ){ |
| 413 |
|
| 414 |
if( !empty( $property_field ) && 'yes' === $property_field ){ |
| 415 |
$options['support_priority'] = '1'; |
| 416 |
} else{ |
| 417 |
$options['support_priority'] = 0; |
| 418 |
} |
| 419 |
update_option( 'wpas_options', serialize( $options ) ); |
| 420 |
} |
| 421 |
|
| 422 |
wp_safe_redirect( esc_url_raw( $this->get_next_step_link() ) ); |
| 423 |
} |
| 424 |
|
| 425 |
/** |
| 426 |
* Awesome Support ticket submit allowed roles setup view. |
| 427 |
*/ |
| 428 |
public function as_setup_ticket_submit_user_roles(){ |
| 429 |
|
| 430 |
?> |
| 431 |
<form method="post"> |
| 432 |
|
| 433 |
<h2><?php esc_html_e( 'Important! How do you want to handle your existing users?', 'awesome-support' ); ?></h2> |
| 434 |
<p><em><?php esc_html_e( 'By default, none of your existing users will be allowed to submit ticket. However, you can adjust this based on your existing user roles.', 'awesome-support' ); ?></em></p> |
| 435 |
<p><b><?php esc_html_e( 'Any of the user roles you check below will automatically be allowed to submit tickets.', 'awesome-support' ); ?></b> |
| 436 |
<span><em><?php esc_html_e( ' If you do not choose any roles then only new users will be allowed to submit tickets! If this is a new installation of WordPress with no existing users then you can just skip to the next step by clicking the CONTINUE button. ', 'awesome-support' ); ?></em></span> |
| 437 |
</p> |
| 438 |
|
| 439 |
<?php |
| 440 |
|
| 441 |
$all_roles = get_editable_roles(); |
| 442 |
|
| 443 |
$skip_roles = array( |
| 444 |
'wpas_manager', |
| 445 |
'wpas_support_manager', |
| 446 |
'wpas_agent', |
| 447 |
'wpas_user' |
| 448 |
); |
| 449 |
|
| 450 |
foreach( $all_roles as $r_name => $r ) { |
| 451 |
if( !in_array( $r_name, $skip_roles ) ) { |
| 452 |
printf( '<label><input type="checkbox" name="roles[]" value="%s" /> %s</label><br />', esc_attr( $r_name ), esc_html( $r['name'] ) ); |
| 453 |
} |
| 454 |
} |
| 455 |
|
| 456 |
?> |
| 457 |
<br /> |
| 458 |
<input type="submit" name="save_step" value="Continue"> |
| 459 |
<?php wp_nonce_field( 'as-setup' ); ?> |
| 460 |
</form> |
| 461 |
<?php |
| 462 |
} |
| 463 |
|
| 464 |
/** |
| 465 |
* Awesome Support ticket submit allowed roles setup on save. |
| 466 |
*/ |
| 467 |
public function as_setup_ticket_submit_user_roles_save(){ |
| 468 |
|
| 469 |
check_admin_referer( 'as-setup' ); |
| 470 |
|
| 471 |
$selected_roles = filter_input( INPUT_POST, 'roles' , FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
| 472 |
|
| 473 |
$selected_roles = $selected_roles && is_array( $selected_roles ) ? $selected_roles : array(); |
| 474 |
|
| 475 |
$capabilities = array( |
| 476 |
'view_ticket', |
| 477 |
'create_ticket', |
| 478 |
'close_ticket', |
| 479 |
'reply_ticket', |
| 480 |
'attach_files' |
| 481 |
); |
| 482 |
|
| 483 |
foreach( $selected_roles as $role_name ) { |
| 484 |
$role = get_role( $role_name ); |
| 485 |
|
| 486 |
foreach ( $capabilities as $capability ) { |
| 487 |
$role->add_cap( $capability ); |
| 488 |
} |
| 489 |
|
| 490 |
} |
| 491 |
|
| 492 |
// Don't show setup wizard link on plug-in activation. |
| 493 |
update_option('wpas_plugin_setup', 'done'); |
| 494 |
|
| 495 |
wp_safe_redirect( esc_url_raw( $this->get_next_step_link() ) ); |
| 496 |
} |
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
/** |
| 501 |
* Awesome Support departments setup view. |
| 502 |
*/ |
| 503 |
public function as_setup_departments(){ |
| 504 |
$departments = wpas_get_option( 'departments' ); |
| 505 |
?> |
| 506 |
<form method="post"> |
| 507 |
<p><b><?php esc_html_e( 'Do you want to enable Departments?', 'awesome-support' );?> </b></p> |
| 508 |
<p><?php esc_html_e( 'Turn this option on if you would like to assign departments to your tickets.', 'awesome-support' );?> </p> |
| 509 |
<p><?php esc_html_e( 'Once enabled, you can configure your list of departments by going to TICKETS->DEPARTMENTS.', 'awesome-support' );?> </p> |
| 510 |
<p><?php esc_html_e( 'You can turn this off later if you change your mind by going to the TICKETS->SETTINGS->FIELDS tab.', 'awesome-support' );?> </p> |
| 511 |
<label for='departments_field_yes'>Yes</label> |
| 512 |
<input type="radio" name="departments_field" id='departments_field_yes' value="yes" checked /> |
| 513 |
<label for='departments_field_no'>No</label> |
| 514 |
<input type="radio" name="departments_field" id='departments_field_no' value="no"/> |
| 515 |
<input type="submit" name="save_step" value="Continue"> |
| 516 |
<?php wp_nonce_field( 'as-setup' ); ?> |
| 517 |
</form> |
| 518 |
<?php |
| 519 |
} |
| 520 |
|
| 521 |
/** |
| 522 |
* Awesome Support departments setup on save. |
| 523 |
*/ |
| 524 |
public function as_setup_departments_save(){ |
| 525 |
check_admin_referer( 'as-setup' ); |
| 526 |
$departments_field = (isset( $_POST['departments_field'] ) )? sanitize_text_field( wp_unslash( $_POST['departments_field'] ) ): ''; |
| 527 |
|
| 528 |
//Safely retrieve and unserialize options |
| 529 |
$raw_options = get_option( 'wpas_options', array() ); |
| 530 |
if ( is_serialized( $raw_options ) ) { |
| 531 |
$options = @unserialize( $raw_options, ['allowed_classes' => false] ); |
| 532 |
} elseif ( is_array( $raw_options ) ) { |
| 533 |
$options = $raw_options; |
| 534 |
} else { |
| 535 |
$options = array(); |
| 536 |
} |
| 537 |
if ( ! empty( $options ) ) { |
| 538 |
if( !empty( $departments_field ) && 'yes' === $departments_field ){ |
| 539 |
$options['departments'] = '1'; |
| 540 |
} else{ |
| 541 |
$options['departments'] = '0'; |
| 542 |
} |
| 543 |
update_option( 'wpas_options', serialize( $options ) ); |
| 544 |
} |
| 545 |
// Don't show setup wizard link on plug-in activation. |
| 546 |
update_option('wpas_plugin_setup', 'done'); |
| 547 |
wp_safe_redirect( esc_url_raw( $this->get_next_step_link() ) ); |
| 548 |
} |
| 549 |
|
| 550 |
/** |
| 551 |
* Lets Go page view for think you message and all. |
| 552 |
*/ |
| 553 |
public function as_setup_lets_go(){ |
| 554 |
|
| 555 |
// translators: %1$s are additional attributes for the link to the article. |
| 556 |
$x_content = __( 'If so, you will want to read <b><u><a %1$s>this article</a></b></u> on our website.', 'awesome-support' ); |
| 557 |
|
| 558 |
?> |
| 559 |
<form method="post"> |
| 560 |
<p><b><?php esc_html_e( "Your new support system is all set up and ready to go!", "awesome-support" ); ?></b></p> |
| 561 |
<p><?php esc_html_e( "If your menus are active in your theme your users will now able to register for an account and submit tickets.", "awesome-support" ); ?></p> |
| 562 |
<p><b><?php esc_html_e( "Do you have existing users in your WordPress System?", "awesome-support" ); ?></b></p> |
| 563 |
<p><?php |
| 564 |
echo sprintf( wp_kses_post( $x_content ), 'href="https://getawesomesupport.com/documentation/awesome-support/admin-handling-existing-users-after-installation/" target="_blank" ' ); |
| 565 |
?></p> |
| 566 |
<p><b><?php esc_html_e( "Where are my support tickets?", "awesome-support" ); ?></b></p> |
| 567 |
<p><?php esc_html_e( "You can now access your support tickets and other support options under the new TICKETS menu option.", "awesome-support" ); ?></p> |
| 568 |
<input type="submit" name="save_step" value="Let's Go"> |
| 569 |
<?php wp_nonce_field( 'as-setup' ); ?> |
| 570 |
</form> |
| 571 |
<?php |
| 572 |
} |
| 573 |
|
| 574 |
/** |
| 575 |
* Lets Go button click |
| 576 |
*/ |
| 577 |
public function as_setup_lets_go_save(){ |
| 578 |
wp_redirect( add_query_arg( array( 'post_type' => 'ticket', 'page' => 'wpas-about' ), admin_url( 'edit.php' ) ) ); |
| 579 |
exit; |
| 580 |
} |
| 581 |
|
| 582 |
/** |
| 583 |
* Get the URL for the next step's screen. |
| 584 |
* |
| 585 |
* @param string $step slug (default: current step). |
| 586 |
* @return string URL for next step if a next step exists. |
| 587 |
* Admin URL if it's the last step. |
| 588 |
* Empty string on failure. |
| 589 |
*/ |
| 590 |
public function get_next_step_link( $step = '' ) { |
| 591 |
if ( ! $step ) { |
| 592 |
$step = $this->step; |
| 593 |
} |
| 594 |
|
| 595 |
$keys = array_keys( $this->steps ); |
| 596 |
if ( end( $keys ) === $step ) { |
| 597 |
return admin_url(); |
| 598 |
} |
| 599 |
|
| 600 |
$step_index = array_search( $step, $keys, true ); |
| 601 |
if ( false === $step_index ) { |
| 602 |
return ''; |
| 603 |
} |
| 604 |
|
| 605 |
return add_query_arg( 'step', $keys[ $step_index + 1 ], remove_query_arg( 'activate_error' ) ); |
| 606 |
} |
| 607 |
|
| 608 |
} |
| 609 |
new AS_Admin_Setup_Wizard(); |
| 610 |
|