opencredit / BadgeOS-Community-Add-on

The "BadgeOS Community Add-on" integrates BadgeOS features into BuddyPress and bbPress. Site members complete achievements and earn badges based on a range of community activity and triggers. This add-on to BadgeOS also includes the ability to display badges and achievements on user profiles and activity feeds.
GNU Affero General Public License v3.0
11 stars 8 forks source link

Change setup_nav WP_Query usage to prevent ID leakage. #41

Open tw2113 opened 9 years ago

tw2113 commented 9 years ago

I believe our usage of

while ( $query->have_posts() ) : $query->the_post();
    $arr_achivement_types[$query->post->post_name] = $query->post->ID;
endwhile;

in bp-members.php setup_nav method has been causing ID setting that isn't being properly cleaned up, and potentially causes global variable issues for other snippets of code. wp_reset_postdata() didn't help solve it either.

I propose we switch to a standard foreach loop that doesn't use $query->the_post() and just construct our data another way.

foreach( $query->posts as $p ) {
    $arr_achivement_types[$p->post_name] = $p->ID;
}
tw2113 commented 9 years ago

Similar issues in: Comment editing was being affected.

https://wordpress.org/support/topic/comment-on-specific-post-and-submission-issue?replies=10

Returning on is_admin() solved the issue for this case, but may still have issues on frontend with globals etc.

tw2113 commented 9 years ago

Adding is_admin to the method regardless, as we shouldn't be doing this in the admin. Still possible the original part of this filed issue is playing parts on frontend.

tw2113 commented 8 years ago

Perhaps wp_reset_postdata() would solve these issues?