Making WordPress.org

Changeset 9850


Ignore:
Timestamp:
05/12/2020 05:46:00 AM (4 years ago)
Author:
dd32
Message:

Support Forums: Canonical: Don't redirect bbPress root page parents to random topics.
Examples: /users/ /topics/ and /reply

Fixes #4606.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-hooks.php

    r9848 r9850  
    1616        add_filter( 'bbp_map_meta_caps',               array( $this, 'disallow_editing_past_lock_time' ), 10, 4 );
    1717        add_filter( 'redirect_canonical',              array( $this, 'disable_redirect_guess_404_permalink' ) );
     18        add_filter( 'redirect_canonical',              array( $this, 'handle_bbpress_root_pages' ), 10, 2 );
    1819        add_filter( 'old_slug_redirect_post_id',       array( $this, 'disable_wp_old_slug_redirect' ) );
    1920        add_action( 'template_redirect',               array( $this, 'redirect_update_php_page' ) );
     
    241242        // Avoid redirecting the old slug of "Update PHP" page to a forum topic.
    242243        if ( is_404() && 'upgrade-php' === get_query_var( 'pagename' ) ) {
     244            $redirect_url = false;
     245        }
     246
     247        return $redirect_url;
     248    }
     249
     250    /**
     251     * Prevent a redirect for some base bbPress pages to random topics.
     252     */
     253    public function handle_bbpress_root_pages( $redirect_url, $requested_url ) {
     254        $url = str_replace( home_url('/'), '', $requested_url );
     255
     256        if ( $url && preg_match( '!^(topic|topic-[^/]+|reply|users|view)(/[?]|/?$)!i', $url ) ) {
    243257            $redirect_url = false;
    244258        }
     
    11861200     * Alter the bbPress topic freshness links to use the date in the title attribute rather than thread title.
    11871201     */
    1188     function bbp_get_topic_freshness_link( $anchor, $topic_id, $time_since, $link_url, $title ) {
     1202    public function bbp_get_topic_freshness_link( $anchor, $topic_id, $time_since, $link_url, $title ) {
    11891203
    11901204        // Copy-paste from bbp_get_topic_last_active_time() which only returns humanized times.
Note: See TracChangeset for help on using the changeset viewer.