Skip to:
Content
Pages
Categories
Search
Top
Bottom

extending groups slug with images


  • 3004134
    Inactive

    I want to extend Buddypress groups to include images. I have added a small PHP form that allows group admin to upload bunch of images and now I would like to display those images. The URL format should be <bp_site>/groups/<group_name>/images/

    In addition the images page will display all the images for that group, clicking on an image will load up lightbox-2 (or any modal) and display corresponding full sized images.

    Here’s where I am stuck…. BP has slug that looks like http://<bp_site>/groups/<group_name>/wire How do I add a custom slug to use something like http://<bp_site>/groups/<group_name>/images

    http://buddypress.org/blog/how-to/customizable-slugs-in-buddypress/ talks about how slugs interact and how to modify them, but I don’t have any slug definition in my wp-config.php file. Should I be looking elsewhere?

    Once this works, I will be committing my changes back out here for everyone else to use.

Viewing 12 replies - 1 through 12 (of 12 total)

  • Burt Adsit
    Participant

    @burtadsit

    What you are talking about is a custom component. See : https://codex.buddypress.org/how-to-guides/creating-a-custom-buddypress-component/


    3004134
    Inactive

    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.


    Burt Adsit
    Participant

    @burtadsit

    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.


    Burt Adsit
    Participant

    @burtadsit

    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.


    Burt Adsit
    Participant

    @burtadsit

    $bp->action_variables[0] in the above case would be ‘imagename.jpg’


    3004134
    Inactive

    thanks…. its working.


    Burt Adsit
    Participant

    @burtadsit

    Cool, you’re welcome.


    3004134
    Inactive

    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?


    Burt Adsit
    Participant

    @burtadsit

    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


    3004134
    Inactive

    Thanks. I ended up writing my own function but will revert back and use BP_Groups_Group::get_id_from_slug($slug)


    Burt Adsit
    Participant

    @burtadsit

    You betcha.


    3004134
    Inactive

    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?

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘extending groups slug with images’ is closed to new replies.
Skip to toolbar