/**
  * Setup BuddyBar navigation
  */
 public function setup_nav($main_nav = array(), $sub_nav = array())
 {
     // Only grab count if we're on a user page and current user has access
     if (bp_is_user() && bp_user_has_access()) {
         $count = bp_get_total_unread_messages_count();
         $class = 0 === $count ? 'no-count' : 'count';
         $nav_name = sprintf(__('Messages <span class="%s">%s</span>', 'buddypress'), esc_attr($class), number_format_i18n($count));
     } else {
         $nav_name = __('Messages', 'buddypress');
     }
     // Add 'Messages' to the main navigation
     $main_nav = array('name' => $nav_name, 'slug' => $this->slug, 'position' => 50, 'show_for_displayed_user' => false, 'screen_function' => 'messages_screen_inbox', 'default_subnav_slug' => 'inbox', 'item_css_id' => $this->id);
     // Determine user to use
     if (bp_displayed_user_domain()) {
         $user_domain = bp_displayed_user_domain();
     } elseif (bp_loggedin_user_domain()) {
         $user_domain = bp_loggedin_user_domain();
     } else {
         return;
     }
     // Link to user messages
     $messages_link = trailingslashit($user_domain . $this->slug);
     // Add the subnav items to the profile
     $sub_nav[] = array('name' => __('Inbox', 'buddypress'), 'slug' => 'inbox', 'parent_url' => $messages_link, 'parent_slug' => $this->slug, 'screen_function' => 'messages_screen_inbox', 'position' => 10, 'user_has_access' => bp_core_can_edit_settings());
     $sub_nav[] = array('name' => __('Sent', 'buddypress'), 'slug' => 'sentbox', 'parent_url' => $messages_link, 'parent_slug' => $this->slug, 'screen_function' => 'messages_screen_sentbox', 'position' => 20, 'user_has_access' => bp_core_can_edit_settings());
     $sub_nav[] = array('name' => __('Compose', 'buddypress'), 'slug' => 'compose', 'parent_url' => $messages_link, 'parent_slug' => $this->slug, 'screen_function' => 'messages_screen_compose', 'position' => 30, 'user_has_access' => bp_core_can_edit_settings());
     if (bp_current_user_can('bp_moderate')) {
         $sub_nav[] = array('name' => __('Notices', 'buddypress'), 'slug' => 'notices', 'parent_url' => $messages_link, 'parent_slug' => $this->slug, 'screen_function' => 'messages_screen_notices', 'position' => 90, 'user_has_access' => bp_current_user_can('bp_moderate'));
     }
     parent::setup_nav($main_nav, $sub_nav);
 }
 public function test_should_return_true_on_own_profile()
 {
     $users = $this->factory->user->create_many(2);
     $this->set_current_user($users[0]);
     $this->go_to(bp_core_get_user_domain($users[0]));
     $this->assertTrue(bp_user_has_access($users[0]));
 }
 /**
  * Set up component navigation.
  *
  * @since BuddyPress (1.9.0)
  *
  * @see BP_Component::setup_nav() for a description of arguments.
  *
  * @param array $main_nav Optional. See BP_Component::setup_nav() for
  *        description.
  * @param array $sub_nav Optional. See BP_Component::setup_nav() for
  *        description.
  */
 public function setup_nav($main_nav = array(), $sub_nav = array())
 {
     // Only grab count if we're on a user page and current user has access
     if (bp_is_user() && bp_user_has_access()) {
         $count = bp_notifications_get_unread_notification_count(bp_displayed_user_id());
         $class = 0 === $count ? 'no-count' : 'count';
         $nav_name = sprintf(_x('Notifications <span class="%s">%s</span>', 'Profile screen nav', 'buddypress'), esc_attr($class), number_format_i18n($count));
     } else {
         $nav_name = _x('Notifications', 'Profile screen nav', 'buddypress');
     }
     // Add 'Notifications' to the main navigation
     $main_nav = array('name' => $nav_name, 'slug' => $this->slug, 'position' => 30, 'show_for_displayed_user' => bp_core_can_edit_settings(), 'screen_function' => 'bp_notifications_screen_unread', 'default_subnav_slug' => 'unread', 'item_css_id' => $this->id);
     // Determine user to use
     if (bp_displayed_user_domain()) {
         $user_domain = bp_displayed_user_domain();
     } elseif (bp_loggedin_user_domain()) {
         $user_domain = bp_loggedin_user_domain();
     } else {
         return;
     }
     $notifications_link = trailingslashit($user_domain . bp_get_notifications_slug());
     // Add the subnav items to the notifications nav item
     $sub_nav[] = array('name' => _x('Unread', 'Notification screen nav', 'buddypress'), 'slug' => 'unread', 'parent_url' => $notifications_link, 'parent_slug' => bp_get_notifications_slug(), 'screen_function' => 'bp_notifications_screen_unread', 'position' => 10, 'item_css_id' => 'notifications-my-notifications', 'user_has_access' => bp_core_can_edit_settings());
     $sub_nav[] = array('name' => _x('Read', 'Notification screen nav', 'buddypress'), 'slug' => 'read', 'parent_url' => $notifications_link, 'parent_slug' => bp_get_notifications_slug(), 'screen_function' => 'bp_notifications_screen_read', 'position' => 20, 'user_has_access' => bp_core_can_edit_settings());
     parent::setup_nav($main_nav, $sub_nav);
 }
/**
 * Adds a navigation item to the main navigation array used in BuddyPress themes.
 *
 * @package BuddyPress Core
 * @global object $bp Global BuddyPress settings object
 */
function bp_core_new_nav_item($args = '')
{
    global $bp;
    $defaults = array('name' => false, 'slug' => false, 'item_css_id' => false, 'show_for_displayed_user' => true, 'site_admin_only' => false, 'position' => 99, 'screen_function' => false, 'default_subnav_slug' => false);
    $r = nxt_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    // If we don't have the required info we need, don't create this subnav item
    if (empty($name) || empty($slug)) {
        return false;
    }
    // If this is for site admins only and the user is not one, don't create the subnav item
    if ($site_admin_only && !is_super_admin()) {
        return false;
    }
    if (empty($item_css_id)) {
        $item_css_id = $slug;
    }
    $bp->bp_nav[$slug] = array('name' => $name, 'slug' => $slug, 'link' => $bp->loggedin_user->domain . $slug . '/', 'css_id' => $item_css_id, 'show_for_displayed_user' => $show_for_displayed_user, 'position' => $position, 'screen_function' => &$screen_function);
    /***
     * If this nav item is hidden for the displayed user, and
     * the logged in user is not the displayed user
     * looking at their own profile, don't create the nav item.
     */
    if (!$show_for_displayed_user && !bp_user_has_access()) {
        return false;
    }
    /***
     * If the nav item is visible, we are not viewing a user, and this is a root
     * component, don't attach the default subnav function so we can display a
     * directory or something else.
     */
    if (-1 != $position && bp_is_root_component($slug) && !bp_displayed_user_id()) {
        return;
    }
    // Look for current component
    if (bp_is_current_component($slug) && !bp_current_action()) {
        if (!is_object($screen_function[0])) {
            add_action('bp_screens', $screen_function);
        } else {
            add_action('bp_screens', array(&$screen_function[0], $screen_function[1]), 3);
        }
        if (!empty($default_subnav_slug)) {
            $bp->current_action = apply_filters('bp_default_component_subnav', $default_subnav_slug, $r);
        }
        // Look for current item
    } elseif (bp_is_current_item($slug) && !bp_current_action()) {
        if (!is_object($screen_function[0])) {
            add_action('bp_screens', $screen_function);
        } else {
            add_action('bp_screens', array(&$screen_function[0], $screen_function[1]), 3);
        }
        if (!empty($default_subnav_slug)) {
            $bp->current_action = apply_filters('bp_default_component_subnav', $default_subnav_slug, $r);
        }
    }
    do_action('bp_core_new_nav_item', $r, $args, $defaults);
}
/**
 * Add an item to the main BuddyPress navigation array.
 *
 * @global BuddyPress $bp The one true BuddyPress instance.
 *
 * @param array $args {
 *     Array describing the new nav item.
 *     @type string $name Display name for the nav item.
 *     @type string $slug Unique URL slug for the nav item.
 *     @type bool|string $item_css_id Optional. 'id' attribute for the nav
 *           item. Default: the value of $slug.
 *     @type bool $show_for_displayed_user Optional. Whether the nav item
 *           should be visible when viewing a member profile other than your
 *           own. Default: true.
 *     @type bool $site_admin_only Optional. Whether the nav item should be
 *           visible only to site admins (those with the 'bp_moderate' cap).
 *           Default: false.
 *     @type int $position Optional. Numerical index specifying where the item
 *           should appear in the nav array. Default: 99.
 *     @type callable $screen_function The callback function that will run
 *           when the nav item is clicked.
 *     @type bool|string $default_subnav_slug Optional. The slug of the default
 *           subnav item to select when the nav item is clicked.
 * }
 * @return bool|null Returns false on failure.
 */
function bp_core_new_nav_item($args = '')
{
    global $bp;
    $defaults = array('name' => false, 'slug' => false, 'item_css_id' => false, 'show_for_displayed_user' => true, 'site_admin_only' => false, 'position' => 99, 'screen_function' => false, 'default_subnav_slug' => false);
    $r = wp_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    // If we don't have the required info we need, don't create this subnav item
    if (empty($name) || empty($slug)) {
        return false;
    }
    // If this is for site admins only and the user is not one, don't create the subnav item
    if (!empty($site_admin_only) && !bp_current_user_can('bp_moderate')) {
        return false;
    }
    if (empty($item_css_id)) {
        $item_css_id = $slug;
    }
    $bp->bp_nav[$slug] = array('name' => $name, 'slug' => $slug, 'link' => trailingslashit(bp_loggedin_user_domain() . $slug), 'css_id' => $item_css_id, 'show_for_displayed_user' => $show_for_displayed_user, 'position' => $position, 'screen_function' => &$screen_function, 'default_subnav_slug' => $default_subnav_slug);
    /**
     * If this nav item is hidden for the displayed user, and
     * the logged in user is not the displayed user
     * looking at their own profile, don't create the nav item.
     */
    if (empty($show_for_displayed_user) && !bp_user_has_access()) {
        return false;
    }
    /**
     * If the nav item is visible, we are not viewing a user, and this is a root
     * component, don't attach the default subnav function so we can display a
     * directory or something else.
     */
    if (-1 != $position && bp_is_root_component($slug) && !bp_displayed_user_id()) {
        return;
    }
    // Look for current component
    if (bp_is_current_component($slug) || bp_is_current_item($slug)) {
        // The requested URL has explicitly included the default subnav
        // (eg: http://example.com/members/membername/activity/just-me/)
        // The canonical version will not contain this subnav slug.
        if (!empty($default_subnav_slug) && bp_is_current_action($default_subnav_slug) && !bp_action_variable(0)) {
            unset($bp->canonical_stack['action']);
        } elseif (!bp_current_action()) {
            // Add our screen hook if screen function is callable
            if (is_callable($screen_function)) {
                add_action('bp_screens', $screen_function, 3);
            }
            if (!empty($default_subnav_slug)) {
                $bp->current_action = apply_filters('bp_default_component_subnav', $default_subnav_slug, $r);
            }
        }
    }
    do_action('bp_core_new_nav_item', $r, $args, $defaults);
}
 /**
  * Set up bp-core global settings.
  *
  * Sets up a majority of the BuddyPress globals that require a minimal
  * amount of processing, meaning they cannot be set in the BuddyPress class.
  *
  * @since BuddyPress (1.5.0)
  *
  * @see BP_Component::setup_globals() for description of parameters.
  *
  * @param array $args See {@link BP_Component::setup_globals()}.
  */
 public function setup_globals($args = array())
 {
     $bp = buddypress();
     /** Database **********************************************************/
     // Get the base database prefix
     if (empty($bp->table_prefix)) {
         $bp->table_prefix = bp_core_get_table_prefix();
     }
     // The domain for the root of the site where the main blog resides
     if (empty($bp->root_domain)) {
         $bp->root_domain = bp_core_get_root_domain();
     }
     // Fetches all of the core BuddyPress settings in one fell swoop
     if (empty($bp->site_options)) {
         $bp->site_options = bp_core_get_root_options();
     }
     // The names of the core WordPress pages used to display BuddyPress content
     if (empty($bp->pages)) {
         $bp->pages = bp_core_get_directory_pages();
     }
     /** Basic current user data *******************************************/
     // Logged in user is the 'current_user'
     $current_user = wp_get_current_user();
     // The user ID of the user who is currently logged in.
     $bp->loggedin_user = new stdClass();
     $bp->loggedin_user->id = isset($current_user->ID) ? $current_user->ID : 0;
     /** Avatars ***********************************************************/
     // Fetches the default Gravatar image to use if the user/group/blog has no avatar or gravatar
     $bp->grav_default = new stdClass();
     $bp->grav_default->user = apply_filters('bp_user_gravatar_default', $bp->site_options['avatar_default']);
     $bp->grav_default->group = apply_filters('bp_group_gravatar_default', $bp->grav_default->user);
     $bp->grav_default->blog = apply_filters('bp_blog_gravatar_default', $bp->grav_default->user);
     // Notifications table. Included here for legacy purposes. Use
     // bp-notifications instead.
     $bp->core->table_name_notifications = $bp->table_prefix . 'bp_notifications';
     /**
      * Used to determine if user has admin rights on current content. If the
      * logged in user is viewing their own profile and wants to delete
      * something, is_item_admin is used. This is a generic variable so it
      * can be used by other components. It can also be modified, so when
      * viewing a group 'is_item_admin' would be 'true' if they are a group
      * admin, and 'false' if they are not.
      */
     bp_update_is_item_admin(bp_user_has_access(), 'core');
     // Is the logged in user is a mod for the current item?
     bp_update_is_item_mod(false, 'core');
     do_action('bp_core_setup_globals');
 }
Example #7
0
/**
 * Register a screen function for an item in the main nav array.
 *
 * @since BuddyPress (2.4.0)
 *
 * @param array $args {
 *     Array describing the new nav item.
 *     @type string      $name                    Display name for the nav item.
 *     @type string      $slug                    Unique URL slug for the nav item.
 *     @type bool|string $item_css_id             Optional. 'id' attribute for the nav item. Default: the value of `$slug`.
 *     @type bool        $show_for_displayed_user Optional. Whether the nav item should be visible when viewing a
 *                                                member profile other than your own. Default: true.
 *     @type bool        $site_admin_only         Optional. Whether the nav item should be visible only to site admins
 *                                                (those with the 'bp_moderate' cap). Default: false.
 *     @type int         $position                Optional. Numerical index specifying where the item should appear in
 *                                                the nav array. Default: 99.
 *     @type callable    $screen_function         The callback function that will run when the nav item is clicked.
 *     @type bool|string $default_subnav_slug     Optional. The slug of the default subnav item to select when the nav
 *                                                item is clicked.
 * }
 * @return bool|null Returns false on failure.
 */
function bp_core_register_nav_screen_function($args = '')
{
    $bp = buddypress();
    $defaults = array('name' => false, 'slug' => false, 'item_css_id' => false, 'show_for_displayed_user' => true, 'site_admin_only' => false, 'position' => 99, 'screen_function' => false, 'default_subnav_slug' => false);
    $r = wp_parse_args($args, $defaults);
    // If we don't have the required info we need, don't register this screen function.
    if (empty($r['slug'])) {
        return false;
    }
    /**
     * If this is for site admins only and the user is not one,
     * don't register this screen function.
     */
    if (!empty($r['site_admin_only']) && !bp_current_user_can('bp_moderate')) {
        return false;
    }
    /**
     * If this nav item is hidden for the displayed user, and
     * the logged in user is not the displayed user
     * looking at their own profile, don't don't register this screen function.
     */
    if (empty($r['show_for_displayed_user']) && !bp_user_has_access()) {
        return false;
    }
    /**
     * If the nav item is visible, we are not viewing a user, and this is a root
     * component, don't attach the default subnav function so we can display a
     * directory or something else.
     */
    if (-1 != $r['position'] && bp_is_root_component($r['slug']) && !bp_displayed_user_id()) {
        return;
    }
    // Look for current component
    if (bp_is_current_component($r['slug']) || bp_is_current_item($r['slug'])) {
        // The requested URL has explicitly included the default subnav
        // (eg: http://example.com/members/membername/activity/just-me/)
        // The canonical version will not contain this subnav slug.
        if (!empty($r['default_subnav_slug']) && bp_is_current_action($r['default_subnav_slug']) && !bp_action_variable(0)) {
            unset($bp->canonical_stack['action']);
        } elseif (!bp_current_action()) {
            // Add our screen hook if screen function is callable
            if (is_callable($r['screen_function'])) {
                add_action('bp_screens', $r['screen_function'], 3);
            }
            if (!empty($r['default_subnav_slug'])) {
                /**
                 * Filters the default component subnav item.
                 *
                 * @since BuddyPress (1.5.0)
                 *
                 * @param string $value The slug of the default subnav item
                 *                      to select when clicked.
                 * @param array  $r     Parsed arguments for the nav item.
                 */
                $bp->current_action = apply_filters('bp_default_component_subnav', $r['default_subnav_slug'], $r);
            }
        }
    }
    /**
     * Fires after the screen function for an item in the BuddyPress main
     * navigation is registered.
     *
     * @since BuddyPress (2.4.0)
     *
     * @param array $r        Parsed arguments for the nav item.
     * @param array $args     Originally passed in arguments for the nav item.
     * @param array $defaults Default arguments for a nav item.
     */
    do_action('bp_core_register_nav_screen_function', $r, $args, $defaults);
}
Example #8
0
    // get the current users role
    $user_role = bas_get_user_role();
    // get avatars
    $avatar = get_avatar($current_user_email, 25);
    $avatar_200 = get_avatar($current_user_email, 220);
    $loginClass = '4';
    $loginLink = "/intranet/members/" . $current_user_username;
} else {
    $current_user_displayname = 'Login';
    $avatar = '<span class="float:right;"><img src="' . get_template_directory_uri() . '/includes/img/bas-avatar.png"></span>';
    $avatar_200 = get_avatar('Bard Access Systems', 220);
    $loginClass = '1';
    $loginLink = "#";
}
if (function_exists(bp_is_active)) {
    if (bp_is_user() && bp_user_has_access()) {
        $notification_count = bp_notifications_get_unread_notification_count(bp_loggedin_user_id());
    } else {
        $notification_count = 0;
    }
} else {
    $notification_count = 0;
}
?>

  </head>

	<body <?php 
body_class();
?>
>
 function setup_globals()
 {
     global $bp;
     /** Database **********************************************************/
     // Get the base database prefix
     if (empty($bp->table_prefix)) {
         $bp->table_prefix = bp_core_get_table_prefix();
     }
     // The domain for the root of the site where the main blog resides
     if (empty($bp->root_domain)) {
         $bp->root_domain = bp_core_get_root_domain();
     }
     // Fetches all of the core BuddyPress settings in one fell swoop
     if (empty($bp->site_options)) {
         $bp->site_options = bp_core_get_root_options();
     }
     // The names of the core NXTClass pages used to display BuddyPress content
     if (empty($bp->pages)) {
         $bp->pages = bp_core_get_directory_pages();
     }
     /** Admin Bar *********************************************************/
     // Set the 'My Account' global to prevent debug notices
     $bp->my_account_menu_id = false;
     /** Component and Action **********************************************/
     // Used for overriding the 2nd level navigation menu so it can be used to
     // display custom navigation for an item (for example a group)
     $bp->is_single_item = false;
     // Sets up the array container for the component navigation rendered
     // by bp_get_nav()
     $bp->bp_nav = array();
     // Sets up the array container for the component options navigation
     // rendered by bp_get_options_nav()
     $bp->bp_options_nav = array();
     // Contains an array of all the active components. The key is the slug,
     // value the internal ID of the component.
     //$bp->active_components = array();
     /** Basic current user data *******************************************/
     // Logged in user is the 'current_user'
     $current_user = nxt_get_current_user();
     // The user ID of the user who is currently logged in.
     $bp->loggedin_user->id = $current_user->ID;
     /** Avatars ***********************************************************/
     // Fetches the default Gravatar image to use if the user/group/blog has no avatar or gravatar
     $bp->grav_default->user = apply_filters('bp_user_gravatar_default', $bp->site_options['avatar_default']);
     $bp->grav_default->group = apply_filters('bp_group_gravatar_default', $bp->grav_default->user);
     $bp->grav_default->blog = apply_filters('bp_blog_gravatar_default', $bp->grav_default->user);
     // Notifications Table
     $bp->core->table_name_notifications = $bp->table_prefix . 'bp_notifications';
     /**
      * Used to determine if user has admin rights on current content. If the
      * logged in user is viewing their own profile and wants to delete
      * something, is_item_admin is used. This is a generic variable so it
      * can be used by other components. It can also be modified, so when
      * viewing a group 'is_item_admin' would be 'true' if they are a group
      * admin, and 'false' if they are not.
      */
     bp_update_is_item_admin(bp_user_has_access(), 'core');
     // Is the logged in user is a mod for the current item?
     bp_update_is_item_mod(false, 'core');
     do_action('bp_core_setup_globals');
 }
Example #10
0
/**
 * Adds a navigation item to the main navigation array used in BuddyPress themes.
 *
 * @package BuddyPress Core
 * @global object $bp Global BuddyPress settings object
 */
function bp_core_new_nav_item($args = '')
{
    global $bp;
    $defaults = array('name' => false, 'slug' => false, 'item_css_id' => false, 'show_for_displayed_user' => true, 'site_admin_only' => false, 'position' => 99, 'screen_function' => false, 'default_subnav_slug' => false);
    $r = wp_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    // If we don't have the required info we need, don't create this subnav item
    if (empty($name) || empty($slug)) {
        return false;
    }
    // If this is for site admins only and the user is not one, don't create the subnav item
    if ($site_admin_only && !bp_current_user_can('bp_moderate')) {
        return false;
    }
    if (empty($item_css_id)) {
        $item_css_id = $slug;
    }
    $bp->bp_nav[$slug] = array('name' => $name, 'slug' => $slug, 'link' => $bp->loggedin_user->domain . $slug . '/', 'css_id' => $item_css_id, 'show_for_displayed_user' => $show_for_displayed_user, 'position' => $position, 'screen_function' => &$screen_function);
    /***
     * If this nav item is hidden for the displayed user, and
     * the logged in user is not the displayed user
     * looking at their own profile, don't create the nav item.
     */
    if (!$show_for_displayed_user && !bp_user_has_access()) {
        return false;
    }
    /***
     * If the nav item is visible, we are not viewing a user, and this is a root
     * component, don't attach the default subnav function so we can display a
     * directory or something else.
     */
    if (-1 != $position && bp_is_root_component($slug) && !bp_displayed_user_id()) {
        return;
    }
    // Look for current component
    if (bp_is_current_component($slug) && !bp_current_action()) {
        if (!is_object($screen_function[0])) {
            add_action('bp_screens', $screen_function);
        } else {
            add_action('bp_screens', array(&$screen_function[0], $screen_function[1]), 3);
        }
        if (!empty($default_subnav_slug)) {
            /**
             * BuddyPress will attempt to resolve to the most specific URL possible,
             * to avoid search-engine-unfriendly content reduplication. Filter
             * bp_guarantee_unique_uris (and return false) to avoid this behavior
             */
            if (apply_filters('bp_guarantee_unique_uris', true)) {
                bp_core_redirect(bp_displayed_user_domain() . $slug . '/' . apply_filters('bp_default_component_subnav', $default_subnav_slug, $r));
            } else {
                $bp->current_action = apply_filters('bp_default_component_subnav', $default_subnav_slug, $r);
            }
        }
        // Look for current item
    } elseif (bp_is_current_item($slug) && !bp_current_action()) {
        if (!is_object($screen_function[0])) {
            add_action('bp_screens', $screen_function);
        } else {
            add_action('bp_screens', array(&$screen_function[0], $screen_function[1]), 3);
        }
        if (!empty($default_subnav_slug)) {
            /**
             * BuddyPress will attempt to resolve to the most specific URL possible,
             * to avoid search-engine-unfriendly content reduplication. Filter
             * bp_guarantee_unique_uris (and return false) to avoid this behavior
             */
            if (apply_filters('bp_guarantee_unique_uris', true)) {
                bp_core_redirect(bp_get_root_domain() . '/' . bp_get_root_slug(bp_current_component()) . '/' . $slug . '/' . apply_filters('bp_default_component_subnav', $default_subnav_slug, $r));
            } else {
                $bp->current_action = apply_filters('bp_default_component_subnav', $default_subnav_slug, $r);
            }
        }
    }
    do_action('bp_core_new_nav_item', $r, $args, $defaults);
}
Example #11
0
/**
 * bp_core_new_nav_item()
 *
 * Adds a navigation item to the main navigation array used in BuddyPress themes.
 *
 * @package BuddyPress Core
 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
 */
function bp_core_new_nav_item( $args = '' ) {
	global $bp;

	$defaults = array(
		'name' => false, // Display name for the nav item
		'slug' => false, // URL slug for the nav item
		'item_css_id' => false, // The CSS ID to apply to the HTML of the nav item
		'show_for_displayed_user' => true, // When viewing another user does this nav item show up?
		'site_admin_only' => false, // Can only site admins see this nav item?
		'position' => 99, // Index of where this nav item should be positioned
		'screen_function' => false, // The name of the function to run when clicked
		'default_subnav_slug' => false // The slug of the default subnav item to select when clicked
	);

	$r = wp_parse_args( $args, $defaults );
	extract( $r, EXTR_SKIP );

	/* If we don't have the required info we need, don't create this subnav item */
	if ( empty($name) || empty($slug) )
		return false;

	/* If this is for site admins only and the user is not one, don't create the subnav item */
	if ( $site_admin_only && !is_super_admin() )
		return false;

	if ( empty( $item_css_id ) )
		$item_css_id = $slug;

	$bp->bp_nav[$slug] = array(
		'name' => $name,
		'slug' => $slug,
		'link' => $bp->loggedin_user->domain . $slug . '/',
		'css_id' => $item_css_id,
		'show_for_displayed_user' => $show_for_displayed_user,
		'position' => $position
	);

 	/***
	 * If this nav item is hidden for the displayed user, and
	 * the logged in user is not the displayed user
	 * looking at their own profile, don't create the nav item.
	 */
	if ( !$show_for_displayed_user && !bp_user_has_access() )
		return false;

	/***
 	 * If we are not viewing a user, and this is a root component, don't attach the
 	 * default subnav function so we can display a directory or something else.
 	 */
	if ( bp_core_is_root_component( $slug ) && !$bp->displayed_user->id )
		return;

	if ( $bp->current_component == $slug && !$bp->current_action ) {
		if ( !is_object( $screen_function[0] ) )
			add_action( 'wp', $screen_function, 3 );
		else
			add_action( 'wp', array( &$screen_function[0], $screen_function[1] ), 3 );

		if ( $default_subnav_slug )
			$bp->current_action = $default_subnav_slug;
	}
}