PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.11.14
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.11.14
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 +55 -465 4.0.83.11.14 View file →
@@ -119,15 +119,8 @@
119 119 */
120 120 private $loaded_promo;
121 121
122 122 /**
123 - * Whether promotions were processed for the current screen.
124 - *
125 - * @var bool
126 - */
127 - private $available_promotions_loaded = false;
128 -
129 - /**
130 123 * Woo promotions.
131 124 *
132 125 * @var array
133 126 */
@@ -208,225 +201,21 @@
208 201
209 202 add_filter( 'attachment_fields_to_edit', array( $this, 'add_attachment_field' ), 10, 2 );
210 203 add_action( 'current_screen', [ $this, 'load_available' ] );
211 204 add_action( 'elementor/editor/after_enqueue_scripts', array( $this, 'enqueue' ) );
212 - add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_visualizer_block_editor_shim' ), 100 );
213 205 add_action( 'wp_ajax_tisdk_update_option', array( $this, 'dismiss_promotion' ) );
214 - add_filter( 'plugins_api_result', array( $this, 'inject_visualizer_block_directory_suggestion' ), 10, 3 );
215 - add_filter( 'option_visualizer-activated', array( $this, 'suppress_visualizer_onboarding_in_editor' ) );
216 206 add_filter( 'themeisle_sdk_ran_promos', '__return_true' );
217 207
218 208 if ( get_option( $this->option_neve, false ) !== true ) {
219 - add_action( 'wp_ajax_themeisle_sdk_dismiss_notice', 'ThemeisleSDK\Modules\Notification::dismiss' );
209 + add_action( 'wp_ajax_themeisle_sdk_dismiss_notice', 'ThemeisleSDK\Modules\Notification::regular_dismiss' );
220 210 }
221 211 }
222 212
223 -
224 213 /**
225 - * Inject Visualizer as the first block-directory suggestion for chart queries.
226 - *
227 - * @param object|WP_Error $res Response object or WP_Error.
228 - * @param string $action The API action.
229 - * @param object $args The API arguments.
230 - * @return object|WP_Error
231 - */
232 - public function inject_visualizer_block_directory_suggestion( $res, $action, $args ) {
233 - if ( 'query_plugins' !== $action || ! is_object( $args ) || empty( $args->block ) ) {
234 - return $res;
235 - }
236 -
237 - if ( ! $this->should_suggest_visualizer( $args->block ) ) {
238 - return $res;
239 - }
240 -
241 - if ( $this->is_plugin_installed( 'visualizer' ) ) {
242 - return $res;
243 - }
244 -
245 - $plugin = $this->get_visualizer_block_directory_data();
246 - if ( empty( $plugin ) ) {
247 - return $res;
248 - }
249 -
250 - if ( is_wp_error( $res ) ) {
251 - $res = (object) array( 'plugins' => array() );
252 - }
253 -
254 - if ( ! isset( $res->plugins ) || ! is_array( $res->plugins ) ) {
255 - $res->plugins = array();
256 - }
257 -
258 - $res->plugins = array_values(
259 - array_filter(
260 - $res->plugins,
261 - function ( $existing ) use ( $plugin ) {
262 - return ! isset( $existing['slug'] ) || $existing['slug'] !== $plugin['slug'];
263 - }
264 - )
265 - );
266 -
267 - array_unshift( $res->plugins, $plugin );
268 -
269 - return $res;
270 - }
271 -
272 - /**
273 - * Check if the query should trigger the Visualizer suggestion.
274 - *
275 - * @param string $term Search term.
276 - * @return bool
277 - */
278 - private function should_suggest_visualizer( $term ) {
279 - $term = strtolower( (string) $term );
280 - return false !== strpos( $term, 'chart' ) || false !== strpos( $term, 'visualizer' ) || false !== strpos( $term, 'visualization' ) || false !== strpos( $term, 'graph' );
281 - }
282 -
283 - /**
284 - * Build the plugin data for Visualizer block directory results.
285 - *
286 - * @return array
287 - */
288 - private function get_visualizer_block_directory_data() {
289 - $slug = 'visualizer';
290 - $plugin_info = $this->call_plugin_api( $slug );
291 -
292 - if ( is_wp_error( $plugin_info ) || empty( $plugin_info ) ) {
293 - return array();
294 - }
295 -
296 - $icons = array();
297 - if ( ! empty( $plugin_info->icons ) ) {
298 - if ( ! empty( $plugin_info->icons['1x'] ) ) {
299 - $icons['1x'] = $plugin_info->icons['1x'];
300 - }
301 - if ( ! empty( $plugin_info->icons['2x'] ) ) {
302 - $icons['2x'] = $plugin_info->icons['2x'];
303 - }
304 - }
305 -
306 - $name = isset( $plugin_info->name ) ? $plugin_info->name : 'Visualizer';
307 -
308 - return array(
309 - 'slug' => $slug,
310 - 'name' => $name,
311 - 'short_description' => isset( $plugin_info->short_description ) ? $plugin_info->short_description : '',
312 - 'author' => isset( $plugin_info->author ) ? wp_strip_all_tags( $plugin_info->author ) : '',
313 - 'rating' => isset( $plugin_info->rating ) ? (int) $plugin_info->rating : 0,
314 - 'num_ratings' => isset( $plugin_info->num_ratings ) ? (int) $plugin_info->num_ratings : 0,
315 - 'active_installs' => isset( $plugin_info->active_installs ) ? (int) $plugin_info->active_installs : 0,
316 - 'author_block_rating' => isset( $plugin_info->author_block_rating ) ? (int) $plugin_info->author_block_rating : 0,
317 - 'author_block_count' => isset( $plugin_info->author_block_count ) ? (int) $plugin_info->author_block_count : 0,
318 - 'icons' => $icons,
319 - 'last_updated' => isset( $plugin_info->last_updated ) ? $plugin_info->last_updated : gmdate( 'Y-m-d H:i:s' ),
320 - 'blocks' => array(
321 - array(
322 - 'name' => 'visualizer/chart',
323 - 'title' => $name,
324 - ),
325 - ),
326 - );
327 - }
328 -
329 -
330 - /**
331 - * Prevent Visualizer onboarding redirects while in the block editor.
332 - *
333 - * @param mixed $value Option value.
334 - * @return mixed
335 - */
336 - public function suppress_visualizer_onboarding_in_editor( $value ) {
337 - if ( ! $this->is_block_editor_screen() ) {
338 - return $value;
339 - }
340 -
341 - return false;
342 - }
343 -
344 - /**
345 - * Add a small compatibility shim for Visualizer's block editor bundle.
346 - *
347 - * Visualizer's "Display an existing chart" flow reads
348 - * `google.visualization.Version` before the Google Charts loader has fully
349 - * populated `google.visualization`, which can throw after dynamic install.
350 - *
351 - * @return void
352 - */
353 - public function enqueue_visualizer_block_editor_shim() {
354 - global $themeisle_sdk_max_version;
355 -
356 - if ( ! $this->is_block_editor_screen() ) {
357 - return;
358 - }
359 -
360 - if ( ! wp_script_is( 'visualizer-gutenberg-block', 'enqueued' ) ) {
361 - return;
362 - }
363 -
364 - wp_register_script(
365 - 'ti-sdk-visualizer-editor-shim',
366 - '',
367 - array(),
368 - $themeisle_sdk_max_version,
369 - true
370 - );
371 - wp_enqueue_script( 'ti-sdk-visualizer-editor-shim' );
372 - wp_add_inline_script(
373 - 'ti-sdk-visualizer-editor-shim',
374 - 'window.google = window.google || {}; window.google.visualization = window.google.visualization || {}; window.google.visualization.Version = window.google.visualization.Version || "current";'
375 - );
376 - }
377 -
378 - /**
379 - * Check if the current admin screen is the block editor.
380 - *
381 - * @return bool
382 - */
383 - private function is_block_editor_screen() {
384 - if ( ! function_exists( 'get_current_screen' ) ) {
385 - return $this->is_block_editor_request();
386 - }
387 -
388 - $screen = get_current_screen();
389 - if ( is_object( $screen ) && method_exists( $screen, 'is_block_editor' ) && $screen->is_block_editor() ) {
390 - return true;
391 - }
392 -
393 - return $this->is_block_editor_request();
394 - }
395 -
396 - /**
397 - * Detect block editor requests before the current screen is available.
398 - *
399 - * @return bool
400 - */
401 - private function is_block_editor_request() {
402 - global $pagenow;
403 -
404 - if ( 'post-new.php' === $pagenow ) {
405 - $post_type = isset( $_GET['post_type'] ) ? sanitize_key( $_GET['post_type'] ) : 'post';
406 -
407 - return function_exists( 'use_block_editor_for_post_type' ) ? use_block_editor_for_post_type( $post_type ) : true;
408 - }
409 -
410 - if ( 'post.php' === $pagenow && isset( $_GET['post'] ) ) {
411 - $post_id = absint( $_GET['post'] );
412 -
413 - return function_exists( 'use_block_editor_for_post' ) ? use_block_editor_for_post( $post_id ) : true;
414 - }
415 -
416 - return false;
417 - }
418 -
419 - /**
420 214 * Load available promotions.
421 215 */
422 216 public function load_available() {
423 - if ( $this->available_promotions_loaded ) {
424 - return;
425 - }
426 -
427 - $this->available_promotions_loaded = true;
428 - $this->promotions = $this->filter_by_screen_and_merge();
217 + $this->promotions = $this->filter_by_screen_and_merge();
429 218 if ( empty( $this->promotions ) ) {
430 219 return;
431 220 }
432 221
@@ -632,17 +421,14 @@
632 421 $has_sparks = defined( 'SPARKS_WC_VERSION' ) || $this->is_plugin_installed( 'sparks-for-woocommerce' );
633 422 $has_ppom = defined( 'PPOM_VERSION' ) || $this->is_plugin_installed( 'woocommerce-product-addon' );
634 423 $has_redirection_cf7 = defined( 'WPCF7_PRO_REDIRECT_PLUGIN_VERSION' ) || $this->is_plugin_installed( 'wpcf7-redirect' );
635 424 $had_redirection_cf7_promo = get_option( $this->option_redirection_cf7, false );
636 - $is_min_php_7_4 = version_compare( PHP_VERSION, '7.4', '>=' );
637 - $is_min_php_7_2 = version_compare( PHP_VERSION, '7.2', '>=' );
638 - $can_check_plugin_install = $this->can_check_plugin_install_promo();
639 425 $has_hyve = defined( 'HYVE_LITE_VERSION' ) || $this->is_plugin_installed( 'hyve' ) || $this->is_plugin_installed( 'hyve-lite' );
640 426 $had_hyve_from_promo = get_option( $this->option_hyve, false );
641 - $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();
427 + $has_hyve_conditions = version_compare( get_bloginfo( 'version' ), '6.2', '>=' ) && $this->has_support_page();
642 428 $has_wfp_full_pay = defined( 'WP_FULL_STRIPE_BASENAME' ) || $this->is_plugin_installed( 'wp-full-stripe-free' );
643 429 $had_wfp_from_promo = get_option( $this->option_wp_full_pay, false );
644 - $has_wfp_conditions = ! $has_wfp_full_pay && ! $had_wfp_from_promo && $can_check_plugin_install && $this->has_donate_page();
430 + $has_wfp_conditions = $this->has_donate_page();
645 431 $is_min_req_v = version_compare( get_bloginfo( 'version' ), '5.8', '>=' );
646 432 $current_theme = wp_get_theme();
647 433 $has_neve = $current_theme->template === 'neve' || $current_theme->parent() === 'neve';
648 434 $has_neve_from_promo = get_option( $this->option_neve, false );
@@ -647,12 +433,15 @@
647 433 $has_neve = $current_theme->template === 'neve' || $current_theme->parent() === 'neve';
648 434 $has_neve_from_promo = get_option( $this->option_neve, false );
649 435 $has_enough_attachments = $this->has_min_media_attachments();
650 436 $has_enough_old_posts = $this->has_old_posts();
437 + $is_min_php_7_4 = version_compare( PHP_VERSION, '7.4', '>=' );
651 438 $has_feedzy = defined( 'FEEDZY_BASEFILE' ) || $this->is_plugin_installed( 'feedzy-rss-feedss' );
652 439 $had_feedzy_from_promo = get_option( $this->option_feedzy, false );
440 + $has_masteriyo = defined( 'MASTERIYO_VERSION' ) || $this->is_plugin_installed( 'learning-management-system' );
653 441 $had_masteriyo_from_promo = get_option( $this->option_masteriyo, false );
654 - $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();
442 + $has_masteriyo_conditions = $this->has_lms_tagline();
443 + $is_min_php_7_2 = version_compare( PHP_VERSION, '7.2', '>=' );
655 444
656 445 $all = [
657 446 'optimole' => [
658 447 'om-editor' => [
@@ -748,21 +537,21 @@
748 537 ],
749 538 ],
750 539 'hyve' => [
751 540 'hyve-plugins-install' => [
752 - 'env' => $has_hyve_conditions,
541 + 'env' => $is_min_php_7_4 && ! $has_hyve && ! $had_hyve_from_promo && $has_hyve_conditions,
753 542 'screen' => 'plugin-install',
754 543 ],
755 544 ],
756 545 'wp_full_pay' => [
757 546 'wp-full-pay-plugins-install' => [
758 - 'env' => $has_wfp_conditions,
547 + 'env' => ! $has_wfp_full_pay && ! $had_wfp_from_promo && $has_wfp_conditions,
759 548 'screen' => 'plugin-install',
760 549 ],
761 550 ],
762 551 'learning-management-system' => [
763 552 'masteriyo-plugins-install' => [
764 - 'env' => $has_masteriyo_conditions,
553 + 'env' => $is_min_php_7_2 && ! $has_masteriyo && ! $had_masteriyo_from_promo && $has_masteriyo_conditions,
765 554 'screen' => 'plugin-install',
766 555 ],
767 556 ],
768 557 ];
@@ -840,19 +629,10 @@
840 629 $product_install_time = (int) $this->product->get_install_time();
841 630 $is_older = time() > ( $product_install_time + ( 3 * DAY_IN_SECONDS ) );
842 631 $is_newer = time() < ( $product_install_time + ( 6 * HOUR_IN_SECONDS ) );
843 632 foreach ( $this->promotions as $slug => $promos ) {
844 - if ( ! is_array( $promos ) ) {
845 - continue;
846 - }
847 -
848 633 foreach ( $promos as $key => $data ) {
849 - if ( ! is_array( $data ) || ! array_key_exists( 'screen', $data ) ) {
850 - unset( $this->promotions[ $slug ][ $key ] );
851 634
852 - continue;
853 - }
854 -
855 635 $data = wp_parse_args(
856 636 $data,
857 637 [
858 638 'delayed' => false,
@@ -1618,265 +1398,75 @@
1618 1398 /**
1619 1399 * Check if the user has a support page.
1620 1400 */
1621 1401 public function has_support_page() {
1622 - $page_title_matches = $this->get_page_title_keyword_matches();
1402 + $transient_name = 'tisdk_has_support_page';
1403 + $has_support = get_transient( $transient_name );
1623 1404
1624 - return 'yes' === $page_title_matches['support'];
1625 - }
1405 + if ( false === $has_support ) {
1406 + global $wpdb;
1626 1407
1627 - /**
1628 - * Check if the user has a donate page.
1629 - */
1630 - public function has_donate_page() {
1631 - $page_title_matches = $this->get_page_title_keyword_matches();
1408 + // We use %i escape identifier that was added in WP 6.2.0, hence need to ignore PHPCS warning.
1409 + // We only show this notice to users on higher version as that is the minimum for Hyve as well.
1410 + $query = $wpdb->get_var( //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
1411 + $wpdb->prepare( // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber
1412 + '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
1413 + $wpdb->posts,
1414 + 'page',
1415 + 'publish',
1416 + '%support%'
1417 + )
1418 + );
1632 1419
1633 - return 'yes' === $page_title_matches['donate'];
1634 - }
1420 + $has_support = $query ? 'yes' : 'no';
1635 1421
1636 - /**
1637 - * Check if the tagline or a published page title contains LMS related keywords.
1638 - *
1639 - * @return bool True if LMS-related keywords are found, false otherwise.
1640 - */
1641 - public function has_lms_tagline() {
1642 - $tagline = strtolower( get_bloginfo( 'description' ) );
1643 -
1644 - foreach ( $this->get_lms_keywords() as $keyword ) {
1645 - if ( $this->has_lms_keyword_match( $tagline, $keyword ) ) {
1646 - return true;
1647 - }
1422 + set_transient( $transient_name, $has_support, 7 * DAY_IN_SECONDS );
1648 1423 }
1649 1424
1650 - return $this->has_lms_page_title();
1425 + return 'yes' === $has_support;
1651 1426 }
1652 1427
1653 1428 /**
1654 - * Check if a supported LMS plugin is active.
1655 - *
1656 - * @return bool True if an LMS plugin is active, false otherwise.
1429 + * Check if the user has a donate page.
1657 1430 */
1658 - private function has_active_lms_plugin() {
1659 - if ( defined( 'MASTERIYO_VERSION' ) ) {
1660 - return true;
1661 - }
1431 + public function has_donate_page() {
1432 + $transient_name = 'tisdk_has_donate_page';
1433 + $has_donate = get_transient( $transient_name );
1662 1434
1663 - include_once ABSPATH . 'wp-admin/includes/plugin.php';
1435 + if ( false === $has_donate ) {
1436 + global $wpdb;
1664 1437
1665 - $lms_plugins = array(
1666 - 'tutor/tutor.php',
1667 - 'sfwd-lms/sfwd_lms.php',
1668 - 'lifterlms/lifterlms.php',
1669 - 'sensei-lms/sensei-lms.php',
1670 - 'learnpress/learnpress.php',
1671 - 'masterstudy-lms-learning-management-system/masterstudy-lms-learning-management-system.php',
1672 - 'learning-management-system/lms.php',
1673 - );
1438 + $query = $wpdb->get_var( //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
1439 + $wpdb->prepare(
1440 + 'SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_status = %s AND post_title LIKE %s LIMIT 1',
1441 + 'page',
1442 + 'publish',
1443 + '%donate%'
1444 + )
1445 + );
1674 1446
1675 - foreach ( $lms_plugins as $plugin ) {
1676 - if ( is_plugin_active( $plugin ) || ( is_multisite() && is_plugin_active_for_network( $plugin ) ) ) {
1677 - return true;
1678 - }
1679 - }
1447 + $has_donate = $query ? 'yes' : 'no';
1680 1448
1681 - return false;
1682 - }
1683 -
1684 - /**
1685 - * Check if the current request can display a plugin install promo.
1686 - *
1687 - * @return bool True if a plugin install promo can be displayed, false otherwise.
1688 - */
1689 - private function can_check_plugin_install_promo() {
1690 - if ( ! is_admin() || ! current_user_can( 'install_plugins' ) ) {
1691 - return false;
1449 + set_transient( $transient_name, $has_donate, 7 * DAY_IN_SECONDS );
1692 1450 }
1693 1451
1694 - $current_screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null;
1695 - if ( isset( $current_screen->id ) ) {
1696 - return $current_screen->id === 'plugin-install';
1697 - }
1698 -
1699 - global $pagenow;
1700 -
1701 - return isset( $pagenow ) && $pagenow === 'plugin-install.php';
1452 + return 'yes' === $has_donate;
1702 1453 }
1703 1454
1704 1455 /**
1705 - * Check if a published page title contains LMS related keywords.
1456 + * Check if the tagline contains LMS related keywords.
1706 1457 *
1707 - * @return bool True if an LMS-related page title is found, false otherwise.
1458 + * @return bool True if the tagline contains LMS-related keywords, false otherwise.
1708 1459 */
1709 - private function has_lms_page_title() {
1710 - $lms_page_title_signal = get_transient( 'tisdk_lms_page_title_signal_v1' );
1460 + public function has_lms_tagline() {
1461 + $tagline = strtolower( get_bloginfo( 'description' ) );
1462 + $lms_keywords = array( 'learning', 'courses' );
1711 1463
1712 - if ( in_array( $lms_page_title_signal, array( 'yes', 'no' ), true ) ) {
1713 - return 'yes' === $lms_page_title_signal;
1714 - }
1715 -
1716 - $has_lms_page_title = $this->has_published_page_title_with_keywords( $this->get_lms_page_title_keywords() );
1717 -
1718 - set_transient( 'tisdk_lms_page_title_signal_v1', $has_lms_page_title ? 'yes' : 'no', 7 * DAY_IN_SECONDS );
1719 -
1720 - return $has_lms_page_title;
1721 - }
1722 -
1723 - /**
1724 - * Get cached keyword matches for published page titles.
1725 - *
1726 - * @return array Page title keyword matches.
1727 - */
1728 - private function get_page_title_keyword_matches() {
1729 - $default_matches = array(
1730 - 'support' => 'no',
1731 - 'donate' => 'no',
1732 - );
1733 -
1734 - $page_title_matches = get_transient( 'tisdk_page_title_signals_v1' );
1735 -
1736 - if ( is_array( $page_title_matches ) && empty( array_diff_key( $default_matches, $page_title_matches ) ) ) {
1737 - return array_merge( $default_matches, $page_title_matches );
1738 - }
1739 -
1740 - global $wpdb;
1741 -
1742 - $select_clauses = array();
1743 - $query_values = array();
1744 - $page_checks = $this->get_page_title_checks();
1745 -
1746 - foreach ( $page_checks as $match_key => $keywords ) {
1747 - $match_clauses = array();
1748 -
1749 - $query_values[] = 'page';
1750 - $query_values[] = 'publish';
1751 -
1752 - foreach ( $keywords as $keyword ) {
1753 - $match_clauses[] = 'post_title LIKE %s';
1754 - $query_values[] = '%' . $wpdb->esc_like( $keyword ) . '%';
1464 + foreach ( $lms_keywords as $keyword ) {
1465 + if ( strpos( $tagline, $keyword ) !== false ) {
1466 + return true;
1755 1467 }
1756 -
1757 - $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;
1758 1468 }
1759 1469
1760 - // phpcs:disable WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
1761 - $query = $wpdb->get_row( //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
1762 - $wpdb->prepare(
1763 - 'SELECT ' . implode( ', ', $select_clauses ),
1764 - $query_values
1765 - ),
1766 - ARRAY_A
1767 - );
1768 - // phpcs:enable WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
1769 -
1770 - $page_title_matches = $default_matches;
1771 -
1772 - if ( is_array( $query ) ) {
1773 - foreach ( array_keys( $page_checks ) as $match_key ) {
1774 - $page_title_matches[ $match_key ] = ! empty( $query[ 'has_' . $match_key ] ) ? 'yes' : 'no';
1775 - }
1776 - }
1777 -
1778 - set_transient( 'tisdk_page_title_signals_v1', $page_title_matches, 7 * DAY_IN_SECONDS );
1779 -
1780 - return $page_title_matches;
1781 - }
1782 -
1783 - /**
1784 - * Check if a keyword matches content.
1785 - *
1786 - * @param string $content Content to check.
1787 - * @param string $keyword Keyword to look for.
1788 - *
1789 - * @return bool True if the keyword matches, false otherwise.
1790 - */
1791 - private function has_lms_keyword_match( $content, $keyword ) {
1792 - if ( in_array( $keyword, array( 'lms', 'course', 'class' ), true ) ) {
1793 - return preg_match( '/(^|[^a-z0-9])' . preg_quote( $keyword, '/' ) . '([^a-z0-9]|$)/', $content ) === 1;
1794 - }
1795 -
1796 - return strpos( $content, $keyword ) !== false;
1797 - }
1798 -
1799 - /**
1800 - * Get LMS related keywords.
1801 - *
1802 - * @return array LMS related keywords.
1803 - */
1804 - private function get_lms_keywords() {
1805 - return array(
1806 - 'lms',
1807 - 'learning',
1808 - 'course',
1809 - 'courses',
1810 - 'academy',
1811 - 'training',
1812 - 'lesson',
1813 - 'lessons',
1814 - 'class',
1815 - 'classes',
1816 - 'student',
1817 - 'students',
1818 - 'teach',
1819 - 'teaching',
1820 - 'tutor',
1821 - 'quiz',
1822 - 'education',
1823 - 'online course',
1824 - 'online courses',
1825 - );
1826 - }
1827 -
1828 - /**
1829 - * Get LMS related keywords for page title matching.
1830 - *
1831 - * @return array LMS related keywords.
1832 - */
1833 - private function get_lms_page_title_keywords() {
1834 - return array_values( array_diff( $this->get_lms_keywords(), array( 'lms', 'course', 'class' ) ) );
1835 - }
1836 -
1837 - /**
1838 - * Check if a published page title contains any of the provided keywords.
1839 - *
1840 - * @param array $keywords Keywords to look for.
1841 - *
1842 - * @return bool True if a matching page title is found, false otherwise.
1843 - */
1844 - private function has_published_page_title_with_keywords( $keywords ) {
1845 - if ( empty( $keywords ) ) {
1846 - return false;
1847 - }
1848 -
1849 - global $wpdb;
1850 -
1851 - $query_values = array( 'page', 'publish' );
1852 - $clauses = array();
1853 -
1854 - foreach ( $keywords as $keyword ) {
1855 - $clauses[] = 'post_title LIKE %s';
1856 - $query_values[] = '%' . $wpdb->esc_like( $keyword ) . '%';
1857 - }
1858 -
1859 - // phpcs:disable WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
1860 - $page_title_match = $wpdb->get_var( //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
1861 - $wpdb->prepare(
1862 - 'SELECT 1 FROM ' . $wpdb->posts . ' WHERE post_type = %s AND post_status = %s AND ( ' . implode( ' OR ', $clauses ) . ' ) LIMIT 1',
1863 - $query_values
1864 - )
1865 - );
1866 - // phpcs:enable WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
1867 -
1868 - return ! empty( $page_title_match );
1869 - }
1870 -
1871 - /**
1872 - * Get page title keyword checks.
1873 - *
1874 - * @return array Page title keyword checks.
1875 - */
1876 - private function get_page_title_checks() {
1877 - return array(
1878 - 'support' => array( 'support' ),
1879 - 'donate' => array( 'donate' ),
1880 - );
1470 + return false;
1881 1471 }
1882 1472 }