| @@ -7,9 +7,8 @@ | ||
| 7 | 7 | use YayMail\Elements\Heading; |
| 8 | 8 | use YayMail\Elements\Logo; |
| 9 | 9 | use YayMail\Elements\Text; |
| 10 | 10 | use YayMail\Elements\Footer; |
| 11 | -use YayMail\Integrations\TranslationModule; | |
| 12 | 11 | use YayMail\YayMailTemplate; |
| 13 | 12 | use YayMail\Utils\SingletonTrait; |
| 14 | 13 | use YayMail\PostTypes\TemplatePostType; |
| 15 | 14 | use YayMail\Shortcodes\ShortcodesExecutor; |
| @@ -14,8 +13,9 @@ | ||
| 14 | 13 | use YayMail\PostTypes\TemplatePostType; |
| 15 | 14 | use YayMail\Shortcodes\ShortcodesExecutor; |
| 16 | 15 | use YayMail\SupportedPlugins; |
| 17 | 16 | use YayMail\Utils\TemplateHelpers; |
| 17 | + | |
| 18 | 18 | /** |
| 19 | 19 | * Template Model |
| 20 | 20 | * |
| 21 | 21 | * @method static TemplateModel get_instance() |
| @@ -26,11 +26,8 @@ | ||
| 26 | 26 | private const POST_TABLE = 'posts'; |
| 27 | 27 | private const POST_META_TABLE = 'postmeta'; |
| 28 | 28 | private static $meta_keys = YayMailTemplate::META_KEYS; |
| 29 | 29 | |
| 30 | - /** @var string[]|null Per-request memo for get_active_default_template_names(). */ | |
| 31 | - private static $active_default_template_names = null; | |
| 32 | - | |
| 33 | 30 | /** |
| 34 | 31 | * Query post with given arguments. |
| 35 | 32 | * Build query string base on given arguments |
| 36 | 33 | * then use $wpdb to query it. |
| @@ -58,36 +55,14 @@ | ||
| 58 | 55 | |
| 59 | 56 | if ( isset( $args['name'] ) ) { |
| 60 | 57 | $template_name = $args['name']; |
| 61 | 58 | $template_meta_key = self::$meta_keys['name']; |
| 62 | - $clauses['where'] .= $wpdb->prepare( | |
| 63 | - ' AND ( postmeta.meta_key=%s AND postmeta.meta_value = %s )', | |
| 64 | - $template_meta_key, | |
| 65 | - $template_name | |
| 66 | - ); | |
| 59 | + $clauses['where'] .= " AND ( postmeta.meta_key='$template_meta_key' AND postmeta.meta_value = '$template_name' )"; | |
| 67 | 60 | } |
| 68 | 61 | |
| 69 | - // Variant clause is always present so default lookups never return a variant post. | |
| 70 | - $variant_meta_key = self::$meta_keys['variant']; | |
| 71 | - if ( isset( $args['variant'] ) && '' !== $args['variant'] ) { | |
| 72 | - $clauses['join'] .= " JOIN $post_meta AS postmeta3 ON ( posts.ID = postmeta3.post_id )"; | |
| 73 | - $clauses['where'] .= $wpdb->prepare( | |
| 74 | - ' AND ( postmeta3.meta_key=%s AND postmeta3.meta_value = %s )', | |
| 75 | - $variant_meta_key, | |
| 76 | - $args['variant'] | |
| 77 | - ); | |
| 78 | - } else { | |
| 79 | - $clauses['join'] .= $wpdb->prepare( | |
| 80 | - " LEFT JOIN $post_meta AS postmeta3 ON ( posts.ID = postmeta3.post_id AND postmeta3.meta_key = %s )", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared | |
| 81 | - $variant_meta_key | |
| 82 | - ); | |
| 83 | - $clauses['where'] .= " AND ( postmeta3.meta_value IS NULL OR postmeta3.meta_value = '' )"; | |
| 84 | - } | |
| 62 | + $query_string = implode( ' ', $clauses ); | |
| 63 | + $post_id = $wpdb->get_var( $query_string ); | |
| 85 | 64 | |
| 86 | - // Oldest post wins when duplicates exist so customizer and send target the same row. | |
| 87 | - $query_string = implode( ' ', $clauses ) . ' ORDER BY posts.ID ASC LIMIT 1'; | |
| 88 | - $post_id = $wpdb->get_var( $query_string ); //phpcs:ignore | |
| 89 | - | |
| 90 | 65 | return $post_id; |
| 91 | 66 | } |
| 92 | 67 | |
| 93 | 68 | /** |
| @@ -109,40 +84,36 @@ | ||
| 109 | 84 | $templates = []; |
| 110 | 85 | |
| 111 | 86 | $excluded_templates = apply_filters( 'yaymail_excluded_templates', [ 'yaymail_global_header_footer' ] ); |
| 112 | 87 | |
| 113 | - if ( yaymail_is_wc_installed() ) { | |
| 114 | - /* Wc Emails, may or may not be supported by us */ | |
| 115 | - $wc_emails = \WC_Emails::instance()->get_emails(); | |
| 88 | + /* Wc Emails, may or may not be supported by us */ | |
| 89 | + $wc_emails = \WC_Emails::instance()->get_emails(); | |
| 116 | 90 | |
| 117 | - foreach ( $wc_emails as $wc_email ) { | |
| 118 | - $template_id = $wc_email->id ?? null; | |
| 91 | + foreach ( $wc_emails as $wc_email ) { | |
| 92 | + $template_id = $wc_email->id ?? null; | |
| 119 | 93 | |
| 120 | - if ( ! isset( $template_id ) ) { | |
| 121 | - continue; | |
| 122 | - } | |
| 94 | + if ( ! isset( $template_id ) ) { | |
| 95 | + continue; | |
| 96 | + } | |
| 123 | 97 | |
| 124 | - if ( in_array( $template_id, $excluded_templates, true ) ) { | |
| 125 | - continue; | |
| 126 | - } | |
| 98 | + if ( in_array( $template_id, $excluded_templates, true ) ) { | |
| 99 | + continue; | |
| 100 | + } | |
| 127 | 101 | |
| 128 | - if ( SupportedPlugins::get_instance()->get_support_info( $template_id )['status'] !== 'already_supported' ) { | |
| 129 | - // Templates is currently not editable, but could be supported by pro/addon | |
| 130 | - $template_data = self::get_uneditable_template( $wc_email, $templates ); | |
| 131 | - $templates[] = $template_data; | |
| 132 | - continue; | |
| 133 | - } | |
| 102 | + if ( SupportedPlugins::get_instance()->get_support_info( $template_id )['status'] !== 'already_supported' ) { | |
| 103 | + // Templates is currently not editable, but could be supported by pro/addon | |
| 104 | + $template_data = self::get_uneditable_template( $wc_email, $templates ); | |
| 105 | + $templates[] = $template_data; | |
| 106 | + continue; | |
| 107 | + } | |
| 134 | 108 | |
| 135 | - $email_data = SupportedPlugins::get_instance()->get_yaymail_template_data( $template_id ); | |
| 136 | - $template_data = self::get_yaymail_template( $email_data ); | |
| 137 | - if ( isset( $template_data ) ) { | |
| 138 | - unset( $template_data['elements'] ); | |
| 139 | - $templates[] = $template_data; | |
| 140 | - } | |
| 141 | - }//end foreach | |
| 142 | - } else { | |
| 143 | - $templates = []; | |
| 144 | - }//end if | |
| 109 | + $email_data = SupportedPlugins::get_instance()->get_yaymail_template_data( $template_id ); | |
| 110 | + $template_data = self::get_yaymail_template( $email_data ); | |
| 111 | + if ( isset( $template_data ) ) { | |
| 112 | + unset( $template_data['elements'] ); | |
| 113 | + $templates[] = $template_data; | |
| 114 | + } | |
| 115 | + }//end foreach | |
| 145 | 116 | |
| 146 | 117 | // Make sure it will show templates for Automatewoo ... |
| 147 | 118 | // Because those templates don't appear in wc_emails |
| 148 | 119 | $template_ids = array_map( fn( $template ) => $template['name'], $templates ); |
| @@ -247,18 +218,12 @@ | ||
| 247 | 218 | * Returns null if not found |
| 248 | 219 | * |
| 249 | 220 | * @param string $name |
| 250 | 221 | */ |
| 251 | - /** | |
| 252 | - * @param string $name | |
| 253 | - * @param string $language Unused in Lite; kept so callers match the Pro signature. | |
| 254 | - * @param string $variant Variant slug, '' for the default design. | |
| 255 | - */ | |
| 256 | - public static function find_by_name( $name, $language = '', $variant = '' ) { | |
| 222 | + public static function find_by_name( $name ) { | |
| 257 | 223 | $template_id = self::query_template( |
| 258 | 224 | [ |
| 259 | - 'name' => $name, | |
| 260 | - 'variant' => $variant, | |
| 225 | + 'name' => $name, | |
| 261 | 226 | ] |
| 262 | 227 | ); |
| 263 | 228 | if ( empty( $template_id ) ) { |
| 264 | 229 | $support_info = SupportedPlugins::get_instance()->get_support_info( $name ); |
| @@ -317,11 +282,8 @@ | ||
| 317 | 282 | } |
| 318 | 283 | if ( ! empty( $args['global_footer_settings'] ) ) { |
| 319 | 284 | update_post_meta( $new_template_id, self::$meta_keys['global_footer_settings'], $args['global_footer_settings'] ); |
| 320 | 285 | } |
| 321 | - if ( isset( $args['variant'] ) && '' !== $args['variant'] ) { | |
| 322 | - update_post_meta( $new_template_id, self::$meta_keys['variant'], $args['variant'] ); | |
| 323 | - } | |
| 324 | 286 | |
| 325 | 287 | // Hook insert data of integrations |
| 326 | 288 | |
| 327 | 289 | return self::get_meta_data( $new_template_id ); |
| @@ -364,12 +326,8 @@ | ||
| 364 | 326 | if ( ! empty( $data['global_footer_settings'] ) && isset( self::$meta_keys['global_footer_settings'] ) ) { |
| 365 | 327 | update_post_meta( $template_id, self::$meta_keys['global_footer_settings'], $data['global_footer_settings'] ); |
| 366 | 328 | } |
| 367 | 329 | |
| 368 | - if ( isset( $data['preheader'] ) && isset( self::$meta_keys['preheader'] ) ) { | |
| 369 | - update_post_meta( $template_id, self::$meta_keys['preheader'], sanitize_text_field( $data['preheader'] ) ); | |
| 370 | - } | |
| 371 | - | |
| 372 | 330 | // Update post_modified |
| 373 | 331 | $post_data = [ |
| 374 | 332 | 'ID' => $template_id, |
| 375 | 333 | 'post_modified' => current_time( 'mysql' ), |
| @@ -405,20 +363,18 @@ | ||
| 405 | 363 | * @return array An array containing the global header and footer elements: |
| 406 | 364 | * - 'global_header_elements': array. |
| 407 | 365 | * - 'global_footer_elements': array. |
| 408 | 366 | */ |
| 409 | - public static function get_global_header_and_footer( $language = '', $template_name = 'yaymail_global_header_footer' ) { | |
| 367 | + public static function get_global_header_and_footer() { | |
| 410 | 368 | $query_args = [ |
| 411 | - 'name' => $template_name, | |
| 412 | - 'language' => in_array( $language, [ 'en', 'en_US' ], true ) ? '' : $language, | |
| 369 | + 'name' => 'yaymail_global_header_footer', | |
| 413 | 370 | ]; |
| 414 | 371 | $template_id = self::query_template( $query_args ); |
| 415 | 372 | if ( empty( $template_id ) ) { |
| 416 | 373 | self::insert( |
| 417 | 374 | [ |
| 418 | - 'name' => $template_name, | |
| 419 | - 'elements' => yaymail_get_default_elements( $template_name ), | |
| 420 | - 'language' => $language, | |
| 375 | + 'name' => 'yaymail_global_header_footer', | |
| 376 | + 'elements' => yaymail_get_default_elements( 'yaymail_global_header_footer' ), | |
| 421 | 377 | ] |
| 422 | 378 | ); |
| 423 | 379 | $template_id = self::query_template( $query_args ); |
| 424 | 380 | } |
| @@ -448,43 +404,8 @@ | ||
| 448 | 404 | 'global_footer_elements' => $global_footer_elements, |
| 449 | 405 | ]; |
| 450 | 406 | } |
| 451 | 407 | |
| 452 | - public static function get_global_headers_and_footers_for_all_available_languages( $template_name = 'yaymail_global_header_footer' ) { | |
| 453 | - $multi_languages_instances = TranslationModule::get_instance()->current_integration; | |
| 454 | - | |
| 455 | - if ( ! empty( $multi_languages_instances ) ) { | |
| 456 | - $languages = $multi_languages_instances->get_available_languages(); | |
| 457 | - } else { | |
| 458 | - $languages = [ [ 'code' => 'en' ] ]; | |
| 459 | - } | |
| 460 | - | |
| 461 | - /** | |
| 462 | - * Each language should have 3 fields: code, name, flag | |
| 463 | - * | |
| 464 | - * @Example [ | |
| 465 | - * code: 'en', | |
| 466 | - * name: 'English', | |
| 467 | - * flag: 'http://localhost:8080/wp-content/plugins/sitepress-multilingual-cms/res/flags/en.svg' | |
| 468 | - * ] | |
| 469 | - */ | |
| 470 | - $result = array_map( | |
| 471 | - function ( $language ) use ( $template_name ) { | |
| 472 | - $code = isset( $language['code'] ) ? $language['code'] : ''; | |
| 473 | - $global_header_and_footer = self::get_global_header_and_footer( 'en' !== $code ? $code : '', $template_name ); | |
| 474 | - | |
| 475 | - return [ | |
| 476 | - 'language' => $code, | |
| 477 | - 'global_header_elements' => $global_header_and_footer['global_header_elements'] ? $global_header_and_footer['global_header_elements'] : [], | |
| 478 | - 'global_footer_elements' => $global_header_and_footer['global_footer_elements'] ? $global_header_and_footer['global_footer_elements'] : [], | |
| 479 | - ]; | |
| 480 | - }, | |
| 481 | - $languages | |
| 482 | - ); | |
| 483 | - | |
| 484 | - return array_values( $result ); | |
| 485 | - } | |
| 486 | - | |
| 487 | 408 | /** |
| 488 | 409 | * Get template meta data from Database |
| 489 | 410 | * |
| 490 | 411 | * @param number $template_post_id |
| @@ -503,9 +424,9 @@ | ||
| 503 | 424 | // /** For editable templates */ |
| 504 | 425 | $template_elements = self::query_meta_data( $template_post_id, self::$meta_keys['elements'], [] ); |
| 505 | 426 | |
| 506 | 427 | $support_info = SupportedPlugins::get_instance()->get_support_info( $template_name ); |
| 507 | - if ( $support_info['status'] !== 'already_supported' && 'wp-core-edd-password_reset' !== $template_name ) { | |
| 428 | + if ( $support_info['status'] !== 'already_supported' ) { | |
| 508 | 429 | // Template is not editable |
| 509 | 430 | $template_elements = self::get_uneditable_template_placeholder_elements( $support_info ); |
| 510 | 431 | } elseif ( isset( $post ) ) { |
| 511 | 432 | // TODO: how to store global default value |
| @@ -513,11 +434,10 @@ | ||
| 513 | 434 | $text_link_color = self::query_meta_data( $template_post_id, self::$meta_keys['text_link_color'], YayMailTemplate::DEFAULT_DATA['text_link_color'] ); |
| 514 | 435 | $title_color = self::query_meta_data( $template_post_id, self::$meta_keys['title_color'], YayMailTemplate::DEFAULT_DATA['title_color'] ); |
| 515 | 436 | $content_background_color = self::query_meta_data( $template_post_id, self::$meta_keys['content_background_color'], YayMailTemplate::DEFAULT_DATA['content_background_color'] ); |
| 516 | 437 | $content_text_color = self::query_meta_data( $template_post_id, self::$meta_keys['content_text_color'], YayMailTemplate::DEFAULT_DATA['content_text_color'] ); |
| 517 | - $global_header_settings = self::query_meta_data( $template_post_id, self::$meta_keys['global_header_settings'], self::get_default_global_header_settings() ); | |
| 518 | - $global_footer_settings = self::query_meta_data( $template_post_id, self::$meta_keys['global_footer_settings'], self::get_default_global_footer_settings() ); | |
| 519 | - $preheader = self::query_meta_data( $template_post_id, self::$meta_keys['preheader'], YayMailTemplate::DEFAULT_DATA['preheader'] ); | |
| 438 | + $global_header_settings = self::query_meta_data( $template_post_id, self::$meta_keys['global_header_settings'], YayMailTemplate::DEFAULT_DATA['global_header_settings'] ); | |
| 439 | + $global_footer_settings = self::query_meta_data( $template_post_id, self::$meta_keys['global_footer_settings'], YayMailTemplate::DEFAULT_DATA['global_footer_settings'] ); | |
| 520 | 440 | } |
| 521 | 441 | |
| 522 | 442 | return [ |
| 523 | 443 | 'id' => $template_post_id, |
| @@ -524,9 +444,8 @@ | ||
| 524 | 444 | 'key' => $template_post_id, |
| 525 | 445 | 'name' => $template_name, |
| 526 | 446 | 'elements' => ElementsHelper::filter_available_elements( $template_elements, $template_name ), |
| 527 | 447 | 'status' => $status, |
| 528 | - 'variant' => self::query_meta_data( $template_post_id, self::$meta_keys['variant'], '' ), | |
| 529 | 448 | 'title_color' => $title_color ?? '#000000', |
| 530 | 449 | 'background_color' => $background_color ?? YAYMAIL_COLOR_BACKGROUND_DEFAULT, |
| 531 | 450 | 'text_link_color' => $text_link_color ?? YAYMAIL_COLOR_WC_DEFAULT, |
| 532 | 451 | 'content_background_color' => $content_background_color ?? '#ffffff', |
| @@ -533,59 +452,13 @@ | ||
| 533 | 452 | 'content_text_color' => $content_text_color ?? '#000000', |
| 534 | 453 | 'support_status' => $support_info['status'] ?? 'already_supported', |
| 535 | 454 | 'addon_info' => $support_info['addon'] ?? '', |
| 536 | 455 | 'post_modified' => $post_modified, |
| 537 | - 'global_header_settings' => isset( $global_header_settings ) ? $global_header_settings : [], | |
| 538 | - 'global_footer_settings' => isset( $global_footer_settings ) ? $global_footer_settings : [], | |
| 539 | - 'preheader' => isset( $preheader ) ? $preheader : YayMailTemplate::DEFAULT_DATA['preheader'], | |
| 540 | - 'email_subject' => self::get_email_subject( $template_name ), | |
| 456 | + 'global_header_settings' => $global_header_settings, | |
| 457 | + 'global_footer_settings' => $global_footer_settings, | |
| 541 | 458 | ]; |
| 542 | 459 | } |
| 543 | 460 | |
| 544 | - /** | |
| 545 | - * Get email subject from WooCommerce email settings. | |
| 546 | - * | |
| 547 | - * @param string $template_name Email / template id. | |
| 548 | - * @return string|null | |
| 549 | - */ | |
| 550 | - private static function get_email_subject( $template_name ) { | |
| 551 | - $settings = self::get_wc_email_settings( $template_name ); | |
| 552 | - return is_array( $settings ) && isset( $settings['subject'] ) ? (string) $settings['subject'] : null; | |
| 553 | - } | |
| 554 | - | |
| 555 | - /** | |
| 556 | - * Save email subject to WooCommerce email settings (same option as Woo admin). | |
| 557 | - * | |
| 558 | - * @param string $template_name Email / template id. | |
| 559 | - * @param string $subject Subject line. | |
| 560 | - */ | |
| 561 | - public static function save_email_subject( $template_name, $subject ) { | |
| 562 | - if ( ! is_string( $template_name ) || '' === $template_name ) { | |
| 563 | - return; | |
| 564 | - } | |
| 565 | - | |
| 566 | - $settings = self::get_wc_email_settings( $template_name ); | |
| 567 | - $settings['subject'] = sanitize_text_field( $subject ); | |
| 568 | - update_option( self::get_wc_email_settings_option_name( $template_name ), $settings ); | |
| 569 | - } | |
| 570 | - | |
| 571 | - /** | |
| 572 | - * @param string $template_name Email / template id. | |
| 573 | - * @return string | |
| 574 | - */ | |
| 575 | - private static function get_wc_email_settings_option_name( $template_name ) { | |
| 576 | - return "woocommerce_{$template_name}_settings"; | |
| 577 | - } | |
| 578 | - | |
| 579 | - /** | |
| 580 | - * @param string $template_name Email / template id. | |
| 581 | - * @return array | |
| 582 | - */ | |
| 583 | - private static function get_wc_email_settings( $template_name ) { | |
| 584 | - $settings = get_option( self::get_wc_email_settings_option_name( $template_name ), [] ); | |
| 585 | - return is_array( $settings ) ? $settings : []; | |
| 586 | - } | |
| 587 | - | |
| 588 | 461 | private static function get_uneditable_template_placeholder_elements( array $support_info ): array { |
| 589 | 462 | $elements = []; |
| 590 | 463 | |
| 591 | 464 | $elements[] = BaseElement::reduce_new_element( Logo::get_data() ); |
| @@ -596,25 +469,9 @@ | ||
| 596 | 469 | return $elements; |
| 597 | 470 | } |
| 598 | 471 | |
| 599 | 472 | |
| 600 | - private static function get_default_global_footer_settings(): array { | |
| 601 | - $default = YayMailTemplate::DEFAULT_DATA['global_footer_settings']; | |
| 602 | - if ( ! function_exists( 'WC' ) ) { | |
| 603 | - $default['footer_content'] = '<p style="font-size: 14px;margin: 0px 0px 16px; text-align: center;">[yaymail_site_name]</p>'; | |
| 604 | - } | |
| 605 | - return apply_filters( 'yaymail_default_global_footer_settings', $default ); | |
| 606 | - } | |
| 607 | - | |
| 608 | - private static function get_default_global_header_settings(): array { | |
| 609 | - $default = YayMailTemplate::DEFAULT_DATA['global_header_settings']; | |
| 610 | - if ( ! function_exists( 'WC' ) ) { | |
| 611 | - $default['heading_content'] = '<h1 style="font-size: 30px; font-weight: 300; line-height: normal; margin: 0px; color: inherit;">[yaymail_site_name]</h1>'; | |
| 612 | - } | |
| 613 | - return apply_filters( 'yaymail_default_global_header_settings', $default ); | |
| 614 | - } | |
| 615 | - | |
| 616 | - protected static function query_meta_data( $post_id, $meta_name, $default ) { | |
| 473 | + private static function query_meta_data( $post_id, $meta_name, $default ) { | |
| 617 | 474 | if ( ! isset( $post_id ) ) { |
| 618 | 475 | return $default; |
| 619 | 476 | } |
| 620 | 477 | |
| @@ -658,82 +515,18 @@ | ||
| 658 | 515 | |
| 659 | 516 | public static function get_elements_for_template( $template_id ): array { |
| 660 | 517 | $support_info = SupportedPlugins::get_instance()->get_support_info( $template_id ); |
| 661 | 518 | if ( $support_info['status'] !== 'already_supported' ) { |
| 662 | - // 'new_order' only exists on WooCommerce sites; fall back to the WP-core | |
| 663 | - // email so unsupported templates still resolve an elements catalog. | |
| 664 | - $fallback_email_id = yaymail_get_email( 'new_order' ) ? 'new_order' : 'wp-core-mail'; | |
| 665 | - $elements = array_map( | |
| 519 | + $elements = array_map( | |
| 666 | 520 | function( $element ) { |
| 667 | 521 | $element['available'] = false; |
| 668 | 522 | return $element; |
| 669 | 523 | }, |
| 670 | - yaymail_get_email_elements_data( $fallback_email_id ) | |
| 524 | + yaymail_get_email_elements_data( 'new_order' ) | |
| 671 | 525 | ); |
| 672 | 526 | return $elements; |
| 673 | 527 | } |
| 674 | 528 | return yaymail_get_email_elements_data( $template_id ); |
| 675 | - } | |
| 676 | - | |
| 677 | - /** | |
| 678 | - * Names of every template whose default post is active, from one query. | |
| 679 | - * | |
| 680 | - * "Default post" mirrors query_template( [ 'name' => $name ] ) followed by the | |
| 681 | - * status meta read: no variant, default language ('' / unset / en_US), oldest | |
| 682 | - * post wins, missing status counts as inactive. Memoised for the request so the | |
| 683 | - * core emails can all consult it at init without one lookup each. | |
| 684 | - * | |
| 685 | - * @return string[] | |
| 686 | - */ | |
| 687 | - public static function get_active_default_template_names() { | |
| 688 | - if ( null !== self::$active_default_template_names ) { | |
| 689 | - return self::$active_default_template_names; | |
| 690 | - } | |
| 691 | - | |
| 692 | - global $wpdb; | |
| 693 | - $posts = $wpdb->prefix . self::POST_TABLE; | |
| 694 | - $post_meta = $wpdb->prefix . self::POST_META_TABLE; | |
| 695 | - | |
| 696 | - $rows = $wpdb->get_results( // phpcs:ignore WordPress.DB.DirectDatabaseQuery | |
| 697 | - $wpdb->prepare( | |
| 698 | - // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared | |
| 699 | - "SELECT posts.ID, name.meta_value AS name, status.meta_value AS status, lang.meta_value AS language, variant.meta_value AS variant | |
| 700 | - FROM $posts AS posts | |
| 701 | - JOIN $post_meta AS name ON ( posts.ID = name.post_id AND name.meta_key = %s ) | |
| 702 | - LEFT JOIN $post_meta AS status ON ( posts.ID = status.post_id AND status.meta_key = %s ) | |
| 703 | - LEFT JOIN $post_meta AS lang ON ( posts.ID = lang.post_id AND lang.meta_key = %s ) | |
| 704 | - LEFT JOIN $post_meta AS variant ON ( posts.ID = variant.post_id AND variant.meta_key = %s ) | |
| 705 | - WHERE posts.post_type = %s AND posts.post_status IN ('publish', 'pending', 'future') | |
| 706 | - ORDER BY posts.ID ASC", | |
| 707 | - self::$meta_keys['name'], | |
| 708 | - self::$meta_keys['status'], | |
| 709 | - self::$meta_keys['language'], | |
| 710 | - self::$meta_keys['variant'], | |
| 711 | - TemplatePostType::POST_TYPE | |
| 712 | - ), | |
| 713 | - ARRAY_A | |
| 714 | - ); | |
| 715 | - | |
| 716 | - $seen = []; | |
| 717 | - $active = []; | |
| 718 | - foreach ( (array) $rows as $row ) { | |
| 719 | - if ( '' !== (string) $row['variant'] ) { | |
| 720 | - continue; | |
| 721 | - } | |
| 722 | - if ( ! in_array( (string) $row['language'], [ '', 'en_US' ], true ) ) { | |
| 723 | - continue; | |
| 724 | - } | |
| 725 | - if ( isset( $seen[ $row['name'] ] ) ) { | |
| 726 | - continue; | |
| 727 | - } | |
| 728 | - $seen[ $row['name'] ] = true; | |
| 729 | - if ( 'active' === $row['status'] ) { | |
| 730 | - $active[] = $row['name']; | |
| 731 | - } | |
| 732 | - } | |
| 733 | - | |
| 734 | - self::$active_default_template_names = $active; | |
| 735 | - return $active; | |
| 736 | 529 | } |
| 737 | 530 | |
| 738 | 531 | public static function get_short_data_by_name( $name ) { |
| 739 | 532 | $template_id = self::query_template( [ 'name' => $name ] ); |