Skip to:
Content
Pages
Categories
Search
Top
Bottom

Conditional tags for BuddyPress

  • Avatar of Simon Wheatley
    Simon Wheatley
    Participant

    @simonwheatley

    I always find the conditional tags for WP very useful, and as I can’t find an equivalent for the BuddyPress pages I’ve started a plugin to fill the gap. Does this code seem sane?

    <?php

    // $identifier can be either the group name, ID or slug
    if ( !function_exists('is_group') ) :
    function is_group( $identifier = false ) {
    global $bp;

    // No $bp? Nothing doing then.
    if ( ! $bp )
    return false;

    // Not in the groups component? Definitely not a group then
    if ( $bp->current_component != 'groups' )
    return false;

    // If no identifier was passed then we've confirmed as
    // much as we need to
    if ( $identifier === false )
    return true;

    // If the identifier passed == the current item, then the
    // identifier must have been the group slug
    if ( $identifier == $bp->current_item )
    return true;

    // Now check the ID
    if ( $identifier == $bp->groups->current_group->id )
    return true;

    // Lastly, check the name
    if ( $identifier == $bp->groups->current_group->name )
    return true;

    // We were passed an identifier, but it doesn't match
    // slug, ID or name, so we must return false.
    return false;
    }
    endif;

Viewing 8 replies - 1 through 8 (of 8 total)
  • In 1.1 you have:

    bp_is_blog_page()
    bp_is_register_page()
    bp_is_activation_page()
    bp_is_directory()
    bp_is_single_item()

    bp_is_profile_component()
    bp_is_activity_component()
    bp_is_blogs_component()
    bp_is_wire_component()
    bp_is_messages_component()
    bp_is_friends_component()
    bp_is_groups_component()
    bp_is_settings_component()

    bp_is_messages_inbox()
    bp_is_messages_sentbox()
    bp_is_messages_compose_screen()
    bp_is_notices()

    bp_is_user_friends()
    bp_is_friend_requests()

    bp_is_user_blogs()
    bp_is_user_recent_posts()
    bp_is_user_recent_commments()
    bp_is_create_blog()

    bp_is_user_groups()
    bp_is_group_create()
    bp_is_group_home()
    bp_is_group_invites()
    bp_is_group_members()
    bp_is_group_forum_topic()
    bp_is_group_forum()
    bp_is_group_wire()
    bp_is_group_leave()
    bp_is_group_admin_page()

    bp_is_user_profile()
    bp_is_profile_wire()
    bp_is_change_avatar()
    bp_is_profile_edit()

    bp_is_user_activity()
    bp_is_user_friends_activity()

    If you wanted to see if this was a single group page, in your template you could do:

    <?php if ( bp_is_group_home() ) : ?>Show this on group home pages <? endif; ?>

    Or if you wanted to show something on every single group page, regardless if it was the home page or not:

    <?php if ( bp_is_groups_component() && bp_is_single_item() ) : ?> Show this on all single group pages <?php endif; ?>

    I was just writing up something, but Andy won that competition.

    It’s also worth pointing out that rather than doing $bp->current_component != ‘groups’, you should be using $bp->current_component != $bp->groups->slug. This works if a site has decided to rename one of the built-in components.

    There are no specific checks on group names etc yet, but you can do this:

    <?php if ( bp_is_groups_component() && 'my-group' == bp_current_item() ) : ?> This is my-group <?php endif; ?>

    Avatar of Simon Wheatley
    Simon Wheatley
    Participant

    @simonwheatley

    Argh! I thought I’d exhaustively checked all the functions in BuddyPress before embarking on mine. Oh well.

    Thanks Andy!

    This is 1.1 only, so if you are using an earlier version then you wouldn’t have seen them. :)

    awesome!!!!!!!!!!!!!!

    I just downloaded and upgraded to 1.1RC, yet I still don’t see some of the functions, specifically “bp_is_profile_component”

    Not in the RC, use the final.

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

You must be logged in to reply to this topic.