| @@ -45,8 +45,15 @@ | ||
| 45 | 45 | */ |
| 46 | 46 | private $settings; |
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | + * KBMigration | |
| 50 | + * | |
| 51 | + * @var KBMigration | |
| 52 | + */ | |
| 53 | + private $kbmigration; | |
| 54 | + | |
| 55 | + /** | |
| 49 | 56 | * Enqueue |
| 50 | 57 | * @var Enqueue |
| 51 | 58 | */ |
| 52 | 59 | private $assets; |
| @@ -56,12 +63,13 @@ | ||
| 56 | 63 | * @var FAQBuilder |
| 57 | 64 | */ |
| 58 | 65 | private $faq_builder; |
| 59 | 66 | |
| 60 | - public function __construct( Container $container, PostType $type, Enqueue $assets, Settings $settings ) { | |
| 67 | + public function __construct( Container $container, PostType $type, Enqueue $assets, Settings $settings, KBMigration $kbmigration ) { | |
| 61 | 68 | $this->container = $container; |
| 62 | 69 | $this->assets = $assets; |
| 63 | 70 | $this->settings = $settings; |
| 71 | + $this->kbmigration = $kbmigration; | |
| 64 | 72 | $this->slug = 'betterdocs-admin'; |
| 65 | 73 | |
| 66 | 74 | add_action( 'init', [ $type, 'register' ], 9 ); |
| 67 | 75 | |
| @@ -102,9 +110,10 @@ | ||
| 102 | 110 | add_filter( 'manage_docs_posts_custom_column', [ $this, 'manage_custom_columns' ], 10, 2 ); |
| 103 | 111 | |
| 104 | 112 | self::$cache_bank = CacheBank::get_instance(); |
| 105 | 113 | try { |
| 106 | - $this->notices(); | |
| 114 | + // $this->notices(); | |
| 115 | + add_action('admin_init', [$this, 'notices']); | |
| 107 | 116 | } catch ( Exception $e ) { |
| 108 | 117 | unset( $e ); |
| 109 | 118 | } |
| 110 | 119 | // Remove OLD notice from 1.0.0 (if other WPDeveloper plugin has notice) |
| @@ -212,15 +221,55 @@ | ||
| 212 | 221 | $notices->add( 'review', $_review_notice, [ |
| 213 | 222 | 'start' => $notices->strtotime( '+10 days' ), |
| 214 | 223 | 'recurrence' => 30, |
| 215 | 224 | 'dismissible' => true |
| 216 | - // 'screens' => [ | |
| 217 | - // 'dashboard', 'plugins', 'themes', 'edit-page', | |
| 218 | - // 'edit-post', 'users', 'tools', 'options-general', | |
| 219 | - // 'nav-menus', 'toplevel_page_betterdocs-admin', 'betterdocs_page_betterdocs-settings', 'betterdocs_page_betterdocs-analytics', 'betterdocs_page_betterdocs-faq', 'edit-doc_tag', 'edit-doc_category' | |
| 220 | - // ] | |
| 221 | 225 | ] ); |
| 222 | 226 | |
| 227 | + if ( $this->kbmigration->existing_plugins && ! in_array( $this->kbmigration->existing_plugins[0][0], $this->kbmigration->migrated_plugins ) ) { | |
| 228 | + $migration_message = sprintf( | |
| 229 | + '<p class="migration-message">%s</p><a class="button button-primary betterdocs-migration-notice" href="%s">%s</a>', | |
| 230 | + __( | |
| 231 | + sprintf( | |
| 232 | + 'Already using %s? Power up your Knowledge Base by migrating all your docs, settings to BetterDocs with just 1 click.', | |
| 233 | + '<strong>' . esc_html($this->kbmigration->existing_plugins[0][1]) . '</strong>', | |
| 234 | + '<strong>' . esc_html($this->kbmigration->existing_plugins[0][1]) . '</strong>' | |
| 235 | + ), | |
| 236 | + 'betterdocs' | |
| 237 | + ), | |
| 238 | + esc_url(admin_url('admin.php?page=betterdocs-settings&tab=tab-migration')), | |
| 239 | + __('Start Migration', 'betterdocs') | |
| 240 | + ); | |
| 241 | + | |
| 242 | + $_migration_notice = [ | |
| 243 | + 'thumbnail' => '', | |
| 244 | + 'html' => $migration_message, | |
| 245 | + 'links' => [ | |
| 246 | + 'maybe_later' => [ | |
| 247 | + 'label' => __( 'Maybe Later', 'betterdocs' ), | |
| 248 | + 'icon_class' => 'dashicons dashicons-calendar-alt', | |
| 249 | + 'attributes' => [ | |
| 250 | + 'data-later' => true, | |
| 251 | + 'class' => 'dismiss-btn' | |
| 252 | + ] | |
| 253 | + ], | |
| 254 | + 'never_show_again' => [ | |
| 255 | + 'label' => __( 'Never show again', 'betterdocs' ), | |
| 256 | + 'icon_class' => 'dashicons dashicons-dismiss', | |
| 257 | + 'attributes' => [ | |
| 258 | + 'data-dismiss' => true | |
| 259 | + ] | |
| 260 | + ] | |
| 261 | + ] | |
| 262 | + ]; | |
| 263 | + | |
| 264 | + $notices->add( 'migration', $_migration_notice, [ | |
| 265 | + 'start' => $notices->time(), | |
| 266 | + 'recurrence' => false, | |
| 267 | + 'dismissible' => true, | |
| 268 | + 'display_if' => current_user_can( 'delete_users' ) | |
| 269 | + ] ); | |
| 270 | + } | |
| 271 | + | |
| 223 | 272 | /** |
| 224 | 273 | * Opt-In Notice |
| 225 | 274 | */ |
| 226 | 275 | if ( $this->insights != null ) { |
| @@ -277,8 +326,9 @@ | ||
| 277 | 326 | $new_columns = []; |
| 278 | 327 | foreach ( $columns as $key => $value ) { |
| 279 | 328 | if ( $key == 'date' ) { |
| 280 | 329 | $new_columns['betterdocs_word_count'] = __( 'Word Count', 'betterdocs' ); // put the tags column before it |
| 330 | + $new_columns['betterdocs_reaction'] = __( 'Reactions', 'betterdocs' ); | |
| 281 | 331 | } |
| 282 | 332 | $new_columns[ $key ] = $value; |
| 283 | 333 | } |
| 284 | 334 | |
| @@ -285,13 +335,72 @@ | ||
| 285 | 335 | return $new_columns; |
| 286 | 336 | } |
| 287 | 337 | |
| 288 | 338 | public function manage_custom_columns( $column, $post_id ) { |
| 339 | + global $wpdb; | |
| 289 | 340 | switch ( $column ) { |
| 290 | 341 | case 'betterdocs_word_count': |
| 291 | 342 | $word_count = str_word_count( trim( strip_tags( get_post_field( 'post_content', $post_id ) ) ) ); |
| 292 | 343 | echo '<span>' . $word_count . '</span>'; |
| 293 | 344 | break; |
| 345 | + case 'betterdocs_reaction' : | |
| 346 | + $where = "WHERE post_id='" . esc_sql($post_id) . "'"; | |
| 347 | + $analytics = $wpdb->get_results( | |
| 348 | + "SELECT | |
| 349 | + sum(impressions) as totalViews, | |
| 350 | + sum(unique_visit) as totalUniqueViews, | |
| 351 | + sum(happy + sad + normal) as totalReactions, | |
| 352 | + sum(happy) as totalHappy, | |
| 353 | + sum(normal) as totalNormal, | |
| 354 | + sum(sad) as totalSad | |
| 355 | + FROM {$wpdb->prefix}betterdocs_analytics | |
| 356 | + $where" | |
| 357 | + ); | |
| 358 | + //echo '<span>'. ($analytics[0]->totalHappy != NULL ? $analytics[0]->totalHappy : 0) .'</span>'; | |
| 359 | + // var_dump($analytics); | |
| 360 | + echo '<ul class="reactions-count"> | |
| 361 | + <li> | |
| 362 | + <a title="happy" class="betterdocs-feelings happy" data-feelings="happy" href="#"> | |
| 363 | + <svg width="15" height="15" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 20 20" style="enable-background:new 0 0 20 20;" xml:space="preserve"> | |
| 364 | + <path class="st0" d="M10,0.1c-5.4,0-9.9,4.4-9.9,9.8c0,5.4,4.4,9.9,9.8,9.9c5.4,0,9.9-4.4,9.9-9.8C19.9,4.5,15.4,0.1,10,0.1z | |
| 365 | + M13.3,6.4c0.8,0,1.5,0.7,1.5,1.5c0,0.8-0.7,1.5-1.5,1.5c-0.8,0-1.5-0.7-1.5-1.5C11.8,7.1,12.5,6.4,13.3,6.4z M6.7,6.4 | |
| 366 | + c0.8,0,1.5,0.7,1.5,1.5c0,0.8-0.7,1.5-1.5,1.5c-0.8,0-1.5-0.7-1.5-1.5C5.2,7.1,5.9,6.4,6.7,6.4z M10,16.1c-2.6,0-4.9-1.6-5.8-4 | |
| 367 | + l1.2-0.4c0.7,1.9,2.5,3.2,4.6,3.2s3.9-1.3,4.6-3.2l1.2,0.4C14.9,14.5,12.6,16.1,10,16.1z" /> | |
| 368 | + <path class="st1" d="M-6.6-119.7c-7.1,0-12.9,5.8-12.9,12.9s5.8,12.9,12.9,12.9s12.9-5.8,12.9-12.9S0.6-119.7-6.6-119.7z | |
| 369 | + M-2.3-111.4c1.1,0,2,0.9,2,2c0,1.1-0.9,2-2,2c-1.1,0-2-0.9-2-2C-4.3-110.5-3.4-111.4-2.3-111.4z M-10.9-111.4c1.1,0,2,0.9,2,2 | |
| 370 | + c0,1.1-0.9,2-2,2c-1.1,0-2-0.9-2-2C-12.9-110.5-12-111.4-10.9-111.4z M-6.6-98.7c-3.4,0-6.4-2.1-7.6-5.3l1.6-0.6 | |
| 371 | + c0.9,2.5,3.3,4.2,6,4.2s5.1-1.7,6-4.2L1-104C-0.1-100.8-3.2-98.7-6.6-98.7z" /> | |
| 372 | + </svg> | |
| 373 | + <span>'. ($analytics[0]->totalHappy != NULL ? $analytics[0]->totalHappy : 0) .'</span> | |
| 374 | + </a> | |
| 375 | + </li> | |
| 376 | + <li> | |
| 377 | + <a title="normal" class="betterdocs-feelings normal" data-feelings="normal" href="#"> | |
| 378 | + <svg width="15" height="15" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 20 20" style="enable-background:new 0 0 20 20;" xml:space="preserve"> | |
| 379 | + <path class="st0" d="M10,0.2c-5.4,0-9.8,4.4-9.8,9.8s4.4,9.8,9.8,9.8s9.8-4.4,9.8-9.8S15.4,0.2,10,0.2z M6.7,6.5 | |
| 380 | + c0.8,0,1.5,0.7,1.5,1.5c0,0.8-0.7,1.5-1.5,1.5C5.9,9.5,5.2,8.9,5.2,8C5.2,7.2,5.9,6.5,6.7,6.5z M14.2,14.3H5.9 | |
| 381 | + c-0.3,0-0.6-0.3-0.6-0.6c0-0.3,0.3-0.6,0.6-0.6h8.3c0.3,0,0.6,0.3,0.6,0.6C14.8,14,14.5,14.3,14.2,14.3z M13.3,9.5 | |
| 382 | + c-0.8,0-1.5-0.7-1.5-1.5c0-0.8,0.7-1.5,1.5-1.5c0.8,0,1.5,0.7,1.5,1.5C14.8,8.9,14.1,9.5,13.3,9.5z" /> | |
| 383 | + </svg> | |
| 384 | + <span>'. ($analytics[0]->totalNormal != NULL ? $analytics[0]->totalNormal : 0) .'</span> | |
| 385 | + </a> | |
| 386 | + </li> | |
| 387 | + <li> | |
| 388 | + <a title="sad" class="betterdocs-feelings sad" data-feelings="sad" href="#"> | |
| 389 | + <svg width="15" height="15" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 20 20" style="enable-background:new 0 0 20 20;" xml:space="preserve"> | |
| 390 | + <circle class="st0" cx="27.5" cy="0.6" r="1.9" /> | |
| 391 | + <circle class="st0" cx="36" cy="0.6" r="1.9" /> | |
| 392 | + <path class="st1" d="M10,0.3c-5.4,0-9.8,4.4-9.8,9.8s4.4,9.8,9.8,9.8s9.8-4.4,9.8-9.8S15.4,0.3,10,0.3z M13.3,6.6 | |
| 393 | + c0.8,0,1.5,0.7,1.5,1.5c0,0.8-0.7,1.5-1.5,1.5c-0.8,0-1.5-0.7-1.5-1.5C11.8,7.3,12.4,6.6,13.3,6.6z M6.7,6.6c0.8,0,1.5,0.7,1.5,1.5 | |
| 394 | + c0,0.8-0.7,1.5-1.5,1.5C5.9,9.6,5.2,9,5.2,8.1C5.2,7.3,5.9,6.6,6.7,6.6z M14.1,15L14.1,15c-0.2,0-0.4-0.1-0.5-0.2 | |
| 395 | + c-0.9-1-2.2-1.7-3.7-1.7s-2.8,0.6-3.7,1.7C6.2,14.9,6,15,5.9,15h0c-0.6,0-0.8-0.6-0.5-1.1c1.1-1.3,2.8-2.1,4.6-2.1 | |
| 396 | + c1.8,0,3.5,0.8,4.6,2.1C15,14.3,14.7,15,14.1,15z" /> | |
| 397 | + </svg> | |
| 398 | + <span>'. ($analytics[0]->totalSad != NULL ? $analytics[0]->totalSad : 0) .'</span> | |
| 399 | + </a> | |
| 400 | + </li> | |
| 401 | + </ul>'; | |
| 402 | + break; | |
| 294 | 403 | } |
| 295 | 404 | } |
| 296 | 405 | |
| 297 | 406 | /** |
| @@ -314,8 +423,9 @@ | ||
| 314 | 423 | } |
| 315 | 424 | |
| 316 | 425 | $this->assets->enqueue( 'betterdocs-select2', 'vendor/css/select2.min.css', [], 'all' ); |
| 317 | 426 | $this->assets->enqueue( 'betterdocs-daterangepicker', 'vendor/css/daterangepicker.css', [], 'all' ); |
| 427 | + $this->assets->enqueue( 'betterdocs-icons', 'admin/btd-icon/style.css' ); | |
| 318 | 428 | $this->assets->enqueue( 'betterdocs', 'admin/css/betterdocs.css', [], 'all' ); |
| 319 | 429 | } |
| 320 | 430 | |
| 321 | 431 | /** |
| @@ -341,9 +451,11 @@ | ||
| 341 | 451 | 'menu_title' => __( 'Switch to BetterDocs UI', 'betterdocs' ), |
| 342 | 452 | 'dark_mode' => ! empty( $dark_mode ) ? boolval( $dark_mode ) : false, |
| 343 | 453 | 'text' => __( 'Copied!', 'betterdocs' ), |
| 344 | 454 | 'test_report' => __( 'Test Report!', 'betterdocs' ), |
| 345 | - 'sending' => __( 'Sending...', 'betterdocs' ) | |
| 455 | + 'sending' => __( 'Sending...', 'betterdocs' ), | |
| 456 | + 'generate_data_url' => get_rest_url( null, '/betterdocs/v1/create-sample-docs' ), | |
| 457 | + 'nonce' => wp_create_nonce( 'wp_rest' ) | |
| 346 | 458 | ] ); |
| 347 | 459 | |
| 348 | 460 | if ( ( $hook === 'edit.php' || $hook === 'toplevel_page_betterdocs-admin' ) && get_post_type() == 'docs' ) { |
| 349 | 461 | $this->assets->enqueue( 'betterdocs-switcher', 'admin/js/switcher.js', [ |
| @@ -356,12 +468,13 @@ | ||
| 356 | 468 | 'betterdocs_pro_plugin' => betterdocs()->is_pro_active() |
| 357 | 469 | ] ); |
| 358 | 470 | } |
| 359 | 471 | |
| 360 | - if ( ! in_array( $hook, [ 'toplevel_page_betterdocs-admin', 'betterdocs_page_betterdocs-analytics' ] ) ) { | |
| 472 | + if ( ! in_array( $hook, ['term.php', 'edit-tags.php','toplevel_page_betterdocs-admin', 'betterdocs_page_betterdocs-analytics' ] ) ) { | |
| 361 | 473 | return; |
| 362 | 474 | } |
| 363 | 475 | |
| 476 | + wp_enqueue_script('wp-editor'); //enqueued on betterdocs-term pages to show SEO data from Yoast | |
| 364 | 477 | wp_enqueue_script( 'wp-color-picker' ); |
| 365 | 478 | |
| 366 | 479 | $this->assets->enqueue( 'betterdocs-select2', 'vendor/js/select2.min.js', [] ); |
| 367 | 480 | $this->assets->enqueue( 'betterdocs-sweetalert', 'vendor/js/sweetalert.min.js', [] ); |
| @@ -619,9 +732,9 @@ | ||
| 619 | 732 | } |
| 620 | 733 | |
| 621 | 734 | $last_visited = get_user_meta( get_current_user_id(), 'last_visited_docs_admin_page', true); |
| 622 | 735 | |
| 623 | - if ( $last_visited === 'classic_ui' && in_array( "betterdocs-admin", $submenu['betterdocs-admin'][0] ) ) { | |
| 736 | + if ($last_visited === 'classic_ui' && isset($submenu['betterdocs-admin']) && in_array("betterdocs-admin", $submenu['betterdocs-admin'][0])) { | |
| 624 | 737 | unset($submenu['betterdocs-admin'][0]); |
| 625 | 738 | $submenu['betterdocs-admin'] = array_values($submenu['betterdocs-admin']); |
| 626 | 739 | } |
| 627 | 740 | } |