| @@ -29,10 +29,8 @@ | ||
| 29 | 29 | class Visualizer_Module_Admin extends Visualizer_Module { |
| 30 | 30 | |
| 31 | 31 | const NAME = __CLASS__; |
| 32 | 32 | |
| 33 | - const OPTION_GLOBAL_SETTINGS = 'visualizer_global_settings'; | |
| 34 | - | |
| 35 | 33 | /** |
| 36 | 34 | * Library page suffix. |
| 37 | 35 | * |
| 38 | 36 | * @since 1.0.0 |
| @@ -42,24 +40,8 @@ | ||
| 42 | 40 | */ |
| 43 | 41 | private $_libraryPage; |
| 44 | 42 | |
| 45 | 43 | /** |
| 46 | - * Support page suffix. | |
| 47 | - * | |
| 48 | - * @access private | |
| 49 | - * @var string | |
| 50 | - */ | |
| 51 | - private $_supportPage; | |
| 52 | - | |
| 53 | - /** | |
| 54 | - * Settings page suffix. | |
| 55 | - * | |
| 56 | - * @access private | |
| 57 | - * @var string | |
| 58 | - */ | |
| 59 | - private $_settingsPage; | |
| 60 | - | |
| 61 | - /** | |
| 62 | 44 | * Constructor. |
| 63 | 45 | * |
| 64 | 46 | * @since 1.0.0 |
| 65 | 47 | * |
| @@ -73,11 +55,8 @@ | ||
| 73 | 55 | $this->_addAction( 'load-post-new.php', 'enqueueMediaScripts' ); |
| 74 | 56 | $this->_addAction( 'enqueue_block_editor_assets', 'enqueueMediaScripts' ); |
| 75 | 57 | $this->_addAction( 'admin_footer', 'renderTemplates' ); |
| 76 | 58 | $this->_addAction( 'admin_enqueue_scripts', 'enqueueLibraryScripts', null, 0 ); |
| 77 | - $this->_addAction( 'admin_enqueue_scripts', 'enqueue_support_page' ); | |
| 78 | - $this->_addAction( 'admin_enqueue_scripts', 'enqueueSettingsScripts' ); | |
| 79 | - $this->_addAction( 'admin_post_visualizer_save_global_settings', 'saveGlobalSettings' ); | |
| 80 | 59 | $this->_addAction( 'admin_menu', 'registerAdminMenu' ); |
| 81 | 60 | $this->_addFilter( 'media_view_strings', 'setupMediaViewStrings' ); |
| 82 | 61 | $this->_addFilter( 'plugin_action_links', 'getPluginActionLinks', 10, 2 ); |
| 83 | 62 | $this->_addFilter( 'plugin_row_meta', 'getPluginMetaLinks', 10, 2 ); |
| @@ -82,9 +61,8 @@ | ||
| 82 | 61 | $this->_addFilter( 'plugin_action_links', 'getPluginActionLinks', 10, 2 ); |
| 83 | 62 | $this->_addFilter( 'plugin_row_meta', 'getPluginMetaLinks', 10, 2 ); |
| 84 | 63 | $this->_addFilter( 'visualizer_logger_data', 'getLoggerData' ); |
| 85 | 64 | $this->_addFilter( 'visualizer_feedback_review_trigger', 'feedbackReviewTrigger' ); |
| 86 | - $this->_addFilter( 'themeisle_sdk_blackfriday_data', 'add_black_friday_data' ); | |
| 87 | 65 | |
| 88 | 66 | // screen pagination |
| 89 | 67 | $this->_addFilter( 'set-screen-option', 'setScreenOptions', 10, 3 ); |
| 90 | 68 | |
| @@ -100,15 +78,16 @@ | ||
| 100 | 78 | $this->_addAction( 'visualizer_chart_languages', 'addMultilingualSupport' ); |
| 101 | 79 | |
| 102 | 80 | $this->_addFilter( 'admin_footer_text', 'render_review_notice' ); |
| 103 | 81 | |
| 104 | - if ( ! defined( 'TI_E2E_TESTING' ) ) { | |
| 82 | + if ( ! defined( 'TI_CYPRESS_TESTING' ) ) { | |
| 105 | 83 | $this->_addFilter( 'themeisle-sdk/survey/' . VISUALIZER_DIRNAME, 'get_survey_metadata', 10, 2 ); |
| 106 | 84 | } |
| 107 | 85 | |
| 108 | - if ( defined( 'TI_E2E_TESTING' ) ) { | |
| 86 | + if ( defined( 'TI_CYPRESS_TESTING' ) ) { | |
| 109 | 87 | $this->load_cypress_hooks(); |
| 110 | 88 | } |
| 89 | + | |
| 111 | 90 | } |
| 112 | 91 | /** |
| 113 | 92 | * Display review notice. |
| 114 | 93 | */ |
| @@ -114,19 +93,18 @@ | ||
| 114 | 93 | */ |
| 115 | 94 | public function render_review_notice( $footer_text ) { |
| 116 | 95 | $current_screen = get_current_screen(); |
| 117 | 96 | |
| 118 | - $visualizer_page_ids = array( 'toplevel_page_visualizer', 'visualizer_page_viz-support', 'visualizer_page_ti-about-visualizer' ); | |
| 97 | + $visualizer_page_ids = ['toplevel_page_visualizer', 'visualizer_page_viz-support', 'visualizer_page_ti-about-visualizer' ]; | |
| 119 | 98 | |
| 120 | 99 | if ( ! empty( $current_screen ) && isset( $current_screen->id ) ) { |
| 121 | 100 | foreach ( $visualizer_page_ids as $page_to_check ) { |
| 122 | 101 | if ( strpos( $current_screen->id, $page_to_check ) !== false ) { |
| 123 | 102 | $footer_text = sprintf( |
| 124 | - // translators: %1$s - the name of the plugin (Visualizer), %2$s - message (You can help us by leaving a), %3$s - HTML entity code. | |
| 125 | 103 | __( 'Enjoying %1$s? %2$s %3$s rating. Thank you for being so supportive!', 'visualizer' ), |
| 126 | 104 | '<b>Visualizer</b>', |
| 127 | 105 | esc_html__( 'You can help us by leaving a', 'visualizer' ), |
| 128 | - '<a href="https://wordpress.org/support/plugin/visualizer/reviews/#new-post" target="_blank">★★★★★</a>' | |
| 106 | + '<a href="https://wordpress.org/support/plugin/visualizer/reviews/" target="_blank">★★★★★</a>' | |
| 129 | 107 | ); |
| 130 | 108 | break; |
| 131 | 109 | } |
| 132 | 110 | } |
| @@ -144,9 +122,9 @@ | ||
| 144 | 122 | */ |
| 145 | 123 | private function load_cypress_hooks() { |
| 146 | 124 | // all charts should load on the same page without pagination. |
| 147 | 125 | add_filter( |
| 148 | - 'visualizer_query_args', function ( $args ) { | |
| 126 | + 'visualizer_query_args', function( $args ) { | |
| 149 | 127 | $args['posts_per_page'] = 20; |
| 150 | 128 | return $args; |
| 151 | 129 | }, 10, 1 |
| 152 | 130 | ); |
| @@ -222,9 +200,9 @@ | ||
| 222 | 200 | |
| 223 | 201 | if ( $meta ) { |
| 224 | 202 | foreach ( $meta as $key => $value ) { |
| 225 | 203 | if ( 0 === strpos( $key, 'visualizer' ) ) { |
| 226 | - add_metadata( 'post', $revision_id, $key, self::maybe_decode_content( $value[0] ) ); | |
| 204 | + add_metadata( 'post', $revision_id, $key, maybe_unserialize( $value[0] ) ); | |
| 227 | 205 | } |
| 228 | 206 | } |
| 229 | 207 | } |
| 230 | 208 | } |
| @@ -250,9 +228,9 @@ | ||
| 250 | 228 | |
| 251 | 229 | if ( $meta ) { |
| 252 | 230 | foreach ( $meta as $key => $value ) { |
| 253 | 231 | if ( 0 === strpos( $key, 'visualizer' ) ) { |
| 254 | - add_post_meta( $post_id, $key, self::maybe_decode_content( $value[0] ) ); | |
| 232 | + add_post_meta( $post_id, $key, maybe_unserialize( $value[0] ) ); | |
| 255 | 233 | } |
| 256 | 234 | } |
| 257 | 235 | } |
| 258 | 236 | } |
| @@ -263,9 +241,10 @@ | ||
| 263 | 241 | * |
| 264 | 242 | * @access public |
| 265 | 243 | */ |
| 266 | 244 | public function init() { |
| 267 | - if ( current_user_can( 'edit_posts' ) && current_user_can( 'edit_pages' ) && 'true' === get_user_option( 'rich_editing' ) ) { | |
| 245 | + // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison | |
| 246 | + if ( current_user_can( 'edit_posts' ) && current_user_can( 'edit_pages' ) && 'true' == get_user_option( 'rich_editing' ) ) { | |
| 268 | 247 | $this->_addFilter( 'mce_external_languages', 'add_tinymce_lang', 10, 1 ); |
| 269 | 248 | $this->_addFilter( 'mce_external_plugins', 'tinymce_plugin', 10, 1 ); |
| 270 | 249 | $this->_addFilter( 'mce_buttons', 'register_mce_button', 10, 1 ); |
| 271 | 250 | $this->_addFilter( 'tiny_mce_before_init', 'get_strings_for_block', 10, 1 ); |
| @@ -277,9 +256,9 @@ | ||
| 277 | 256 | * |
| 278 | 257 | * @since ? |
| 279 | 258 | * @access friendly |
| 280 | 259 | */ |
| 281 | - public function get_strings_for_block( $settings ) { | |
| 260 | + function get_strings_for_block( $settings ) { | |
| 282 | 261 | $class = new Visualizer_Module_Language(); |
| 283 | 262 | $strings = $class->get_strings(); |
| 284 | 263 | $array = array( 'visualizer_tinymce_plugin' => json_encode( $strings ) ); |
| 285 | 264 | return array_merge( $settings, $array ); |
| @@ -360,31 +339,8 @@ | ||
| 360 | 339 | |
| 361 | 340 | if ( post_type_supports( $typenow, 'editor' ) || $current_screen->id === 'widgets' || $current_screen->id === 'customize' ) { |
| 362 | 341 | wp_enqueue_style( 'visualizer-media', VISUALIZER_ABSURL . 'css/media.css', array( 'media-views' ), Visualizer_Plugin::VERSION ); |
| 363 | 342 | |
| 364 | - $d3_renderer_asset = VISUALIZER_ABSPATH . '/classes/Visualizer/D3Renderer/build/index.asset.php'; | |
| 365 | - if ( file_exists( $d3_renderer_asset ) && ! wp_script_is( 'visualizer-d3-renderer', 'registered' ) ) { | |
| 366 | - // @phpstan-ignore-next-line | |
| 367 | - $d3_asset = include $d3_renderer_asset; | |
| 368 | - wp_register_script( | |
| 369 | - 'visualizer-d3-renderer', | |
| 370 | - VISUALIZER_ABSURL . 'classes/Visualizer/D3Renderer/build/index.js', | |
| 371 | - array_merge( $d3_asset['dependencies'], array( 'jquery' ) ), | |
| 372 | - $d3_asset['version'], | |
| 373 | - true | |
| 374 | - ); | |
| 375 | - } | |
| 376 | - if ( wp_script_is( 'visualizer-d3-renderer', 'registered' ) ) { | |
| 377 | - wp_enqueue_script( 'visualizer-d3-renderer' ); | |
| 378 | - wp_localize_script( | |
| 379 | - 'visualizer-d3-renderer', | |
| 380 | - 'vizD3Renderer', | |
| 381 | - array( | |
| 382 | - 'iframeJsUrl' => VISUALIZER_ABSURL . 'classes/Visualizer/D3Renderer/build/iframe.js', | |
| 383 | - ) | |
| 384 | - ); | |
| 385 | - } | |
| 386 | - | |
| 387 | 343 | // Load all the assets for the different libraries we support. |
| 388 | 344 | $deps = array( |
| 389 | 345 | Visualizer_Render_Sidebar_Google::enqueue_assets( array( 'media-editor' ) ), |
| 390 | 346 | Visualizer_Render_Sidebar_Type_DataTable_Tabular::enqueue_assets( array( 'media-editor' ) ), |
| @@ -398,9 +354,9 @@ | ||
| 398 | 354 | 'visualizer-media-view', |
| 399 | 355 | 'visualizer', |
| 400 | 356 | array( |
| 401 | 357 | 'i10n' => array( |
| 402 | - 'insert' => __( 'Insert Chart', 'visualizer' ), | |
| 358 | + 'insert' => __( 'Insert', 'visualizer' ), | |
| 403 | 359 | ), |
| 404 | 360 | ) |
| 405 | 361 | ); |
| 406 | 362 | wp_enqueue_script( 'visualizer-media-toolbar', VISUALIZER_ABSURL . 'js/media/toolbar.js', array( 'visualizer-media-view' ), Visualizer_Plugin::VERSION, true ); |
| @@ -429,9 +385,9 @@ | ||
| 429 | 385 | 'controller' => array( |
| 430 | 386 | 'title' => esc_html__( 'Visualizations', 'visualizer' ), |
| 431 | 387 | ), |
| 432 | 388 | 'routers' => array( |
| 433 | - 'library' => esc_html__( 'Insert from Library', 'visualizer' ), | |
| 389 | + 'library' => esc_html__( 'From Library', 'visualizer' ), | |
| 434 | 390 | 'create' => esc_html__( 'Create New', 'visualizer' ), |
| 435 | 391 | ), |
| 436 | 392 | 'library' => array( |
| 437 | 393 | 'filters' => $chart_types, |
| @@ -436,9 +392,9 @@ | ||
| 436 | 392 | 'library' => array( |
| 437 | 393 | 'filters' => $chart_types, |
| 438 | 394 | 'types' => array_keys( $chart_types ), |
| 439 | 395 | ), |
| 440 | - 'nonce' => wp_create_nonce( Visualizer_Plugin::ACTION_GET_CHARTS ), | |
| 396 | + 'nonce' => wp_create_nonce(), | |
| 441 | 397 | 'buildurl' => esc_url( add_query_arg( 'action', Visualizer_Plugin::ACTION_CREATE_CHART, admin_url( 'admin-ajax.php' ) ) ), |
| 442 | 398 | ); |
| 443 | 399 | |
| 444 | 400 | return $strings; |
| @@ -461,9 +417,9 @@ | ||
| 461 | 417 | 'enabled' => true, |
| 462 | 418 | ); |
| 463 | 419 | } |
| 464 | 420 | |
| 465 | - $enabled = self::proFeaturesEnabled(); | |
| 421 | + $enabled = self::proFeaturesLocked(); | |
| 466 | 422 | |
| 467 | 423 | $types = array_merge( |
| 468 | 424 | $additional, |
| 469 | 425 | array( |
| @@ -682,159 +638,45 @@ | ||
| 682 | 638 | * |
| 683 | 639 | * @param string $suffix The current page suffix. |
| 684 | 640 | */ |
| 685 | 641 | public function enqueueLibraryScripts( $suffix ) { |
| 686 | - if ( $suffix !== $this->_libraryPage ) { | |
| 687 | - return; | |
| 688 | - } | |
| 689 | - | |
| 690 | - wp_enqueue_style( 'visualizer-library', VISUALIZER_ABSURL . 'css/library.css', array(), Visualizer_Plugin::VERSION ); | |
| 691 | - $this->_addFilter( 'media_upload_tabs', 'setupVisualizerTab' ); | |
| 692 | - wp_enqueue_media(); | |
| 693 | - wp_enqueue_script( | |
| 694 | - 'visualizer-library', | |
| 695 | - VISUALIZER_ABSURL . 'js/library.js', | |
| 696 | - array( | |
| 697 | - 'jquery', | |
| 698 | - 'media-views', | |
| 699 | - 'clipboard', | |
| 700 | - ), | |
| 701 | - Visualizer_Plugin::VERSION, | |
| 702 | - true | |
| 703 | - ); | |
| 704 | - | |
| 705 | - wp_enqueue_script( 'visualizer-customization', $this->get_user_customization_js(), array(), null, true ); | |
| 706 | - | |
| 707 | - $has_d3 = false; | |
| 708 | - $query = $this->getQuery(); | |
| 709 | - while ( $query->have_posts() ) { | |
| 710 | - $chart = $query->next_post(); | |
| 711 | - $library = $this->load_chart_type( $chart->ID ); | |
| 712 | - if ( is_null( $library ) ) { | |
| 713 | - continue; | |
| 714 | - } | |
| 642 | + if ( $suffix === $this->_libraryPage ) { | |
| 643 | + wp_enqueue_style( 'visualizer-library', VISUALIZER_ABSURL . 'css/library.css', array(), Visualizer_Plugin::VERSION ); | |
| 644 | + $this->_addFilter( 'media_upload_tabs', 'setupVisualizerTab' ); | |
| 645 | + wp_enqueue_media(); | |
| 715 | 646 | wp_enqueue_script( |
| 716 | - "visualizer-render-$library", | |
| 717 | - VISUALIZER_ABSURL . 'js/render-facade.js', | |
| 718 | - apply_filters( 'visualizer_assets_render', array( 'visualizer-library', 'visualizer-customization' ), true ), | |
| 647 | + 'visualizer-library', | |
| 648 | + VISUALIZER_ABSURL . 'js/library.js', | |
| 649 | + array( | |
| 650 | + 'jquery', | |
| 651 | + 'media-views', | |
| 652 | + 'clipboard', | |
| 653 | + ), | |
| 719 | 654 | Visualizer_Plugin::VERSION, |
| 720 | 655 | true |
| 721 | 656 | ); |
| 722 | - if ( 'd3' === $library ) { | |
| 723 | - $has_d3 = true; | |
| 724 | - } | |
| 725 | - } | |
| 726 | 657 | |
| 727 | - if ( $has_d3 ) { | |
| 728 | - $d3_renderer_asset = VISUALIZER_ABSPATH . '/classes/Visualizer/D3Renderer/build/index.asset.php'; | |
| 729 | - if ( file_exists( $d3_renderer_asset ) && ! wp_script_is( 'visualizer-d3-renderer', 'registered' ) ) { | |
| 730 | - /** | |
| 731 | - * Ignore missing build asset in source checkout. | |
| 732 | - * | |
| 733 | - * @phpstan-ignore-next-line | |
| 734 | - */ | |
| 735 | - $d3_asset = include $d3_renderer_asset; | |
| 736 | - wp_register_script( | |
| 737 | - 'visualizer-d3-renderer', | |
| 738 | - VISUALIZER_ABSURL . 'classes/Visualizer/D3Renderer/build/index.js', | |
| 739 | - array_merge( $d3_asset['dependencies'], array( 'jquery' ) ), | |
| 740 | - $d3_asset['version'], | |
| 741 | - true | |
| 742 | - ); | |
| 743 | - wp_enqueue_script( 'visualizer-d3-renderer' ); | |
| 744 | - } | |
| 745 | - wp_localize_script( | |
| 746 | - 'visualizer-d3-renderer', | |
| 747 | - 'vizD3Renderer', | |
| 748 | - array( | |
| 749 | - 'iframeJsUrl' => VISUALIZER_ABSURL . 'classes/Visualizer/D3Renderer/build/iframe.js', | |
| 750 | - ) | |
| 751 | - ); | |
| 752 | - } | |
| 658 | + wp_enqueue_script( 'visualizer-customization', $this->get_user_customization_js(), array(), null, true ); | |
| 753 | 659 | |
| 754 | - $chart_builder_asset = VISUALIZER_ABSPATH . '/classes/Visualizer/ChartBuilder/build/index.asset.php'; | |
| 755 | - if ( file_exists( $chart_builder_asset ) ) { | |
| 756 | - /** | |
| 757 | - * Ignore missing build asset in source checkout. | |
| 758 | - * | |
| 759 | - * @phpstan-ignore-next-line | |
| 760 | - */ | |
| 761 | - $asset = include $chart_builder_asset; | |
| 762 | - $chart_builder_deps = $asset['dependencies']; | |
| 763 | - if ( ! wp_script_is( 'visualizer-handsontable', 'registered' ) && defined( 'Visualizer_Pro_ABSURL' ) && defined( 'VISUALIZER_PRO_VERSION' ) ) { | |
| 764 | - wp_register_script( | |
| 765 | - 'visualizer-handsontable', | |
| 766 | - Visualizer_Pro_ABSURL . 'vendor/handsontable/dist/handsontable.full.min.js', | |
| 767 | - array(), | |
| 768 | - VISUALIZER_PRO_VERSION, | |
| 660 | + $query = $this->getQuery(); | |
| 661 | + while ( $query->have_posts() ) { | |
| 662 | + $chart = $query->next_post(); | |
| 663 | + $library = $this->load_chart_type( $chart->ID ); | |
| 664 | + if ( is_null( $library ) ) { | |
| 665 | + continue; | |
| 666 | + } | |
| 667 | + wp_enqueue_script( | |
| 668 | + "visualizer-render-$library", | |
| 669 | + VISUALIZER_ABSURL . 'js/render-facade.js', | |
| 670 | + apply_filters( 'visualizer_assets_render', array( 'visualizer-library', 'visualizer-customization' ), true ), | |
| 671 | + Visualizer_Plugin::VERSION, | |
| 769 | 672 | true |
| 770 | 673 | ); |
| 771 | 674 | } |
| 772 | - if ( ! wp_style_is( 'visualizer-handsontable', 'registered' ) && defined( 'Visualizer_Pro_ABSURL' ) && defined( 'VISUALIZER_PRO_VERSION' ) ) { | |
| 773 | - wp_register_style( | |
| 774 | - 'visualizer-handsontable', | |
| 775 | - Visualizer_Pro_ABSURL . 'vendor/handsontable/dist/handsontable.full.min.css', | |
| 776 | - array(), | |
| 777 | - VISUALIZER_PRO_VERSION | |
| 778 | - ); | |
| 779 | - } | |
| 780 | - if ( wp_script_is( 'visualizer-handsontable', 'registered' ) ) { | |
| 781 | - wp_enqueue_script( 'visualizer-handsontable' ); | |
| 782 | - $chart_builder_deps = array_unique( array_merge( $chart_builder_deps, array( 'visualizer-handsontable' ) ) ); | |
| 783 | - } | |
| 784 | - if ( wp_style_is( 'visualizer-handsontable', 'registered' ) ) { | |
| 785 | - wp_enqueue_style( 'visualizer-handsontable' ); | |
| 786 | - } | |
| 787 | - wp_enqueue_script( | |
| 788 | - 'visualizer-chart-builder', | |
| 789 | - VISUALIZER_ABSURL . 'classes/Visualizer/ChartBuilder/build/index.js', | |
| 790 | - $chart_builder_deps, | |
| 791 | - $asset['version'], | |
| 792 | - true | |
| 793 | - ); | |
| 794 | - wp_enqueue_style( | |
| 795 | - 'visualizer-chart-builder', | |
| 796 | - VISUALIZER_ABSURL . 'classes/Visualizer/ChartBuilder/build/style-index.css', | |
| 797 | - array(), | |
| 798 | - $asset['version'] | |
| 799 | - ); | |
| 800 | - $chart_builder_css = VISUALIZER_ABSPATH . '/classes/Visualizer/ChartBuilder/build/index.css'; | |
| 801 | - if ( file_exists( $chart_builder_css ) ) { | |
| 802 | - wp_enqueue_style( | |
| 803 | - 'visualizer-chart-builder-runtime', | |
| 804 | - VISUALIZER_ABSURL . 'classes/Visualizer/ChartBuilder/build/index.css', | |
| 805 | - array( 'visualizer-chart-builder' ), | |
| 806 | - $asset['version'] | |
| 807 | - ); | |
| 808 | - } | |
| 809 | - wp_localize_script( | |
| 810 | - 'visualizer-chart-builder', | |
| 811 | - 'vizAIBuilder', | |
| 812 | - array( | |
| 813 | - 'ajaxUrl' => admin_url( 'admin-ajax.php' ), | |
| 814 | - 'nonce' => wp_create_nonce( 'visualizer-ai-builder' ), | |
| 815 | - 'isPro' => Visualizer_Module::is_pro(), | |
| 816 | - 'upgradeUrl' => tsdk_utmify( Visualizer_Plugin::PRO_TEASER_URL, 'aiBuilderUpgrade', 'dataSource' ), | |
| 817 | - ) | |
| 818 | - ); | |
| 819 | 675 | } |
| 820 | - | |
| 821 | - do_action( 'themeisle_internal_page', VISUALIZER_DIRNAME, 'library' ); | |
| 822 | 676 | } |
| 823 | 677 | |
| 824 | 678 | /** |
| 825 | - * Enqueue script for support page. | |
| 826 | - * | |
| 827 | - * @param string $hook_suffix Current hook. | |
| 828 | - */ | |
| 829 | - public function enqueue_support_page( $hook_suffix ) { | |
| 830 | - if ( $this->_supportPage !== $hook_suffix ) { | |
| 831 | - return; | |
| 832 | - } | |
| 833 | - do_action( 'themeisle_internal_page', VISUALIZER_DIRNAME, 'support' ); | |
| 834 | - } | |
| 835 | - | |
| 836 | - /** | |
| 837 | 679 | * Adds visualizer tab for media upload tabs array. |
| 838 | 680 | * |
| 839 | 681 | * @since 1.0.0 |
| 840 | 682 | * |
| @@ -875,20 +717,10 @@ | ||
| 875 | 717 | __( 'Add New Chart', 'visualizer' ), |
| 876 | 718 | 'edit_posts', |
| 877 | 719 | 'admin.php?page=' . Visualizer_Plugin::NAME . '&vaction=addnew' |
| 878 | 720 | ); |
| 879 | - | |
| 880 | - $this->_settingsPage = add_submenu_page( | |
| 721 | + add_submenu_page( | |
| 881 | 722 | Visualizer_Plugin::NAME, |
| 882 | - __( 'Settings', 'visualizer' ), | |
| 883 | - __( 'Settings', 'visualizer' ), | |
| 884 | - 'manage_options', | |
| 885 | - 'viz-settings', | |
| 886 | - array( $this, 'renderSettingsPage' ) | |
| 887 | - ); | |
| 888 | - | |
| 889 | - $this->_supportPage = add_submenu_page( | |
| 890 | - Visualizer_Plugin::NAME, | |
| 891 | 723 | __( 'Support', 'visualizer' ), |
| 892 | 724 | __( 'Support', 'visualizer' ) . '<span class="dashicons dashicons-editor-help more-features-icon" style="width: 17px; height: 17px; margin-left: 4px; color: #ffca54; font-size: 17px; vertical-align: -3px;"></span>', |
| 893 | 725 | 'edit_posts', |
| 894 | 726 | 'viz-support', |
| @@ -936,9 +768,9 @@ | ||
| 936 | 768 | |
| 937 | 769 | /** |
| 938 | 770 | * Adds the screen options for pagination. |
| 939 | 771 | */ |
| 940 | - public function addScreenOptions() { | |
| 772 | + function addScreenOptions() { | |
| 941 | 773 | $screen = get_current_screen(); |
| 942 | 774 | |
| 943 | 775 | // bail if it's some other page. |
| 944 | 776 | if ( ! is_object( $screen ) || $screen->id !== $this->_libraryPage ) { |
| @@ -955,9 +787,9 @@ | ||
| 955 | 787 | |
| 956 | 788 | /** |
| 957 | 789 | * Returns the screen option for pagination. |
| 958 | 790 | */ |
| 959 | - public function setScreenOptions( $status, $option, $value ) { | |
| 791 | + function setScreenOptions( $status, $option, $value ) { | |
| 960 | 792 | if ( 'visualizer_library_per_page' === $option ) { |
| 961 | 793 | return $value; |
| 962 | 794 | } |
| 963 | 795 | } |
| @@ -1105,95 +937,13 @@ | ||
| 1105 | 937 | * @access public |
| 1106 | 938 | */ |
| 1107 | 939 | public function renderSupportPage() { |
| 1108 | 940 | wp_enqueue_style( 'visualizer-upsell', VISUALIZER_ABSURL . 'css/upsell.css', array(), Visualizer_Plugin::VERSION ); |
| 941 | + do_action( 'themeisle_internal_page', VISUALIZER_DIRNAME, 'support' ); | |
| 1109 | 942 | include_once VISUALIZER_ABSPATH . '/templates/support.php'; |
| 1110 | 943 | } |
| 1111 | 944 | |
| 1112 | 945 | /** |
| 1113 | - * Enqueues scripts/styles for the Settings page. | |
| 1114 | - * | |
| 1115 | - * @access public | |
| 1116 | - */ | |
| 1117 | - public function enqueueSettingsScripts( string $hook_suffix ): void { | |
| 1118 | - if ( $this->_settingsPage !== $hook_suffix ) { | |
| 1119 | - return; | |
| 1120 | - } | |
| 1121 | - wp_enqueue_style( 'wp-color-picker' ); | |
| 1122 | - wp_enqueue_script( 'wp-color-picker' ); | |
| 1123 | - } | |
| 1124 | - | |
| 1125 | - /** | |
| 1126 | - * Renders the global style settings page. | |
| 1127 | - * | |
| 1128 | - * @access public | |
| 1129 | - */ | |
| 1130 | - public function renderSettingsPage(): void { | |
| 1131 | - if ( ! current_user_can( 'manage_options' ) ) { | |
| 1132 | - wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'visualizer' ) ); | |
| 1133 | - } | |
| 1134 | - $settings = self::getGlobalSettings(); | |
| 1135 | - include_once VISUALIZER_ABSPATH . '/templates/global-settings.php'; | |
| 1136 | - } | |
| 1137 | - | |
| 1138 | - /** | |
| 1139 | - * Returns the global style settings option. | |
| 1140 | - * | |
| 1141 | - * @return array<string, string> | |
| 1142 | - * @access public | |
| 1143 | - * @static | |
| 1144 | - */ | |
| 1145 | - public static function getGlobalSettings(): array { | |
| 1146 | - $defaults = array( | |
| 1147 | - 'color_primary' => '', | |
| 1148 | - 'color_secondary' => '', | |
| 1149 | - 'apply_existing' => '0', | |
| 1150 | - ); | |
| 1151 | - $saved = get_option( self::OPTION_GLOBAL_SETTINGS, array() ); | |
| 1152 | - return wp_parse_args( $saved, $defaults ); | |
| 1153 | - } | |
| 1154 | - | |
| 1155 | - /** | |
| 1156 | - * Handles saving of the global style settings. | |
| 1157 | - * | |
| 1158 | - * @access public | |
| 1159 | - */ | |
| 1160 | - public function saveGlobalSettings(): void { | |
| 1161 | - if ( ! current_user_can( 'manage_options' ) ) { | |
| 1162 | - wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'visualizer' ) ); | |
| 1163 | - } | |
| 1164 | - | |
| 1165 | - check_admin_referer( 'visualizer_save_global_settings' ); | |
| 1166 | - | |
| 1167 | - $color_primary = sanitize_hex_color( wp_unslash( $_POST['visualizer_color_primary'] ?? '' ) ); | |
| 1168 | - $color_secondary = sanitize_hex_color( wp_unslash( $_POST['visualizer_color_secondary'] ?? '' ) ); | |
| 1169 | - $apply_existing = ! empty( $_POST['visualizer_apply_existing'] ) ? '1' : '0'; | |
| 1170 | - $clear = ! empty( $_POST['visualizer_clear_settings'] ); | |
| 1171 | - | |
| 1172 | - if ( $clear ) { | |
| 1173 | - delete_option( self::OPTION_GLOBAL_SETTINGS ); | |
| 1174 | - } else { | |
| 1175 | - $settings = array( | |
| 1176 | - 'color_primary' => $color_primary ? $color_primary : '', | |
| 1177 | - 'color_secondary' => $color_secondary ? $color_secondary : '', | |
| 1178 | - 'apply_existing' => $apply_existing, | |
| 1179 | - ); | |
| 1180 | - update_option( self::OPTION_GLOBAL_SETTINGS, $settings ); | |
| 1181 | - } | |
| 1182 | - | |
| 1183 | - wp_safe_redirect( | |
| 1184 | - add_query_arg( | |
| 1185 | - array( | |
| 1186 | - 'page' => 'viz-settings', | |
| 1187 | - 'updated' => $clear ? 'cleared' : 'true', | |
| 1188 | - ), | |
| 1189 | - admin_url( 'admin.php' ) | |
| 1190 | - ) | |
| 1191 | - ); | |
| 1192 | - exit; | |
| 1193 | - } | |
| 1194 | - | |
| 1195 | - /** | |
| 1196 | 946 | * Renders visualizer library page. |
| 1197 | 947 | * |
| 1198 | 948 | * @since 1.0.0 |
| 1199 | 949 | * |
| @@ -1277,9 +1027,8 @@ | ||
| 1277 | 1027 | |
| 1278 | 1028 | // add chart to the array |
| 1279 | 1029 | $charts[ $id ] = array( |
| 1280 | 1030 | 'id' => $chart->ID, |
| 1281 | - 'title' => $chart->post_title, | |
| 1282 | 1031 | 'type' => $type, |
| 1283 | 1032 | 'series' => $series, |
| 1284 | 1033 | 'settings' => $settings, |
| 1285 | 1034 | 'data' => $data, |
| @@ -1284,11 +1033,8 @@ | ||
| 1284 | 1033 | 'settings' => $settings, |
| 1285 | 1034 | 'data' => $data, |
| 1286 | 1035 | 'library' => $library, |
| 1287 | 1036 | ); |
| 1288 | - if ( 'd3' === $library ) { | |
| 1289 | - $charts[ $id ]['code'] = get_post_meta( $chart->ID, Visualizer_Module_AIBuilder::CF_D3_CODE, true ); | |
| 1290 | - } | |
| 1291 | 1037 | } |
| 1292 | 1038 | // enqueue charts array |
| 1293 | 1039 | $ajaxurl = admin_url( 'admin-ajax.php' ); |
| 1294 | 1040 | |
| @@ -1348,8 +1094,14 @@ | ||
| 1348 | 1094 | 'type' => 'array', |
| 1349 | 1095 | ) |
| 1350 | 1096 | ); |
| 1351 | 1097 | |
| 1098 | + do_action( 'themeisle_internal_page', VISUALIZER_DIRNAME, 'library' ); | |
| 1099 | + | |
| 1100 | + if ( ! apply_filters( 'visualizer_is_business', false ) ) { | |
| 1101 | + do_action( 'themeisle_sdk_load_banner', 'visualizer' ); | |
| 1102 | + } | |
| 1103 | + | |
| 1352 | 1104 | $render->render(); |
| 1353 | 1105 | } |
| 1354 | 1106 | |
| 1355 | 1107 | /** |
| @@ -1391,36 +1143,19 @@ | ||
| 1391 | 1143 | * |
| 1392 | 1144 | * @return array Updated array of plugin meta links. |
| 1393 | 1145 | */ |
| 1394 | 1146 | public function getPluginMetaLinks( $plugin_meta, $plugin_file ) { |
| 1395 | - if ( Visualizer_Module::is_pro() ) { | |
| 1396 | - return $plugin_meta; | |
| 1397 | - } | |
| 1398 | - | |
| 1399 | - // Also suppress the upsell when Pro is installed but not currently active. | |
| 1400 | - if ( ! function_exists( 'get_plugins' ) ) { | |
| 1401 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; | |
| 1402 | - } | |
| 1403 | - foreach ( array_keys( get_plugins() ) as $installed_plugin ) { | |
| 1404 | - if ( false !== strpos( $installed_plugin, 'visualizer-pro' ) ) { | |
| 1405 | - return $plugin_meta; | |
| 1406 | - } | |
| 1407 | - } | |
| 1408 | - | |
| 1409 | 1147 | if ( $plugin_file === plugin_basename( VISUALIZER_BASEFILE ) ) { |
| 1410 | - $is_black_friday = apply_filters( 'themeisle_sdk_is_black_friday_sale', false ); | |
| 1411 | 1148 | // knowledge base link |
| 1412 | 1149 | $plugin_meta[] = sprintf( |
| 1413 | 1150 | '<a href="' . VISUALIZER_MAIN_DOC . '" target="_blank">%s</a>', |
| 1414 | 1151 | esc_html__( 'Docs', 'visualizer' ) |
| 1415 | 1152 | ); |
| 1416 | - if ( ! $is_black_friday ) { | |
| 1417 | - // flattr link | |
| 1418 | - $plugin_meta[] = sprintf( | |
| 1419 | - '<a style="color:red" href="' . tsdk_utmify( Visualizer_Plugin::PRO_TEASER_URL, 'pluginrow' ) . '" target="_blank">%s</a>', | |
| 1420 | - esc_html__( 'Get Visualizer Pro', 'visualizer' ) | |
| 1421 | - ); | |
| 1422 | - } | |
| 1153 | + // flattr link | |
| 1154 | + $plugin_meta[] = sprintf( | |
| 1155 | + '<a style="color:red" href="' . tsdk_utmify( Visualizer_Plugin::PRO_TEASER_URL, 'pluginrow' ) . '" target="_blank">%s</a>', | |
| 1156 | + esc_html__( 'Get Visualizer Pro', 'visualizer' ) | |
| 1157 | + ); | |
| 1423 | 1158 | } |
| 1424 | 1159 | |
| 1425 | 1160 | return $plugin_meta; |
| 1426 | 1161 | } |
| @@ -1425,39 +1160,17 @@ | ||
| 1425 | 1160 | return $plugin_meta; |
| 1426 | 1161 | } |
| 1427 | 1162 | |
| 1428 | 1163 | /** |
| 1429 | - * Returns true when premium chart types should be enabled for the current user. | |
| 1164 | + * If check is existing user. | |
| 1430 | 1165 | * |
| 1431 | - * Pro 1.9.0+ hooks the 'visualizer_is_pro' filter and returns true only when | |
| 1432 | - * the license is valid. Pre-1.9.0 Pro defined a Visualizer_Pro class instead; | |
| 1433 | - * we detect that as a fallback so those legacy installs still work. | |
| 1434 | - * | |
| 1435 | - * Passing false as the filter default ensures the constant VISUALIZER_PRO | |
| 1436 | - * (which is set to true whenever the Pro class exists, regardless of license | |
| 1437 | - * state) cannot bypass the license check. | |
| 1438 | - * | |
| 1439 | - * @return bool | |
| 1166 | + * @return bool Default false | |
| 1440 | 1167 | */ |
| 1441 | - public static function proFeaturesEnabled() { | |
| 1442 | - $is_pro_filter = apply_filters( 'visualizer_is_pro', false ); | |
| 1443 | - | |
| 1444 | - // Pro 1.9.0+: filter is hooked and returns true only with a valid license. | |
| 1445 | - if ( $is_pro_filter ) { | |
| 1168 | + public static function proFeaturesLocked() { | |
| 1169 | + if ( Visualizer_Module::is_pro() ) { | |
| 1446 | 1170 | return true; |
| 1447 | 1171 | } |
| 1448 | - | |
| 1449 | - // Pro is installed (active) but the license check above did not pass. | |
| 1450 | - // Do NOT fall through to the legacy "old user" path — that path exists | |
| 1451 | - // only for sites that never had Pro installed. If Pro is present but | |
| 1452 | - // the license is inactive we should lock, regardless of chart history. | |
| 1453 | - if ( class_exists( 'Visualizer_Pro', false ) ) { | |
| 1454 | - return false; | |
| 1455 | - } | |
| 1456 | - | |
| 1457 | - // No Pro installed at all: grant legacy access to existing users so | |
| 1458 | - // their charts are not suddenly broken when they upgrade the free plugin. | |
| 1459 | - return 'yes' === get_option( 'visualizer-new-user' ) ? false : true; | |
| 1172 | + return 'yes' === get_option( 'visualizer-new-user', 'yes' ) ? false : true; | |
| 1460 | 1173 | } |
| 1461 | 1174 | |
| 1462 | 1175 | /** |
| 1463 | 1176 | * Multilingual Support. |
| @@ -1589,70 +1302,6 @@ | ||
| 1589 | 1302 | ); |
| 1590 | 1303 | |
| 1591 | 1304 | $query = new WP_Query( $args); |
| 1592 | 1305 | return $query->post_count; |
| 1593 | - } | |
| 1594 | - | |
| 1595 | - /** | |
| 1596 | - * Set the black friday data. | |
| 1597 | - * | |
| 1598 | - * @param array $configs The configuration array for the loaded products. | |
| 1599 | - * @return array | |
| 1600 | - */ | |
| 1601 | - public function add_black_friday_data( $configs ) { | |
| 1602 | - $config = $configs['default']; | |
| 1603 | - | |
| 1604 | - $message = __( 'Database queries, private charts, auto-sync. Go beyond basic charts. Exclusively for existing Visualizer users.', 'visualizer' ); | |
| 1605 | - $cta_label = __( 'Get Visualizer Pro', 'visualizer' ); | |
| 1606 | - | |
| 1607 | - $plan = apply_filters( 'product_visualizer_license_plan', 0 ); | |
| 1608 | - $license = apply_filters( 'product_visualizer_license_key', false ); | |
| 1609 | - $status = apply_filters( 'product_visualizer_license_status', false ); | |
| 1610 | - $pro_product_slug = defined( 'VISUALIZER_PRO_BASEFILE' ) ? basename( dirname( VISUALIZER_PRO_BASEFILE ) ) : ''; | |
| 1611 | - | |
| 1612 | - $is_pro = 'valid' === $status; | |
| 1613 | - $is_expired = 'expired' === $status || 'active-expired' === $status; | |
| 1614 | - | |
| 1615 | - if ( $is_pro ) { | |
| 1616 | - // translators: %s is the discount percentage. | |
| 1617 | - $config['plugin_meta_message'] = sprintf( __( 'Black Friday Sale - up to %s off', 'visualizer' ), '30%' ); | |
| 1618 | - // translators: %1$s - discount, %2$s - discount. | |
| 1619 | - $message = sprintf( __( 'Upgrade your Visualizer Pro plan: %1$s off this week. Already on the plan you need? Renew early and save up to %2$s.', 'visualizer' ), '30%', '20%' ); | |
| 1620 | - $cta_label = __( 'See your options', 'visualizer' ); | |
| 1621 | - } elseif ( $is_expired ) { | |
| 1622 | - // translators: %s is the discount percentage. | |
| 1623 | - $config['upgrade_menu_text'] = sprintf( __( 'BF Sale - %s off', 'visualizer' ), '50%' ); | |
| 1624 | - // translators: %s is the discount percentage. | |
| 1625 | - $config['plugin_meta_message'] = sprintf( __( 'Black Friday Sale - %s off', 'visualizer' ), '50%' ); | |
| 1626 | - $message = __( 'Your Visualizer Pro features are still here, just locked. Renew at a reduced rate this week.', 'visualizer' ); | |
| 1627 | - $cta_label = __( 'Reactivate now', 'visualizer' ); | |
| 1628 | - } else { | |
| 1629 | - // translators: %s is the discount percentage. | |
| 1630 | - $config['plugin_meta_message'] = sprintf( __( 'Black Friday Sale - %s off', 'visualizer' ), '60%' ); | |
| 1631 | - $config['title'] = __( 'Visualizer Pro: 60% off this week', 'visualizer' ); | |
| 1632 | - // translators: %s is the discount percentage. | |
| 1633 | - $config['upgrade_menu_text'] = sprintf( __( 'BF Sale - %s off', 'visualizer' ), '60%' ); | |
| 1634 | - } | |
| 1635 | - | |
| 1636 | - $url_params = array( | |
| 1637 | - 'utm_term' => $is_pro ? 'plan-' . $plan : 'free', | |
| 1638 | - 'lkey' => ! empty( $license ) ? $license : false, | |
| 1639 | - 'expired' => $is_expired ? '1' : false, | |
| 1640 | - ); | |
| 1641 | - | |
| 1642 | - if ( ( $is_pro || $is_expired ) && ! empty( $pro_product_slug ) ) { | |
| 1643 | - $config['plugin_meta_targets'] = array( $pro_product_slug ); | |
| 1644 | - } | |
| 1645 | - | |
| 1646 | - $config['message'] = $message; | |
| 1647 | - $config['cta_label'] = $cta_label; | |
| 1648 | - | |
| 1649 | - $config['sale_url'] = add_query_arg( | |
| 1650 | - $url_params, | |
| 1651 | - tsdk_translate_link( tsdk_utmify( 'https://themeisle.link/vizualizer-bf', 'bfcm', 'visualizer' ) ) | |
| 1652 | - ); | |
| 1653 | - | |
| 1654 | - $configs[ VISUALIZER_DIRNAME ] = $config; | |
| 1655 | - | |
| 1656 | - return $configs; | |
| 1657 | 1306 | } |
| 1658 | 1307 | } |