[buddypress-trac] [BuddyPress Trac] #6628: WordPress Page Post ID being overwritten to 0 by BuddyPress

buddypress-trac noreply at wordpress.org
Fri Sep 18 18:18:16 UTC 2015


#6628: WordPress Page Post ID being overwritten to 0 by BuddyPress
------------------------------+-----------------------------
 Reporter:  layotte           |      Owner:
     Type:  defect (bug)      |     Status:  new
 Priority:  normal            |  Milestone:  Awaiting Review
Component:  Component - Core  |    Version:
 Severity:  normal            |   Keywords:  needs-patch
------------------------------+-----------------------------
 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 );
 }}}

--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/6628>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac


More information about the buddypress-trac mailing list