Changeset 7394
- Timestamp:
- 12/30/2025 05:29:34 PM (4 weeks ago)
- Location:
- trunk/src/includes/core
- Files:
-
- 2 edited
-
template-loader.php (modified) (4 diffs)
-
theme-compat.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/core/template-loader.php
r7380 r7394 29 29 function bbp_template_include_theme_supports( $template = '' ) { 30 30 31 // phpcs:disable 32 33 // Editing a user 34 if ( bbp_is_single_user_edit() && ( $new_template = bbp_get_single_user_edit_template() ) ) : //phpcs:ignore 35 36 // User favorites 37 elseif ( bbp_is_favorites() && ( $new_template = bbp_get_favorites_template() ) ) : 38 39 // User favorites 40 elseif ( bbp_is_subscriptions() && ( $new_template = bbp_get_subscriptions_template() ) ) : 41 42 // Viewing a user 43 elseif ( bbp_is_single_user() && ( $new_template = bbp_get_single_user_template() ) ) : 44 45 // Single View 46 elseif ( bbp_is_single_view() && ( $new_template = bbp_get_single_view_template() ) ) : 47 48 // Search 49 elseif ( bbp_is_search() && ( $new_template = bbp_get_search_template() ) ) : 50 51 // Forum edit 52 elseif ( bbp_is_forum_edit() && ( $new_template = bbp_get_forum_edit_template() ) ) : 53 54 // Single Forum 55 elseif ( bbp_is_single_forum() && ( $new_template = bbp_get_single_forum_template() ) ) : 56 57 // Forum Archive 58 elseif ( bbp_is_forum_archive() && ( $new_template = bbp_get_forum_archive_template() ) ) : 59 60 // Topic merge 61 elseif ( bbp_is_topic_merge() && ( $new_template = bbp_get_topic_merge_template() ) ) : 62 63 // Topic split 64 elseif ( bbp_is_topic_split() && ( $new_template = bbp_get_topic_split_template() ) ) : 65 66 // Topic edit 67 elseif ( bbp_is_topic_edit() && ( $new_template = bbp_get_topic_edit_template() ) ) : 68 69 // Single Topic 70 elseif ( bbp_is_single_topic() && ( $new_template = bbp_get_single_topic_template() ) ) : 71 72 // Topic Archive 73 elseif ( bbp_is_topic_archive() && ( $new_template = bbp_get_topic_archive_template() ) ) : 74 75 // Reply move 76 elseif ( bbp_is_reply_move() && ( $new_template = bbp_get_reply_move_template() ) ) : 77 78 // Editing a reply 79 elseif ( bbp_is_reply_edit() && ( $new_template = bbp_get_reply_edit_template() ) ) : 80 81 // Single Reply 82 elseif ( bbp_is_single_reply() && ( $new_template = bbp_get_single_reply_template() ) ) : 83 84 // Editing a topic tag 85 elseif ( bbp_is_topic_tag_edit() && ( $new_template = bbp_get_topic_tag_edit_template() ) ) : 86 87 // Viewing a topic tag 88 elseif ( bbp_is_topic_tag() && ( $new_template = bbp_get_topic_tag_template() ) ) : 89 endif; 90 91 // phpcs:enable 92 93 // A bbPress template file was located, so override the WordPress template 94 // and use it to switch off theme compatibility. 95 if ( ! empty( $new_template ) ) { 96 $template = bbp_set_template_included( $new_template ); 31 // Default return value 32 $retval = $template; 33 34 // Get the templates 35 $bbp_templates = bbp_get_template_include_templates(); 36 37 // Loop through each of the template conditionals 38 if ( ! empty( $bbp_templates ) ) { 39 foreach ( $bbp_templates as $checker => $getter ) { 40 41 // Skip if check fails 42 if ( ! function_exists( $checker ) || ! call_user_func( $checker ) ) { 43 continue; 44 } 45 46 // Maybe get a template file 47 $new_template = function_exists( $getter ) 48 ? call_user_func( $getter ) 49 : ''; 50 51 // Skip if new template not found 52 if ( empty( $new_template ) ) { 53 continue; 54 } 55 56 // A bbPress template file was located, so set the return value 57 // that will override the WordPress template, and switches off 58 // theme compatibility. 59 $retval = bbp_set_template_included( $new_template ); 60 61 // Exit the loop 62 break; 63 } 97 64 } 98 65 … … 102 69 * @since 2.0.0 bbPress (r3032) 103 70 * 104 * @param string $template The path to the template file. 71 * @param string $retval Path to the filtered template file. 72 * @param string $template Path to the original template file. 105 73 */ 106 return apply_filters( 'bbp_template_include_theme_supports', $ template );74 return apply_filters( 'bbp_template_include_theme_supports', $retval, $template ); 107 75 } 108 76 … … 460 428 461 429 /** 462 * Get the templates to use as the endpoint for bbPress template parts. 463 * 464 * @since 2.0.0 bbPress (r3311) 465 * @since 2.6.0 bbPress (r5950) Added `singular.php` to template stack 466 * 467 * @return string Path to template file. 468 */ 469 function bbp_get_theme_compat_templates() { 430 * Get the template to use as the wrapper for bbPress template parts. 431 * 432 * @since 2.7.0 bbPress (r7393) 433 * 434 * @return string Path to template file. 435 */ 436 function bbp_get_theme_compat_template() { 470 437 $templates = array( 471 438 'plugin-bbpress.php', … … 481 448 return bbp_get_query_template( 'bbpress', $templates ); 482 449 } 450 451 /** 452 * Get the theme canvas template, used for Block Themes. 453 * 454 * @since 2.7.0 bbPress (r7383) 455 * 456 * @return string Path to canvas file. 457 */ 458 function bbp_get_theme_canvas_template() { 459 460 // Default WordPress Canvas 461 $template = ABSPATH . WPINC . '/template-canvas.php'; 462 463 // Filter & return 464 return apply_filters( 'bbp_get_theme_canvas_template', $template ); 465 } 466 467 /** 468 * Get the array of _is_ functions and their template finders. 469 * 470 * This function abstracts the template checkers & getters to allow third-party 471 * plugins to add their own bbPress component functionality more easily. 472 * 473 * @since 2.7.0 bbPress (r7393) 474 * 475 * @return array Key => Value array of checkers & getters. 476 */ 477 function bbp_get_template_include_templates() { 478 479 // Possible templates: checker => getter 480 $templates = array( 481 482 // User 483 'bbp_is_single_user_edit' => 'bbp_get_single_user_edit_template', 484 'bbp_is_favorites' => 'bbp_get_favorites_template', 485 'bbp_is_subscriptions' => 'bbp_get_subscriptions_template', 486 'bbp_is_single_user' => 'bbp_get_single_user_template', 487 488 // Topic view 489 'bbp_is_single_view' => 'bbp_get_single_view_template', 490 491 // Search 492 'bbp_is_search' => 'bbp_get_search_template', 493 494 // Forum 495 'bbp_is_forum_edit' => 'bbp_get_forum_edit_template', 496 'bbp_is_single_forum' => 'bbp_get_single_forum_template', 497 'bbp_is_forum_archive' => 'bbp_get_forum_archive_template', 498 499 // Topic 500 'bbp_is_topic_merge' => 'bbp_get_topic_merge_template', 501 'bbp_is_topic_split' => 'bbp_get_topic_split_template', 502 'bbp_is_topic_edit' => 'bbp_get_topic_edit_template', 503 'bbp_is_single_topic' => 'bbp_get_single_topic_template', 504 'bbp_is_topic_archive' => 'bbp_get_topic_archive_template', 505 506 // Reply 507 'bbp_is_reply_move' => 'bbp_get_reply_move_template', 508 'bbp_is_reply_edit' => 'bbp_get_reply_edit_template', 509 'bbp_is_single_reply' => 'bbp_get_single_reply_template', 510 511 // Topic tag 512 'bbp_is_topic_tag_edit' => 'bbp_get_topic_tag_edit_template', 513 'bbp_is_topic_tag' => 'bbp_get_topic_tag_template', 514 ); 515 516 // Filter & return 517 return (array) apply_filters( 'bbp_get_template_include_templates', $templates ); 518 } 519 520 /** Deprecated ****************************************************************/ 521 522 /** 523 * Get the templates to use as the endpoint for bbPress template parts. 524 * 525 * This function was deprecated because it was named plural when it should have 526 * been singular, as it only returns the path to a single file. 527 * 528 * @since 2.0.0 bbPress (r3311) 529 * @since 2.6.0 bbPress (r5950) Added `singular.php` to template stack 530 * @deprecated 2.7.0 bbPress (r7393) 531 * 532 * @return string Path to template file. 533 */ 534 function bbp_get_theme_compat_templates() { 535 return bbp_get_theme_compat_template(); 536 } 537 -
trunk/src/includes/core/theme-compat.php
r7380 r7394 482 482 * 483 483 * @since 2.0.0 bbPress (r3032) 484 * @since 2.7.0 bbPress (r7393) Added support for Block Themes 484 485 * 485 486 * @param string $template … … 488 489 489 490 /** 490 * Bail if a root template was already found. This prevents unintended 491 * recursive filtering of 'the_content'. 492 * 493 * @link https://bbpress.trac.wordpress.org/ticket/2429 491 * Bail if the template already matches a bbPress template. This includes 492 * archive-* and single-* WordPress post_type matches (allowing 493 * themes to use the expected format) as well as all bbPress-specific 494 * template files for users, topics, forums, etc... 495 * 496 * @see https://bbpress.trac.wordpress.org/ticket/1478 497 * @see https://bbpress.trac.wordpress.org/ticket/2429 494 498 */ 495 499 if ( bbp_is_template_included() ) { … … 838 842 839 843 /** 840 * Bail if the template already matches a bbPress template. This includes841 * archive-* and single-* WordPress post_type matches (allowing842 * themes to use the expected format) as well as all bbPress-specific843 * template files for users, topics, forums, etc...844 *845 * We do this after the above checks to prevent incorrect 404 body classes846 * and header statuses, as well as to set the post global as needed.847 *848 * @see https://bbpress.trac.wordpress.org/ticket/1478/849 */850 if ( bbp_is_template_included() ) {851 return $template;852 853 /**854 844 * If we are relying on the built-in theme compatibility API to load 855 845 * the proper content, we need to intercept the_content, replace the … … 858 848 * To do this, we first remove all filters from 'the_content' and hook 859 849 * our own function into it, which runs a series of checks to determine 860 * the context, and then uses the built in shortcodes to output the861 * correctresults from inside an output buffer.862 * 863 * Uses bbp_get_theme_compat_template s() to provide fall-backs that850 * the context, and then uses the shortcodes API to output the correct 851 * results from inside an output buffer. 852 * 853 * Uses bbp_get_theme_compat_template() to provide fall-backs that 864 854 * should be coded without superfluous mark-up and logic (prev/next 865 855 * navigation, comments, date/time, etc...) 866 856 * 867 * Hook into the 'bbp_get_bbpress_template' to override the array of857 * Hook into the 'bbp_get_bbpress_template' filter to override the array of 868 858 * possible templates, or 'bbp_bbpress_template' to override the result. 859 * 860 * This is Block Theme aware as of 2.7.0 and will use the Canvas file that 861 * block themes expect instead of a theme-compat template. 869 862 */ 870 } elseif ( bbp_is_theme_compat_active() ) {863 if ( bbp_is_theme_compat_active() ) { 871 864 bbp_remove_all_filters( 'the_content' ); 872 865 873 $template = bbp_get_theme_compat_templates(); 866 // Block themes 867 if ( current_theme_supports( 'block-templates' ) ) { 868 $template = bbp_get_theme_canvas_template(); 869 870 // Non-block themes 871 } else { 872 $template = bbp_get_theme_compat_template(); 873 } 874 874 } 875 875
Note: See TracChangeset
for help on using the changeset viewer.