| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | - * bbPress Theme Compatibility. | |
| 4 | + * bbPress Theme Compatibility | |
| 5 | 5 | * |
| 6 | 6 | * @package bbPress |
| 7 | 7 | * @subpackage Core |
| 8 | 8 | */ |
| @@ -24,12 +24,12 @@ | ||
| 24 | 24 | |
| 25 | 25 | /** Base Class ****************************************************************/ |
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | - * Theme Compatibility base class. | |
| 28 | + * Theme Compatibility base class | |
| 29 | 29 | * |
| 30 | 30 | * This is only intended to be extended, and is included here as a basic guide |
| 31 | - * for future Template Packs to use. @link bbp_setup_theme_compat(). | |
| 31 | + * for future Template Packs to use. @link bbp_setup_theme_compat() | |
| 32 | 32 | * |
| 33 | 33 | * @since 2.0.0 bbPress (r3506) |
| 34 | 34 | */ |
| 35 | 35 | class BBP_Theme_Compat { |
| @@ -45,9 +45,9 @@ | ||
| 45 | 45 | * 'url' => URL to theme |
| 46 | 46 | * ); |
| 47 | 47 | * @var array |
| 48 | 48 | */ |
| 49 | - private $_data = array(); // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore | |
| 49 | + private $_data = array(); | |
| 50 | 50 | |
| 51 | 51 | /** |
| 52 | 52 | * Pass the $properties to the object on creation. |
| 53 | 53 | * |
| @@ -229,9 +229,9 @@ | ||
| 229 | 229 | return apply_filters( 'bbp_get_theme_compat_url', bbp_get_current_template_pack()->url ); |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /** |
| 233 | - * Gets true/false if page is currently inside theme compatibility. | |
| 233 | + * Gets true/false if page is currently inside theme compatibility | |
| 234 | 234 | * |
| 235 | 235 | * @since 2.0.0 bbPress (r3265) |
| 236 | 236 | * |
| 237 | 237 | * @return bool |
| @@ -246,9 +246,9 @@ | ||
| 246 | 246 | return $bbp->theme_compat->active; |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | /** |
| 250 | - * Sets true/false if page is currently inside theme compatibility. | |
| 250 | + * Sets true/false if page is currently inside theme compatibility | |
| 251 | 251 | * |
| 252 | 252 | * @since 2.0.0 bbPress (r3265) |
| 253 | 253 | * |
| 254 | 254 | * @param bool $set |
| @@ -260,9 +260,9 @@ | ||
| 260 | 260 | return (bool) bbpress()->theme_compat->active; |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | /** |
| 264 | - * Set the theme compat templates global. | |
| 264 | + * Set the theme compat templates global | |
| 265 | 265 | * |
| 266 | 266 | * Stash possible template files for the current query. Useful if plugins want |
| 267 | 267 | * to override them, or see what files are being scanned for inclusion. |
| 268 | 268 | * |
| @@ -274,9 +274,9 @@ | ||
| 274 | 274 | return bbpress()->theme_compat->templates; |
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | /** |
| 278 | - * Set the theme compat template global. | |
| 278 | + * Set the theme compat template global | |
| 279 | 279 | * |
| 280 | 280 | * Stash the template file for the current query. Useful if plugins want |
| 281 | 281 | * to override it, or see what file is being included. |
| 282 | 282 | * |
| @@ -288,9 +288,9 @@ | ||
| 288 | 288 | return bbpress()->theme_compat->template; |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | /** |
| 292 | - * Set the theme compat original_template global. | |
| 292 | + * Set the theme compat original_template global | |
| 293 | 293 | * |
| 294 | 294 | * Stash the original template file for the current query. Useful for checking |
| 295 | 295 | * if bbPress was able to find a more appropriate template. |
| 296 | 296 | * |
| @@ -302,9 +302,9 @@ | ||
| 302 | 302 | return bbpress()->theme_compat->original_template; |
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | /** |
| 306 | - * Is a template the original_template global. | |
| 306 | + * Is a template the original_template global | |
| 307 | 307 | * |
| 308 | 308 | * Stash the original template file for the current query. Useful for checking |
| 309 | 309 | * if bbPress was able to find a more appropriate template. |
| 310 | 310 | * |
| @@ -321,9 +321,9 @@ | ||
| 321 | 321 | return (bool) ( $bbp->theme_compat->original_template === $template ); |
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | /** |
| 325 | - * Register a new bbPress theme package to the active theme packages array. | |
| 325 | + * Register a new bbPress theme package to the active theme packages array | |
| 326 | 326 | * |
| 327 | 327 | * @since 2.1.0 bbPress (r3829) |
| 328 | 328 | * |
| 329 | 329 | * @param array $theme |
| @@ -466,10 +466,8 @@ | ||
| 466 | 466 | // Reset is_singular based on page/single args |
| 467 | 467 | // https://bbpress.trac.wordpress.org/ticket/2545 |
| 468 | 468 | $wp_query->is_singular = $wp_query->is_single; |
| 469 | 469 | |
| 470 | - // phpcs:enable | |
| 471 | - | |
| 472 | 470 | // Clean up the dummy post |
| 473 | 471 | unset( $dummy ); |
| 474 | 472 | |
| 475 | 473 | // If we are resetting a post, we are in theme compat |
| @@ -487,15 +485,12 @@ | ||
| 487 | 485 | */ |
| 488 | 486 | function bbp_template_include_theme_compat( $template = '' ) { |
| 489 | 487 | |
| 490 | 488 | /** |
| 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... | |
| 489 | + * Bail if a root template was already found. This prevents unintended | |
| 490 | + * recursive filtering of 'the_content'. | |
| 495 | 491 | * |
| 496 | - * @see https://bbpress.trac.wordpress.org/ticket/1478 | |
| 497 | - * @see https://bbpress.trac.wordpress.org/ticket/2429 | |
| 492 | + * @link https://bbpress.trac.wordpress.org/ticket/2429 | |
| 498 | 493 | */ |
| 499 | 494 | if ( bbp_is_template_included() ) { |
| 500 | 495 | return $template; |
| 501 | 496 | } |
| @@ -519,9 +514,9 @@ | ||
| 519 | 514 | if ( ! is_a( $bbp_shortcodes, 'BBP_Shortcodes' ) ) { |
| 520 | 515 | return $template; |
| 521 | 516 | } |
| 522 | 517 | |
| 523 | - /** Users *****************************************************************/ | |
| 518 | + /** Users *************************************************************/ | |
| 524 | 519 | |
| 525 | 520 | if ( bbp_is_single_user_edit() || bbp_is_single_user() ) { |
| 526 | 521 | |
| 527 | 522 | // Reset post |
| @@ -538,9 +533,9 @@ | ||
| 538 | 533 | 'comment_status' => 'closed' |
| 539 | 534 | ) |
| 540 | 535 | ); |
| 541 | 536 | |
| 542 | - /** Forums ****************************************************************/ | |
| 537 | + /** Forums ************************************************************/ | |
| 543 | 538 | |
| 544 | 539 | // Forum archive |
| 545 | 540 | } elseif ( bbp_is_forum_archive() ) { |
| 546 | 541 | |
| @@ -633,9 +628,9 @@ | ||
| 633 | 628 | 'comment_status' => 'closed' |
| 634 | 629 | ) |
| 635 | 630 | ); |
| 636 | 631 | |
| 637 | - /** Topics ****************************************************************/ | |
| 632 | + /** Topics ************************************************************/ | |
| 638 | 633 | |
| 639 | 634 | // Topic archive |
| 640 | 635 | } elseif ( bbp_is_topic_archive() ) { |
| 641 | 636 | |
| @@ -656,9 +651,9 @@ | ||
| 656 | 651 | $new_title = bbp_get_topic_archive_title(); |
| 657 | 652 | |
| 658 | 653 | // ...or use the existing page title? |
| 659 | 654 | } else { |
| 660 | - $new_title = apply_filters( 'the_title', $page->post_title, $page->ID ); | |
| 655 | + $new_title = apply_filters( 'the_title', $page->post_title ); | |
| 661 | 656 | } |
| 662 | 657 | |
| 663 | 658 | // Reset post |
| 664 | 659 | bbp_theme_compat_reset_post( |
| @@ -663,9 +658,9 @@ | ||
| 663 | 658 | // Reset post |
| 664 | 659 | bbp_theme_compat_reset_post( |
| 665 | 660 | array( |
| 666 | 661 | 'ID' => ! empty( $page->ID ) ? $page->ID : 0, |
| 667 | - 'post_title' => $new_title, | |
| 662 | + 'post_title' => bbp_get_topic_archive_title(), | |
| 668 | 663 | 'post_author' => 0, |
| 669 | 664 | 'post_date' => bbp_get_empty_datetime(), |
| 670 | 665 | 'post_content' => $new_content, |
| 671 | 666 | 'post_type' => bbp_get_topic_post_type(), |
| @@ -712,9 +707,9 @@ | ||
| 712 | 707 | 'comment_status' => 'closed' |
| 713 | 708 | ) |
| 714 | 709 | ); |
| 715 | 710 | |
| 716 | - /** Replies ***************************************************************/ | |
| 711 | + /** Replies ***********************************************************/ | |
| 717 | 712 | |
| 718 | 713 | // Reply archive |
| 719 | 714 | } elseif ( is_post_type_archive( bbp_get_reply_post_type() ) ) { |
| 720 | 715 | |
| @@ -766,9 +761,9 @@ | ||
| 766 | 761 | 'comment_status' => 'closed' |
| 767 | 762 | ) |
| 768 | 763 | ); |
| 769 | 764 | |
| 770 | - /** Views *****************************************************************/ | |
| 765 | + /** Views *************************************************************/ | |
| 771 | 766 | |
| 772 | 767 | } elseif ( bbp_is_single_view() ) { |
| 773 | 768 | |
| 774 | 769 | // Reset post |
| @@ -785,9 +780,9 @@ | ||
| 785 | 780 | 'comment_status' => 'closed' |
| 786 | 781 | ) |
| 787 | 782 | ); |
| 788 | 783 | |
| 789 | - /** Search ****************************************************************/ | |
| 784 | + /** Search ************************************************************/ | |
| 790 | 785 | |
| 791 | 786 | } elseif ( bbp_is_search() ) { |
| 792 | 787 | |
| 793 | 788 | // Reset post |
| @@ -804,9 +799,9 @@ | ||
| 804 | 799 | 'comment_status' => 'closed' |
| 805 | 800 | ) |
| 806 | 801 | ); |
| 807 | 802 | |
| 808 | - /** Topic Tags ************************************************************/ | |
| 803 | + /** Topic Tags ********************************************************/ | |
| 809 | 804 | |
| 810 | 805 | // Topic Tag Edit |
| 811 | 806 | } elseif ( bbp_is_topic_tag_edit() || bbp_is_topic_tag() ) { |
| 812 | 807 | |
| @@ -840,8 +835,22 @@ | ||
| 840 | 835 | ); |
| 841 | 836 | } |
| 842 | 837 | |
| 843 | 838 | /** |
| 839 | + * Bail if the template already matches a bbPress template. This includes | |
| 840 | + * archive-* and single-* WordPress post_type matches (allowing | |
| 841 | + * themes to use the expected format) as well as all bbPress-specific | |
| 842 | + * template files for users, topics, forums, etc... | |
| 843 | + * | |
| 844 | + * We do this after the above checks to prevent incorrect 404 body classes | |
| 845 | + * and header statuses, as well as to set the post global as needed. | |
| 846 | + * | |
| 847 | + * @see https://bbpress.trac.wordpress.org/ticket/1478/ | |
| 848 | + */ | |
| 849 | + if ( bbp_is_template_included() ) { | |
| 850 | + return $template; | |
| 851 | + | |
| 852 | + /** | |
| 844 | 853 | * If we are relying on the built-in theme compatibility API to load |
| 845 | 854 | * the proper content, we need to intercept the_content, replace the |
| 846 | 855 | * output, and display ours instead. |
| 847 | 856 | * |
| @@ -846,22 +855,19 @@ | ||
| 846 | 855 | * output, and display ours instead. |
| 847 | 856 | * |
| 848 | 857 | * To do this, we first remove all filters from 'the_content' and hook |
| 849 | 858 | * our own function into it, which runs a series of checks to determine |
| 850 | - * the context, and then uses the shortcodes API to output the correct | |
| 851 | - * results from inside an output buffer. | |
| 859 | + * the context, and then uses the built in shortcodes to output the | |
| 860 | + * correct results from inside an output buffer. | |
| 852 | 861 | * |
| 853 | - * Uses bbp_get_theme_compat_template() to provide fall-backs that | |
| 862 | + * Uses bbp_get_theme_compat_templates() to provide fall-backs that | |
| 854 | 863 | * should be coded without superfluous mark-up and logic (prev/next |
| 855 | 864 | * navigation, comments, date/time, etc...) |
| 856 | 865 | * |
| 857 | - * Hook into the 'bbp_get_bbpress_template' filter to override the array of | |
| 866 | + * Hook into the 'bbp_get_bbpress_template' to override the array of | |
| 858 | 867 | * 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. | |
| 862 | 868 | */ |
| 863 | - if ( bbp_is_theme_compat_active() ) { | |
| 869 | + } elseif ( bbp_is_theme_compat_active() ) { | |
| 864 | 870 | bbp_remove_all_filters( 'the_content' ); |
| 865 | 871 | |
| 866 | 872 | // Block themes |
| 867 | 873 | if ( wp_is_block_theme() ) { |
| @@ -868,9 +874,9 @@ | ||
| 868 | 874 | $template = bbp_get_theme_canvas_template(); |
| 869 | 875 | |
| 870 | 876 | // Non-block themes |
| 871 | 877 | } else { |
| 872 | - $template = bbp_get_theme_compat_template(); | |
| 878 | + $template = bbp_get_theme_compat_templates(); | |
| 873 | 879 | } |
| 874 | 880 | } |
| 875 | 881 | |
| 876 | 882 | // Filter & return |
| @@ -876,84 +882,59 @@ | ||
| 876 | 882 | // Filter & return |
| 877 | 883 | return apply_filters( 'bbp_template_include_theme_compat', $template ); |
| 878 | 884 | } |
| 879 | 885 | |
| 880 | -/** Redirection ***************************************************************/ | |
| 886 | +/** Helpers *******************************************************************/ | |
| 881 | 887 | |
| 882 | 888 | /** |
| 883 | - * Prevent canonical redirection when editing forums, topics, topic-tags, | |
| 884 | - * replies, and users. | |
| 889 | + * Remove the canonical redirect to allow pretty pagination | |
| 885 | 890 | * |
| 886 | - * @since 2.7.0 bbPress (r7345) | |
| 891 | + * @since 2.0.0 bbPress (r2628) | |
| 887 | 892 | * |
| 888 | - * @param string $redirect_url The redirect URL. | |
| 893 | + * @param string $redirect_url Redirect url | |
| 889 | 894 | * |
| 890 | - * @return string Empty string if cancelling redirection. | |
| 895 | + * @return bool|string False if it's a topic/forum and their first page, | |
| 896 | + * otherwise the redirect url | |
| 891 | 897 | */ |
| 892 | -function bbp_do_not_redirect_edits( $redirect_url = '' ) { | |
| 898 | +function bbp_redirect_canonical( $redirect_url ) { | |
| 893 | 899 | |
| 894 | - // Default return value | |
| 895 | - $retval = $redirect_url; | |
| 900 | + // Canonical is for the beautiful | |
| 901 | + if ( bbp_use_pretty_urls() ) { | |
| 896 | 902 | |
| 897 | - // Pretty URLs only | |
| 898 | - if ( ! bbp_use_pretty_urls() ) { | |
| 899 | - return $retval; | |
| 900 | - } | |
| 903 | + // If viewing beyond page 1 of several | |
| 904 | + if ( 1 < bbp_get_paged() ) { | |
| 901 | 905 | |
| 902 | - // If editing a forum, topic, topic-tag, reply, or user | |
| 903 | - if ( bbp_is_edit() ) { | |
| 904 | - $retval = ''; | |
| 905 | - } | |
| 906 | + // Only on single topics... | |
| 907 | + if ( bbp_is_single_topic() ) { | |
| 908 | + $redirect_url = false; | |
| 906 | 909 | |
| 907 | - // Return | |
| 908 | - return $retval; | |
| 909 | -} | |
| 910 | + // ...and single forums... | |
| 911 | + } elseif ( bbp_is_single_forum() ) { | |
| 912 | + $redirect_url = false; | |
| 910 | 913 | |
| 911 | -/** | |
| 912 | - * Prevent canonical redirection to allow pretty pagination of forums & topics. | |
| 913 | - * | |
| 914 | - * @since 2.7.0 bbPress (r7345) | |
| 915 | - * | |
| 916 | - * @param string $redirect_url The redirect URL. | |
| 917 | - * | |
| 918 | - * @return string Empty string if cancelling redirection. | |
| 919 | - */ | |
| 920 | -function bbp_do_not_redirect_paginations( $redirect_url = '' ) { | |
| 914 | + // ...and single replies... | |
| 915 | + } elseif ( bbp_is_single_reply() ) { | |
| 916 | + $redirect_url = false; | |
| 921 | 917 | |
| 922 | - // Default return value | |
| 923 | - $retval = $redirect_url; | |
| 918 | + // ...and any single anything else... | |
| 919 | + // | |
| 920 | + // @todo - Find a more accurate way to disable paged canonicals for | |
| 921 | + // paged shortcode usage within other posts. | |
| 922 | + } elseif ( is_page() || is_singular() ) { | |
| 923 | + $redirect_url = false; | |
| 924 | + } | |
| 924 | 925 | |
| 925 | - // Pretty URLs only | |
| 926 | - if ( ! bbp_use_pretty_urls() ) { | |
| 927 | - return $retval; | |
| 928 | - } | |
| 926 | + // If editing a topic | |
| 927 | + } elseif ( bbp_is_topic_edit() ) { | |
| 928 | + $redirect_url = false; | |
| 929 | 929 | |
| 930 | - // If viewing beyond page 1 of several | |
| 931 | - if ( 1 < bbp_get_paged() ) { | |
| 932 | - | |
| 933 | - // Only on single topics... | |
| 934 | - if ( bbp_is_single_topic() ) { | |
| 935 | - $retval = ''; | |
| 936 | - | |
| 937 | - // ...and single forums... | |
| 938 | - } elseif ( bbp_is_single_forum() ) { | |
| 939 | - $retval = ''; | |
| 940 | - | |
| 941 | - // ...and single replies... | |
| 942 | - } elseif ( bbp_is_single_reply() ) { | |
| 943 | - $retval = ''; | |
| 944 | - | |
| 945 | - // ...and any single anything else... | |
| 946 | - // | |
| 947 | - // @todo - Find a more accurate way to disable paged canonicals for | |
| 948 | - // paged shortcode usage within other posts. | |
| 949 | - } elseif ( is_page() || is_singular() ) { | |
| 950 | - $retval = ''; | |
| 930 | + // If editing a reply | |
| 931 | + } elseif ( bbp_is_reply_edit() ) { | |
| 932 | + $redirect_url = false; | |
| 951 | 933 | } |
| 952 | 934 | } |
| 953 | 935 | |
| 954 | - // Return | |
| 955 | - return $retval; | |
| 936 | + return $redirect_url; | |
| 956 | 937 | } |
| 957 | 938 | |
| 958 | 939 | /** Filters *******************************************************************/ |
| 959 | 940 | |
| @@ -1011,9 +992,9 @@ | ||
| 1011 | 992 | } |
| 1012 | 993 | |
| 1013 | 994 | /** |
| 1014 | 995 | * Restores filters from the $bbp global that were removed using |
| 1015 | - * bbp_remove_all_filters(). | |
| 996 | + * bbp_remove_all_filters() | |
| 1016 | 997 | * |
| 1017 | 998 | * @since 2.0.0 bbPress (r3251) |
| 1018 | 999 | * |
| 1019 | 1000 | * @global WP_filter $wp_filter |
| @@ -1061,15 +1042,13 @@ | ||
| 1061 | 1042 | // Unset the filters |
| 1062 | 1043 | unset( $bbp->filters->merged_filters[ $tag ] ); |
| 1063 | 1044 | } |
| 1064 | 1045 | |
| 1065 | - // phpcs:enable | |
| 1066 | - | |
| 1067 | 1046 | return true; |
| 1068 | 1047 | } |
| 1069 | 1048 | |
| 1070 | 1049 | /** |
| 1071 | - * Force comments_status to 'closed' for bbPress post types. | |
| 1050 | + * Force comments_status to 'closed' for bbPress post types | |
| 1072 | 1051 | * |
| 1073 | 1052 | * @since 2.1.0 bbPress (r3589) |
| 1074 | 1053 | * |
| 1075 | 1054 | * @param bool $open True if open, false if closed |