| 1 |
<?php |
| 2 |
if( ! class_exists( 'BetterDocsSetupWizard' ) ){ |
| 3 |
class BetterDocsSetupWizard { |
| 4 |
public static $sections_array = array(); |
| 5 |
public static $optionGroupName = 'betterdocs_settings'; |
| 6 |
public static function load(){ |
| 7 |
// Menu. |
| 8 |
// add_action( 'admin_menu', array( __CLASS__, 'admin_menu' ) ); |
| 9 |
|
| 10 |
// tab builder |
| 11 |
add_action( 'admin_enqueue_scripts', array(__CLASS__, 'setup_wizard_scripts'), 30 ); |
| 12 |
add_action('betterdocs_nav_tabs', array(__CLASS__, 'add_nav_tabs')); |
| 13 |
add_action('betterdocs_tabs_content', array(__CLASS__, 'add_tab_content')); |
| 14 |
// ajax request |
| 15 |
add_action( 'wp_ajax_better_docs_quick_setup_wizard_data_save', array(__CLASS__, 'better_docs_quick_setup_wizard_data_save') ); |
| 16 |
// ajax url change |
| 17 |
add_action( 'wp_ajax_better_docs_setup_generate_live_url', array(__CLASS__, 'better_docs_setup_generate_live_url') ); |
| 18 |
} |
| 19 |
|
| 20 |
public static function setup_wizard_scripts(){ |
| 21 |
wp_enqueue_style( 'betterdocs-setup-wizard', BETTERDOCS_ADMIN_URL . 'setup-wizard/assets/css/betterdocs-setup-wizard.css' ); |
| 22 |
$BetterDocsQswVersionNumber = date("ymd-Gis", filemtime( BETTERDOCS_ADMIN_DIR_PATH . 'setup-wizard/assets/js/betterdocs-setup-wizard.js' )); |
| 23 |
wp_enqueue_script( 'betterdocs-setup-wizard', BETTERDOCS_ADMIN_URL . 'setup-wizard/assets/js/betterdocs-setup-wizard.js', array('jquery'), $BetterDocsQswVersionNumber, false ); |
| 24 |
|
| 25 |
// Localize the script with new data |
| 26 |
|
| 27 |
wp_localize_script( 'betterdocs-setup-wizard', 'bdquicksetup', array( |
| 28 |
'finish_txt' => __('Finish', 'betterdocs'), |
| 29 |
'next_txt' => __('Next', 'betterdocs'), |
| 30 |
'customizerurl' => betterdocs_setup_get_customizer_setting_url(), |
| 31 |
'docspageurl' => betterdocs_setup_docs_page_url(), |
| 32 |
'currentslug' => BetterDocs_DB::get_settings('docs_slug'), |
| 33 |
)); |
| 34 |
} |
| 35 |
|
| 36 |
// add admin page |
| 37 |
public static function admin_menu() { |
| 38 |
add_submenu_page( |
| 39 |
null, |
| 40 |
'Better Docs Setup', |
| 41 |
'Better Docs Setup', |
| 42 |
'manage_options', |
| 43 |
'betterdocs-setup', |
| 44 |
array( __CLASS__, 'plugin_setting_page' ) |
| 45 |
); |
| 46 |
} |
| 47 |
|
| 48 |
// add admin page |
| 49 |
public static function knowledge_base_plugins() { |
| 50 |
include_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
| 51 |
$plugins = array(); |
| 52 |
if (is_plugin_active('wedocs/wedocs.php')) { |
| 53 |
$plugins[] = array('wedocs', 'weDocs'); |
| 54 |
} |
| 55 |
if (is_plugin_active('bsf-docs/bsf-docs.php')) { |
| 56 |
$plugins[] = array('bsf-docs', 'BSF docs'); |
| 57 |
} |
| 58 |
if (is_plugin_active('documentor-lite/documentor-lite.php')) { |
| 59 |
$plugins[] = array('documentor-lite', 'Documentor'); |
| 60 |
} |
| 61 |
if (is_plugin_active('echo-knowledge-base/echo-knowledge-base.php')) { |
| 62 |
$plugins[] = array('echo-knowledge-base', 'Echo Knowledge Base'); |
| 63 |
} |
| 64 |
if (is_plugin_active('pressapps-knowledge-base/pressapps-knowledge-base.php')) { |
| 65 |
$plugins[] = array('pressapps-knowledge-base', 'PressApps Knowledge Base'); |
| 66 |
} |
| 67 |
return $plugins; |
| 68 |
} |
| 69 |
|
| 70 |
// add admin page |
| 71 |
public static function existing_plugins_data($plugins) { |
| 72 |
$plugins_data = array(); |
| 73 |
if ($plugins === 'wedocs') { |
| 74 |
$plugins_data['name'] = 'wedocs'; |
| 75 |
$plugins_data['url'] = 'wedocs/wedocs.php'; |
| 76 |
} |
| 77 |
if ($plugins === 'bsf-docs') { |
| 78 |
$plugins_data['name'] = 'bsf-docs'; |
| 79 |
$plugins_data['url'] = 'bsf-docs/bsf-docs.php'; |
| 80 |
} |
| 81 |
if ($plugins === 'documentor-lite') { |
| 82 |
$plugins_data['name'] = 'documentor-lite'; |
| 83 |
$plugins_data['url'] = 'documentor-lite/documentor-lite.php'; |
| 84 |
} |
| 85 |
if ($plugins === 'echo-knowledge-base') { |
| 86 |
$plugins_data['name'] = 'echo-knowledge-base'; |
| 87 |
$plugins_data['url'] = 'echo-knowledge-base/echo-knowledge-base.php'; |
| 88 |
} |
| 89 |
if ($plugins === 'pressapps-knowledge-base') { |
| 90 |
$plugins_data['name'] = 'pressapps-knowledge-base'; |
| 91 |
$plugins_data['url'] = 'pressapps-knowledge-base/pressapps-knowledge-base.php'; |
| 92 |
} |
| 93 |
return $plugins_data; |
| 94 |
} |
| 95 |
|
| 96 |
public static function insert_terms_hierarchically($existing_term, $new_term, $parentId = 0) { |
| 97 |
$into = array(); |
| 98 |
$cats = get_terms($existing_term, array('hide_empty' => false)); |
| 99 |
if ($cats) { |
| 100 |
foreach ($cats as $i => $cat) { |
| 101 |
if ($cat->parent == $parentId) { |
| 102 |
$into[$cat->term_id] = $cat; |
| 103 |
unset($cats[$i]); |
| 104 |
$doc_parent_term = term_exists( $cat->name, $new_term ); |
| 105 |
wp_insert_term ( |
| 106 |
$cat->name, |
| 107 |
$new_term, |
| 108 |
array( |
| 109 |
'alias_of' => $cat->slug, |
| 110 |
'description' => $cat->description, |
| 111 |
'slug' => $cat->slug, |
| 112 |
'parent' => $cat->parent, |
| 113 |
) |
| 114 |
); |
| 115 |
} |
| 116 |
} |
| 117 |
if ($cats) { |
| 118 |
foreach ($cats as $i => $cat) { |
| 119 |
$get_existing_term = get_term_by('id', $cat->parent, $existing_term); |
| 120 |
$doc_parent_term = term_exists( $get_existing_term->name, $new_term ); |
| 121 |
wp_insert_term ( |
| 122 |
$cat->name, |
| 123 |
$new_term, |
| 124 |
array( |
| 125 |
'alias_of' => $cat->slug, |
| 126 |
'description' => $cat->description, |
| 127 |
'slug' => $cat->slug, |
| 128 |
'parent' => $doc_parent_term['term_id'], |
| 129 |
) |
| 130 |
); |
| 131 |
} |
| 132 |
} |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
public static function insert_posts($existing_post, $existing_cat, $existing_tag) { |
| 137 |
$args = array( |
| 138 |
'post_type' => $existing_post, |
| 139 |
'post_status' => 'any', |
| 140 |
'posts_per_page' => -1 |
| 141 |
); |
| 142 |
$postslist = get_posts( $args ); |
| 143 |
if($postslist) { |
| 144 |
foreach ($postslist as $post) { |
| 145 |
// Create post object |
| 146 |
if (!get_page_by_title($post->post_title, 'OBJECT', 'docs') ){ |
| 147 |
$post_args = array( |
| 148 |
'post_type' => 'docs', |
| 149 |
'post_title' => $post->post_title, |
| 150 |
'post_content' => $post->post_content, |
| 151 |
'post_status' => $post->post_status, |
| 152 |
'post_author' => $post->post_author, |
| 153 |
'post_date' => $post->post_date, |
| 154 |
'post_date_gmt' => $post->post_date_gmt, |
| 155 |
'post_excerpt' => $post->post_excerpt, |
| 156 |
'comment_status' => $post->comment_status, |
| 157 |
'ping_status' => $post->ping_status, |
| 158 |
'post_password' => $post->post_password, |
| 159 |
'post_name' => $post->post_name, |
| 160 |
'to_ping' => $post->to_ping, |
| 161 |
'pinged' => $post->pinged, |
| 162 |
'post_modified' => $post->post_modified, |
| 163 |
'post_modified_gmt' => $post->post_modified_gmt, |
| 164 |
'post_content_filtered' => $post->post_content_filtered, |
| 165 |
'post_parent' => $post->post_parent, |
| 166 |
'post_mime_type' => $post->post_mime_type, |
| 167 |
'comment_count' => $post->comment_count, |
| 168 |
'filter' => $post->filter, |
| 169 |
); |
| 170 |
// Insert the post into the database |
| 171 |
$result = wp_insert_post( $post_args ); |
| 172 |
if ( $result && ! is_wp_error( $result ) ) { |
| 173 |
$cat_list = wp_get_post_terms($post->ID, $existing_cat, array('fields' => 'all')); |
| 174 |
if($cat_list) { |
| 175 |
$post_id = $result; |
| 176 |
wp_set_object_terms( $post_id, array($cat_list['0']->name), 'doc_category', false ); |
| 177 |
} |
| 178 |
$tag_list = wp_get_post_terms($post->ID, $existing_tag, array('fields' => 'all')); |
| 179 |
if($tag_list) { |
| 180 |
$post_id = $result; |
| 181 |
wp_set_object_terms( $post_id, array($tag_list['0']->name), 'doc_tag', false ); |
| 182 |
} |
| 183 |
} |
| 184 |
} |
| 185 |
} |
| 186 |
} |
| 187 |
} |
| 188 |
|
| 189 |
public static function eco_knowledgerbase_migration() { |
| 190 |
self::insert_terms_hierarchically('epkb_post_type_1_category', 'doc_category'); |
| 191 |
self::insert_terms_hierarchically('epkb_post_type_1_tag', 'doc_tag'); |
| 192 |
self::insert_posts('epkb_post_type_1', 'epkb_post_type_1_category', 'epkb_post_type_1_tag'); |
| 193 |
} |
| 194 |
|
| 195 |
public static function pressapps_migration() { |
| 196 |
self::insert_terms_hierarchically('knowledgebase_category', 'doc_category'); |
| 197 |
self::insert_terms_hierarchically('knowledgebase_tags', 'doc_tag'); |
| 198 |
self::insert_posts('knowledgebase', 'knowledgebase_category', 'knowledgebase_tags'); |
| 199 |
} |
| 200 |
|
| 201 |
public static function better_docs_quick_setup_wizard_data_save() { |
| 202 |
check_ajax_referer( 'betterdocsqswnonce', 'security'); |
| 203 |
$oldValue = get_option( self::$optionGroupName, true ); |
| 204 |
|
| 205 |
// duplicate existing plugin data and deactivate |
| 206 |
if(isset($_POST['activate_plugin'])) { |
| 207 |
$existing_plugins_data = self::existing_plugins_data($_POST['activate_plugin']); |
| 208 |
if ( $existing_plugins_data['name'] === 'echo-knowledge-base' ) { |
| 209 |
self::eco_knowledgerbase_migration(); |
| 210 |
} elseif ( $existing_plugins_data['name'] === 'pressapps-knowledge-base' ) { |
| 211 |
self::pressapps_migration(); |
| 212 |
} |
| 213 |
deactivate_plugins( $existing_plugins_data['url'] ); |
| 214 |
} |
| 215 |
$newValue['builtin_doc_page'] = (isset($_POST['builtin_doc_page']) ? $_POST['builtin_doc_page'] : 'off'); |
| 216 |
$newValue['docs_slug'] = (isset($_POST['docs_slug']) ? $_POST['docs_slug'] : 'docs'); |
| 217 |
$newValue['enable_disable'] = (isset($_POST['enable_disable']) ? $_POST['enable_disable'] : 'off'); |
| 218 |
// new update value |
| 219 |
$updatedValue = array_merge($oldValue, $newValue); |
| 220 |
if(!get_option(self::$optionGroupName)) { |
| 221 |
add_option(self::$optionGroupName, $updatedValue); |
| 222 |
} else { |
| 223 |
update_option(self::$optionGroupName, $updatedValue); |
| 224 |
} |
| 225 |
wp_die(); // this is required to terminate immediately and return a proper response |
| 226 |
} |
| 227 |
|
| 228 |
public static function better_docs_setup_generate_live_url(){ |
| 229 |
$query = []; |
| 230 |
$query['autofocus[panel]'] = 'betterdocs_customize_options'; |
| 231 |
$query['return'] = admin_url( 'edit.php?post_type=docs' ); |
| 232 |
$docs_slug = (isset($_POST['docs_slug']) ? $_POST['docs_slug'] : null); |
| 233 |
if($docs_slug){ |
| 234 |
$query['url'] = site_url( '/'.$docs_slug ); |
| 235 |
} |
| 236 |
$customizer_link = add_query_arg( $query, admin_url( 'customize.php' ) ); |
| 237 |
|
| 238 |
|
| 239 |
$result = array( |
| 240 |
'customizerurl' => $customizer_link, |
| 241 |
'siteurl' => esc_url( site_url( '/'.$docs_slug ) ) |
| 242 |
); |
| 243 |
print json_encode( $result); |
| 244 |
wp_die(); |
| 245 |
} |
| 246 |
|
| 247 |
public static function plugin_setting_page() { |
| 248 |
?> |
| 249 |
<div id="wpwrap"> |
| 250 |
<div class="betterdocs-settings-wrap"> |
| 251 |
<div class="betterdocs-topbar-logo text-center"> |
| 252 |
<img width="150" src="<?php print esc_url( BETTERDOCS_ADMIN_URL . 'assets/img/betterdocs-logo.svg'); ?>" alt="logo"> |
| 253 |
</div> |
| 254 |
<!-- setup wizard --> |
| 255 |
<div class="betterdocs-setup-wizard"> |
| 256 |
<form method="post" action="#"> |
| 257 |
<input type="hidden" name="betterdocsqswnonce" value="<?php print wp_create_nonce( 'betterdocsqswnonce' ); ?>"> |
| 258 |
<div class="betterdocs-tabnav-wrap"> |
| 259 |
<ul class="tab-nav"> |
| 260 |
<?php do_action('betterdocs_nav_tabs'); ?> |
| 261 |
</ul> |
| 262 |
</div> |
| 263 |
<div class="betterdocs-tab-content-wrap"> |
| 264 |
<?php |
| 265 |
do_action('betterdocs_tabs_content'); |
| 266 |
?> |
| 267 |
<div class="betterdocs-button-wrap"> |
| 268 |
<a id="betterdocs-prev-option" href="#" class="btn betterdocs-prev-option"><?php esc_html_e('Previous', 'betterdocs'); ?></a> |
| 269 |
<a id="betterdocs-next-option" href="#" class="btn betterdocs-next-option"><?php esc_html_e('Next', 'betterdocs'); ?></a> |
| 270 |
</div> |
| 271 |
<div class="bottom-notice-left"> |
| 272 |
<p class="whatwecollecttext"><?php esc_html_e('We collect non-sensitive diagnostic data and plugin usage information. Your site URL, WordPress & PHP version, plugins & themes and email address to send you the discount coupon. This data lets us make sure this plugin always stays compatible with the most popular plugins and themes. No spam, we promise.', 'betterdocs') ?></p> |
| 273 |
<button type="button" class="btn-collect"><?php esc_html_e('What We Collect?', 'betterdocs'); ?></button> |
| 274 |
</div> |
| 275 |
<div class="bottom-notice"> |
| 276 |
<button type="button" id="betterdocsqswemailskipbutton" class="btn-skip"><?php esc_html_e('Skip This Step', 'betterdocs'); ?></button> |
| 277 |
</div> |
| 278 |
</div> |
| 279 |
</form> |
| 280 |
</div> |
| 281 |
</div> |
| 282 |
</div> |
| 283 |
<?php |
| 284 |
} |
| 285 |
|
| 286 |
public static function setSection( $section ){ |
| 287 |
// Bail if not array. |
| 288 |
if ( ! is_array( $section ) ) { |
| 289 |
return false; |
| 290 |
} |
| 291 |
|
| 292 |
self::$sections_array[$section['id']] = $section; |
| 293 |
|
| 294 |
// Assign to the sections array |
| 295 |
return self::$sections_array; |
| 296 |
} |
| 297 |
|
| 298 |
public static function get_value($args){ |
| 299 |
if($args == null || $args == ''){ |
| 300 |
return; |
| 301 |
} |
| 302 |
$optionValue = get_option( self::$optionGroupName ) ; |
| 303 |
if(isset($optionValue[$args['id']])) { |
| 304 |
return $optionValue[$args['id']]; |
| 305 |
}else if(isset($args['default'])){ |
| 306 |
return $args['default']; |
| 307 |
} |
| 308 |
return; |
| 309 |
} |
| 310 |
|
| 311 |
public static function get_field_description($args){ |
| 312 |
if ( ! empty( $args['desc'] ) ) { |
| 313 |
$desc = sprintf( '<p class="description">%s</p>', $args['desc'] ); |
| 314 |
} else { |
| 315 |
$desc = ''; |
| 316 |
} |
| 317 |
|
| 318 |
return $desc; |
| 319 |
} |
| 320 |
|
| 321 |
/** |
| 322 |
* Fields Type: Text |
| 323 |
* @param array |
| 324 |
* @return Markup |
| 325 |
*/ |
| 326 |
public static function callback_text($args) { |
| 327 |
$value = esc_attr( self::get_value($args) ); |
| 328 |
$size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular'; |
| 329 |
$type = isset( $args['type'] ) ? $args['type'] : 'text'; |
| 330 |
$field = ''; |
| 331 |
$markup = ''; |
| 332 |
$field = sprintf( '<input type="%1$s" class="%2$s-text" name="%3$s" value="%4$s" placeholder="%5$s"/>', $type, $size, $args['id'], $value, $args['placeholder'] ); |
| 333 |
$field .= self::get_field_description( $args ); |
| 334 |
$markup .= '<tr> |
| 335 |
<th scope="row"> |
| 336 |
<label for="'.$args['id'].'">'.$args['title'].'</label> |
| 337 |
</th> |
| 338 |
<td> |
| 339 |
'.$field.' |
| 340 |
</td> |
| 341 |
</tr>'; |
| 342 |
echo $markup; |
| 343 |
} |
| 344 |
|
| 345 |
/** |
| 346 |
* Fields Type: textarea |
| 347 |
* @param array |
| 348 |
* @return Markup |
| 349 |
*/ |
| 350 |
public static function callback_textarea( $args ) { |
| 351 |
$value = esc_textarea( self::get_value($args) ); |
| 352 |
$size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular'; |
| 353 |
$field = ''; |
| 354 |
$markup = ''; |
| 355 |
$field = sprintf( '<textarea rows="5" cols="55" class="%1$s-text" id="%2$s" name="%3$s" placeholder="%4$s">%5$s</textarea>', $size, $args['id'], $args['id'], $args['placeholder'], $value ); |
| 356 |
$field .= self::get_field_description( $args ); |
| 357 |
$markup .= '<tr> |
| 358 |
<th scope="row"> |
| 359 |
<label for="'.$args['id'].'">'.$args['title'].'</label> |
| 360 |
</th> |
| 361 |
<td> |
| 362 |
'.$field.' |
| 363 |
</td> |
| 364 |
</tr>'; |
| 365 |
echo $markup; |
| 366 |
} |
| 367 |
|
| 368 |
/** |
| 369 |
* Fields Type: checkbox |
| 370 |
* @param array |
| 371 |
* @return Markup |
| 372 |
*/ |
| 373 |
public static function callback_checkbox_pro_feature( $args ) { |
| 374 |
$value = self::get_value($args); |
| 375 |
$field = ''; |
| 376 |
$markup = ''; |
| 377 |
$field = sprintf( '<input class="%1$s-checkbox" id="%1$s" name="%1$s" type="checkbox" %3$s>', $args['id'], 1, checked( 1, $value, false ) ); |
| 378 |
$field .= self::get_field_description( $args ); |
| 379 |
$markup .= '<tr> |
| 380 |
<th scope="row"> |
| 381 |
<label for="'.$args['id'].'">'.$args['title'].'</label> |
| 382 |
</th> |
| 383 |
<td>'; |
| 384 |
if(!class_exists('Betterdocs_Pro')) { |
| 385 |
$markup .='<div class="betterdocs-checkbox betterdocs-pro-feature-checkbox" data-id="instant_answer"> |
| 386 |
<input disabled="" type="checkbox" id="instant_answer" name="instant_answer"> |
| 387 |
<label for="instant_answer"></label> |
| 388 |
<p class="betterdocs-module-title">Instant Answer |
| 389 |
<sup class="betterdocs-pro-label has-to-update"></sup><sup class="betterdocs-pro-label">Pro</sup> |
| 390 |
</p> |
| 391 |
</div>'; |
| 392 |
} else { |
| 393 |
$markup .= $field; |
| 394 |
} |
| 395 |
$markup .='</td> |
| 396 |
</tr>'; |
| 397 |
echo $markup; |
| 398 |
} |
| 399 |
|
| 400 |
/** |
| 401 |
* Fields Type: link |
| 402 |
* @param array |
| 403 |
* @return Markup |
| 404 |
*/ |
| 405 |
public static function callback_link( $args ) { |
| 406 |
$value = self::get_value($args); |
| 407 |
$field = ''; |
| 408 |
$markup = ''; |
| 409 |
$field = sprintf( '<input class="%1$s-checkbox" id="%1$s" name="%1$s" type="checkbox" %3$s>', $args['id'], 1, checked( 1, $value, false ) ); |
| 410 |
$field .= self::get_field_description( $args ); |
| 411 |
$markup .= '<tr class="text-center"> |
| 412 |
<td colspan="2"> |
| 413 |
<h2 class="bd-sw-title">'.(isset($args['title']) ? $args['title'] : '').'</h2> |
| 414 |
<p class="bd-sw-sub-title">'.(isset($args['sub_title']) ? $args['sub_title'] : '').'</p> |
| 415 |
</td> |
| 416 |
</tr> |
| 417 |
<tr> |
| 418 |
<td> |
| 419 |
<ul class="betterdocs-setup-feature-list">'; |
| 420 |
if(is_array($args['options'])){ |
| 421 |
foreach($args['options'] as $item){ |
| 422 |
$markup .='<li> |
| 423 |
<div class="bd-media-left"><span><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" fill="#37de89" width="40px"><path d="M 21.1875 9.28125 L 19.78125 10.71875 L 24.0625 15 L 4 15 L 4 17 L 24.0625 17 L 19.78125 21.28125 L 21.1875 22.71875 L 27.90625 16 Z"></path></svg></span></div> |
| 424 |
<div class="bd-media-body"> |
| 425 |
<h4><a href="'.esc_url($item['url']).'" target="_blank">'.(isset($item['feature_title']) ? $item['feature_title'] : '').'</a></h4> |
| 426 |
<p>'.(isset($item['feature_content']) ? $item['feature_content'] : '').'</p> |
| 427 |
<a '.(isset($item['id']) ? 'id="'.$item['id'].'"' : '' ).' href="'.esc_url($item['url']).'" class="btn-setup-wizard" target="_blank">'.$item['title'].'</a> |
| 428 |
</div> |
| 429 |
</li>'; |
| 430 |
} |
| 431 |
} |
| 432 |
$markup .='</ul> |
| 433 |
</td> |
| 434 |
<td> |
| 435 |
<img src="'.(isset($args['image_url']) ? esc_url($args['image_url']) : '').'" /> |
| 436 |
</td> |
| 437 |
</tr>'; |
| 438 |
echo $markup; |
| 439 |
} |
| 440 |
/** |
| 441 |
* Fields Type: link |
| 442 |
* @param array |
| 443 |
* @return Markup |
| 444 |
*/ |
| 445 |
public static function callback_final_step( $args ) { |
| 446 |
$value = self::get_value($args); |
| 447 |
$field = ''; |
| 448 |
$markup = ''; |
| 449 |
$field = sprintf( '<input class="%1$s-checkbox" id="%1$s" name="%1$s" type="checkbox" %3$s>', $args['id'], 1, checked( 1, $value, false ) ); |
| 450 |
$field .= self::get_field_description( $args ); |
| 451 |
$markup .= '<tr class="text-center"> |
| 452 |
<td colspan="2">'; |
| 453 |
if(isset($args['image_url'])){ |
| 454 |
$markup .= '<img src="'.(isset($args['image_url']) ? $args['image_url'] : '').'" alt="" />'; |
| 455 |
} |
| 456 |
$markup .='<h2 class="bd-sw-title">'.(isset($args['title']) ? $args['title'] : '').'</h2> |
| 457 |
<p class="bd-sw-sub-title">'.(isset($args['sub_title']) ? $args['sub_title'] : '').'</p> |
| 458 |
</td> |
| 459 |
</tr> |
| 460 |
<tr class="text-center"> |
| 461 |
<td>'; |
| 462 |
foreach($args['options'] as $item){ |
| 463 |
$markup .='<a '.(isset($item['id']) ? 'id="'.$item['id'].'"' : '' ).' href="'.esc_url($item['url']).'" class="btn-setup-wizard" target="_blank">'.$item['title'].'</a>'; |
| 464 |
} |
| 465 |
$markup .='</td> |
| 466 |
</tr>'; |
| 467 |
echo $markup; |
| 468 |
} |
| 469 |
|
| 470 |
/** |
| 471 |
* Fields Type: link |
| 472 |
* @param array |
| 473 |
* @return Markup |
| 474 |
*/ |
| 475 |
public static function callback_migration( $args ) { |
| 476 |
$field = ''; |
| 477 |
$markup = ''; |
| 478 |
$markup .= '<tr class="text-center"> |
| 479 |
<td colspan="2">'; |
| 480 |
$markup .='<p class="bd-sw-sub-title">'.(isset($args['sub_title']) ? $args['sub_title'] : '').'</p> |
| 481 |
</td> |
| 482 |
</tr>'; |
| 483 |
|
| 484 |
foreach($args['options'] as $item){ |
| 485 |
$field = sprintf( '<input class="%1$s-checkbox activate_plugin" id="%1$s" name="activate_plugin" type="checkbox" value="%1$s" %2$s>', $item['id'], checked( 1, $item['default'], false ) ); |
| 486 |
$markup .= '<tr> |
| 487 |
<th scope="row"> |
| 488 |
<label for="'.$item['id'].'">'.$item['title'].'</label> |
| 489 |
</th> |
| 490 |
<td> |
| 491 |
'.$field.' |
| 492 |
</td> |
| 493 |
</tr>'; |
| 494 |
} |
| 495 |
echo $markup; |
| 496 |
} |
| 497 |
|
| 498 |
/** |
| 499 |
* Fields Type: checkbox |
| 500 |
* @param array |
| 501 |
* @return Markup |
| 502 |
*/ |
| 503 |
public static function callback_checkbox( $args ) { |
| 504 |
$value = self::get_value($args); |
| 505 |
$field = ''; |
| 506 |
$markup = ''; |
| 507 |
$field = sprintf( '<input class="%1$s-checkbox" id="%1$s" name="%1$s" type="checkbox" %3$s>', $args['id'], 1, checked( 1, $value, false ) ); |
| 508 |
$field .= self::get_field_description( $args ); |
| 509 |
$markup .= '<tr> |
| 510 |
<th scope="row"> |
| 511 |
<label for="'.$args['id'].'">'.$args['title'].'</label> |
| 512 |
</th> |
| 513 |
<td> |
| 514 |
'.$field.' |
| 515 |
</td> |
| 516 |
</tr>'; |
| 517 |
echo $markup; |
| 518 |
} |
| 519 |
|
| 520 |
/** |
| 521 |
* Fields Type: radio |
| 522 |
* @param array |
| 523 |
* @return Markup |
| 524 |
*/ |
| 525 |
public static function callback_radio( $args ) { |
| 526 |
$value = self::get_value($args); |
| 527 |
$field = ''; |
| 528 |
$markup = ''; |
| 529 |
if(is_array($args['options'])){ |
| 530 |
foreach($args['options'] as $key => $option){ |
| 531 |
$field .= sprintf( '<input class="%1$s-radio" type="radio" name="%1$s" value="%2$s" %4$s>%3$s', $args['id'], $key, $option, checked( $key, $value, false ) ); |
| 532 |
} |
| 533 |
} |
| 534 |
$field .= self::get_field_description( $args ); |
| 535 |
$markup .= '<tr> |
| 536 |
<th scope="row"> |
| 537 |
<label for="'.$args['id'].'">'.$args['title'].'</label> |
| 538 |
</th> |
| 539 |
<td> |
| 540 |
'.$field.' |
| 541 |
</td> |
| 542 |
</tr>'; |
| 543 |
echo $markup; |
| 544 |
} |
| 545 |
|
| 546 |
|
| 547 |
public static function callback_select( $args ){ |
| 548 |
$value = self::get_value($args); |
| 549 |
$field = $markup = ''; |
| 550 |
$field .= sprintf( '<select id="%1$s" class="%1$s-select" name="%1$s" multiple>', $args['id'] ); |
| 551 |
if(is_array($args['options'])){ |
| 552 |
$field .='<option value=""></option>'; |
| 553 |
foreach($args['options'] as $key => $option){ |
| 554 |
$field .= sprintf( '<option value="%1$s" '.(($value != "") ? (in_array($key, $value) ? 'selected' : '') : '').'>%2$s</option>',$key, $option); |
| 555 |
} |
| 556 |
} |
| 557 |
$field .= '</select>'; |
| 558 |
$field .= self::get_field_description( $args ); |
| 559 |
$markup .= '<tr> |
| 560 |
<th scope="row"> |
| 561 |
<label for="'.$args['id'].'">'.$args['title'].'</label> |
| 562 |
</th> |
| 563 |
<td> |
| 564 |
'.$field.' |
| 565 |
</td> |
| 566 |
</tr>'; |
| 567 |
echo $markup; |
| 568 |
} |
| 569 |
|
| 570 |
public static function callback_welcome( $args ){ |
| 571 |
$current_user = wp_get_current_user(); |
| 572 |
?> |
| 573 |
<tr> |
| 574 |
<td> |
| 575 |
<h2 id="<?php print (isset($args['id']) ? $args['id'] : ''); ?>"><?php print (isset($args['title']) ? $args['title'] : ''); ?></h2> |
| 576 |
<p class="welcome-sub-title"><?php print (isset($args['sub_title']) ? $args['sub_title'] : ''); ?></p> |
| 577 |
<?php |
| 578 |
if(isset($args['video_url'])) : |
| 579 |
?> |
| 580 |
<div class="wpscp-getting-started-video"> |
| 581 |
<iframe width="620" height="350" src="<?php print (isset($args['video_url']) ? esc_url($args['video_url']) : '') ?>" frameborder="0"></iframe> |
| 582 |
</div> |
| 583 |
<?php |
| 584 |
endif; |
| 585 |
?> |
| 586 |
</td> |
| 587 |
</tr> |
| 588 |
<tr> |
| 589 |
<td> |
| 590 |
<div class="betterdocs_getting_started_form text-center"> |
| 591 |
<input type="checkbox" id="betterdocs_user_email_address" name="betterdocs_user_email_address" value="<?php print $current_user->user_email; ?>"> |
| 592 |
<?php esc_html_e('Share non-sensitive diagnostic data and plugin usage information.','betterdocs') ?> |
| 593 |
</div> |
| 594 |
</td> |
| 595 |
</tr> |
| 596 |
<?php |
| 597 |
} |
| 598 |
|
| 599 |
public static function add_nav_tabs(){ |
| 600 |
$tabNavCounter = 0; |
| 601 |
$allSections = apply_filters( 'betterdocs_setup_wizard_fields', self::$sections_array ); |
| 602 |
foreach ($allSections as $section) : |
| 603 |
?> |
| 604 |
<li class="nav-item<?php print ($tabNavCounter == 0 ? ' tab-active' : ''); ?>"> |
| 605 |
<span class="text"><?php print (isset($section['title']) ? $section['title'] : ''); ?></span> |
| 606 |
<span class="number"><?php print (isset($section['sub_title']) ? $section['sub_title'] : ''); ?></span> |
| 607 |
</li> |
| 608 |
<?php |
| 609 |
$tabNavCounter++; |
| 610 |
endforeach; |
| 611 |
} |
| 612 |
|
| 613 |
public static function add_tab_content(){ |
| 614 |
$tabContentCounter = 0; |
| 615 |
$allSections = apply_filters( 'betterdocs_setup_wizard_fields', self::$sections_array ); |
| 616 |
foreach ($allSections as $section) : |
| 617 |
?> |
| 618 |
<div class="tab-content" id="<?php print (isset($section['id']) ? $section['id'] : 'default-nav'); ?>"> |
| 619 |
<table class="form-table" role="presentation"> |
| 620 |
<tbody> |
| 621 |
<?php |
| 622 |
if(isset($section['fields']) && is_array($section['fields'])){ |
| 623 |
foreach ( $section['fields'] as $field ) { |
| 624 |
$methodName = 'callback_' . $field['type']; |
| 625 |
self::$methodName($field); |
| 626 |
} |
| 627 |
} |
| 628 |
?> |
| 629 |
</tbody> |
| 630 |
</table> |
| 631 |
</div> |
| 632 |
<?php |
| 633 |
$tabContentCounter++; |
| 634 |
endforeach; |
| 635 |
} |
| 636 |
|
| 637 |
|
| 638 |
} |
| 639 |
BetterDocsSetupWizard::load(); |
| 640 |
} |