WordPress.org

Making WordPress.org

Changeset 8229


Ignore:
Timestamp:
02/12/2019 05:21:45 PM (6 months ago)
Author:
SergeyBiryukov
Message:

Support Forums: Disable wp_old_slug_redirect() for hidden topics to avoid a redirect loop.

H/t joostdevalk.
See #2671.

File:
1 edited

Legend:

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

    r8225 r8229  
    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( 'old_slug_redirect_post_id',       array( $this, 'disable_wp_old_slug_redirect' ) );
    1819        add_action( 'template_redirect',               array( $this, 'redirect_update_php_page' ) );
    1920        add_filter( 'wp_insert_post_data',             array( $this, 'set_post_date_gmt_for_pending_posts' ) );
     
    207208
    208209        return $redirect_url;
     210    }
     211
     212    /**
     213     * Disable wp_old_slug_redirect() for hidden topics.
     214     *
     215     * Prevents Spam, Pending, or Archived topics that the current user cannot view
     216     * from performing a redirect loop.
     217     *
     218     * @param int $post_id The redirect post ID.
     219     * @return int Filtered redirect post ID.
     220     */
     221    public function disable_wp_old_slug_redirect( $post_id ) {
     222        if ( is_404() && 'topic' === get_query_var( 'post_type' ) && get_query_var( 'name' ) ) {
     223            $hidden_topic = get_post( $post_id );
     224
     225            if ( $hidden_topic && ! current_user_can( 'read_topic', $hidden_topic->ID ) ) {
     226                $post_id = 0;
     227            }
     228        }
     229
     230        return $post_id;
    209231    }
    210232
Note: See TracChangeset for help on using the changeset viewer.