| @@ -462,8 +462,9 @@ | ||
| 462 | 462 | return; |
| 463 | 463 | } |
| 464 | 464 | if ( wp_is_block_theme() ) { |
| 465 | 465 | $this->handle_old_fse_css(); |
| 466 | + $this->handle_fse_template_parts_css(); | |
| 466 | 467 | } |
| 467 | 468 | $css = ''; |
| 468 | 469 | $post_id = ultimate_post()->get_ID(); |
| 469 | 470 | if ( isset($_GET['preview_id']) && isset($_GET['preview_nonce']) ) { // @codingStandardsIgnoreLine. |
| @@ -564,8 +565,31 @@ | ||
| 564 | 565 | } |
| 565 | 566 | } |
| 566 | 567 | if ( ! is_admin() && |
| 567 | 568 | isset( $block['blockName'] ) && |
| 569 | + $block['blockName'] === 'core/block' && | |
| 570 | + ! empty( $block['attrs']['ref'] ) | |
| 571 | + ) { | |
| 572 | + // Validate ref_id is a positive integer | |
| 573 | + $ref_id = absint( $block['attrs']['ref'] ); | |
| 574 | + if ( $ref_id < 1 ) { | |
| 575 | + return $block_content; | |
| 576 | + } | |
| 577 | + | |
| 578 | + if ( get_post_type( $ref_id ) === 'wp_block' && | |
| 579 | + get_post_meta( $ref_id, '_ultp_active', true ) === 'yes' | |
| 580 | + ) { | |
| 581 | + do_action( | |
| 582 | + 'ultp_enqueue_postx_block_css', | |
| 583 | + array( | |
| 584 | + 'post_id' => $ref_id, | |
| 585 | + 'css' => '', | |
| 586 | + ) | |
| 587 | + ); | |
| 588 | + } | |
| 589 | + } | |
| 590 | + if ( ! is_admin() && | |
| 591 | + isset( $block['blockName'] ) && | |
| 568 | 592 | strpos( $block['blockName'], 'ultimate-post/' ) === 0 |
| 569 | 593 | && ! empty( $block['attrs']['currentPostId'] ) |
| 570 | 594 | ) { |
| 571 | 595 | do_action( |
| @@ -616,8 +640,58 @@ | ||
| 616 | 640 | ultimate_post()->register_scripts_common(); |
| 617 | 641 | wp_register_style( "ultp-post-{$post_id}", false ); |
| 618 | 642 | wp_enqueue_style( "ultp-post-{$post_id}" ); |
| 619 | 643 | wp_add_inline_style( "ultp-post-{$post_id}", $css ); |
| 644 | + } | |
| 645 | + } | |
| 646 | + } | |
| 647 | + | |
| 648 | + /** | |
| 649 | + * Enqueue CSS for FSE template parts (header, footer, etc.) that contain PostX blocks. | |
| 650 | + * Must run during wp_enqueue_scripts (before wp_head) so styles land in <head>. | |
| 651 | + * | |
| 652 | + * @since v.4.1.8 | |
| 653 | + * @return void | |
| 654 | + */ | |
| 655 | + public function handle_fse_template_parts_css() { | |
| 656 | + $parts = get_posts( | |
| 657 | + array( | |
| 658 | + 'post_type' => 'wp_template_part', | |
| 659 | + 'meta_query' => array( | |
| 660 | + array( | |
| 661 | + 'key' => '_ultp_active', | |
| 662 | + 'value' => 'yes', | |
| 663 | + ), | |
| 664 | + ), | |
| 665 | + 'posts_per_page' => -1, | |
| 666 | + 'fields' => 'ids', | |
| 667 | + ) | |
| 668 | + ); | |
| 669 | + | |
| 670 | + if ( empty( $parts ) ) { | |
| 671 | + return; | |
| 672 | + } | |
| 673 | + | |
| 674 | + $upload_dir = wp_upload_dir(); | |
| 675 | + $dir = trailingslashit( $upload_dir['basedir'] ) . 'ultimate-post/'; | |
| 676 | + | |
| 677 | + foreach ( $parts as $part_id ) { | |
| 678 | + // Validate post ID is numeric | |
| 679 | + $part_id = absint( $part_id ); | |
| 680 | + if ( $part_id < 1 ) { | |
| 681 | + continue; | |
| 682 | + } | |
| 683 | + | |
| 684 | + $css_file = $dir . "ultp-css-{$part_id}.css"; | |
| 685 | + | |
| 686 | + if ( file_exists( $css_file ) ) { | |
| 687 | + do_action( | |
| 688 | + 'ultp_enqueue_postx_block_css', | |
| 689 | + array( | |
| 690 | + 'post_id' => $part_id, | |
| 691 | + 'css' => '', | |
| 692 | + ) | |
| 693 | + ); | |
| 620 | 694 | } |
| 621 | 695 | } |
| 622 | 696 | } |
| 623 | 697 | |