Changeset 3492675
- Timestamp:
- 03/27/2026 12:55:11 PM (6 days ago)
- Location:
- firetap-knowledge-panel-schema
- Files:
-
- 2 edited
-
tags/2.7/includes/class-kpsp-faq-display.php (modified) (5 diffs)
-
trunk/includes/class-kpsp-faq-display.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
firetap-knowledge-panel-schema/tags/2.7/includes/class-kpsp-faq-display.php
r3492628 r3492675 22 22 private function __construct() { 23 23 add_action( 'init', array( $this, 'register_post_type' ) ); 24 add_action( 'admin_init', array( $this, 'maybe_migrate_legacy_faq_groups' ) ); 24 25 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_editor_assets' ) ); 25 26 add_action( 'add_meta_boxes', array( $this, 'add_metabox' ) ); … … 77 78 public function render_metabox( $post ) { 78 79 wp_nonce_field( 'kpsp_save_faq_group', 'kpsp_faq_group_nonce' ); 80 81 $this->maybe_migrate_single_legacy_faq_group( $post->ID ); 79 82 80 83 $faqs = get_post_meta( $post->ID, 'kpsp_faq_group_items', true ); … … 360 363 } 361 364 365 $this->maybe_migrate_single_legacy_faq_group( $post_id ); 366 362 367 $faqs = get_post_meta( $post_id, 'kpsp_faq_group_items', true ); 363 368 if ( empty( $faqs ) || ! is_array( $faqs ) ) { … … 593 598 } 594 599 600 public function maybe_migrate_legacy_faq_groups() { 601 if ( ! is_admin() || ! current_user_can( 'manage_options' ) ) { 602 return; 603 } 604 605 $legacy_posts = get_posts( 606 array( 607 'post_type' => 'faq_group', 608 'post_status' => array( 'publish', 'draft', 'pending', 'private' ), 609 'posts_per_page' => 50, 610 'fields' => 'ids', 611 'meta_query' => array( 612 array( 613 'key' => 'fgp_faqs', 614 'compare' => 'EXISTS', 615 ), 616 ), 617 'orderby' => 'ID', 618 'order' => 'ASC', 619 ) 620 ); 621 622 if ( empty( $legacy_posts ) ) { 623 return; 624 } 625 626 foreach ( $legacy_posts as $post_id ) { 627 $this->maybe_migrate_single_legacy_faq_group( $post_id ); 628 } 629 } 630 595 631 private function get_site_brand_colors() { 596 632 $defaults = array( … … 637 673 } 638 674 675 private function maybe_migrate_single_legacy_faq_group( $post_id ) { 676 $post_id = absint( $post_id ); 677 if ( ! $post_id || 'faq_group' !== get_post_type( $post_id ) ) { 678 return; 679 } 680 681 $legacy_faqs = get_post_meta( $post_id, 'fgp_faqs', true ); 682 $new_faqs = get_post_meta( $post_id, 'kpsp_faq_group_items', true ); 683 684 if ( empty( $legacy_faqs ) || ! is_array( $legacy_faqs ) ) { 685 return; 686 } 687 688 if ( empty( $new_faqs ) || ! is_array( $new_faqs ) ) { 689 $migrated_items = array(); 690 691 foreach ( $legacy_faqs as $faq ) { 692 $question = isset( $faq['question'] ) ? sanitize_text_field( $faq['question'] ) : ''; 693 $answer = isset( $faq['answer'] ) ? wp_kses_post( $faq['answer'] ) : ''; 694 695 if ( '' !== $question && '' !== trim( wp_strip_all_tags( $answer ) ) ) { 696 $migrated_items[] = array( 697 'question' => $question, 698 'answer' => $answer, 699 ); 700 } 701 } 702 703 if ( ! empty( $migrated_items ) ) { 704 update_post_meta( $post_id, 'kpsp_faq_group_items', $migrated_items ); 705 } 706 } 707 708 $this->migrate_legacy_meta_value( $post_id, 'fgp_title_color', 'kpsp_faq_title_color', '#000000' ); 709 $this->migrate_legacy_meta_value( $post_id, 'fgp_answer_color', 'kpsp_faq_answer_color', '#333333' ); 710 $this->migrate_legacy_meta_value( $post_id, 'fgp_background_color', 'kpsp_faq_background', '#ffffff' ); 711 $this->migrate_legacy_meta_value( $post_id, 'fgp_button_color', 'kpsp_faq_accent', '#0073aa' ); 712 $this->migrate_legacy_meta_value( $post_id, 'fgp_title_size', 'kpsp_faq_title_size', '18px' ); 713 $this->migrate_legacy_meta_value( $post_id, 'fgp_answer_size', 'kpsp_faq_answer_size', '14px' ); 714 715 if ( '' === (string) get_post_meta( $post_id, 'kpsp_faq_layout_style', true ) ) { 716 update_post_meta( $post_id, 'kpsp_faq_layout_style', 'boxed' ); 717 } 718 719 if ( '' === (string) get_post_meta( $post_id, 'kpsp_faq_color_mode', true ) ) { 720 update_post_meta( $post_id, 'kpsp_faq_color_mode', 'manual' ); 721 } 722 723 if ( '' === (string) get_post_meta( $post_id, 'kpsp_faq_read_more_after', true ) ) { 724 update_post_meta( $post_id, 'kpsp_faq_read_more_after', 4 ); 725 } 726 727 if ( '' === (string) get_post_meta( $post_id, 'kpsp_faq_output_schema', true ) ) { 728 update_post_meta( $post_id, 'kpsp_faq_output_schema', '1' ); 729 } 730 } 731 732 private function migrate_legacy_meta_value( $post_id, $old_key, $new_key, $default = '' ) { 733 $current_value = get_post_meta( $post_id, $new_key, true ); 734 if ( '' !== (string) $current_value && null !== $current_value ) { 735 return; 736 } 737 738 $legacy_value = get_post_meta( $post_id, $old_key, true ); 739 if ( '' === (string) $legacy_value || null === $legacy_value ) { 740 $legacy_value = $default; 741 } 742 743 update_post_meta( $post_id, $new_key, $legacy_value ); 744 } 745 639 746 private function get_global_faq_style() { 640 747 $settings = get_option( 'kpsp_pro_settings', array() ); -
firetap-knowledge-panel-schema/trunk/includes/class-kpsp-faq-display.php
r3492628 r3492675 22 22 private function __construct() { 23 23 add_action( 'init', array( $this, 'register_post_type' ) ); 24 add_action( 'admin_init', array( $this, 'maybe_migrate_legacy_faq_groups' ) ); 24 25 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_editor_assets' ) ); 25 26 add_action( 'add_meta_boxes', array( $this, 'add_metabox' ) ); … … 77 78 public function render_metabox( $post ) { 78 79 wp_nonce_field( 'kpsp_save_faq_group', 'kpsp_faq_group_nonce' ); 80 81 $this->maybe_migrate_single_legacy_faq_group( $post->ID ); 79 82 80 83 $faqs = get_post_meta( $post->ID, 'kpsp_faq_group_items', true ); … … 360 363 } 361 364 365 $this->maybe_migrate_single_legacy_faq_group( $post_id ); 366 362 367 $faqs = get_post_meta( $post_id, 'kpsp_faq_group_items', true ); 363 368 if ( empty( $faqs ) || ! is_array( $faqs ) ) { … … 593 598 } 594 599 600 public function maybe_migrate_legacy_faq_groups() { 601 if ( ! is_admin() || ! current_user_can( 'manage_options' ) ) { 602 return; 603 } 604 605 $legacy_posts = get_posts( 606 array( 607 'post_type' => 'faq_group', 608 'post_status' => array( 'publish', 'draft', 'pending', 'private' ), 609 'posts_per_page' => 50, 610 'fields' => 'ids', 611 'meta_query' => array( 612 array( 613 'key' => 'fgp_faqs', 614 'compare' => 'EXISTS', 615 ), 616 ), 617 'orderby' => 'ID', 618 'order' => 'ASC', 619 ) 620 ); 621 622 if ( empty( $legacy_posts ) ) { 623 return; 624 } 625 626 foreach ( $legacy_posts as $post_id ) { 627 $this->maybe_migrate_single_legacy_faq_group( $post_id ); 628 } 629 } 630 595 631 private function get_site_brand_colors() { 596 632 $defaults = array( … … 637 673 } 638 674 675 private function maybe_migrate_single_legacy_faq_group( $post_id ) { 676 $post_id = absint( $post_id ); 677 if ( ! $post_id || 'faq_group' !== get_post_type( $post_id ) ) { 678 return; 679 } 680 681 $legacy_faqs = get_post_meta( $post_id, 'fgp_faqs', true ); 682 $new_faqs = get_post_meta( $post_id, 'kpsp_faq_group_items', true ); 683 684 if ( empty( $legacy_faqs ) || ! is_array( $legacy_faqs ) ) { 685 return; 686 } 687 688 if ( empty( $new_faqs ) || ! is_array( $new_faqs ) ) { 689 $migrated_items = array(); 690 691 foreach ( $legacy_faqs as $faq ) { 692 $question = isset( $faq['question'] ) ? sanitize_text_field( $faq['question'] ) : ''; 693 $answer = isset( $faq['answer'] ) ? wp_kses_post( $faq['answer'] ) : ''; 694 695 if ( '' !== $question && '' !== trim( wp_strip_all_tags( $answer ) ) ) { 696 $migrated_items[] = array( 697 'question' => $question, 698 'answer' => $answer, 699 ); 700 } 701 } 702 703 if ( ! empty( $migrated_items ) ) { 704 update_post_meta( $post_id, 'kpsp_faq_group_items', $migrated_items ); 705 } 706 } 707 708 $this->migrate_legacy_meta_value( $post_id, 'fgp_title_color', 'kpsp_faq_title_color', '#000000' ); 709 $this->migrate_legacy_meta_value( $post_id, 'fgp_answer_color', 'kpsp_faq_answer_color', '#333333' ); 710 $this->migrate_legacy_meta_value( $post_id, 'fgp_background_color', 'kpsp_faq_background', '#ffffff' ); 711 $this->migrate_legacy_meta_value( $post_id, 'fgp_button_color', 'kpsp_faq_accent', '#0073aa' ); 712 $this->migrate_legacy_meta_value( $post_id, 'fgp_title_size', 'kpsp_faq_title_size', '18px' ); 713 $this->migrate_legacy_meta_value( $post_id, 'fgp_answer_size', 'kpsp_faq_answer_size', '14px' ); 714 715 if ( '' === (string) get_post_meta( $post_id, 'kpsp_faq_layout_style', true ) ) { 716 update_post_meta( $post_id, 'kpsp_faq_layout_style', 'boxed' ); 717 } 718 719 if ( '' === (string) get_post_meta( $post_id, 'kpsp_faq_color_mode', true ) ) { 720 update_post_meta( $post_id, 'kpsp_faq_color_mode', 'manual' ); 721 } 722 723 if ( '' === (string) get_post_meta( $post_id, 'kpsp_faq_read_more_after', true ) ) { 724 update_post_meta( $post_id, 'kpsp_faq_read_more_after', 4 ); 725 } 726 727 if ( '' === (string) get_post_meta( $post_id, 'kpsp_faq_output_schema', true ) ) { 728 update_post_meta( $post_id, 'kpsp_faq_output_schema', '1' ); 729 } 730 } 731 732 private function migrate_legacy_meta_value( $post_id, $old_key, $new_key, $default = '' ) { 733 $current_value = get_post_meta( $post_id, $new_key, true ); 734 if ( '' !== (string) $current_value && null !== $current_value ) { 735 return; 736 } 737 738 $legacy_value = get_post_meta( $post_id, $old_key, true ); 739 if ( '' === (string) $legacy_value || null === $legacy_value ) { 740 $legacy_value = $default; 741 } 742 743 update_post_meta( $post_id, $new_key, $legacy_value ); 744 } 745 639 746 private function get_global_faq_style() { 640 747 $settings = get_option( 'kpsp_pro_settings', array() );
Note: See TracChangeset
for help on using the changeset viewer.