Category Archives: Buddypress

Customize Client Admin dashboard

  1. Assign one user an “Editor” Role.
  2. Add capabilities “manage_options”, “list_users” and “delete users” using User Role Editor.
  3. Uninstall URE after making the changes. (the changes are permanent for this user)
  4. Add following to functions.php

// Remove some menus from Client Admin's Dashboard

function remove_menus(){
  
  if (current_user_can('manage_options')  && !current_user_can('update_core')) {
  remove_menu_page( 'options-general.php' );        //Settings
  remove_menu_page( 'edit.php?post_type=ia_invites');  //Buddypress Invitations
  remove_menu_page ( 'tools.php' );
  }
}
add_action( 'admin_menu', 'remove_menus' );

Group forum search for buddypress

This is Chris Mavricos’s solution extended to enable single forum search inside Buddypress groups.

Step 1. Create a blank file called form-search.php in your theme’s bbpress folder. Put the following code inside this file (your-theme/bbpress/form-search.php):

<?php

/**
 * Search
 *
 * @package bbPress
 * @subpackage Theme
 */
$forum_id = bbp_get_forum_id();
?>

<form role="search" method="get" id="bbp-search-form" action="<?php bbp_search_url(); ?>">
    <div>
        <label class="screen-reader-text hidden" for="bbp_search"><?php _e( 'Search for:', 'bbpress' ); ?></label>
        <input tabindex="<?php bbp_tab_index(); ?>" type="text" value="<?php echo esc_attr( bbp_get_search_terms() ); ?>" name="bbp_search" id="bbp_search" />
        <?php if( $forum_id ): ?>
        <input class="button" type="hidden" name="bbp_search_forum_id" value="<?php echo $forum_id; ?>" />
        <?php endif; ?>
        <input tabindex="<?php bbp_tab_index(); ?>" class="button" type="submit" id="bbp_search_submit" value="<?php esc_attr_e( 'Search', 'bbpress' ); ?>" />
    </div>
</form>

Step 2. Put the following code inside your theme’s functions.php:

/*
 * Search only a specific forum
 */
function my_bbp_filter_search_results( $r ){

    //Get the submitted forum ID (from the hidden field added in step 1)
    $forum_id = sanitize_title_for_query( $_GET['bbp_search_forum_id'] );

    //If the forum ID exits, filter the query
    if( $forum_id && is_numeric( $forum_id ) ){

        $r['meta_query'] = array(
            array(
                'key' => '_bbp_forum_id',
                'value' => $forum_id,
                'compare' => '=',
            )
        );

        $group_id = bbp_get_forum_group_ids( $forum_id );
        if( groups_is_user_member( bp_loggedin_user_id(), $group_id[0] ) )
        {
            function my_allow_all_forums () { return true; }
            add_filter( 'bbp_include_all_forums', 'my_allow_all_forums' );
        }
    }

    return $r;
}
add_filter( 'bbp_after_has_search_results_parse_args' , 'my_bbp_filter_search_results' );

You should find a functional search box inside Buddypress group forums now.

Thanks to tobyhawkins for providing the additional code snippet.