Skip to:
Content

BuddyPress.org

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#6628 closed defect (bug)

WordPress Page Post ID being overwritten to 0 by BuddyPress

Reported by: layotte Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Core Keywords:
Cc:

Description

There are several calls to bp_theme_compat_reset_post() that set the post ID to 0... which sets the global $post->ID to 0. This is problematic for plugins/themes that need to use the Post ID later to get meta information.

How to reproduce:

First, add this code to a mu-plugins file:

function buddypress_post_id( $content ) {
	global $post;
	echo 'Post ID: ' . $post->ID;
}
add_filter( 'the_content', 'buddypress_post_id' );

Second, visit http://domain.tld/members/ (or another BuddyPress page that is associated with a WordPress page).

See this: http://l3w.us/images/c68671.png
But it makes sense on the fake pages like this: http://l3w.us/images/94fb4c.png but even then, it'd be nice if the parent ID was set to the parent WordPress page (e.g. the post ID for the members page in this example).

I'm not really sure what the best way to fix this is. But this is my work-around.

function get_post_id() {
	global $post, $buddypress_post_id;
	$buddypress_post_id = $post->ID;
}
add_action( 'wp', 'get_post_id', 1 );

function my_custom_stuff( $content ) {
	if ( function_exists( 'is_buddypress' ) && is_buddypress() ) {
		global $buddypress_post_id, $post;		
		$post->ID = $buddypress_post_id;
		// other work
	}
	return $content;
}
add_filter( 'the_content', 'my_custom_stuff', 5 );

Change History (2)

#1 @DJPaul
4 years ago

@r-a-y can you consider this sometime and decide if it's a bug we need to address? I think you poked around this area of code last and know the most.

#2 @r-a-y
4 years ago

  • Keywords needs-patch removed
  • Milestone Awaiting Review deleted
  • Status changed from new to closed

Hi @layotte,

Sorry for replying to this ticket late.

Your ticket is basically the same as #6230 (read ticket:6230#comment:6 and on). My recommendation to "fix" this can be found at ticket:6230#comment:15.

I'm going to mark this as a duplicate of #6230. Please leave feedback on that ticket.

Last edited 4 years ago by r-a-y (previous) (diff)
Note: See TracTickets for help on using tickets.