PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.11.10
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.11.10
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 All 149 releases
← All changes | vendor/codeinwp/themeisle-sdk/src/Modules/Promotions.php +53 -505 4.0.33.11.10 View file →
@@ -105,15 +105,8 @@
105 105 */
106 106 private $option_feedzy = 'themeisle_sdk_promotions_feedzy_installed';
107 107
108 108 /**
109 - * Option key for Masteriyo promos.
110 - *
111 - * @var string
112 - */
113 - private $option_masteriyo = 'themeisle_sdk_promotions_masteriyo_installed';
114 -
115 - /**
116 109 * Loaded promotion.
117 110 *
118 111 * @var string
119 112 */
@@ -158,9 +151,8 @@
158 151 $promotions_to_load[] = 'redirection-cf7';
159 152 $promotions_to_load[] = 'hyve';
160 153 $promotions_to_load[] = 'wp_full_pay';
161 154 $promotions_to_load[] = 'feedzy_import';
162 - $promotions_to_load[] = 'learning-management-system';
163 155
164 156 if ( defined( 'NEVE_VERSION' ) || defined( 'WPMM_PATH' ) || defined( 'OTTER_BLOCKS_VERSION' ) || defined( 'OBFX_URL' ) ) {
165 157 $promotions_to_load[] = 'feedzy_embed';
166 158 }
@@ -201,12 +193,9 @@
201 193
202 194 add_filter( 'attachment_fields_to_edit', array( $this, 'add_attachment_field' ), 10, 2 );
203 195 add_action( 'current_screen', [ $this, 'load_available' ] );
204 196 add_action( 'elementor/editor/after_enqueue_scripts', array( $this, 'enqueue' ) );
205 - add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_visualizer_block_editor_shim' ), 100 );
206 197 add_action( 'wp_ajax_tisdk_update_option', array( $this, 'dismiss_promotion' ) );
207 - add_filter( 'plugins_api_result', array( $this, 'inject_visualizer_block_directory_suggestion' ), 10, 3 );
208 - add_filter( 'option_visualizer-activated', array( $this, 'suppress_visualizer_onboarding_in_editor' ) );
209 198 add_filter( 'themeisle_sdk_ran_promos', '__return_true' );
210 199
211 200 if ( get_option( $this->option_neve, false ) !== true ) {
212 201 add_action( 'wp_ajax_themeisle_sdk_dismiss_notice', 'ThemeisleSDK\Modules\Notification::regular_dismiss' );
@@ -212,205 +201,9 @@
212 201 add_action( 'wp_ajax_themeisle_sdk_dismiss_notice', 'ThemeisleSDK\Modules\Notification::regular_dismiss' );
213 202 }
214 203 }
215 204
216 -
217 205 /**
218 - * Inject Visualizer as the first block-directory suggestion for chart queries.
219 - *
220 - * @param object|WP_Error $res Response object or WP_Error.
221 - * @param string $action The API action.
222 - * @param object $args The API arguments.
223 - * @return object|WP_Error
224 - */
225 - public function inject_visualizer_block_directory_suggestion( $res, $action, $args ) {
226 - if ( 'query_plugins' !== $action || ! is_object( $args ) || empty( $args->block ) ) {
227 - return $res;
228 - }
229 -
230 - if ( ! $this->should_suggest_visualizer( $args->block ) ) {
231 - return $res;
232 - }
233 -
234 - if ( $this->is_plugin_installed( 'visualizer' ) ) {
235 - return $res;
236 - }
237 -
238 - $plugin = $this->get_visualizer_block_directory_data();
239 - if ( empty( $plugin ) ) {
240 - return $res;
241 - }
242 -
243 - if ( is_wp_error( $res ) ) {
244 - $res = (object) array( 'plugins' => array() );
245 - }
246 -
247 - if ( ! isset( $res->plugins ) || ! is_array( $res->plugins ) ) {
248 - $res->plugins = array();
249 - }
250 -
251 - $res->plugins = array_values(
252 - array_filter(
253 - $res->plugins,
254 - function ( $existing ) use ( $plugin ) {
255 - return ! isset( $existing['slug'] ) || $existing['slug'] !== $plugin['slug'];
256 - }
257 - )
258 - );
259 -
260 - array_unshift( $res->plugins, $plugin );
261 -
262 - return $res;
263 - }
264 -
265 - /**
266 - * Check if the query should trigger the Visualizer suggestion.
267 - *
268 - * @param string $term Search term.
269 - * @return bool
270 - */
271 - private function should_suggest_visualizer( $term ) {
272 - $term = strtolower( (string) $term );
273 - return false !== strpos( $term, 'chart' ) || false !== strpos( $term, 'visualizer' ) || false !== strpos( $term, 'visualization' ) || false !== strpos( $term, 'graph' );
274 - }
275 -
276 - /**
277 - * Build the plugin data for Visualizer block directory results.
278 - *
279 - * @return array
280 - */
281 - private function get_visualizer_block_directory_data() {
282 - $slug = 'visualizer';
283 - $plugin_info = $this->call_plugin_api( $slug );
284 -
285 - if ( is_wp_error( $plugin_info ) || empty( $plugin_info ) ) {
286 - return array();
287 - }
288 -
289 - $icons = array();
290 - if ( ! empty( $plugin_info->icons ) ) {
291 - if ( ! empty( $plugin_info->icons['1x'] ) ) {
292 - $icons['1x'] = $plugin_info->icons['1x'];
293 - }
294 - if ( ! empty( $plugin_info->icons['2x'] ) ) {
295 - $icons['2x'] = $plugin_info->icons['2x'];
296 - }
297 - }
298 -
299 - $name = isset( $plugin_info->name ) ? $plugin_info->name : 'Visualizer';
300 -
301 - return array(
302 - 'slug' => $slug,
303 - 'name' => $name,
304 - 'short_description' => isset( $plugin_info->short_description ) ? $plugin_info->short_description : '',
305 - 'author' => isset( $plugin_info->author ) ? wp_strip_all_tags( $plugin_info->author ) : '',
306 - 'rating' => isset( $plugin_info->rating ) ? (int) $plugin_info->rating : 0,
307 - 'num_ratings' => isset( $plugin_info->num_ratings ) ? (int) $plugin_info->num_ratings : 0,
308 - 'active_installs' => isset( $plugin_info->active_installs ) ? (int) $plugin_info->active_installs : 0,
309 - 'author_block_rating' => isset( $plugin_info->author_block_rating ) ? (int) $plugin_info->author_block_rating : 0,
310 - 'author_block_count' => isset( $plugin_info->author_block_count ) ? (int) $plugin_info->author_block_count : 0,
311 - 'icons' => $icons,
312 - 'last_updated' => isset( $plugin_info->last_updated ) ? $plugin_info->last_updated : gmdate( 'Y-m-d H:i:s' ),
313 - 'blocks' => array(
314 - array(
315 - 'name' => 'visualizer/chart',
316 - 'title' => $name,
317 - ),
318 - ),
319 - );
320 - }
321 -
322 -
323 - /**
324 - * Prevent Visualizer onboarding redirects while in the block editor.
325 - *
326 - * @param mixed $value Option value.
327 - * @return mixed
328 - */
329 - public function suppress_visualizer_onboarding_in_editor( $value ) {
330 - if ( ! $this->is_block_editor_screen() ) {
331 - return $value;
332 - }
333 -
334 - return false;
335 - }
336 -
337 - /**
338 - * Add a small compatibility shim for Visualizer's block editor bundle.
339 - *
340 - * Visualizer's "Display an existing chart" flow reads
341 - * `google.visualization.Version` before the Google Charts loader has fully
342 - * populated `google.visualization`, which can throw after dynamic install.
343 - *
344 - * @return void
345 - */
346 - public function enqueue_visualizer_block_editor_shim() {
347 - global $themeisle_sdk_max_version;
348 -
349 - if ( ! $this->is_block_editor_screen() ) {
350 - return;
351 - }
352 -
353 - if ( ! wp_script_is( 'visualizer-gutenberg-block', 'enqueued' ) ) {
354 - return;
355 - }
356 -
357 - wp_register_script(
358 - 'ti-sdk-visualizer-editor-shim',
359 - '',
360 - array(),
361 - $themeisle_sdk_max_version,
362 - true
363 - );
364 - wp_enqueue_script( 'ti-sdk-visualizer-editor-shim' );
365 - wp_add_inline_script(
366 - 'ti-sdk-visualizer-editor-shim',
367 - 'window.google = window.google || {}; window.google.visualization = window.google.visualization || {}; window.google.visualization.Version = window.google.visualization.Version || "current";'
368 - );
369 - }
370 -
371 - /**
372 - * Check if the current admin screen is the block editor.
373 - *
374 - * @return bool
375 - */
376 - private function is_block_editor_screen() {
377 - if ( ! function_exists( 'get_current_screen' ) ) {
378 - return $this->is_block_editor_request();
379 - }
380 -
381 - $screen = get_current_screen();
382 - if ( is_object( $screen ) && method_exists( $screen, 'is_block_editor' ) && $screen->is_block_editor() ) {
383 - return true;
384 - }
385 -
386 - return $this->is_block_editor_request();
387 - }
388 -
389 - /**
390 - * Detect block editor requests before the current screen is available.
391 - *
392 - * @return bool
393 - */
394 - private function is_block_editor_request() {
395 - global $pagenow;
396 -
397 - if ( 'post-new.php' === $pagenow ) {
398 - $post_type = isset( $_GET['post_type'] ) ? sanitize_key( $_GET['post_type'] ) : 'post';
399 -
400 - return function_exists( 'use_block_editor_for_post_type' ) ? use_block_editor_for_post_type( $post_type ) : true;
401 - }
402 -
403 - if ( 'post.php' === $pagenow && isset( $_GET['post'] ) ) {
404 - $post_id = absint( $_GET['post'] );
405 -
406 - return function_exists( 'use_block_editor_for_post' ) ? use_block_editor_for_post( $post_id ) : true;
407 - }
408 -
409 - return false;
410 - }
411 -
412 - /**
413 206 * Load available promotions.
414 207 */
415 208 public function load_available() {
416 209 $this->promotions = $this->filter_by_screen_and_merge();
@@ -463,9 +256,8 @@
463 256
464 257 if ( isset( $_GET['wp_full_pay_reference_key'] ) ) {
465 258 update_option( 'wp_full_pay_reference_key', sanitize_key( $_GET['wp_full_pay_reference_key'] ) );
466 259 }
467 -
468 260 if ( isset( $_GET['feedzy_reference_key'] ) || ( isset( $_GET['from'], $_GET['plugin'] ) && $_GET['from'] === 'import' && str_starts_with( sanitize_key( $_GET['plugin'] ), 'feedzy' ) ) ) {
469 261 update_option( 'feedzy_reference_key', sanitize_key( $_GET['feedzy_reference_key'] ?? 'i-' . $this->product->get_key() ) );
470 262 update_option( $this->option_feedzy, 1 );
471 263 }
@@ -557,18 +349,8 @@
557 349 'show_in_rest' => true,
558 350 'default' => false,
559 351 )
560 352 );
561 - register_setting(
562 - 'themeisle_sdk_settings',
563 - $this->option_masteriyo,
564 - array(
565 - 'type' => 'boolean',
566 - 'sanitize_callback' => 'rest_sanitize_boolean',
567 - 'show_in_rest' => true,
568 - 'default' => false,
569 - )
570 - );
571 353 }
572 354
573 355 /**
574 356 * Check if the path is writable.
@@ -620,17 +402,14 @@
620 402 $has_sparks = defined( 'SPARKS_WC_VERSION' ) || $this->is_plugin_installed( 'sparks-for-woocommerce' );
621 403 $has_ppom = defined( 'PPOM_VERSION' ) || $this->is_plugin_installed( 'woocommerce-product-addon' );
622 404 $has_redirection_cf7 = defined( 'WPCF7_PRO_REDIRECT_PLUGIN_VERSION' ) || $this->is_plugin_installed( 'wpcf7-redirect' );
623 405 $had_redirection_cf7_promo = get_option( $this->option_redirection_cf7, false );
624 - $is_min_php_7_4 = version_compare( PHP_VERSION, '7.4', '>=' );
625 - $is_min_php_7_2 = version_compare( PHP_VERSION, '7.2', '>=' );
626 - $can_check_plugin_install = $this->can_check_plugin_install_promo();
627 406 $has_hyve = defined( 'HYVE_LITE_VERSION' ) || $this->is_plugin_installed( 'hyve' ) || $this->is_plugin_installed( 'hyve-lite' );
628 407 $had_hyve_from_promo = get_option( $this->option_hyve, false );
629 - $has_hyve_conditions = $is_min_php_7_4 && ! $has_hyve && ! $had_hyve_from_promo && version_compare( get_bloginfo( 'version' ), '6.2', '>=' ) && $can_check_plugin_install && $this->has_support_page();
408 + $has_hyve_conditions = version_compare( get_bloginfo( 'version' ), '6.2', '>=' ) && $this->has_support_page();
630 409 $has_wfp_full_pay = defined( 'WP_FULL_STRIPE_BASENAME' ) || $this->is_plugin_installed( 'wp-full-stripe-free' );
631 410 $had_wfp_from_promo = get_option( $this->option_wp_full_pay, false );
632 - $has_wfp_conditions = ! $has_wfp_full_pay && ! $had_wfp_from_promo && $can_check_plugin_install && $this->has_donate_page();
411 + $has_wfp_conditions = $this->has_donate_page();
633 412 $is_min_req_v = version_compare( get_bloginfo( 'version' ), '5.8', '>=' );
634 413 $current_theme = wp_get_theme();
635 414 $has_neve = $current_theme->template === 'neve' || $current_theme->parent() === 'neve';
636 415 $has_neve_from_promo = get_option( $this->option_neve, false );
@@ -635,15 +414,15 @@
635 414 $has_neve = $current_theme->template === 'neve' || $current_theme->parent() === 'neve';
636 415 $has_neve_from_promo = get_option( $this->option_neve, false );
637 416 $has_enough_attachments = $this->has_min_media_attachments();
638 417 $has_enough_old_posts = $this->has_old_posts();
639 - $has_feedzy = defined( 'FEEDZY_BASEFILE' ) || $this->is_plugin_installed( 'feedzy-rss-feedss' );
640 - $had_feedzy_from_promo = get_option( $this->option_feedzy, false );
641 - $had_masteriyo_from_promo = get_option( $this->option_masteriyo, false );
642 - $has_masteriyo_conditions = $is_min_php_7_2 && ! $had_masteriyo_from_promo && ! $this->has_active_lms_plugin() && $can_check_plugin_install && $this->has_lms_tagline();
418 + $is_min_php_8_1 = version_compare( PHP_VERSION, '8.1', '>=' );
643 419
420 + $has_feedzy = defined( 'FEEDZY_BASEFILE' ) || $this->is_plugin_installed( 'feedzy-rss-feedss' );
421 + $had_feedzy_from_promo = get_option( $this->option_feedzy, false );
422 +
644 423 $all = [
645 - 'optimole' => [
424 + 'optimole' => [
646 425 'om-editor' => [
647 426 'env' => ! $has_optimole && $is_min_req_v && ! $had_optimole_from_promo,
648 427 'screen' => 'editor',
649 428 'delayed' => true,
@@ -666,9 +445,9 @@
666 445 'screen' => 'elementor',
667 446 'delayed' => true,
668 447 ],
669 448 ],
670 - 'feedzy_import' => [
449 + 'feedzy_import' => [
671 450 'feedzy-import' => [
672 451 'env' => true,
673 452 'screen' => 'import',
674 453 'always' => true,
@@ -673,15 +452,15 @@
673 452 'screen' => 'import',
674 453 'always' => true,
675 454 ],
676 455 ],
677 - 'feedzy_embed' => [
456 + 'feedzy_embed' => [
678 457 'feedzy-editor' => [
679 458 'env' => ! $has_feedzy && is_main_site() && ! $had_feedzy_from_promo,
680 459 'screen' => 'editor',
681 460 ],
682 461 ],
683 - 'otter' => [
462 + 'otter' => [
684 463 'blocks-css' => [
685 464 'env' => ! $has_otter && $is_min_req_v && ! $had_otter_from_promo,
686 465 'screen' => 'editor',
687 466 'delayed' => true,
@@ -696,9 +475,9 @@
696 475 'screen' => 'editor',
697 476 'delayed' => true,
698 477 ],
699 478 ],
700 - 'rop' => [
479 + 'rop' => [
701 480 'rop-posts' => [
702 481 'env' => ! $has_rop && ! $had_rop_from_promo && $has_enough_old_posts,
703 482 'screen' => 'edit-post',
704 483 'delayed' => true,
@@ -703,9 +482,9 @@
703 482 'screen' => 'edit-post',
704 483 'delayed' => true,
705 484 ],
706 485 ],
707 - 'woo_plugins' => [
486 + 'woo_plugins' => [
708 487 'ppom' => [
709 488 'env' => ! $has_ppom && $has_woocommerce,
710 489 'screen' => 'edit-product',
711 490 ],
@@ -721,15 +500,15 @@
721 500 'env' => ! $has_sparks && $has_woocommerce,
722 501 'screen' => 'edit-product',
723 502 ],
724 503 ],
725 - 'neve' => [
504 + 'neve' => [
726 505 'neve-themes-popular' => [
727 506 'env' => ! $has_neve && ! $has_neve_from_promo,
728 507 'screen' => 'themes-install-popular',
729 508 ],
730 509 ],
731 - 'redirection-cf7' => [
510 + 'redirection-cf7' => [
732 511 'wpcf7' => [
733 512 'env' => ! $has_redirection_cf7 && ! $had_redirection_cf7_promo,
734 513 'screen' => 'wpcf7',
735 514 'delayed' => true,
@@ -734,26 +513,20 @@
734 513 'screen' => 'wpcf7',
735 514 'delayed' => true,
736 515 ],
737 516 ],
738 - 'hyve' => [
517 + 'hyve' => [
739 518 'hyve-plugins-install' => [
740 - 'env' => $has_hyve_conditions,
519 + 'env' => $is_min_php_8_1 && ! $has_hyve && ! $had_hyve_from_promo && $has_hyve_conditions,
741 520 'screen' => 'plugin-install',
742 521 ],
743 522 ],
744 - 'wp_full_pay' => [
523 + 'wp_full_pay' => [
745 524 'wp-full-pay-plugins-install' => [
746 - 'env' => $has_wfp_conditions,
525 + 'env' => ! $has_wfp_full_pay && ! $had_wfp_from_promo && $has_wfp_conditions,
747 526 'screen' => 'plugin-install',
748 527 ],
749 528 ],
750 - 'learning-management-system' => [
751 - 'masteriyo-plugins-install' => [
752 - 'env' => $has_masteriyo_conditions,
753 - 'screen' => 'plugin-install',
754 - ],
755 - ],
756 529 ];
757 530
758 531 foreach ( $all as $slug => $data ) {
759 532 foreach ( $data as $key => $conditions ) {
@@ -949,12 +722,8 @@
949 722 if ( $this->get_upsells_dismiss_time( 'wp-full-pay-plugins-install' ) === false ) {
950 723 add_action( 'admin_notices', [ $this, 'render_wp_full_pay_notice' ] );
951 724 }
952 725
953 - if ( $this->get_upsells_dismiss_time( 'masteriyo-plugins-install' ) === false ) {
954 - add_action( 'admin_notices', [ $this, 'render_masteriyo_notice' ] );
955 - }
956 -
957 726 add_action( 'load-import.php', [ $this, 'add_import' ] );
958 727 $this->load_woo_promos();
959 728
960 729 return;
@@ -1018,12 +787,8 @@
1018 787 case 'wp-full-pay-plugins-install':
1019 788 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue' ] );
1020 789 add_action( 'admin_notices', [ $this, 'render_wp_full_pay_notice' ] );
1021 790 break;
1022 - case 'masteriyo-plugins-install':
1023 - add_action( 'admin_enqueue_scripts', [ $this, 'enqueue' ] );
1024 - add_action( 'admin_notices', [ $this, 'render_masteriyo_notice' ] );
1025 - break;
1026 791 }
1027 792 }
1028 793
1029 794 /**
@@ -1115,10 +880,8 @@
1115 880 'hyveActivationUrl' => $this->get_plugin_activation_link( 'hyve-lite' ),
1116 881 'hyveDash' => esc_url( add_query_arg( [ 'page' => 'wpfs-settings-stripe' ], admin_url( 'admin.php' ) ) ),
1117 882 'wpFullPayActivationUrl' => $this->get_plugin_activation_link( 'wp-full-stripe-free' ),
1118 883 'wpFullPayDash' => esc_url( add_query_arg( [ 'page' => 'wpfs-settings-stripe' ], admin_url( 'admin.php' ) ) ),
1119 - 'masteriyoActivationUrl' => $this->get_plugin_activation_link( 'masteriyo' ),
1120 - 'masteriyoDash' => esc_url( add_query_arg( [ 'page' => 'masteriyo-onboard' ], admin_url( 'index.php' ) ) ),
1121 884 'nevePreviewURL' => esc_url( add_query_arg( [ 'theme' => 'neve' ], admin_url( 'theme-install.php' ) ) ),
1122 885 'neveAction' => $neve_action,
1123 886 'activateNeveURL' => esc_url(
1124 887 add_query_arg(
@@ -1177,15 +940,8 @@
1177 940 echo '<div id="ti-redirection-cf7-notice" class="notice notice-info ti-sdk-om-notice"></div>';
1178 941 }
1179 942
1180 943 /**
1181 - * Render Masteriyo notice.
1182 - */
1183 - public function render_masteriyo_notice() {
1184 - echo '<div id="ti-masteriyo-notice" class="notice notice-info ti-sdk-om-notice"></div>';
1185 - }
1186 -
1187 - /**
1188 944 * Add promo to attachment modal.
1189 945 *
1190 946 * @param array $fields Fields array.
1191 947 * @param \WP_Post $post Post object.
@@ -1597,265 +1353,57 @@
1597 1353 /**
1598 1354 * Check if the user has a support page.
1599 1355 */
1600 1356 public function has_support_page() {
1601 - $page_title_matches = $this->get_page_title_keyword_matches();
1357 + $transient_name = 'tisdk_has_support_page';
1358 + $has_support = get_transient( $transient_name );
1602 1359
1603 - return 'yes' === $page_title_matches['support'];
1604 - }
1360 + if ( false === $has_support ) {
1361 + global $wpdb;
1605 1362
1606 - /**
1607 - * Check if the user has a donate page.
1608 - */
1609 - public function has_donate_page() {
1610 - $page_title_matches = $this->get_page_title_keyword_matches();
1363 + // We use %i escape identifier that was added in WP 6.2.0, hence need to ignore PHPCS warning.
1364 + // We only show this notice to users on higher version as that is the minimum for Hyve as well.
1365 + $query = $wpdb->get_var( //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
1366 + $wpdb->prepare( // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber
1367 + 'SELECT ID FROM %i WHERE post_type = %s AND post_status = %s AND post_title LIKE %s LIMIT 1', // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnsupportedPlaceholder
1368 + $wpdb->posts,
1369 + 'page',
1370 + 'publish',
1371 + '%support%'
1372 + )
1373 + );
1611 1374
1612 - return 'yes' === $page_title_matches['donate'];
1613 - }
1375 + $has_support = $query ? 'yes' : 'no';
1614 1376
1615 - /**
1616 - * Check if the tagline or a published page title contains LMS related keywords.
1617 - *
1618 - * @return bool True if LMS-related keywords are found, false otherwise.
1619 - */
1620 - public function has_lms_tagline() {
1621 - $tagline = strtolower( get_bloginfo( 'description' ) );
1622 -
1623 - foreach ( $this->get_lms_keywords() as $keyword ) {
1624 - if ( $this->has_lms_keyword_match( $tagline, $keyword ) ) {
1625 - return true;
1626 - }
1377 + set_transient( $transient_name, $has_support, 7 * DAY_IN_SECONDS );
1627 1378 }
1628 1379
1629 - return $this->has_lms_page_title();
1380 + return 'yes' === $has_support;
1630 1381 }
1631 1382
1632 1383 /**
1633 - * Check if a supported LMS plugin is active.
1634 - *
1635 - * @return bool True if an LMS plugin is active, false otherwise.
1384 + * Check if the user has a donate page.
1636 1385 */
1637 - private function has_active_lms_plugin() {
1638 - if ( defined( 'MASTERIYO_VERSION' ) ) {
1639 - return true;
1640 - }
1386 + public function has_donate_page() {
1387 + $transient_name = 'tisdk_has_donate_page';
1388 + $has_donate = get_transient( $transient_name );
1641 1389
1642 - include_once ABSPATH . 'wp-admin/includes/plugin.php';
1390 + if ( false === $has_donate ) {
1391 + global $wpdb;
1643 1392
1644 - $lms_plugins = array(
1645 - 'tutor/tutor.php',
1646 - 'sfwd-lms/sfwd_lms.php',
1647 - 'lifterlms/lifterlms.php',
1648 - 'sensei-lms/sensei-lms.php',
1649 - 'learnpress/learnpress.php',
1650 - 'masterstudy-lms-learning-management-system/masterstudy-lms-learning-management-system.php',
1651 - 'learning-management-system/lms.php',
1652 - );
1393 + $query = $wpdb->get_var( //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
1394 + $wpdb->prepare(
1395 + 'SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_status = %s AND post_title LIKE %s LIMIT 1',
1396 + 'page',
1397 + 'publish',
1398 + '%donate%'
1399 + )
1400 + );
1653 1401
1654 - foreach ( $lms_plugins as $plugin ) {
1655 - if ( is_plugin_active( $plugin ) || ( is_multisite() && is_plugin_active_for_network( $plugin ) ) ) {
1656 - return true;
1657 - }
1658 - }
1402 + $has_donate = $query ? 'yes' : 'no';
1659 1403
1660 - return false;
1661 - }
1662 -
1663 - /**
1664 - * Check if the current request can display a plugin install promo.
1665 - *
1666 - * @return bool True if a plugin install promo can be displayed, false otherwise.
1667 - */
1668 - private function can_check_plugin_install_promo() {
1669 - if ( ! is_admin() || ! current_user_can( 'install_plugins' ) ) {
1670 - return false;
1404 + set_transient( $transient_name, $has_donate, 7 * DAY_IN_SECONDS );
1671 1405 }
1672 1406
1673 - $current_screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null;
1674 - if ( isset( $current_screen->id ) ) {
1675 - return $current_screen->id === 'plugin-install';
1676 - }
1677 -
1678 - global $pagenow;
1679 -
1680 - return isset( $pagenow ) && $pagenow === 'plugin-install.php';
1681 - }
1682 -
1683 - /**
1684 - * Check if a published page title contains LMS related keywords.
1685 - *
1686 - * @return bool True if an LMS-related page title is found, false otherwise.
1687 - */
1688 - private function has_lms_page_title() {
1689 - $lms_page_title_signal = get_transient( 'tisdk_lms_page_title_signal_v1' );
1690 -
1691 - if ( in_array( $lms_page_title_signal, array( 'yes', 'no' ), true ) ) {
1692 - return 'yes' === $lms_page_title_signal;
1693 - }
1694 -
1695 - $has_lms_page_title = $this->has_published_page_title_with_keywords( $this->get_lms_page_title_keywords() );
1696 -
1697 - set_transient( 'tisdk_lms_page_title_signal_v1', $has_lms_page_title ? 'yes' : 'no', 7 * DAY_IN_SECONDS );
1698 -
1699 - return $has_lms_page_title;
1700 - }
1701 -
1702 - /**
1703 - * Get cached keyword matches for published page titles.
1704 - *
1705 - * @return array Page title keyword matches.
1706 - */
1707 - private function get_page_title_keyword_matches() {
1708 - $default_matches = array(
1709 - 'support' => 'no',
1710 - 'donate' => 'no',
1711 - );
1712 -
1713 - $page_title_matches = get_transient( 'tisdk_page_title_signals_v1' );
1714 -
1715 - if ( is_array( $page_title_matches ) && empty( array_diff_key( $default_matches, $page_title_matches ) ) ) {
1716 - return array_merge( $default_matches, $page_title_matches );
1717 - }
1718 -
1719 - global $wpdb;
1720 -
1721 - $select_clauses = array();
1722 - $query_values = array();
1723 - $page_checks = $this->get_page_title_checks();
1724 -
1725 - foreach ( $page_checks as $match_key => $keywords ) {
1726 - $match_clauses = array();
1727 -
1728 - $query_values[] = 'page';
1729 - $query_values[] = 'publish';
1730 -
1731 - foreach ( $keywords as $keyword ) {
1732 - $match_clauses[] = 'post_title LIKE %s';
1733 - $query_values[] = '%' . $wpdb->esc_like( $keyword ) . '%';
1734 - }
1735 -
1736 - $select_clauses[] = 'EXISTS( SELECT 1 FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_status = %s AND ( ' . implode( ' OR ', $match_clauses ) . ' ) LIMIT 1 ) AS has_' . $match_key;
1737 - }
1738 -
1739 - // phpcs:disable WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
1740 - $query = $wpdb->get_row( //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
1741 - $wpdb->prepare(
1742 - 'SELECT ' . implode( ', ', $select_clauses ),
1743 - $query_values
1744 - ),
1745 - ARRAY_A
1746 - );
1747 - // phpcs:enable WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
1748 -
1749 - $page_title_matches = $default_matches;
1750 -
1751 - if ( is_array( $query ) ) {
1752 - foreach ( array_keys( $page_checks ) as $match_key ) {
1753 - $page_title_matches[ $match_key ] = ! empty( $query[ 'has_' . $match_key ] ) ? 'yes' : 'no';
1754 - }
1755 - }
1756 -
1757 - set_transient( 'tisdk_page_title_signals_v1', $page_title_matches, 7 * DAY_IN_SECONDS );
1758 -
1759 - return $page_title_matches;
1760 - }
1761 -
1762 - /**
1763 - * Check if a keyword matches content.
1764 - *
1765 - * @param string $content Content to check.
1766 - * @param string $keyword Keyword to look for.
1767 - *
1768 - * @return bool True if the keyword matches, false otherwise.
1769 - */
1770 - private function has_lms_keyword_match( $content, $keyword ) {
1771 - if ( in_array( $keyword, array( 'lms', 'course', 'class' ), true ) ) {
1772 - return preg_match( '/(^|[^a-z0-9])' . preg_quote( $keyword, '/' ) . '([^a-z0-9]|$)/', $content ) === 1;
1773 - }
1774 -
1775 - return strpos( $content, $keyword ) !== false;
1776 - }
1777 -
1778 - /**
1779 - * Get LMS related keywords.
1780 - *
1781 - * @return array LMS related keywords.
1782 - */
1783 - private function get_lms_keywords() {
1784 - return array(
1785 - 'lms',
1786 - 'learning',
1787 - 'course',
1788 - 'courses',
1789 - 'academy',
1790 - 'training',
1791 - 'lesson',
1792 - 'lessons',
1793 - 'class',
1794 - 'classes',
1795 - 'student',
1796 - 'students',
1797 - 'teach',
1798 - 'teaching',
1799 - 'tutor',
1800 - 'quiz',
1801 - 'education',
1802 - 'online course',
1803 - 'online courses',
1804 - );
1805 - }
1806 -
1807 - /**
1808 - * Get LMS related keywords for page title matching.
1809 - *
1810 - * @return array LMS related keywords.
1811 - */
1812 - private function get_lms_page_title_keywords() {
1813 - return array_values( array_diff( $this->get_lms_keywords(), array( 'lms', 'course', 'class' ) ) );
1814 - }
1815 -
1816 - /**
1817 - * Check if a published page title contains any of the provided keywords.
1818 - *
1819 - * @param array $keywords Keywords to look for.
1820 - *
1821 - * @return bool True if a matching page title is found, false otherwise.
1822 - */
1823 - private function has_published_page_title_with_keywords( $keywords ) {
1824 - if ( empty( $keywords ) ) {
1825 - return false;
1826 - }
1827 -
1828 - global $wpdb;
1829 -
1830 - $query_values = array( 'page', 'publish' );
1831 - $clauses = array();
1832 -
1833 - foreach ( $keywords as $keyword ) {
1834 - $clauses[] = 'post_title LIKE %s';
1835 - $query_values[] = '%' . $wpdb->esc_like( $keyword ) . '%';
1836 - }
1837 -
1838 - // phpcs:disable WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
1839 - $page_title_match = $wpdb->get_var( //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
1840 - $wpdb->prepare(
1841 - 'SELECT 1 FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_status = %s AND ( ' . implode( ' OR ', $clauses ) . ' ) LIMIT 1',
1842 - $query_values
1843 - )
1844 - );
1845 - // phpcs:enable WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
1846 -
1847 - return ! empty( $page_title_match );
1848 - }
1849 -
1850 - /**
1851 - * Get page title keyword checks.
1852 - *
1853 - * @return array Page title keyword checks.
1854 - */
1855 - private function get_page_title_checks() {
1856 - return array(
1857 - 'support' => array( 'support' ),
1858 - 'donate' => array( 'donate' ),
1859 - );
1407 + return 'yes' === $has_donate;
1860 1408 }
1861 1409 }