Skip to:
Content

BuddyPress.org

Changeset 9936


Ignore:
Timestamp:
06/11/2015 06:53:59 AM (11 years ago)
Author:
johnjamesjacoby
Message:

Loaders: Micro-optimizations:

  • Add brackets for improved readability
  • Only instantiate $bp from buddypress() when used more than once, and after all early return conditions have executed
  • Use _slug_ functions where appropriate, and avoid $this->slug references as they do not run filters
  • Reduce mulitple calls to the same functions into 1 function call: I.E. bp_core_can_edit_settings()
  • Remove BP_Core_Component::setup_nav() method - it's been handled and duplicated by BP_Members_Component for several years now, and only when XProfile is disabled
  • Use new bp_get_profile_slug() functions where appropriate
  • Use bp_core_number_format() where appropriate
  • Avoid duplicate trailingslashit() calls on the same variables
  • Rely on canonical menu URLs for all components

This change touches each component's -loader.php file and makes several small optimizations that avoid executing hundreds of function calls that return data (specifically gettext) that never gets used on logged-out users. This results in an approximate 20% reduction in time spent running our full unit test suite in my testing, and also improves site performance for logged-out users.

Location:
trunk
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-activity/bp-activity-loader.php

    r9843 r9936  
    4646         */
    4747        public function includes( $includes = array() ) {
     48
    4849                // Files to include
    4950                $includes = array(
     
    9091
    9192                // Define a slug, if necessary
    92                 if ( !defined( 'BP_ACTIVITY_SLUG' ) )
     93                if ( ! defined( 'BP_ACTIVITY_SLUG' ) ) {
    9394                        define( 'BP_ACTIVITY_SLUG', $this->id );
     95                }
    9496
    9597                // Global tables for activity component
     
    136138        public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
    137139
    138                 // Add 'Activity' to the main navigation
    139                 $main_nav = array(
    140                         'name'                => _x( 'Activity', 'Profile activity screen nav', 'buddypress' ),
    141                         'slug'                => $this->slug,
    142                         'position'            => 10,
    143                         'screen_function'     => 'bp_activity_screen_my_activity',
    144                         'default_subnav_slug' => 'just-me',
    145                         'item_css_id'         => $this->id
    146                 );
    147 
    148140                // Stop if there is no user displayed or logged in
    149                 if ( !is_user_logged_in() && !bp_displayed_user_id() )
     141                if ( ! is_user_logged_in() && ! bp_displayed_user_id() ) {
    150142                        return;
     143                }
    151144
    152145                // Determine user to use
     
    159152                }
    160153
    161                 // User link
    162                 $activity_link = trailingslashit( $user_domain . $this->slug );
     154                $slug          = bp_get_activity_slug();
     155                $activity_link = trailingslashit( $user_domain . $slug );
     156
     157                // Add 'Activity' to the main navigation
     158                $main_nav = array(
     159                        'name'                => _x( 'Activity', 'Profile activity screen nav', 'buddypress' ),
     160                        'slug'                => $slug,
     161                        'position'            => 10,
     162                        'screen_function'     => 'bp_activity_screen_my_activity',
     163                        'default_subnav_slug' => 'just-me',
     164                        'item_css_id'         => $this->id
     165                );
    163166
    164167                // Add the subnav items to the activity nav item if we are using a theme that supports this
     
    167170                        'slug'            => 'just-me',
    168171                        'parent_url'      => $activity_link,
    169                         'parent_slug'     => $this->slug,
     172                        'parent_slug'     => $slug,
    170173                        'screen_function' => 'bp_activity_screen_my_activity',
    171174                        'position'        => 10
     
    178181                                'slug'            => 'mentions',
    179182                                'parent_url'      => $activity_link,
    180                                 'parent_slug'     => $this->slug,
     183                                'parent_slug'     => $slug,
    181184                                'screen_function' => 'bp_activity_screen_mentions',
    182185                                'position'        => 20,
     
    191194                                'slug'            => 'favorites',
    192195                                'parent_url'      => $activity_link,
    193                                 'parent_slug'     => $this->slug,
     196                                'parent_slug'     => $slug,
    194197                                'screen_function' => 'bp_activity_screen_favorites',
    195198                                'position'        => 30,
     
    204207                                'slug'            => bp_get_friends_slug(),
    205208                                'parent_url'      => $activity_link,
    206                                 'parent_slug'     => $this->slug,
     209                                'parent_slug'     => $slug,
    207210                                'screen_function' => 'bp_activity_screen_friends',
    208211                                'position'        => 40,
     
    217220                                'slug'            => bp_get_groups_slug(),
    218221                                'parent_url'      => $activity_link,
    219                                 'parent_slug'     => $this->slug,
     222                                'parent_slug'     => $slug,
    220223                                'screen_function' => 'bp_activity_screen_groups',
    221224                                'position'        => 50,
     
    246249         */
    247250        public function setup_admin_bar( $wp_admin_nav = array() ) {
    248                 $bp = buddypress();
    249251
    250252                // Menus for logged in user
     
    252254
    253255                        // Setup the logged in user variables
    254                         $user_domain   = bp_loggedin_user_domain();
    255                         $activity_link = trailingslashit( $user_domain . $this->slug );
     256                        $activity_link = trailingslashit( bp_loggedin_user_domain() . bp_get_activity_slug() );
    256257
    257258                        // Unread message count
     
    259260                                $count = bp_get_total_mention_count_for_user( bp_loggedin_user_id() );
    260261                                if ( !empty( $count ) ) {
    261                                         $title = sprintf( _x( 'Mentions <span class="count">%s</span>', 'Toolbar Mention logged in user', 'buddypress' ), number_format_i18n( $count ) );
     262                                        $title = sprintf( _x( 'Mentions <span class="count">%s</span>', 'Toolbar Mention logged in user', 'buddypress' ), bp_core_number_format( $count ) );
    262263                                } else {
    263264                                        $title = _x( 'Mentions', 'Toolbar Mention logged in user', 'buddypress' );
     
    267268                        // Add the "Activity" sub menu
    268269                        $wp_admin_nav[] = array(
    269                                 'parent' => $bp->my_account_menu_id,
     270                                'parent' => buddypress()->my_account_menu_id,
    270271                                'id'     => 'my-account-' . $this->id,
    271272                                'title'  => _x( 'Activity', 'My Account Activity sub nav', 'buddypress' ),
    272                                 'href'   => trailingslashit( $activity_link )
     273                                'href'   => $activity_link
    273274                        );
    274275
     
    278279                                'id'     => 'my-account-' . $this->id . '-personal',
    279280                                'title'  => _x( 'Personal', 'My Account Activity sub nav', 'buddypress' ),
    280                                 'href'   => trailingslashit( $activity_link )
     281                                'href'   => $activity_link
    281282                        );
    282283
     
    336337         */
    337338        public function setup_title() {
    338                 $bp = buddypress();
    339339
    340340                // Adjust title based on view
    341341                if ( bp_is_activity_component() ) {
     342                        $bp = buddypress();
     343
    342344                        if ( bp_is_my_profile() ) {
    343345                                $bp->bp_options_title = _x( 'My Activity', 'Page and <title>', 'buddypress' );
     
    361363         */
    362364        public function setup_actions() {
     365
    363366                // Spam prevention
    364367                add_action( 'bp_include', 'bp_activity_setup_akismet' );
  • trunk/src/bp-blogs/bp-blogs-loader.php

    r9898 r9936  
    144144         */
    145145        public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
    146                 $bp = buddypress();
    147146
    148147                /**
     
    155154                }
    156155
    157                 // Add 'Sites' to the main navigation
    158                 $count    = (int) bp_get_total_blog_count_for_user();
    159                 $class    = ( 0 === $count ) ? 'no-count' : 'count';
    160                 $nav_text = sprintf( __( 'Sites <span class="%s">%s</span>', 'buddypress' ), esc_attr( $class ), number_format_i18n( $count )  );
    161                 $main_nav = array(
    162                         'name'                => $nav_text,
    163                         'slug'                => $this->slug,
    164                         'position'            => 30,
    165                         'screen_function'     => 'bp_blogs_screen_my_blogs',
    166                         'default_subnav_slug' => 'my-sites',
    167                         'item_css_id'         => $this->id
    168                 );
    169 
    170156                // Determine user to use
    171157                if ( bp_displayed_user_domain() ) {
     
    177163                }
    178164
    179                 $parent_url = trailingslashit( $user_domain . bp_get_blogs_slug() );
     165                $slug       = bp_get_blogs_slug();
     166                $parent_url = trailingslashit( $user_domain . $slug );
     167
     168                // Add 'Sites' to the main navigation
     169                $count    = (int) bp_get_total_blog_count_for_user();
     170                $class    = ( 0 === $count ) ? 'no-count' : 'count';
     171                $nav_text = sprintf( __( 'Sites <span class="%s">%s</span>', 'buddypress' ), esc_attr( $class ), bp_core_number_format( $count )  );
     172                $main_nav = array(
     173                        'name'                => $nav_text,
     174                        'slug'                => $slug,
     175                        'position'            => 30,
     176                        'screen_function'     => 'bp_blogs_screen_my_blogs',
     177                        'default_subnav_slug' => 'my-sites',
     178                        'item_css_id'         => $this->id
     179                );
    180180
    181181                $sub_nav[] = array(
     
    183183                        'slug'            => 'my-sites',
    184184                        'parent_url'      => $parent_url,
    185                         'parent_slug'     => $bp->blogs->slug,
     185                        'parent_slug'     => $slug,
    186186                        'screen_function' => 'bp_blogs_screen_my_blogs',
    187187                        'position'        => 10
     
    203203         */
    204204        public function setup_admin_bar( $wp_admin_nav = array() ) {
    205                 $bp = buddypress();
    206205
    207206                /**
     
    217216                if ( is_user_logged_in() ) {
    218217
    219                         $blogs_link = trailingslashit( bp_loggedin_user_domain() . $this->slug );
     218                        // Setup the logged in user variables
     219                        $blogs_link = trailingslashit( bp_loggedin_user_domain() . bp_get_blogs_slug() );
    220220
    221221                        // Add the "Sites" sub menu
    222222                        $wp_admin_nav[] = array(
    223                                 'parent' => $bp->my_account_menu_id,
     223                                'parent' => buddypress()->my_account_menu_id,
    224224                                'id'     => 'my-account-' . $this->id,
    225225                                'title'  => __( 'Sites', 'buddypress' ),
    226                                 'href'   => trailingslashit( $blogs_link )
     226                                'href'   => $blogs_link
    227227                        );
    228228
     
    232232                                'id'     => 'my-account-' . $this->id . '-my-sites',
    233233                                'title'  => __( 'My Sites', 'buddypress' ),
    234                                 'href'   => trailingslashit( $blogs_link )
     234                                'href'   => $blogs_link
    235235                        );
    236236
     
    253253         */
    254254        public function setup_title() {
    255                 $bp = buddypress();
    256255
    257256                // Set up the component options navigation for Site
    258257                if ( bp_is_blogs_component() ) {
     258                        $bp = buddypress();
     259
    259260                        if ( bp_is_my_profile() ) {
    260261                                if ( bp_is_active( 'xprofile' ) ) {
     
    300301         */
    301302        public function post_tracking_args( $params = null, $post_type = 0 ) {
     303
    302304                /**
    303305                 * Filters the post types to track for the Blogs component.
  • trunk/src/bp-core/bp-core-loader.php

    r9819 r9936  
    151151        public function includes( $includes = array() ) {
    152152
    153                 if ( !is_admin() )
     153                if ( ! is_admin() ) {
    154154                        return;
     155                }
    155156
    156157                $includes = array(
     
    179180
    180181                // Get the base database prefix
    181                 if ( empty( $bp->table_prefix ) )
     182                if ( empty( $bp->table_prefix ) ) {
    182183                        $bp->table_prefix = bp_core_get_table_prefix();
     184                }
    183185
    184186                // The domain for the root of the site where the main blog resides
    185                 if ( empty( $bp->root_domain ) )
     187                if ( empty( $bp->root_domain ) ) {
    186188                        $bp->root_domain = bp_core_get_root_domain();
     189                }
    187190
    188191                // Fetches all of the core BuddyPress settings in one fell swoop
    189                 if ( empty( $bp->site_options ) )
     192                if ( empty( $bp->site_options ) ) {
    190193                        $bp->site_options = bp_core_get_root_options();
     194                }
    191195
    192196                // The names of the core WordPress pages used to display BuddyPress content
    193                 if ( empty( $bp->pages ) )
     197                if ( empty( $bp->pages ) ) {
    194198                        $bp->pages = bp_core_get_directory_pages();
     199                }
    195200
    196201                /** Basic current user data *******************************************/
     
    261266
    262267        /**
    263          * Set up component navigation.
    264          *
    265          * @since BuddyPress (1.5.0)
    266          *
    267          * @see BP_Component::setup_nav() for a description of arguments.
    268          *
    269          * @param array $main_nav Optional. See BP_Component::setup_nav() for
    270          *        description.
    271          * @param array $sub_nav Optional. See BP_Component::setup_nav() for
    272          *        description.
    273          */
    274         public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
    275                 $bp = buddypress();
    276 
    277                  // If xprofile component is disabled, revert to WordPress profile
    278                 if ( !bp_is_active( 'xprofile' ) ) {
    279 
    280                         // Fallback values if xprofile is disabled
    281                         if ( ! isset( $bp->core->profile ) ) {
    282                                 $bp->core->profile = new stdClass;
    283                         }
    284                         $bp->core->profile->slug = 'profile';
    285                         $bp->active_components[$bp->core->profile->slug] = $bp->core->profile->slug;
    286 
    287                         // Add 'Profile' to the main navigation
    288                         $main_nav = array(
    289                                 'name'                => _x( 'Profile', 'Main navigation', 'buddypress' ),
    290                                 'slug'                => $bp->core->profile->slug,
    291                                 'position'            => 20,
    292                                 'screen_function'     => 'bp_core_catch_profile_uri',
    293                                 'default_subnav_slug' => 'public'
    294                         );
    295 
    296                         $profile_link = trailingslashit( bp_loggedin_user_domain() . '/' . $bp->core->profile->slug );
    297 
    298                         // Add the subnav items to the profile
    299                         $sub_nav[] = array(
    300                                 'name'            => _x( 'View', 'Profile sub nav', 'buddypress' ),
    301                                 'slug'            => 'public',
    302                                 'parent_url'      => $profile_link,
    303                                 'parent_slug'     => $bp->core->profile->slug,
    304                                 'screen_function' => 'bp_core_catch_profile_uri'
    305                         );
    306 
    307                         parent::setup_nav( $main_nav, $sub_nav );
    308                 }
    309         }
    310 
    311         /**
    312268         * Setup cache groups
    313269         *
  • trunk/src/bp-forums/bp-forums-loader.php

    r9819 r9936  
    5050
    5151                // Define the parent forum ID
    52                 if ( !defined( 'BP_FORUMS_PARENT_FORUM_ID' ) )
     52                if ( ! defined( 'BP_FORUMS_PARENT_FORUM_ID' ) ) {
    5353                        define( 'BP_FORUMS_PARENT_FORUM_ID', 1 );
     54                }
    5455
    5556                // Define a slug, if necessary
    56                 if ( !defined( 'BP_FORUMS_SLUG' ) )
     57                if ( ! defined( 'BP_FORUMS_SLUG' ) ) {
    5758                        define( 'BP_FORUMS_SLUG', $this->id );
     59                }
    5860
    5961                // The location of the bbPress stand-alone config file
    6062                $bbconfig = bp_core_get_root_option( 'bb-config-location' );
    61                 if ( '' !== $bbconfig )
     63                if ( '' !== $bbconfig ) {
    6264                        $this->bbconfig = $bbconfig;
     65                }
    6366
    6467                // All globals for messaging component.
     
    9598
    9699                // bbPress stand-alone
    97                 if ( !defined( 'BB_PATH' ) )
     100                if ( ! defined( 'BB_PATH' ) ) {
    98101                        $includes[] = 'bbpress-sa';
     102                }
    99103
    100104                // Admin-specific code
     
    122126
    123127                // Stop if forums haven't been set up yet
    124                 if ( !bp_forums_is_installed_correctly() )
     128                if ( ! bp_forums_is_installed_correctly() ) {
    125129                        return;
     130                }
    126131
    127132                // Stop if there is no user displayed or logged in
    128                 if ( !is_user_logged_in() && !bp_displayed_user_id() )
     133                if ( ! is_user_logged_in() && ! bp_displayed_user_id() ) {
    129134                        return;
    130 
    131                 // Add 'Forums' to the main navigation
    132                 $main_nav = array(
    133                         'name'                => __( 'Forums', 'buddypress' ),
    134                         'slug'                => $this->slug,
    135                         'position'            => 80,
    136                         'screen_function'     => 'bp_member_forums_screen_topics',
    137                         'default_subnav_slug' => 'topics',
    138                         'item_css_id'         => $this->id
    139                 );
     135                }
    140136
    141137                // Determine user to use
     
    149145
    150146                // User link
    151                 $forums_link = trailingslashit( $user_domain . $this->slug );
    152 
    153                 // Additional menu if friends is active
     147                $slug        = bp_get_forums_slug();
     148                $forums_link = trailingslashit( $user_domain . $slug );
     149
     150                // Add 'Forums' to the main navigation
     151                $main_nav = array(
     152                        'name'                => __( 'Forums', 'buddypress' ),
     153                        'slug'                => $slug,
     154                        'position'            => 80,
     155                        'screen_function'     => 'bp_member_forums_screen_topics',
     156                        'default_subnav_slug' => 'topics',
     157                        'item_css_id'         => $this->id
     158                );
     159
     160                // Topics started
    154161                $sub_nav[] = array(
    155162                        'name'            => __( 'Topics Started', 'buddypress' ),
    156163                        'slug'            => 'topics',
    157164                        'parent_url'      => $forums_link,
    158                         'parent_slug'     => $this->slug,
     165                        'parent_slug'     => $slug,
    159166                        'screen_function' => 'bp_member_forums_screen_topics',
    160167                        'position'        => 20,
     
    162169                );
    163170
    164                 // Additional menu if friends is active
     171                // Topics replied to
    165172                $sub_nav[] = array(
    166173                        'name'            => __( 'Replied To', 'buddypress' ),
    167174                        'slug'            => 'replies',
    168175                        'parent_url'      => $forums_link,
    169                         'parent_slug'     => $this->slug,
     176                        'parent_slug'     => $slug,
    170177                        'screen_function' => 'bp_member_forums_screen_replies',
    171178                        'position'        => 40,
     
    192199
    193200                        // Setup the logged in user variables
    194                         $forums_link = trailingslashit( bp_loggedin_user_domain() . $this->slug );
     201                        $forums_link = trailingslashit( bp_loggedin_user_domain() . bp_get_forums_slug() );
    195202
    196203                        // Add the "My Account" sub menus
     
    199206                                'id'     => 'my-account-' . $this->id,
    200207                                'title'  => __( 'Forums', 'buddypress' ),
    201                                 'href'   => trailingslashit( $forums_link )
     208                                'href'   => $forums_link
    202209                        );
    203210
     
    207214                                'id'     => 'my-account-' . $this->id . '-topics-started',
    208215                                'title'  => __( 'Topics Started', 'buddypress' ),
    209                                 'href'   => trailingslashit( $forums_link . 'topics' )
     216                                'href'   => $forums_link
    210217                        );
    211218
     
    234241         */
    235242        public function setup_title() {
    236                 $bp = buddypress();
    237243
    238244                // Adjust title based on view
    239245                if ( bp_is_forums_component() ) {
     246                        $bp = buddypress();
     247
    240248                        if ( bp_is_my_profile() ) {
    241249                                $bp->bp_options_title = __( 'Forums', 'buddypress' );
  • trunk/src/bp-friends/bp-friends-loader.php

    r9819 r9936  
    7676
    7777                // Define a slug, if necessary
    78                 if ( !defined( 'BP_FRIENDS_SLUG' ) )
     78                if ( ! defined( 'BP_FRIENDS_SLUG' ) ) {
    7979                        define( 'BP_FRIENDS_SLUG', $this->id );
     80                }
    8081
    8182                // Global tables for the friends component
     
    111112         */
    112113        public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
    113                 $bp = buddypress();
    114 
    115                 // Add 'Friends' to the main navigation
    116                 $count    = friends_get_total_friend_count();
    117                 $class    = ( 0 === $count ) ? 'no-count' : 'count';
    118                 $main_nav = array(
    119                         'name'                => sprintf( __( 'Friends <span class="%s">%s</span>', 'buddypress' ), esc_attr( $class ), number_format_i18n( $count ) ),
    120                         'slug'                => $this->slug,
    121                         'position'            => 60,
    122                         'screen_function'     => 'friends_screen_my_friends',
    123                         'default_subnav_slug' => 'my-friends',
    124                         'item_css_id'         => $bp->friends->id
    125                 );
    126114
    127115                // Determine user to use
     
    134122                }
    135123
    136                 $friends_link = trailingslashit( $user_domain . bp_get_friends_slug() );
     124                $access       = bp_core_can_edit_settings();
     125                $slug         = bp_get_friends_slug();
     126                $friends_link = trailingslashit( $user_domain . $slug );
     127
     128                // Add 'Friends' to the main navigation
     129                $count    = friends_get_total_friend_count();
     130                $class    = ( 0 === $count ) ? 'no-count' : 'count';
     131                $main_nav = array(
     132                        'name'                => sprintf( __( 'Friends <span class="%s">%s</span>', 'buddypress' ), esc_attr( $class ), bp_core_number_format( $count ) ),
     133                        'slug'                => $slug,
     134                        'position'            => 60,
     135                        'screen_function'     => 'friends_screen_my_friends',
     136                        'default_subnav_slug' => 'my-friends',
     137                        'item_css_id'         => $this->id
     138                );
    137139
    138140                // Add the subnav items to the friends nav item
     
    141143                        'slug'            => 'my-friends',
    142144                        'parent_url'      => $friends_link,
    143                         'parent_slug'     => bp_get_friends_slug(),
     145                        'parent_slug'     => $slug,
    144146                        'screen_function' => 'friends_screen_my_friends',
    145147                        'position'        => 10,
     
    151153                        'slug'            => 'requests',
    152154                        'parent_url'      => $friends_link,
    153                         'parent_slug'     => bp_get_friends_slug(),
     155                        'parent_slug'     => $slug,
    154156                        'screen_function' => 'friends_screen_requests',
    155157                        'position'        => 20,
    156                         'user_has_access' => bp_core_can_edit_settings()
     158                        'user_has_access' => $access
    157159                );
    158160
     
    171173         */
    172174        public function setup_admin_bar( $wp_admin_nav = array() ) {
    173                 $bp = buddypress();
    174175
    175176                // Menus for logged in user
     
    177178
    178179                        // Setup the logged in user variables
    179                         $user_domain  = bp_loggedin_user_domain();
    180                         $friends_link = trailingslashit( $user_domain . $this->slug );
     180                        $friends_link = trailingslashit( bp_loggedin_user_domain() . bp_get_friends_slug() );
    181181
    182182                        // Pending friend requests
    183183                        $count = count( friends_get_friendship_request_user_ids( bp_loggedin_user_id() ) );
    184184                        if ( !empty( $count ) ) {
    185                                 $title   = sprintf( _x( 'Friends <span class="count">%s</span>', 'My Account Friends menu', 'buddypress' ), number_format_i18n( $count ) );
    186                                 $pending = sprintf( _x( 'Pending Requests <span class="count">%s</span>', 'My Account Friends menu sub nav', 'buddypress' ), number_format_i18n( $count ) );
     185                                $title   = sprintf( _x( 'Friends <span class="count">%s</span>',          'My Account Friends menu',         'buddypress' ), bp_core_number_format( $count ) );
     186                                $pending = sprintf( _x( 'Pending Requests <span class="count">%s</span>', 'My Account Friends menu sub nav', 'buddypress' ), bp_core_number_format( $count ) );
    187187                        } else {
    188                                 $title   = _x( 'Friends', 'My Account Friends menu', 'buddypress' );
     188                                $title   = _x( 'Friends',            'My Account Friends menu',        'buddypress' );
    189189                                $pending = _x( 'No Pending Requests','My Account Friends menu sub nav', 'buddypress' );
    190190                        }
     
    192192                        // Add the "My Account" sub menus
    193193                        $wp_admin_nav[] = array(
    194                                 'parent' => $bp->my_account_menu_id,
     194                                'parent' => buddypress()->my_account_menu_id,
    195195                                'id'     => 'my-account-' . $this->id,
    196196                                'title'  => $title,
    197                                 'href'   => trailingslashit( $friends_link )
     197                                'href'   => $friends_link
    198198                        );
    199199
     
    203203                                'id'     => 'my-account-' . $this->id . '-friendships',
    204204                                'title'  => _x( 'Friendships', 'My Account Friends menu sub nav', 'buddypress' ),
    205                                 'href'   => trailingslashit( $friends_link )
     205                                'href'   => $friends_link
    206206                        );
    207207
     
    222222         */
    223223        public function setup_title() {
    224                 $bp = buddypress();
    225224
    226225                // Adjust title
    227226                if ( bp_is_friends_component() ) {
     227                        $bp = buddypress();
     228
    228229                        if ( bp_is_my_profile() ) {
    229230                                $bp->bp_options_title = __( 'Friendships', 'buddypress' );
  • trunk/src/bp-groups/bp-groups-loader.php

    r9906 r9936  
    121121                );
    122122
    123                 if ( is_admin() )
     123                if ( is_admin() ) {
    124124                        $includes[] = 'admin';
     125                }
    125126
    126127                parent::includes( $includes );
     
    143144
    144145                // Define a slug, if necessary
    145                 if ( !defined( 'BP_GROUPS_SLUG' ) )
     146                if ( ! defined( 'BP_GROUPS_SLUG' ) ) {
    146147                        define( 'BP_GROUPS_SLUG', $this->id );
     148                }
    147149
    148150                // Global tables for groups component
     
    214216
    215217                        // Using "item" not "group" for generic support in other components.
    216                         if ( bp_current_user_can( 'bp_moderate' ) )
     218                        if ( bp_current_user_can( 'bp_moderate' ) ) {
    217219                                bp_update_is_item_admin( true, 'groups' );
    218                         else
     220                        } else {
    219221                                bp_update_is_item_admin( groups_is_user_admin( bp_loggedin_user_id(), $this->current_group->id ), 'groups' );
     222                        }
    220223
    221224                        // If the user is not an admin, check if they are a moderator
    222                         if ( !bp_is_item_admin() )
     225                        if ( ! bp_is_item_admin() ) {
    223226                                bp_update_is_item_mod  ( groups_is_user_mod  ( bp_loggedin_user_id(), $this->current_group->id ), 'groups' );
     227                        }
    224228
    225229                        // Is the logged in user a member of the group?
    226                         if ( ( is_user_logged_in() && groups_is_user_member( bp_loggedin_user_id(), $this->current_group->id ) ) )
     230                        if ( ( is_user_logged_in() && groups_is_user_member( bp_loggedin_user_id(), $this->current_group->id ) ) ) {
    227231                                $this->current_group->is_user_member = true;
    228                         else
     232                        } else {
    229233                                $this->current_group->is_user_member = false;
     234                        }
    230235
    231236                        // Should this group be visible to the logged in user?
    232                         if ( 'public' == $this->current_group->status || $this->current_group->is_user_member )
     237                        if ( 'public' == $this->current_group->status || $this->current_group->is_user_member ) {
    233238                                $this->current_group->is_visible = true;
    234                         else
     239                        } else {
    235240                                $this->current_group->is_visible = false;
     241                        }
    236242
    237243                        // If this is a private or hidden group, does the user have access?
    238244                        if ( 'private' == $this->current_group->status || 'hidden' == $this->current_group->status ) {
    239                                 if ( $this->current_group->is_user_member && is_user_logged_in() || bp_current_user_can( 'bp_moderate' ) )
     245                                if ( $this->current_group->is_user_member && is_user_logged_in() || bp_current_user_can( 'bp_moderate' ) ) {
    240246                                        $this->current_group->user_has_access = true;
    241                                 else
     247                                } else {
    242248                                        $this->current_group->user_has_access = false;
     249                                }
    243250                        } else {
    244251                                $this->current_group->user_has_access = true;
     
    346353                }
    347354
    348 
    349355                /**
    350356                 * Filters the default groups extension.
     
    357363                $this->default_extension = apply_filters( 'bp_groups_default_extension', defined( 'BP_GROUPS_DEFAULT_EXTENSION' ) ? BP_GROUPS_DEFAULT_EXTENSION : 'home' );
    358364
    359                 if ( !bp_current_action() ) {
    360                         buddypress()->current_action = $this->default_extension;
     365                $bp = buddypress();
     366
     367                if ( ! bp_current_action() ) {
     368                        $bp->current_action = $this->default_extension;
    361369                }
    362370
    363371                // Prepare for a redirect to the canonical URL
    364                 buddypress()->canonical_stack['base_url'] = bp_get_group_permalink( $this->current_group );
     372                $bp->canonical_stack['base_url'] = bp_get_group_permalink( $this->current_group );
    365373
    366374                if ( bp_current_action() ) {
    367                         buddypress()->canonical_stack['action'] = bp_current_action();
    368                 }
    369 
    370                 if ( !empty( buddypress()->action_variables ) ) {
    371                         buddypress()->canonical_stack['action_variables'] = bp_action_variables();
     375                        $bp->canonical_stack['action'] = bp_current_action();
     376                }
     377
     378                if ( ! empty( $bp->action_variables ) ) {
     379                        $bp->canonical_stack['action_variables'] = bp_action_variables();
    372380                }
    373381
     
    375383                // that extension's slug, unless more has been tacked onto the URL via
    376384                // action variables
    377                 if ( bp_is_current_action( $this->default_extension ) && empty( buddypress()->action_variables ) )  {
    378                         unset( buddypress()->canonical_stack['action'] );
     385                if ( bp_is_current_action( $this->default_extension ) && empty( $bp->action_variables ) )  {
     386                        unset( $bp->canonical_stack['action'] );
    379387                }
    380388        }
     
    391399         */
    392400        public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
    393 
    394                 // Only grab count if we're on a user page
    395                 if ( bp_is_user() ) {
    396                         $count    = bp_get_total_group_count_for_user();
    397                         $class    = ( 0 === $count ) ? 'no-count' : 'count';
    398                         $nav_name = sprintf( _x( 'Groups <span class="%s">%s</span>', 'Group screen nav with counter', 'buddypress' ), esc_attr( $class ), number_format_i18n( $count ) );
    399                 } else {
    400                         $nav_name = _x( 'Groups', 'Group screen nav without counter', 'buddypress' );
    401                 }
    402 
    403                 // Add 'Groups' to the main navigation
    404                 $main_nav = array(
    405                         'name'                => $nav_name,
    406                         'slug'                => $this->slug,
    407                         'position'            => 70,
    408                         'screen_function'     => 'groups_screen_my_groups',
    409                         'default_subnav_slug' => 'my-groups',
    410                         'item_css_id'         => $this->id
    411                 );
    412401
    413402                // Determine user to use
     
    420409                }
    421410
    422                 if ( !empty( $user_domain ) ) {
    423                         $groups_link = trailingslashit( $user_domain . $this->slug );
     411                // Only grab count if we're on a user page
     412                if ( bp_is_user() ) {
     413                        $count    = bp_get_total_group_count_for_user();
     414                        $class    = ( 0 === $count ) ? 'no-count' : 'count';
     415                        $nav_name = sprintf( _x( 'Groups <span class="%s">%s</span>', 'Group screen nav with counter', 'buddypress' ), esc_attr( $class ), bp_core_number_format( $count ) );
     416                } else {
     417                        $nav_name = _x( 'Groups', 'Group screen nav without counter', 'buddypress' );
     418                }
     419
     420                $slug = bp_get_groups_slug();
     421
     422                // Add 'Groups' to the main navigation
     423                $main_nav = array(
     424                        'name'                => $nav_name,
     425                        'slug'                => $slug,
     426                        'position'            => 70,
     427                        'screen_function'     => 'groups_screen_my_groups',
     428                        'default_subnav_slug' => 'my-groups',
     429                        'item_css_id'         => $this->id
     430                );
     431
     432                if ( ! empty( $user_domain ) ) {
     433                        $access      = bp_core_can_edit_settings();
     434                        $groups_link = trailingslashit( $user_domain . $slug );
    424435
    425436                        // Add the My Groups nav item
     
    428439                                'slug'            => 'my-groups',
    429440                                'parent_url'      => $groups_link,
    430                                 'parent_slug'     => $this->slug,
     441                                'parent_slug'     => $slug,
    431442                                'screen_function' => 'groups_screen_my_groups',
    432443                                'position'        => 10,
     
    439450                                'slug'            => 'invites',
    440451                                'parent_url'      => $groups_link,
    441                                 'parent_slug'     => $this->slug,
     452                                'parent_slug'     => $slug,
    442453                                'screen_function' => 'groups_screen_group_invites',
    443                                 'user_has_access' => bp_core_can_edit_settings(),
     454                                'user_has_access' => $access,
    444455                                'position'        => 30
    445456                        );
     
    487498
    488499                                $sub_nav[] = array(
    489                                         'name'               => _x( 'Request Membership','Group screen nav', 'buddypress' ),
    490                                         'slug'               => 'request-membership',
    491                                         'parent_url'         => $group_link,
    492                                         'parent_slug'        => $this->current_group->slug,
    493                                         'screen_function'    => 'groups_screen_group_request_membership',
    494                                         'position'           => 30
     500                                        'name'            => _x( 'Request Membership','Group screen nav', 'buddypress' ),
     501                                        'slug'            => 'request-membership',
     502                                        'parent_url'      => $group_link,
     503                                        'parent_slug'     => $this->current_group->slug,
     504                                        'screen_function' => 'groups_screen_group_request_membership',
     505                                        'position'        => 30
    495506                                );
    496507                        }
     
    562573
    563574                                $sub_nav[] = array_merge( array(
    564                                         'name'            => __( 'Details', 'buddypress' ),
    565                                         'slug'            => 'edit-details',
    566                                         'position'        => 0,
     575                                        'name'     => __( 'Details', 'buddypress' ),
     576                                        'slug'     => 'edit-details',
     577                                        'position' => 0,
    567578                                ), $default_params );
    568579
    569580                                $sub_nav[] = array_merge( array(
    570                                         'name'            => __( 'Settings', 'buddypress' ),
    571                                         'slug'            => 'group-settings',
    572                                         'position'        => 10,
     581                                        'name'     => __( 'Settings', 'buddypress' ),
     582                                        'slug'     => 'group-settings',
     583                                        'position' => 10,
    573584                                ), $default_params );
    574585
    575586                                if ( ! bp_disable_group_avatar_uploads() && buddypress()->avatar->show_avatars ) {
    576587                                        $sub_nav[] = array_merge( array(
    577                                                 'name'        => __( 'Photo', 'buddypress' ),
    578                                                 'slug'        => 'group-avatar',
    579                                                 'position'    => 20,
     588                                                'name'     => __( 'Photo', 'buddypress' ),
     589                                                'slug'     => 'group-avatar',
     590                                                'position' => 20,
    580591                                        ), $default_params );
    581592                                }
    582593
    583594                                $sub_nav[] = array_merge( array(
    584                                         'name'            => __( 'Members', 'buddypress' ),
    585                                         'slug'            => 'manage-members',
    586                                         'position'        => 30,
     595                                        'name'     => __( 'Members', 'buddypress' ),
     596                                        'slug'     => 'manage-members',
     597                                        'position' => 30,
    587598                                ), $default_params );
    588599
    589600                                if ( 'private' == $this->current_group->status ) {
    590601                                        $sub_nav[] = array_merge( array(
    591                                                 'name'            => __( 'Requests', 'buddypress' ),
    592                                                 'slug'            => 'membership-requests',
    593                                                 'position'        => 40,
     602                                                'name'     => __( 'Requests', 'buddypress' ),
     603                                                'slug'     => 'membership-requests',
     604                                                'position' => 40,
    594605                                        ), $default_params );
    595606                                }
    596607
    597608                                $sub_nav[] = array_merge( array(
    598                                         'name'            => __( 'Delete', 'buddypress' ),
    599                                         'slug'            => 'delete-group',
    600                                         'position'        => 1000,
     609                                        'name'     => __( 'Delete', 'buddypress' ),
     610                                        'slug'     => 'delete-group',
     611                                        'position' => 1000,
    601612                                ), $default_params );
    602613                        }
     
    631642         */
    632643        public function setup_admin_bar( $wp_admin_nav = array() ) {
    633                 $bp = buddypress();
    634644
    635645                // Menus for logged in user
     
    637647
    638648                        // Setup the logged in user variables
    639                         $user_domain = bp_loggedin_user_domain();
    640                         $groups_link = trailingslashit( $user_domain . $this->slug );
     649                        $groups_link = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() );
    641650
    642651                        // Pending group invites
     
    645654                        $pending = _x( 'No Pending Invites', 'My Account Groups sub nav', 'buddypress' );
    646655
    647                         if ( !empty( $count['total'] ) ) {
    648                                 $title   = sprintf( _x( 'Groups <span class="count">%s</span>', 'My Account Groups nav', 'buddypress' ), $count );
    649                                 $pending = sprintf( _x( 'Pending Invites <span class="count">%s</span>', 'My Account Groups sub nav', 'buddypress' ), $count );
     656                        if ( ! empty( $count['total'] ) ) {
     657                                $title   = sprintf( _x( 'Groups <span class="count">%s</span>',          'My Account Groups nav',     'buddypress' ), bp_core_number_format( $count ) );
     658                                $pending = sprintf( _x( 'Pending Invites <span class="count">%s</span>', 'My Account Groups sub nav', 'buddypress' ), bp_core_number_format( $count ) );
    650659                        }
    651660
    652661                        // Add the "My Account" sub menus
    653662                        $wp_admin_nav[] = array(
    654                                 'parent' => $bp->my_account_menu_id,
     663                                'parent' => buddypress()->my_account_menu_id,
    655664                                'id'     => 'my-account-' . $this->id,
    656665                                'title'  => $title,
    657                                 'href'   => trailingslashit( $groups_link )
     666                                'href'   => $groups_link
    658667                        );
    659668
     
    663672                                'id'     => 'my-account-' . $this->id . '-memberships',
    664673                                'title'  => _x( 'Memberships', 'My Account Groups sub nav', 'buddypress' ),
    665                                 'href'   => trailingslashit( $groups_link )
     674                                'href'   => $groups_link
    666675                        );
    667676
     
    692701         */
    693702        public function setup_title() {
    694                 $bp = buddypress();
    695703
    696704                if ( bp_is_groups_component() ) {
     705                        $bp = buddypress();
    697706
    698707                        if ( bp_is_my_profile() && !bp_is_single_item() ) {
  • trunk/src/bp-members/bp-members-filters.php

    r9877 r9936  
    111111        // If xprofile is active, use profile domain link
    112112        if ( ! is_admin() && bp_is_active( 'xprofile' ) ) {
    113                 $profile_link = trailingslashit( bp_core_get_user_domain( $user_id ) . buddypress()->profile->slug . '/edit' );
     113                $profile_link = trailingslashit( bp_core_get_user_domain( $user_id ) . bp_get_profile_slug() . '/edit' );
    114114
    115115        // Default to $url
  • trunk/src/bp-members/bp-members-loader.php

    r9877 r9936  
    142142                /** Profiles Fallback *************************************************/
    143143
    144                 if ( !bp_is_active( 'xprofile' ) ) {
     144                if ( ! bp_is_active( 'xprofile' ) ) {
    145145                        $bp->profile       = new stdClass;
    146146                        $bp->profile->slug = 'profile';
     
    231231                }
    232232
    233                 $bp = buddypress();
     233                // Determine user to use
     234                if ( bp_displayed_user_domain() ) {
     235                        $user_domain = bp_displayed_user_domain();
     236                } elseif ( bp_loggedin_user_domain() ) {
     237                        $user_domain = bp_loggedin_user_domain();
     238                } else {
     239                        return;
     240                }
     241
     242                $slug         = bp_get_profile_slug();
     243                $profile_link = trailingslashit( $user_domain . $slug );
    234244
    235245                // Setup the main navigation
    236246                $main_nav = array(
    237247                        'name'                => _x( 'Profile', 'Member profile main navigation', 'buddypress' ),
    238                         'slug'                => $bp->profile->slug,
     248                        'slug'                => $slug,
    239249                        'position'            => 20,
    240250                        'screen_function'     => 'bp_members_screen_display_profile',
    241251                        'default_subnav_slug' => 'public',
    242                         'item_css_id'         => $bp->profile->id
    243                 );
    244 
    245                 // User links
    246                 $user_domain  = bp_displayed_user_domain() ? bp_displayed_user_domain() : bp_loggedin_user_domain();
    247                 $profile_link = trailingslashit( $user_domain . $bp->profile->slug );
     252                        'item_css_id'         => buddypress()->profile->id
     253                );
    248254
    249255                // Setup the subnav items for the member profile
     
    252258                        'slug'            => 'public',
    253259                        'parent_url'      => $profile_link,
    254                         'parent_slug'     => $bp->profile->slug,
     260                        'parent_slug'     => $slug,
    255261                        'screen_function' => 'bp_members_screen_display_profile',
    256262                        'position'        => 10
  • trunk/src/bp-messages/bp-messages-loader.php

    r9934 r9936  
    9191
    9292                // Define a slug, if necessary
    93                 if ( !defined( 'BP_MESSAGES_SLUG' ) ) {
     93                if ( ! defined( 'BP_MESSAGES_SLUG' ) ) {
    9494                        define( 'BP_MESSAGES_SLUG', $this->id );
    9595                }
     
    130130        public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
    131131
    132                 // Only grab count if we're on a user page and current user has access
    133                 if ( bp_is_user() && bp_user_has_access() ) {
    134                         $count    = bp_get_total_unread_messages_count();
    135                         $class    = ( 0 === $count ) ? 'no-count' : 'count';
    136                         $nav_name = sprintf( __( 'Messages <span class="%s">%s</span>', 'buddypress' ), esc_attr( $class ), number_format_i18n( $count ) );
    137                 } else {
    138                         $nav_name = __( 'Messages', 'buddypress' );
    139                 }
    140 
    141                 // Add 'Messages' to the main navigation
    142                 $main_nav = array(
    143                         'name'                    => $nav_name,
    144                         'slug'                    => $this->slug,
    145                         'position'                => 50,
    146                         'show_for_displayed_user' => bp_core_can_edit_settings(),
    147                         'screen_function'         => 'messages_screen_inbox',
    148                         'default_subnav_slug'     => 'inbox',
    149                         'item_css_id'             => $this->id
    150                 );
    151 
    152132                // Determine user to use
    153133                if ( bp_displayed_user_domain() ) {
     
    159139                }
    160140
    161                 // Link to user messages
    162                 $messages_link = trailingslashit( $user_domain . $this->slug );
     141                $access        = bp_core_can_edit_settings();
     142                $slug          = bp_get_messages_slug();
     143                $messages_link = trailingslashit( $user_domain . $slug );
     144
     145                // Only grab count if we're on a user page and current user has access
     146                if ( bp_is_user() && bp_user_has_access() ) {
     147                        $count    = bp_get_total_unread_messages_count();
     148                        $class    = ( 0 === $count ) ? 'no-count' : 'count';
     149                        $nav_name = sprintf( __( 'Messages <span class="%s">%s</span>', 'buddypress' ), esc_attr( $class ), bp_core_number_format( $count ) );
     150                } else {
     151                        $nav_name = __( 'Messages', 'buddypress' );
     152                }
     153
     154                // Add 'Messages' to the main navigation
     155                $main_nav = array(
     156                        'name'                    => $nav_name,
     157                        'slug'                    => $slug,
     158                        'position'                => 50,
     159                        'show_for_displayed_user' => $access,
     160                        'screen_function'         => 'messages_screen_inbox',
     161                        'default_subnav_slug'     => 'inbox',
     162                        'item_css_id'             => $this->id
     163                );
    163164
    164165                // Add the subnav items to the profile
     
    167168                        'slug'            => 'inbox',
    168169                        'parent_url'      => $messages_link,
    169                         'parent_slug'     => $this->slug,
     170                        'parent_slug'     => $slug,
    170171                        'screen_function' => 'messages_screen_inbox',
    171172                        'position'        => 10,
    172                         'user_has_access' => bp_core_can_edit_settings()
     173                        'user_has_access' => $access
    173174                );
    174175
     
    178179                                'slug'            => bp_get_messages_starred_slug(),
    179180                                'parent_url'      => $messages_link,
    180                                 'parent_slug'     => $this->slug,
     181                                'parent_slug'     => $slug,
    181182                                'screen_function' => 'bp_messages_star_screen',
    182183                                'position'        => 11,
    183                                 'user_has_access' => bp_core_can_edit_settings()
     184                                'user_has_access' => $access
    184185                        );
    185186                }
     
    189190                        'slug'            => 'sentbox',
    190191                        'parent_url'      => $messages_link,
    191                         'parent_slug'     => $this->slug,
     192                        'parent_slug'     => $slug,
    192193                        'screen_function' => 'messages_screen_sentbox',
    193194                        'position'        => 20,
    194                         'user_has_access' => bp_core_can_edit_settings()
     195                        'user_has_access' => $access
    195196                );
    196197
     
    199200                        'slug'            => 'compose',
    200201                        'parent_url'      => $messages_link,
    201                         'parent_slug'     => $this->slug,
     202                        'parent_slug'     => $slug,
    202203                        'screen_function' => 'messages_screen_compose',
    203204                        'position'        => 30,
    204                         'user_has_access' => bp_core_can_edit_settings()
     205                        'user_has_access' => $access
    205206                );
    206207
     
    210211                                'slug'            => 'notices',
    211212                                'parent_url'      => $messages_link,
    212                                 'parent_slug'     => $this->slug,
     213                                'parent_slug'     => $slug,
    213214                                'screen_function' => 'messages_screen_notices',
    214215                                'position'        => 90,
    215                                 'user_has_access' => bp_current_user_can( 'bp_moderate' )
     216                                'user_has_access' => true
    216217                        );
    217218                }
     
    227228         */
    228229        public function setup_admin_bar( $wp_admin_nav = array() ) {
    229                 $bp = buddypress();
    230230
    231231                // Menus for logged in user
     
    233233
    234234                        // Setup the logged in user variables
    235                         $user_domain   = bp_loggedin_user_domain();
    236                         $messages_link = trailingslashit( $user_domain . $this->slug );
     235                        $messages_link = trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() );
    237236
    238237                        // Unread message count
    239238                        $count = messages_get_unread_count();
    240239                        if ( !empty( $count ) ) {
    241                                 $title = sprintf( __( 'Messages <span class="count">%s</span>', 'buddypress' ), number_format_i18n( $count ) );
    242                                 $inbox = sprintf( __( 'Inbox <span class="count">%s</span>',    'buddypress' ), number_format_i18n( $count ) );
     240                                $title = sprintf( __( 'Messages <span class="count">%s</span>', 'buddypress' ), bp_core_number_format( $count ) );
     241                                $inbox = sprintf( __( 'Inbox <span class="count">%s</span>',    'buddypress' ), bp_core_number_format( $count ) );
    243242                        } else {
    244243                                $title = __( 'Messages', 'buddypress' );
     
    248247                        // Add main Messages menu
    249248                        $wp_admin_nav[] = array(
    250                                 'parent' => $bp->my_account_menu_id,
     249                                'parent' => buddypress()->my_account_menu_id,
    251250                                'id'     => 'my-account-' . $this->id,
    252251                                'title'  => $title,
    253                                 'href'   => trailingslashit( $messages_link )
     252                                'href'   => $messages_link
    254253                        );
    255254
     
    259258                                'id'     => 'my-account-' . $this->id . '-inbox',
    260259                                'title'  => $inbox,
    261                                 'href'   => trailingslashit( $messages_link . 'inbox' )
     260                                'href'   => $messages_link
    262261                        );
    263262
     
    306305         */
    307306        public function setup_title() {
    308                 $bp = buddypress();
    309307
    310308                if ( bp_is_messages_component() ) {
     309                        $bp = buddypress();
     310
    311311                        if ( bp_is_my_profile() ) {
    312312                                $bp->bp_options_title = __( 'My Messages', 'buddypress' );
  • trunk/src/bp-notifications/bp-notifications-loader.php

    r9819 r9936  
    6868
    6969                // Define a slug, if necessary
    70                 if ( !defined( 'BP_NOTIFICATIONS_SLUG' ) ) {
     70                if ( ! defined( 'BP_NOTIFICATIONS_SLUG' ) ) {
    7171                        define( 'BP_NOTIFICATIONS_SLUG', $this->id );
    7272                }
     
    104104        public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
    105105
    106                 // Only grab count if we're on a user page and current user has access
    107                 if ( bp_is_user() && bp_user_has_access() ) {
    108                         $count    = bp_notifications_get_unread_notification_count( bp_displayed_user_id() );
    109                         $class    = ( 0 === $count ) ? 'no-count' : 'count';
    110                         $nav_name = sprintf( _x( 'Notifications <span class="%s">%s</span>', 'Profile screen nav', 'buddypress' ), esc_attr( $class ), number_format_i18n( $count ) );
    111                 } else {
    112                         $nav_name = _x( 'Notifications', 'Profile screen nav', 'buddypress' );
    113                 }
    114 
    115                 // Add 'Notifications' to the main navigation
    116                 $main_nav = array(
    117                         'name'                    => $nav_name,
    118                         'slug'                    => $this->slug,
    119                         'position'                => 30,
    120                         'show_for_displayed_user' => bp_core_can_edit_settings(),
    121                         'screen_function'         => 'bp_notifications_screen_unread',
    122                         'default_subnav_slug'     => 'unread',
    123                         'item_css_id'             => $this->id,
    124                 );
    125 
    126106                // Determine user to use
    127107                if ( bp_displayed_user_domain() ) {
     
    133113                }
    134114
    135                 $notifications_link = trailingslashit( $user_domain . bp_get_notifications_slug() );
     115                $access             = bp_core_can_edit_settings();
     116                $slug               = bp_get_notifications_slug();
     117                $notifications_link = trailingslashit( $user_domain . $slug );
     118
     119                // Only grab count if we're on a user page and current user has access
     120                if ( bp_is_user() && bp_user_has_access() ) {
     121                        $count    = bp_notifications_get_unread_notification_count( bp_displayed_user_id() );
     122                        $class    = ( 0 === $count ) ? 'no-count' : 'count';
     123                        $nav_name = sprintf( _x( 'Notifications <span class="%s">%s</span>', 'Profile screen nav', 'buddypress' ), esc_attr( $class ), bp_core_number_format( $count ) );
     124                } else {
     125                        $nav_name = _x( 'Notifications', 'Profile screen nav', 'buddypress' );
     126                }
     127
     128                // Add 'Notifications' to the main navigation
     129                $main_nav = array(
     130                        'name'                    => $nav_name,
     131                        'slug'                    => $slug,
     132                        'position'                => 30,
     133                        'show_for_displayed_user' => $access,
     134                        'screen_function'         => 'bp_notifications_screen_unread',
     135                        'default_subnav_slug'     => 'unread',
     136                        'item_css_id'             => $this->id,
     137                );
    136138
    137139                // Add the subnav items to the notifications nav item
     
    140142                        'slug'            => 'unread',
    141143                        'parent_url'      => $notifications_link,
    142                         'parent_slug'     => bp_get_notifications_slug(),
     144                        'parent_slug'     => $slug,
    143145                        'screen_function' => 'bp_notifications_screen_unread',
    144146                        'position'        => 10,
    145147                        'item_css_id'     => 'notifications-my-notifications',
    146                         'user_has_access' => bp_core_can_edit_settings(),
     148                        'user_has_access' => $access,
    147149                );
    148150
     
    151153                        'slug'            => 'read',
    152154                        'parent_url'      => $notifications_link,
    153                         'parent_slug'     => bp_get_notifications_slug(),
     155                        'parent_slug'     => $slug,
    154156                        'screen_function' => 'bp_notifications_screen_read',
    155157                        'position'        => 20,
    156                         'user_has_access' => bp_core_can_edit_settings(),
     158                        'user_has_access' => $access,
    157159                );
    158160
     
    177179
    178180                        // Setup the logged in user variables
    179                         $notifications_link = trailingslashit( bp_loggedin_user_domain() . $this->slug );
     181                        $notifications_link = trailingslashit( bp_loggedin_user_domain() . bp_get_notifications_slug() );
    180182
    181183                        // Pending notification requests
    182184                        $count = bp_notifications_get_unread_notification_count( bp_loggedin_user_id() );
    183185                        if ( ! empty( $count ) ) {
    184                                 $title  = sprintf( _x( 'Notifications <span class="count">%s</span>', 'My Account Notification pending', 'buddypress' ), number_format_i18n( $count ) );
    185                                 $unread = sprintf( _x( 'Unread <span class="count">%s</span>', 'My Account Notification pending', 'buddypress' ), number_format_i18n( $count ) );
     186                                $title  = sprintf( _x( 'Notifications <span class="count">%s</span>', 'My Account Notification pending', 'buddypress' ), bp_core_number_format( $count ) );
     187                                $unread = sprintf( _x( 'Unread <span class="count">%s</span>',        'My Account Notification pending', 'buddypress' ), bp_core_number_format( $count ) );
    186188                        } else {
    187                                 $title  = _x( 'Notifications', 'My Account Notification', 'buddypress' );
    188                                 $unread = _x( 'Unread', 'My Account Notification sub nav', 'buddypress' );
     189                                $title  = _x( 'Notifications', 'My Account Notification',         'buddypress' );
     190                                $unread = _x( 'Unread',        'My Account Notification sub nav', 'buddypress' );
    189191                        }
    190192
     
    194196                                'id'     => 'my-account-' . $this->id,
    195197                                'title'  => $title,
    196                                 'href'   => trailingslashit( $notifications_link ),
     198                                'href'   => $notifications_link
    197199                        );
    198200
     
    202204                                'id'     => 'my-account-' . $this->id . '-unread',
    203205                                'title'  => $unread,
    204                                 'href'   => trailingslashit( $notifications_link ),
     206                                'href'   => $notifications_link
    205207                        );
    206208
     
    223225         */
    224226        public function setup_title() {
    225                 $bp = buddypress();
    226227
    227228                // Adjust title
    228229                if ( bp_is_notifications_component() ) {
     230                        $bp = buddypress();
     231
    229232                        if ( bp_is_my_profile() ) {
    230233                                $bp->bp_options_title = __( 'Notifications', 'buddypress' );
  • trunk/src/bp-settings/bp-settings-loader.php

    r9819 r9936  
    3131        /**
    3232         * Include files
    33          *
    34          * @global BuddyPress $bp The one true BuddyPress instance
    3533         */
    3634        public function includes( $includes = array() ) {
     
    5452
    5553                // Define a slug, if necessary
    56                 if ( !defined( 'BP_SETTINGS_SLUG' ) )
     54                if ( ! defined( 'BP_SETTINGS_SLUG' ) ) {
    5755                        define( 'BP_SETTINGS_SLUG', $this->id );
     56                }
    5857
    5958                // All globals for settings component.
     
    6867         */
    6968        public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
    70 
    71                 // Add the settings navigation item
    72                 $main_nav = array(
    73                         'name'                    => __( 'Settings', 'buddypress' ),
    74                         'slug'                    => $this->slug,
    75                         'position'                => 100,
    76                         'show_for_displayed_user' => bp_core_can_edit_settings(),
    77                         'screen_function'         => 'bp_settings_screen_general',
    78                         'default_subnav_slug'     => 'general'
    79                 );
    8069
    8170                // Determine user to use
     
    8877                }
    8978
    90                 $settings_link = trailingslashit( $user_domain . $this->slug );
     79                $access        = bp_core_can_edit_settings();
     80                $slug          = bp_get_settings_slug();
     81                $settings_link = trailingslashit( $user_domain . $slug );
     82
     83                // Add the settings navigation item
     84                $main_nav = array(
     85                        'name'                    => __( 'Settings', 'buddypress' ),
     86                        'slug'                    => $slug,
     87                        'position'                => 100,
     88                        'show_for_displayed_user' => $access,
     89                        'screen_function'         => 'bp_settings_screen_general',
     90                        'default_subnav_slug'     => 'general'
     91                );
    9192
    9293                // Add General Settings nav item
     
    9596                        'slug'            => 'general',
    9697                        'parent_url'      => $settings_link,
    97                         'parent_slug'     => $this->slug,
     98                        'parent_slug'     => $slug,
    9899                        'screen_function' => 'bp_settings_screen_general',
    99100                        'position'        => 10,
    100                         'user_has_access' => bp_core_can_edit_settings()
     101                        'user_has_access' => $access
    101102                );
    102103
     
    107108                        'slug'            => 'notifications',
    108109                        'parent_url'      => $settings_link,
    109                         'parent_slug'     => $this->slug,
     110                        'parent_slug'     => $slug,
    110111                        'screen_function' => 'bp_settings_screen_notification',
    111112                        'position'        => 20,
    112                         'user_has_access' => bp_core_can_edit_settings()
     113                        'user_has_access' => $access
    113114                );
    114115
     
    119120                                'slug'            => 'capabilities',
    120121                                'parent_url'      => $settings_link,
    121                                 'parent_slug'     => $this->slug,
     122                                'parent_slug'     => $slug,
    122123                                'screen_function' => 'bp_settings_screen_capabilities',
    123124                                'position'        => 80,
     
    132133                                'slug'            => 'delete-account',
    133134                                'parent_url'      => $settings_link,
    134                                 'parent_slug'     => $this->slug,
     135                                'parent_slug'     => $slug,
    135136                                'screen_function' => 'bp_settings_screen_delete_account',
    136137                                'position'        => 90,
     
    147148        public function setup_admin_bar( $wp_admin_nav = array() ) {
    148149
    149                 // The instance
    150                 $bp = buddypress();
    151 
    152150                // Menus for logged in user
    153151                if ( is_user_logged_in() ) {
    154152
    155153                        // Setup the logged in user variables
    156                         $user_domain   = bp_loggedin_user_domain();
    157                         $settings_link = trailingslashit( $user_domain . $this->slug );
     154                        $settings_link = trailingslashit( bp_loggedin_user_domain() . bp_get_settings_slug() );
    158155
    159156                        // Add main Settings menu
    160157                        $wp_admin_nav[] = array(
    161                                 'parent' => $bp->my_account_menu_id,
     158                                'parent' => buddypress()->my_account_menu_id,
    162159                                'id'     => 'my-account-' . $this->id,
    163160                                'title'  => __( 'Settings', 'buddypress' ),
    164                                 'href'   => trailingslashit( $settings_link )
     161                                'href'   => $settings_link
    165162                        );
    166163
     
    170167                                'id'     => 'my-account-' . $this->id . '-general',
    171168                                'title'  => __( 'General', 'buddypress' ),
    172                                 'href'   => trailingslashit( $settings_link . 'general' )
     169                                'href'   => $settings_link
    173170                        );
    174171
  • trunk/src/bp-xprofile/bp-xprofile-activity.php

    r9819 r9936  
    9696        // your language doesn't have this restriction, feel free to use a more
    9797        // natural translation.
    98         $profile_link = trailingslashit( bp_core_get_user_domain( $activity->user_id ) . buddypress()->profile->slug );
     98        $profile_link = trailingslashit( bp_core_get_user_domain( $activity->user_id ) . bp_get_profile_slug() );
    9999        $action       = sprintf( __( '%s&#8217;s profile was updated', 'buddypress' ), '<a href="' . $profile_link . '">' . bp_core_get_user_displayname( $activity->user_id ) . '</a>' );
    100100
     
    318318
    319319        // If we've reached this point, assemble and post the activity item
    320         $profile_link = trailingslashit( bp_core_get_user_domain( $user_id ) . buddypress()->profile->slug );
     320        $profile_link = trailingslashit( bp_core_get_user_domain( $user_id ) . bp_get_profile_slug() );
    321321
    322322        return (bool) xprofile_record_activity( array(
  • trunk/src/bp-xprofile/bp-xprofile-loader.php

    r9819 r9936  
    172172        public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
    173173
    174                 $sub_nav = array();
     174                // Determine user to use
     175                if ( bp_displayed_user_domain() ) {
     176                        $user_domain = bp_displayed_user_domain();
     177                } elseif ( bp_loggedin_user_domain() ) {
     178                        $user_domain = bp_loggedin_user_domain();
     179                } else {
     180                        return;
     181                }
     182
     183                $slug         =
     184                $profile_link = trailingslashit( $user_domain . $this->slug );
    175185
    176186                // Add 'Profile' to the main navigation
     
    183193                        'item_css_id'         => $this->id
    184194                );
    185 
    186                 // Determine user to use
    187                 if ( bp_displayed_user_domain() ) {
    188                         $user_domain = bp_displayed_user_domain();
    189                 } elseif ( bp_loggedin_user_domain() ) {
    190                         $user_domain = bp_loggedin_user_domain();
    191                 } else {
    192                         return;
    193                 }
    194 
    195                 $profile_link = trailingslashit( $user_domain . $this->slug );
    196195
    197196                // Add the subnav items to the profile
     
    276275         */
    277276        public function setup_admin_bar( $wp_admin_nav = array() ) {
    278                 $bp = buddypress();
    279 
    280                 // Prevent debug notices
    281                 $wp_admin_nav = array();
    282277
    283278                // Menus for logged in user
     
    285280
    286281                        // Profile link
    287                         $profile_link = trailingslashit( bp_loggedin_user_domain() . $this->slug );
     282                        $profile_link = trailingslashit( bp_loggedin_user_domain() . bp_get_profile_slug() );
    288283
    289284                        // Add the "Profile" sub menu
    290285                        $wp_admin_nav[] = array(
    291                                 'parent' => $bp->my_account_menu_id,
     286                                'parent' => buddypress()->my_account_menu_id,
    292287                                'id'     => 'my-account-' . $this->id,
    293288                                'title'  => _x( 'Profile', 'My Account Profile', 'buddypress' ),
    294                                 'href'   => trailingslashit( $profile_link )
     289                                'href'   => $profile_link
    295290                        );
    296291
     
    300295                                'id'     => 'my-account-' . $this->id . '-public',
    301296                                'title'  => _x( 'View', 'My Account Profile sub nav', 'buddypress' ),
    302                                 'href'   => trailingslashit( $profile_link . 'public' )
     297                                'href'   => $profile_link
    303298                        );
    304299
     
    339334         */
    340335        public function setup_title() {
    341                 $bp = buddypress();
    342336
    343337                if ( bp_is_profile_component() ) {
     338                        $bp = buddypress();
     339
    344340                        if ( bp_is_my_profile() ) {
    345341                                $bp->bp_options_title = _x( 'My Profile', 'Page title', 'buddypress' );
     
    384380         */
    385381        public function setup_settings_admin_nav( $wp_admin_nav ) {
     382
    386383                // Setup the logged in user variables
    387384                $settings_link = trailingslashit( bp_loggedin_user_domain() . bp_get_settings_slug() );
  • trunk/src/bp-xprofile/bp-xprofile-screens.php

    r9819 r9936  
    5353function xprofile_screen_edit_profile() {
    5454
    55         if ( !bp_is_my_profile() && !bp_current_user_can( 'bp_moderate' ) )
     55        if ( ! bp_is_my_profile() && ! bp_current_user_can( 'bp_moderate' ) ) {
    5656                return false;
    57 
    58         $bp = buddypress();
     57        }
    5958
    6059        // Make sure a group is set.
    61         if ( !bp_action_variable( 1 ) )
    62                 bp_core_redirect( trailingslashit( bp_displayed_user_domain() . $bp->profile->slug . '/edit/group/1' ) );
     60        if ( ! bp_action_variable( 1 ) ) {
     61                bp_core_redirect( trailingslashit( bp_displayed_user_domain() . bp_get_profile_slug() . '/edit/group/1' ) );
     62        }
    6363
    6464        // Check the field group exists
    65         if ( !bp_is_action_variable( 'group' ) || !xprofile_get_field_group( bp_action_variable( 1 ) ) ) {
     65        if ( ! bp_is_action_variable( 'group' ) || ! xprofile_get_field_group( bp_action_variable( 1 ) ) ) {
    6666                bp_do_404();
    6767                return;
     
    7878
    7979                // Check we have field ID's
    80                 if ( empty( $_POST['field_ids'] ) )
    81                         bp_core_redirect( trailingslashit( bp_displayed_user_domain() . $bp->profile->slug . '/edit/group/' . bp_action_variable( 1 ) ) );
     80                if ( empty( $_POST['field_ids'] ) ) {
     81                        bp_core_redirect( trailingslashit( bp_displayed_user_domain() . bp_get_profile_slug() . '/edit/group/' . bp_action_variable( 1 ) ) );
     82                }
    8283
    8384                // Explode the posted field IDs into an array so we know which
     
    181182
    182183                        // Redirect back to the edit screen to display the updates and message
    183                         bp_core_redirect( trailingslashit( bp_displayed_user_domain() . $bp->profile->slug . '/edit/group/' . bp_action_variable( 1 ) ) );
     184                        bp_core_redirect( trailingslashit( bp_displayed_user_domain() . bp_get_profile_slug() . '/edit/group/' . bp_action_variable( 1 ) ) );
    184185                }
    185186        }
     
    212213
    213214        // Bail if not the correct screen
    214         if ( !bp_is_my_profile() && !bp_current_user_can( 'bp_moderate' ) )
     215        if ( ! bp_is_my_profile() && ! bp_current_user_can( 'bp_moderate' ) ) {
    215216                return false;
     217        }
    216218
    217219        // Bail if there are action variables
     
    223225        $bp = buddypress();
    224226
    225         if ( ! isset( $bp->avatar_admin ) )
     227        if ( ! isset( $bp->avatar_admin ) ) {
    226228                $bp->avatar_admin = new stdClass();
     229        }
    227230
    228231        $bp->avatar_admin->step = 'upload-image';
  • trunk/src/bp-xprofile/bp-xprofile-template.php

    r9819 r9936  
    522522                 *                      profile group edit form.
    523523                 */
    524                 return apply_filters( 'bp_get_the_profile_group_edit_form_action', trailingslashit( bp_displayed_user_domain() . $bp->profile->slug . '/edit/group/' . $group->id ) );
     524                return apply_filters( 'bp_get_the_profile_group_edit_form_action', trailingslashit( bp_displayed_user_domain() . bp_get_profile_slug() . '/edit/group/' . $group->id ) );
    525525        }
    526526
     
    10291029
    10301030                // Build the profile field group link
    1031                 $link   = trailingslashit( bp_displayed_user_domain() . buddypress()->profile->slug . '/edit/group/' . $groups[ $i ]->id );
     1031                $link   = trailingslashit( bp_displayed_user_domain() . bp_get_profile_slug() . '/edit/group/' . $groups[ $i ]->id );
    10321032
    10331033                // Add tab to end of tabs array
     
    11361136}
    11371137        function bp_get_avatar_delete_link() {
    1138                 $bp = buddypress();
    11391138
    11401139                /**
     
    11451144                 * @param string $value Nonced URL used for deleting an avatar.
    11461145                 */
    1147                 return apply_filters( 'bp_get_avatar_delete_link', wp_nonce_url( bp_displayed_user_domain() . $bp->profile->slug . '/change-avatar/delete-avatar/', 'bp_delete_avatar_link' ) );
     1146                return apply_filters( 'bp_get_avatar_delete_link', wp_nonce_url( bp_displayed_user_domain() . bp_get_profile_slug() . '/change-avatar/delete-avatar/', 'bp_delete_avatar_link' ) );
    11481147        }
    11491148
    11501149function bp_edit_profile_button() {
    1151         $bp = buddypress();
    1152 
    11531150        bp_button( array(
    11541151                'id'                => 'edit_profile',
     
    11561153                'must_be_logged_in' => true,
    11571154                'block_self'        => true,
    1158                 'link_href'         => trailingslashit( bp_displayed_user_domain() . $bp->profile->slug . '/edit' ),
     1155                'link_href'         => trailingslashit( bp_displayed_user_domain() . bp_get_profile_slug() . '/edit' ),
    11591156                'link_class'        => 'edit',
    11601157                'link_text'         => __( 'Edit Profile', 'buddypress' ),
  • trunk/tests/phpunit/testcases/routing/xprofile.php

    r9819 r9936  
    2020
    2121        function test_member_profile() {
    22                 $this->go_to( bp_core_get_user_domain( bp_loggedin_user_id() ) . buddypress()->profile->slug );
     22                $this->go_to( bp_core_get_user_domain( bp_loggedin_user_id() ) . bp_get_profile_slug() );
    2323                $this->assertTrue( bp_is_user_profile() );
    2424        }
    2525
    2626        function test_member_profile_edit() {
    27                 $this->go_to( bp_core_get_user_domain( bp_loggedin_user_id() ) . buddypress()->profile->slug . '/edit' );
     27                $this->go_to( bp_core_get_user_domain( bp_loggedin_user_id() ) . bp_get_profile_slug() . '/edit' );
    2828                $this->assertTrue( bp_is_user_profile_edit() );
    2929        }
    3030
    3131        function test_member_profile_change_avatar() {
    32                 $this->go_to( bp_core_get_user_domain( bp_loggedin_user_id() ) . buddypress()->profile->slug . '/change-avatar' );
     32                $this->go_to( bp_core_get_user_domain( bp_loggedin_user_id() ) . bp_get_profile_slug() . '/change-avatar' );
    3333                $this->assertTrue( bp_is_user_change_avatar() );
    3434        }
  • trunk/tests/phpunit/testcases/xprofile/activity.php

    r9819 r9936  
    304304                ) );
    305305
    306                 $expected = sprintf( __( '%s&#8217;s profile was updated', 'buddypress' ), '<a href="' . bp_core_get_user_domain( $u ) . buddypress()->profile->slug . '/">' . bp_core_get_user_displayname( $u ) . '</a>' );
     306                $expected = sprintf( __( '%s&#8217;s profile was updated', 'buddypress' ), '<a href="' . bp_core_get_user_domain( $u ) . bp_get_profile_slug() . '/">' . bp_core_get_user_displayname( $u ) . '</a>' );
    307307
    308308                $a_obj = new BP_Activity_Activity( $a );
Note: See TracChangeset for help on using the changeset viewer.