WordPress.org

Making WordPress.org

Ticket #4606: 4606.diff

File 4606.diff, 1001 bytes (added by valentinbora, 9 months ago)

A first patch to prevent redirecting to guessed topics within forums

  • wordpress.org/public_html/wp-content/plugins/wporg-bbp-redirect/wporg-bbp-redirect.php

    diff --git wordpress.org/public_html/wp-content/plugins/wporg-bbp-redirect/wporg-bbp-redirect.php wordpress.org/public_html/wp-content/plugins/wporg-bbp-redirect/wporg-bbp-redirect.php
    index 474f3996a..61de4fbc8 100644
    class WPORG_bbPress_Old_Id_Redirect { 
    2929        public function __construct() {
    3030                // Add action to template redirect after wp_old_slug_redirect.
    3131                add_action( 'template_redirect', array( $this, 'maybe_redirect' ), 11 );
     32                add_filter( 'redirect_canonical', array( $this, 'no_redirect_on_404' ), 10, 2 );
     33        }
     34
     35        public function no_redirect_on_404( $redirect_url, $requested_url ) {
     36                global $wp_query;
     37
     38                if ( is_404() && 0 === strpos( $wp_query->query['pagename'], bbp_get_root_slug() ) ) {
     39                        return null;
     40                }
     41
     42                return $redirect_url;
    3243        }
    3344
    3445        public function maybe_redirect() {