Rehook maybe_redirect_404() to run later than the default.

Description Description

WordPress’s maybe_redirect_404() allows admins on a multisite installation to define ‘NOBLOGREDIRECT’, a URL to which 404 requests will be redirected. maybe_redirect_404() is hooked to template_redirect at priority 10, which creates a race condition with bp_template_redirect(), our piggyback hook. Due to a legacy bug in BuddyPress, internal BP content (such as members and groups) is marked 404 in $wp_query until bp_core_load_template(), when BP manually overrides the automatic 404. However, the race condition with maybe_redirect_404() means that this manual un-404-ing doesn’t happen in time, with the results that maybe_redirect_404() thinks that the page is a legitimate 404, and redirects incorrectly to NOBLOGREDIRECT.

By switching maybe_redirect_404() to catch at a higher priority, we avoid the race condition. If bp_core_load_template() runs, it dies before reaching maybe_redirect_404(). If bp_core_load_template() does not run, it means that the 404 is legitimate, and maybe_redirect_404() can proceed as expected.

This function will be removed in a later version of BuddyPress. Plugins (and plugin authors!) should ignore it.

Source Source

File: bp-core/bp-core-catchuri.php

function _bp_rehook_maybe_redirect_404() {
	if ( defined( 'NOBLOGREDIRECT' ) && is_multisite() ) {
		remove_action( 'template_redirect', 'maybe_redirect_404' );
		add_action( 'template_redirect', 'maybe_redirect_404', 100 );

Top ↑

Changelog Changelog

Version Description
1.6.1 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.