Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
08/13/2012 11:07:49 PM (12 years ago)
Author:
boonebgorges
Message:

When running NOBLOGREDIRECT, rehook maybe_redirect_404() to priority 100.

WP's maybe_redirect_404() must run after BuddyPress's template loader function
bp_core_load_template(), or else it'll register incorrectly as a 404 and
redirect to the value of NOBLOGREDIRECT. See inline documentation for more
details.

Fixes #4415

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-catchuri.php

    r6228 r6253  
    682682
    683683/**
     684 * Rehook maybe_redirect_404() to run later than the default
     685 *
     686 * WordPress's maybe_redirect_404() allows admins on a multisite installation
     687 * to define 'NOBLOGREDIRECT', a URL to which 404 requests will be redirected.
     688 * maybe_redirect_404() is hooked to template_redirect at priority 10, which
     689 * creates a race condition with bp_template_redirect(), our piggyback hook.
     690 * Due to a legacy bug in BuddyPress, internal BP content (such as members and
     691 * groups) is marked 404 in $wp_query until bp_core_load_template(), when BP
     692 * manually overrides the automatic 404. However, the race condition with
     693 * maybe_redirect_404() means that this manual un-404-ing doesn't happen in
     694 * time, with the results that maybe_redirect_404() thinks that the page is
     695 * a legitimate 404, and redirects incorrectly to NOBLOGREDIRECT.
     696 *
     697 * By switching maybe_redirect_404() to catch at a higher priority, we avoid
     698 * the race condition. If bp_core_load_template() runs, it dies before reaching
     699 * maybe_redirect_404(). If bp_core_load_template() does not run, it means that
     700 * the 404 is legitimate, and maybe_redirect_404() can proceed as expected.
     701 *
     702 * This function will be removed in a later version of BuddyPress. Plugins
     703 * (and plugin authors!) should ignore it.
     704 *
     705 * @since 1.6.1
     706 *
     707 * @link http://buddypress.trac.wordpress.org/ticket/4329
     708 * @link http://buddypress.trac.wordpress.org/ticket/4415
     709 */
     710function _bp_rehook_maybe_redirect_404() {
     711    if ( defined( 'NOBLOGREDIRECT' ) ) {
     712        remove_action( 'template_redirect', 'maybe_redirect_404' );
     713        add_action( 'template_redirect', 'maybe_redirect_404', 100 );
     714    }
     715}
     716add_action( 'template_redirect', '_bp_rehook_maybe_redirect_404', 1 );
     717
     718/**
    684719 * Remove WordPress's rel=canonical HTML tag if we are trying to load BuddyPress
    685720 * specific content.
Note: See TracChangeset for help on using the changeset viewer.