| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPDeveloper\BetterDocs\SetupWizard; |
| 4 |
|
| 5 |
class SetupWizard { |
| 6 |
public static $sections_array = []; |
| 7 |
public static $optionGroupName = 'betterdocs_settings'; |
| 8 |
|
| 9 |
private static $settings; |
| 10 |
|
| 11 |
public static function load( $settings ) { |
| 12 |
self::$settings = $settings; |
| 13 |
// tab builder |
| 14 |
add_action( 'betterdocs_nav_tabs', [__CLASS__, 'add_nav_tabs'] ); |
| 15 |
add_action( 'betterdocs_tabs_content', [__CLASS__, 'add_tab_content'] ); |
| 16 |
// ajax request |
| 17 |
add_action( 'wp_ajax_better_docs_quick_setup_wizard_data_save', [__CLASS__, 'better_docs_quick_setup_wizard_data_save'] ); |
| 18 |
// ajax url change |
| 19 |
add_action( 'wp_ajax_better_docs_setup_generate_live_url', [__CLASS__, 'better_docs_setup_generate_live_url'] ); |
| 20 |
} |
| 21 |
|
| 22 |
// add admin page |
| 23 |
public static function existing_plugins_data( $plugins ) { |
| 24 |
$plugins_data = []; |
| 25 |
if ( $plugins === 'wedocs' ) { |
| 26 |
$plugins_data['name'] = 'wedocs'; |
| 27 |
$plugins_data['url'] = 'wedocs/wedocs.php'; |
| 28 |
} |
| 29 |
if ( $plugins === 'bsf-docs' ) { |
| 30 |
$plugins_data['name'] = 'bsf-docs'; |
| 31 |
$plugins_data['url'] = 'bsf-docs/bsf-docs.php'; |
| 32 |
} |
| 33 |
if ( $plugins === 'documentor-lite' ) { |
| 34 |
$plugins_data['name'] = 'documentor-lite'; |
| 35 |
$plugins_data['url'] = 'documentor-lite/documentor-lite.php'; |
| 36 |
} |
| 37 |
if ( $plugins === 'echo-knowledge-base' ) { |
| 38 |
$plugins_data['name'] = 'echo-knowledge-base'; |
| 39 |
$plugins_data['url'] = 'echo-knowledge-base/echo-knowledge-base.php'; |
| 40 |
} |
| 41 |
if ( $plugins === 'pressapps-knowledge-base' ) { |
| 42 |
$plugins_data['name'] = 'pressapps-knowledge-base'; |
| 43 |
$plugins_data['url'] = 'pressapps-knowledge-base/pressapps-knowledge-base.php'; |
| 44 |
} |
| 45 |
return $plugins_data; |
| 46 |
} |
| 47 |
|
| 48 |
public static function insert_terms_hierarchically( $existing_term, $new_term, $parentId = 0 ) { |
| 49 |
$into = []; |
| 50 |
$cats = get_terms( $existing_term, ['hide_empty' => false] ); |
| 51 |
if ( $cats ) { |
| 52 |
foreach ( $cats as $i => $cat ) { |
| 53 |
if ( $cat->parent == $parentId ) { |
| 54 |
$into[$cat->term_id] = $cat; |
| 55 |
unset( $cats[$i] ); |
| 56 |
$doc_parent_term = term_exists( $cat->name, $new_term ); |
| 57 |
wp_insert_term( |
| 58 |
$cat->name, |
| 59 |
$new_term, |
| 60 |
[ |
| 61 |
'alias_of' => $cat->slug, |
| 62 |
'description' => $cat->description, |
| 63 |
'slug' => $cat->slug, |
| 64 |
'parent' => $cat->parent |
| 65 |
] |
| 66 |
); |
| 67 |
} |
| 68 |
} |
| 69 |
if ( $cats ) { |
| 70 |
foreach ( $cats as $i => $cat ) { |
| 71 |
$get_existing_term = get_term_by( 'id', $cat->parent, $existing_term ); |
| 72 |
$doc_parent_term = term_exists( $get_existing_term->name, $new_term ); |
| 73 |
wp_insert_term( |
| 74 |
$cat->name, |
| 75 |
$new_term, |
| 76 |
[ |
| 77 |
'alias_of' => $cat->slug, |
| 78 |
'description' => $cat->description, |
| 79 |
'slug' => $cat->slug, |
| 80 |
'parent' => $doc_parent_term['term_id'] |
| 81 |
] |
| 82 |
); |
| 83 |
} |
| 84 |
} |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
public static function insert_posts( $existing_post, $existing_cat, $existing_tag ) { |
| 89 |
$args = [ |
| 90 |
'post_type' => $existing_post, |
| 91 |
'post_status' => 'any', |
| 92 |
'posts_per_page' => -1 |
| 93 |
]; |
| 94 |
$postslist = get_posts( $args ); |
| 95 |
if ( $postslist ) { |
| 96 |
foreach ( $postslist as $post ) { |
| 97 |
// Create post object |
| 98 |
if ( ! get_page_by_title( $post->post_title, 'OBJECT', 'docs' ) ) { |
| 99 |
$post_args = [ |
| 100 |
'post_type' => 'docs', |
| 101 |
'post_title' => $post->post_title, |
| 102 |
'post_content' => $post->post_content, |
| 103 |
'post_status' => $post->post_status, |
| 104 |
'post_author' => $post->post_author, |
| 105 |
'post_date' => $post->post_date, |
| 106 |
'post_date_gmt' => $post->post_date_gmt, |
| 107 |
'post_excerpt' => $post->post_excerpt, |
| 108 |
'comment_status' => $post->comment_status, |
| 109 |
'ping_status' => $post->ping_status, |
| 110 |
'post_password' => $post->post_password, |
| 111 |
'post_name' => $post->post_name, |
| 112 |
'to_ping' => $post->to_ping, |
| 113 |
'pinged' => $post->pinged, |
| 114 |
'post_modified' => $post->post_modified, |
| 115 |
'post_modified_gmt' => $post->post_modified_gmt, |
| 116 |
'post_content_filtered' => $post->post_content_filtered, |
| 117 |
'post_parent' => $post->post_parent, |
| 118 |
'post_mime_type' => $post->post_mime_type, |
| 119 |
'comment_count' => $post->comment_count, |
| 120 |
'filter' => $post->filter |
| 121 |
]; |
| 122 |
// Insert the post into the database |
| 123 |
$result = wp_insert_post( $post_args ); |
| 124 |
if ( $result && ! is_wp_error( $result ) ) { |
| 125 |
$cat_list = wp_get_post_terms( $post->ID, $existing_cat, ['fields' => 'all'] ); |
| 126 |
if ( $cat_list ) { |
| 127 |
$post_id = $result; |
| 128 |
wp_set_object_terms( $post_id, [$cat_list['0']->name], 'doc_category', false ); |
| 129 |
} |
| 130 |
$tag_list = wp_get_post_terms( $post->ID, $existing_tag, ['fields' => 'all'] ); |
| 131 |
if ( $tag_list ) { |
| 132 |
$post_id = $result; |
| 133 |
wp_set_object_terms( $post_id, [$tag_list['0']->name], 'doc_tag', false ); |
| 134 |
} |
| 135 |
} |
| 136 |
} |
| 137 |
} |
| 138 |
} |
| 139 |
} |
| 140 |
|
| 141 |
public static function eco_knowledgerbase_migration() { |
| 142 |
self::insert_terms_hierarchically( 'epkb_post_type_1_category', 'doc_category' ); |
| 143 |
self::insert_terms_hierarchically( 'epkb_post_type_1_tag', 'doc_tag' ); |
| 144 |
self::insert_posts( 'epkb_post_type_1', 'epkb_post_type_1_category', 'epkb_post_type_1_tag' ); |
| 145 |
} |
| 146 |
|
| 147 |
public static function pressapps_migration() { |
| 148 |
self::insert_terms_hierarchically( 'knowledgebase_category', 'doc_category' ); |
| 149 |
self::insert_terms_hierarchically( 'knowledgebase_tags', 'doc_tag' ); |
| 150 |
self::insert_posts( 'knowledgebase', 'knowledgebase_category', 'knowledgebase_tags' ); |
| 151 |
} |
| 152 |
|
| 153 |
public static function better_docs_quick_setup_wizard_data_save() { |
| 154 |
check_ajax_referer( 'betterdocsqswnonce', 'security' ); |
| 155 |
|
| 156 |
// duplicate existing plugin data and deactivate |
| 157 |
if ( isset( $_POST['activate_plugin'] ) ) { |
| 158 |
$existing_plugins_data = self::existing_plugins_data( $_POST['activate_plugin'] ); |
| 159 |
if ( isset( $existing_plugins_data['name'] ) && isset( $existing_plugins_data['url'] ) ) { |
| 160 |
if ( $existing_plugins_data['name'] === 'echo-knowledge-base' ) { |
| 161 |
self::eco_knowledgerbase_migration(); |
| 162 |
} elseif ( $existing_plugins_data['name'] === 'pressapps-knowledge-base' ) { |
| 163 |
self::pressapps_migration(); |
| 164 |
} |
| 165 |
deactivate_plugins( $existing_plugins_data['url'] ); |
| 166 |
} |
| 167 |
} |
| 168 |
|
| 169 |
$newValue['builtin_doc_page'] = ( isset( $_POST['builtin_doc_page'] ) ? (bool) $_POST['builtin_doc_page'] : false ); |
| 170 |
$newValue['docs_slug'] = ( isset( $_POST['docs_slug'] ) ? $_POST['docs_slug'] : 'docs' ); |
| 171 |
$newValue['enable_disable'] = ( isset( $_POST['enable_disable'] ) ? (bool) $_POST['enable_disable'] : false ); |
| 172 |
|
| 173 |
self::$settings->save_settings( $newValue ); |
| 174 |
wp_die(); // this is required to terminate immediately and return a proper response |
| 175 |
} |
| 176 |
|
| 177 |
public static function better_docs_setup_generate_live_url() { |
| 178 |
$query = []; |
| 179 |
$query['autofocus[panel]'] = 'betterdocs_customize_options'; |
| 180 |
$query['return'] = admin_url( 'edit.php?post_type=docs' ); |
| 181 |
$docs_slug = ( isset( $_POST['docs_slug'] ) ? $_POST['docs_slug'] : null ); |
| 182 |
if ( $docs_slug ) { |
| 183 |
$query['url'] = site_url( '/' . $docs_slug ); |
| 184 |
} |
| 185 |
$customizer_link = add_query_arg( $query, admin_url( 'customize.php' ) ); |
| 186 |
|
| 187 |
$result = [ |
| 188 |
'customizerurl' => $customizer_link, |
| 189 |
'siteurl' => esc_url( site_url( '/' . $docs_slug ) ) |
| 190 |
]; |
| 191 |
print json_encode( $result ); |
| 192 |
wp_die(); |
| 193 |
} |
| 194 |
|
| 195 |
public static function setSection( $section ) { |
| 196 |
// Bail if not array. |
| 197 |
if ( ! is_array( $section ) ) { |
| 198 |
return false; |
| 199 |
} |
| 200 |
|
| 201 |
self::$sections_array[$section['id']] = $section; |
| 202 |
|
| 203 |
// Assign to the sections array |
| 204 |
return self::$sections_array; |
| 205 |
} |
| 206 |
|
| 207 |
public static function get_value( $args ) { |
| 208 |
if ( $args == null || $args == '' ) { |
| 209 |
return; |
| 210 |
} |
| 211 |
|
| 212 |
// $optionValue = get_option( self::$optionGroupName ); |
| 213 |
// if ( isset( $optionValue[$args['id']] ) ) { |
| 214 |
// return $optionValue[$args['id']]; |
| 215 |
// } else if ( isset( $args['default'] ) ) { |
| 216 |
// return $args['default']; |
| 217 |
// } |
| 218 |
|
| 219 |
return self::$settings->get( $args['id'] ); |
| 220 |
} |
| 221 |
|
| 222 |
public static function get_field_description( $args ) { |
| 223 |
if ( ! empty( $args['desc'] ) ) { |
| 224 |
$desc = sprintf( '<p class="description">%s</p>', $args['desc'] ); |
| 225 |
} else { |
| 226 |
$desc = ''; |
| 227 |
} |
| 228 |
|
| 229 |
return $desc; |
| 230 |
} |
| 231 |
|
| 232 |
/** |
| 233 |
* Fields Type: Text |
| 234 |
* @param array |
| 235 |
* @return void |
| 236 |
*/ |
| 237 |
public static function callback_text( $args ) { |
| 238 |
$value = esc_attr( self::get_value( $args ) ); |
| 239 |
$size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular'; |
| 240 |
$type = isset( $args['type'] ) ? $args['type'] : 'text'; |
| 241 |
$field = ''; |
| 242 |
$markup = ''; |
| 243 |
$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'] ); |
| 244 |
$field .= self::get_field_description( $args ); |
| 245 |
$markup .= '<tr> |
| 246 |
<th scope="row"> |
| 247 |
<label for="' . $args['id'] . '">' . $args['title'] . '</label> |
| 248 |
</th> |
| 249 |
<td> |
| 250 |
' . $field . ' |
| 251 |
</td> |
| 252 |
</tr>'; |
| 253 |
echo $markup; |
| 254 |
} |
| 255 |
|
| 256 |
/** |
| 257 |
* Fields Type: textarea |
| 258 |
* @param array |
| 259 |
* @return void |
| 260 |
*/ |
| 261 |
public static function callback_textarea( $args ) { |
| 262 |
$value = esc_textarea( self::get_value( $args ) ); |
| 263 |
$size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular'; |
| 264 |
$field = ''; |
| 265 |
$markup = ''; |
| 266 |
$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 ); |
| 267 |
$field .= self::get_field_description( $args ); |
| 268 |
$markup .= '<tr> |
| 269 |
<th scope="row"> |
| 270 |
<label for="' . $args['id'] . '">' . $args['title'] . '</label> |
| 271 |
</th> |
| 272 |
<td> |
| 273 |
' . $field . ' |
| 274 |
</td> |
| 275 |
</tr>'; |
| 276 |
echo $markup; |
| 277 |
} |
| 278 |
|
| 279 |
/** |
| 280 |
* Fields Type: checkbox |
| 281 |
* @param array |
| 282 |
* @return void |
| 283 |
*/ |
| 284 |
public static function callback_checkbox_pro_feature( $args ) { |
| 285 |
$value = self::get_value( $args ); |
| 286 |
$field = ''; |
| 287 |
$markup = ''; |
| 288 |
$field = sprintf( '<input class="%1$s-checkbox" id="%1$s" name="%1$s" type="checkbox" %3$s>', $args['id'], 1, checked( 1, $value, false ) ); |
| 289 |
$field .= self::get_field_description( $args ); |
| 290 |
$markup .= '<tr> |
| 291 |
<th scope="row"> |
| 292 |
<label for="' . $args['id'] . '">' . $args['title'] . '</label> |
| 293 |
</th> |
| 294 |
<td>'; |
| 295 |
if ( ! betterdocs()->is_pro_active() ) { |
| 296 |
$markup .= '<div class="betterdocs-checkbox betterdocs-pro-feature-checkbox" data-id="instant_answer"> |
| 297 |
<input disabled="" type="checkbox" id="instant_answer" name="instant_answer"> |
| 298 |
<label for="instant_answer"></label> |
| 299 |
<p class="betterdocs-module-title">Instant Answer |
| 300 |
<sup class="betterdocs-pro-label has-to-update"></sup><sup class="betterdocs-pro-label">Pro</sup> |
| 301 |
</p> |
| 302 |
</div>'; |
| 303 |
} else { |
| 304 |
$markup .= $field; |
| 305 |
} |
| 306 |
$markup .= '</td> |
| 307 |
</tr>'; |
| 308 |
echo $markup; |
| 309 |
} |
| 310 |
|
| 311 |
/** |
| 312 |
* Fields Type: link |
| 313 |
* @param array |
| 314 |
* @return void |
| 315 |
*/ |
| 316 |
public static function callback_link( $args ) { |
| 317 |
$value = self::get_value( $args ); |
| 318 |
$field = ''; |
| 319 |
$markup = ''; |
| 320 |
$field = sprintf( '<input class="%1$s-checkbox" id="%1$s" name="%1$s" type="checkbox" %3$s>', $args['id'], 1, checked( 1, $value, false ) ); |
| 321 |
$field .= self::get_field_description( $args ); |
| 322 |
$markup .= '<tr class="text-center"> |
| 323 |
<td colspan="2"> |
| 324 |
<h2 class="bd-sw-title">' . ( isset( $args['title'] ) ? $args['title'] : '' ) . '</h2> |
| 325 |
<p class="bd-sw-sub-title">' . ( isset( $args['sub_title'] ) ? $args['sub_title'] : '' ) . '</p> |
| 326 |
</td> |
| 327 |
</tr> |
| 328 |
<tr> |
| 329 |
<td> |
| 330 |
<ul class="betterdocs-setup-feature-list">'; |
| 331 |
if ( is_array( $args['options'] ) ) { |
| 332 |
foreach ( $args['options'] as $item ) { |
| 333 |
$markup .= '<li> |
| 334 |
<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> |
| 335 |
<div class="bd-media-body"> |
| 336 |
<h4><a href="' . esc_url( $item['url'] ) . '" target="_blank">' . ( isset( $item['feature_title'] ) ? $item['feature_title'] : '' ) . '</a></h4> |
| 337 |
<p>' . ( isset( $item['feature_content'] ) ? $item['feature_content'] : '' ) . '</p> |
| 338 |
<a ' . ( isset( $item['id'] ) ? 'id="' . $item['id'] . '"' : '' ) . ' href="' . esc_url( $item['url'] ) . '" class="btn-setup-wizard" target="_blank">' . $item['title'] . '</a> |
| 339 |
</div> |
| 340 |
</li>'; |
| 341 |
} |
| 342 |
} |
| 343 |
$markup .= '</ul> |
| 344 |
</td> |
| 345 |
<td> |
| 346 |
<img src="' . ( isset( $args['image_url'] ) ? esc_url( $args['image_url'] ) : '' ) . '" /> |
| 347 |
</td> |
| 348 |
</tr>'; |
| 349 |
echo $markup; |
| 350 |
} |
| 351 |
|
| 352 |
/** |
| 353 |
* Fields Type: link |
| 354 |
* @param array |
| 355 |
* @return void |
| 356 |
*/ |
| 357 |
public static function callback_final_step( $args ) { |
| 358 |
$value = self::get_value( $args ); |
| 359 |
$field = ''; |
| 360 |
$markup = ''; |
| 361 |
$field = sprintf( '<input class="%1$s-checkbox" id="%1$s" name="%1$s" type="checkbox" %3$s>', $args['id'], 1, checked( 1, $value, false ) ); |
| 362 |
$field .= self::get_field_description( $args ); |
| 363 |
$markup .= '<tr class="text-center"> |
| 364 |
<td colspan="2">'; |
| 365 |
if ( isset( $args['image_url'] ) ) { |
| 366 |
$markup .= '<img src="' . ( isset( $args['image_url'] ) ? $args['image_url'] : '' ) . '" alt="" />'; |
| 367 |
} |
| 368 |
$markup .= '<h2 class="bd-sw-title">' . ( isset( $args['title'] ) ? $args['title'] : '' ) . '</h2> |
| 369 |
<p class="bd-sw-sub-title">' . ( isset( $args['sub_title'] ) ? $args['sub_title'] : '' ) . '</p> |
| 370 |
</td> |
| 371 |
</tr> |
| 372 |
<tr class="text-center"> |
| 373 |
<td>'; |
| 374 |
foreach ( $args['options'] as $item ) { |
| 375 |
$markup .= '<a ' . ( isset( $item['id'] ) ? 'id="' . $item['id'] . '"' : '' ) . ' href="' . esc_url( $item['url'] ) . '" class="btn-setup-wizard" target="_blank">' . $item['title'] . '</a>'; |
| 376 |
} |
| 377 |
$markup .= '</td> |
| 378 |
</tr>'; |
| 379 |
echo $markup; |
| 380 |
} |
| 381 |
|
| 382 |
/** |
| 383 |
* Fields Type: link |
| 384 |
* @param array |
| 385 |
* @return void |
| 386 |
*/ |
| 387 |
public static function callback_migration( $args ) { |
| 388 |
$field = ''; |
| 389 |
$markup = ''; |
| 390 |
$markup .= '<tr class="text-center"> |
| 391 |
<td colspan="2">'; |
| 392 |
$markup .= '<p class="bd-sw-sub-title">' . ( isset( $args['sub_title'] ) ? $args['sub_title'] : '' ) . '</p> |
| 393 |
</td> |
| 394 |
</tr>'; |
| 395 |
|
| 396 |
foreach ( $args['options'] as $item ) { |
| 397 |
$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 ) ); |
| 398 |
$markup .= '<tr> |
| 399 |
<th scope="row"> |
| 400 |
<label for="' . $item['id'] . '">' . $item['title'] . '</label> |
| 401 |
</th> |
| 402 |
<td> |
| 403 |
' . $field . ' |
| 404 |
</td> |
| 405 |
</tr>'; |
| 406 |
} |
| 407 |
echo $markup; |
| 408 |
} |
| 409 |
|
| 410 |
/** |
| 411 |
* Fields Type: checkbox |
| 412 |
* @param array |
| 413 |
* @return void |
| 414 |
*/ |
| 415 |
public static function callback_checkbox( $args ) { |
| 416 |
$value = self::get_value( $args ); |
| 417 |
$field = ''; |
| 418 |
$markup = ''; |
| 419 |
$field = sprintf( '<input class="%1$s-checkbox" id="%1$s" name="%1$s" type="checkbox" %3$s>', $args['id'], 1, checked( 1, $value, false ) ); |
| 420 |
$field .= self::get_field_description( $args ); |
| 421 |
$markup .= '<tr> |
| 422 |
<th scope="row"> |
| 423 |
<label for="' . $args['id'] . '">' . $args['title'] . '</label> |
| 424 |
</th> |
| 425 |
<td> |
| 426 |
' . $field . ' |
| 427 |
</td> |
| 428 |
</tr>'; |
| 429 |
echo $markup; |
| 430 |
} |
| 431 |
|
| 432 |
/** |
| 433 |
* Fields Type: radio |
| 434 |
* @param array |
| 435 |
* @return void |
| 436 |
*/ |
| 437 |
public static function callback_radio( $args ) { |
| 438 |
$value = self::get_value( $args ); |
| 439 |
$field = ''; |
| 440 |
$markup = ''; |
| 441 |
if ( is_array( $args['options'] ) ) { |
| 442 |
foreach ( $args['options'] as $key => $option ) { |
| 443 |
$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 ) ); |
| 444 |
} |
| 445 |
} |
| 446 |
$field .= self::get_field_description( $args ); |
| 447 |
$markup .= '<tr> |
| 448 |
<th scope="row"> |
| 449 |
<label for="' . $args['id'] . '">' . $args['title'] . '</label> |
| 450 |
</th> |
| 451 |
<td> |
| 452 |
' . $field . ' |
| 453 |
</td> |
| 454 |
</tr>'; |
| 455 |
echo $markup; |
| 456 |
} |
| 457 |
|
| 458 |
public static function callback_select( $args ) { |
| 459 |
$value = self::get_value( $args ); |
| 460 |
$field = $markup = ''; |
| 461 |
$field .= sprintf( '<select id="%1$s" class="%1$s-select" name="%1$s" multiple>', $args['id'] ); |
| 462 |
if ( is_array( $args['options'] ) ) { |
| 463 |
$field .= '<option value=""></option>'; |
| 464 |
foreach ( $args['options'] as $key => $option ) { |
| 465 |
$field .= sprintf( '<option value="%1$s" ' . ( ( $value != "" ) ? ( in_array( $key, $value ) ? 'selected' : '' ) : '' ) . '>%2$s</option>', $key, $option ); |
| 466 |
} |
| 467 |
} |
| 468 |
$field .= '</select>'; |
| 469 |
$field .= self::get_field_description( $args ); |
| 470 |
$markup .= '<tr> |
| 471 |
<th scope="row"> |
| 472 |
<label for="' . $args['id'] . '">' . $args['title'] . '</label> |
| 473 |
</th> |
| 474 |
<td> |
| 475 |
' . $field . ' |
| 476 |
</td> |
| 477 |
</tr>'; |
| 478 |
echo $markup; |
| 479 |
} |
| 480 |
|
| 481 |
public static function callback_welcome( $args ) { |
| 482 |
$current_user = wp_get_current_user(); |
| 483 |
betterdocs()->views->get( 'admin/setup-wizard/welcome', [ |
| 484 |
'args' => $args, |
| 485 |
'current_user' => $current_user |
| 486 |
] ); |
| 487 |
} |
| 488 |
|
| 489 |
public static function add_nav_tabs() { |
| 490 |
$tabNavCounter = 0; |
| 491 |
$allSections = apply_filters( 'betterdocs_setup_wizard_fields', self::$sections_array ); |
| 492 |
foreach ( $allSections as $section ): |
| 493 |
betterdocs()->views->get( 'admin/setup-wizard/nav-tabs', [ |
| 494 |
'tabNavCounter' => $tabNavCounter, |
| 495 |
'section' => $section |
| 496 |
] ); |
| 497 |
$tabNavCounter++; |
| 498 |
endforeach; |
| 499 |
} |
| 500 |
|
| 501 |
public static function add_tab_content() { |
| 502 |
$tabContentCounter = 0; |
| 503 |
$allSections = apply_filters( 'betterdocs_setup_wizard_fields', self::$sections_array ); |
| 504 |
foreach ( $allSections as $section ): |
| 505 |
|
| 506 |
betterdocs()->views->get( 'admin/setup-wizard/tab-content', [ |
| 507 |
'section' => $section, |
| 508 |
'self' => new self |
| 509 |
] ); |
| 510 |
|
| 511 |
$tabContentCounter++; |
| 512 |
endforeach; |
| 513 |
} |
| 514 |
} |
| 515 |
|