Skip to:

Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#3461 closed enhancement (no action required)

Problem With bp_is_current_component when a Component needs multiple Top level pages(Directory pages)

Reported by: sbrajesh's profile sbrajesh Owned by:
Milestone: 1.5 Priority: normal
Severity: minor Version:
Component: Core Keywords:
Cc: sbrajesh


In Bp 1.2.x when we used bp_core_add_root_component( "my_slug_1" ),bp_core_add_root_component( "my_slug_2" ), we were able to have two top level directory pages where we could check using $bp->current_component=='some_slug_1)'/bp_is_apge('some_slug_1') and so on.

It means, Even if there was a single component, we could use multiple top level directory pages.

After the changes in bp 1.5, specifically #3428, The bp_core_add_root_component("some_slug_1") assumes that we have already registered a component with the slug name and It test for $bp->some_slug_1 and $bp->some_slug_2. If That is not found, It won't create the pages as per the code in the bp_core_add_root_component

if ( isset( $bp->{$slug} ) ) {

$bp->loaded_components[$bp->{$slug}->slug] = $bp->{$slug}->id;
$bp->{$slug}->has_directory = true;



So, if we try to check bp_is_current_component('some_slug_1'), It will fail if the some_Slug_1 is not registered as a component in $bp global variable(and I believe , It is right to do so, after all we want to check for a directory poage, so current component failure is not an issue).

I tried to use bp_is_page('some_slug1') but that fails too(It uses bp_is_current_component).

Is there any reliable way to use multiple directory pages(top level pages) with a component and test for the current page. Like if the current_page_slug is xyz . I just wanted to know if there is anyway to find out a top level page(like we used to have in bp 1.2.x) without registering each page as a component.


Change History (3)

#1 @boonebgorges
13 years ago

Thanks for always asking tough questions, sbrajesh :)

Essentially, if you want to have top-level URLs, then you *must* register a root component (just like in BP 1.2). And if you want to have a root component, you must have a bp-page (this is new in BP 1.5). In order for site admins to get the admin warning that they need to create a WP page for your component, you must successfully pass the !empty( $bp->{$slug} ) test in bp_core_add_root_component(). That's because the admin stuff looks at $bp->loaded_components and, from there, at $bp->{$component_id} - so you really do need to be registered in both places.

For these reasons, the best suggestion I can come up with, at least off the top of my head, is that you register a 'dummy' component in the $bp global before using bp_core_add_root_component(). For example,

function bbg_add_my_components() {
    global $bp;

    // Set up my first component
    $bp->my_slug_1->slug = 'my_slug_1';
    $bp->my_slug_1->id = 'my-slug-1';
    // etc. Register whichever globals you would normally register

    // Set up my first component
    $bp->my_slug_2->slug = 'my_slug_2';
    $bp->my_slug_2->id = 'my_slug_2';
    // That's it for the second, "dummy" component

    bp_core_add_root_component( 'my_slug_1' );
    bp_core_add_root_component( 'my_slug_2' );
add_action( 'bp_setup_globals', 'bbg_add_my_components' );

In other words, choose one of the two slugs as identifying the "real" component, where you store all of your necessary global data. Then register a skeleton, 'dummy' component for any other top-level pages, containing just enough information for the component to be picked up in the bp-pages admin scripts (so users will know that they have to create WP pages for them).

You'll probably also want to have a wrapper function in your plugin:

function bbg_is_foo_component() {
    return bp_is_current_component( 'my_slug_1' ) || bp_is_current_component( 'my_slug_2' );

Or, alternatively, you should be able to use bp_is_page() at this point.

What do you think? I know that this requires a little bit more work than in BP 1.2.x (where you didn't need to put anything in the $bp global in order to have a top-level page), but IMO that's OK - we really shouldn't have allowed it before, as it gave plugins, etc no way to interact with third-party components. In any case, I'm fairly certain that it's an edge case.

(On a side note, we might consider allowing multiple bp-pages per $bp->{$component} as a future enhancement.)

#2 @sbrajesh
13 years ago

  • Resolution set to invalid
  • Status changed from new to closed

Thanks Boone! That gets the work done for now. My only concern is polluting the bp global with the pages as component(like if a plugin needs 3 pages, we will have to use 3 components in bp).

Closing this ticket as it is not a bug.

#3 @johnjamesjacoby
13 years ago

  • Milestone changed from Awaiting Review to 1.5
  • Version 1.5 deleted

Moving closed ticket out of Awaiting Review.

Note: See TracTickets for help on using tickets.