/** * 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); }
/** * 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); }
/** * Checks to see if a component's URL should be in the root, not under a member page: * eg: http://example.com/groups/the-group NOT http://example.com/members/andy/groups/the-group * You should be using bp_is_root_component(). * * @deprecated BuddyPress (1.5) * @deprecated bp_is_root_component() * @return bool True if root component, else false. */ function bp_core_is_root_component($component_name) { _deprecated_function(__FUNCTION__, '1.5', 'bp_is_root_component()'); return bp_is_root_component($component_name); }
/** * 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); }