[buddypress-trac] [BuddyPress] #3422: Components registered via bp_core_add_root_component() produce zillions of pages when original page is deleted

buddypress-trac at lists.automattic.com buddypress-trac at lists.automattic.com
Mon Aug 1 21:20:21 UTC 2011

#3422: Components registered via bp_core_add_root_component() produce zillions of
pages when original page is deleted
 Reporter:  boonebgorges  |      Owner:
     Type:  defect        |     Status:  new
 Priority:  normal        |  Milestone:  1.5
Component:  Core          |    Version:  1.5
 Severity:  normal        |   Keywords:  2nd-opinion
 Steps to reproduce:
 - In a plugin, register a new component in the following way:

 function bbgtest_setup_root_component() {
         bp_core_add_root_component( 'boone_is_cool' );
 add_action( 'bp_setup_root_components', 'bbgtest_setup_root_component' );

 - Load the front end of BP. A page 'Boone_is_cool' will be auto-created.
 - At Dashboard > Pages, send the page Boone_is_cool to the Trash
 - Load the front end of BP. A new page will be created
 - Load the front end of BP again. Two more pages will be created (ad
 infinitum, each time you reload)

 The problem is this. When a component is added with
 bp_core_add_root_component(), BP checks to see whether a corresponding
 item can be found in $bp->pages. If no page is found, it is created using
 the post_name of the $slug passed to bp_core_add_root_component()
 ('boone_is_cool', in our example). When you Trash the page, the
 post_status is set to 'trash', which means that it's no longer picked up
 by the query in bp_core_get_page_names(). As a result, it's not loaded
 into $bp->pages (so far, this seems logical enough). However, when you
 reload BP, it tries to create a new page with the slug 'boone_is_cool',
 but WP prevents this with wp_unique_post_slug(). As a result, pages with
 names like 'boone_is_cool-2' etc are created and added to $bp->pages.

 One quick-and-dirty solution is to modify the query in
 bp_core_get_page_names() so that it gets all posts, not just those with
 post_status = trash. The downside of this approach is that you wouldn't
 have any obvious way of knowing, by looking at $bp->pages, when a page had
 been deleted (and, by extension, the component had been turned off).

 Another option, which I think is better, is to hook into the WP page
 delete action, and remove the page from the bp-pages option. That should
 have the effect of having the newly-generated page be properly added to
 the bp-pages array on the next page load.

 The situation is quite confusing indeed, and needs some more thought.
 Hopefully someone else can pitch in with some thoughts.

Ticket URL: <https://buddypress.trac.wordpress.org/ticket/3422>
BuddyPress <http://buddypress.org/>

More information about the buddypress-trac mailing list