#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 | Owned by: | |
---|---|---|---|
Milestone: | 1.5 | Priority: | normal |
Severity: | minor | Version: | |
Component: | Core | Keywords: | |
Cc: | sbrajesh |
Description
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.
Thanks
Change History (3)
#2
@
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.
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} https://buddypress.trac.wordpress.org/browser/trunk/bp-core/admin/bp-core-admin.php?rev=4920#L486 - 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,
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:
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.)