Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/11/2015 06:53:59 AM (9 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.