Burt
Thanks for the quick reply. I looked around and found the URI structure
http://<site>/members/admin/example
However, if I type http://<site>/groups/<group_name>/example I get redirected to http://<site>/members/admin/example
I assume/hope that there is some configuration in the bp-example that can help me fix this….. let me know if you know any quick work-arounds.
If bp can’t resolve the url to something covered in nav instead of 404’ing out it send you to your profile. The bp nav mechanism is the url dispatch mechanism.
An example:
$profile_link = $bp->loggedin_user->domain . $bp->contents->slug . '/' ;
bp_core_add_subnav_item($bp->contents->slug, 'my-contents' , __( 'Personal',
'oci-contents' ), $profile_link, 'oci_screen_profile_my_contents');
Lets say that $bp->contents->slug is the slug I’ve set up for use in my component which is ‘contents’. Making that call above tells bp to listen for this url structure in the member profile:
/members/burtadsit/contents/my-contents
When the $bp->current_component: /members/burtadsit/(contents)/my-contents and the $bp->current_action /members/burtadsit/contents/(my-contents) is the url then trigger the function oci_screen_profile_my_contents().
What you do in oci_screen_profile_my_contents() is, amongst other things display the template that you want displayed to the user. That can display images or do user input. Whatever you decide it does.
function oci_screen_profile_my_contents() {
global $bp, $bp_unfiltered_uri;
if (!bp_is_home())
return;
if ( isset( $_POST['submit_save_profile_tags'] )) {
$item = oci_get_user_item();
if ($item){
$node = oci_save_global_tags($item->id, '/' . OCI_TAG . '/' . OCI_USER);
}
$path = oci_get_the_profile_action();
bp_core_redirect($path);
}
bp_core_load_template( 'oci-contents/profile/my-contents' );
}
What my function does above is to listen for stuff being submitted by the ‘my-contents’ form and process it. If the user hasn’t hit ‘Save’ then we are just displaying the form for the first time to the user. At the bottom it drops through and just displays the template ‘my-contents’. Default behavior.
You have to create a component and get the group nav stuff working. The group stuff works in a similar fashion. Only the nav call is:
global $group_obj;
$group_link = $bp->root_domain . '/' . $bp->groups->slug . '/' .
$group_obj->slug . '/';
bp_core_add_subnav_item($bp->groups->slug, 'someaction' ,
__( 'Some Action', 'oci-contents' ), $group_link, 'oci_screen_group_someaction');
That listens for /groups/somegroup/someaction and triggers oci_screen_group_someaction() when it finds it. Which happens when the user navigates to Groups > Some Group > Some Action.
Either a link from somewhere in the universe is /groups/somegroup/someaction or the user picks that spot from the member theme menu. The nav system and the urls in bp are intertwined. Your component, when it sets up the nav stuff, determines the urls that your component responds to.
If the url has things like an image name of some sort after the /groups/somegroup/someaction part of the url like: /groups/somegroup/someaction/imagename.jpg then the imagename.jpg is available in bp through the $bp->action_variables. Everything *after* the component/action is available to your component’s code in $bp->action_variables which is an array of things that are stuff after that component/action part of the url.
$bp->action_variables[0] in the above case would be ‘imagename.jpg’
How do I get the group id from a given slug? I looked at https://codex.buddypress.org/developer-docs/the-bp-global/ but it doesn’t print the group-id. I need the group-id for making effective joins between the groups and the images table that I plan to build.
Any pointers?
Depends on where you are.
If you are in the member theme group pages the global $group_obj is available. It’s an instance of BP_Groups_Group class for the current group.
If you are in a group template then the fn bp_get_group_id() in bp-groups-templatetags.php gets you the current group’s id.
Or you could always use the class method BP_Groups_Group::get_id_from_slug($slug) in bp-groups-classes.php
Thanks. I ended up writing my own function but will revert back and use BP_Groups_Group::get_id_from_slug($slug)
I am kinda stuck…. The bp-example plugin works perfectly for non-logged in users but gives a login screen for others. I want it to be public for everyone i.e. no need to login….. any quick fix for this?