Skip to:
Content

BuddyPress.org

Changeset 2695 for trunk/bp-core.php


Ignore:
Timestamp:
02/12/2010 12:31:49 PM (17 years ago)
Author:
apeatling
Message:

Fixing the use of deprecated template tags in bp-default. Merged the fetching of BP runtime settings into one query to significantly reduce the number of run time database hits. Fixed #1916

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core.php

    r2678 r2695  
    2323        define( 'BP_ROOT_BLOG', 1 );
    2424
    25 /* Define the user and usermeta table names, useful if you are using custom or shared tables */
     25/* Define the user and usermeta table names, useful if you are using custom or shared tables. */
    2626if ( !defined( 'CUSTOM_USER_TABLE' ) )
    2727        define( 'CUSTOM_USER_TABLE', $wpdb->base_prefix . 'users' );
     
    4040require ( BP_PLUGIN_DIR . '/bp-core/bp-core-notifications.php' );
    4141require ( BP_PLUGIN_DIR . '/bp-core/bp-core-signup.php' );
    42 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-activation.php' );
    43 
    44 /* If BP_DISABLE_ADMIN_BAR is defined, do not load the global admin bar */
     42
     43/* Multisite includes built in account activation support. */
     44if ( bp_core_is_multisite() )
     45        require ( BP_PLUGIN_DIR . '/bp-core/bp-core-activation.php' );
     46
     47/* If BP_DISABLE_ADMIN_BAR is defined, do not load the global admin bar. */
    4548if ( !defined( 'BP_DISABLE_ADMIN_BAR' ) )
    4649        require ( BP_PLUGIN_DIR . '/bp-core/bp-core-adminbar.php' );
     
    6164if ( !defined( 'BP_SEARCH_SLUG' ) )
    6265        define( 'BP_SEARCH_SLUG', 'search' );
    63 
    64 /* Define the slug for the search page */
    65 if ( !defined( 'BP_HOME_BLOG_SLUG' ) )
    66         define( 'BP_HOME_BLOG_SLUG', 'blog' );
    6766
    6867/* Register BuddyPress themes contained within the bp-theme folder */
     
    142141        }
    143142
     143        /* Fetches all of the core database based BuddyPress settings in one foul swoop */
     144        $bp->site_options = bp_core_get_site_options();
     145
    144146        /* Sets up the array container for the component navigation rendered by bp_get_nav() */
    145147        $bp->bp_nav = array();
     
    148150        $bp->bp_options_nav = array();
    149151
    150         /* Sets up container used for the title of the current component option and rendered by bp_get_options_title() */
    151         $bp->bp_options_title = '';
    152 
    153         /* Sets up container used for the avatar of the current component being viewed. Rendered by bp_get_options_avatar() */
    154         $bp->bp_options_avatar = '';
    155 
    156152        /* Contains an array of all the active components. The key is the slug, value the internal ID of the component */
    157153        $bp->active_components = array();
    158154
    159155        /* Fetches the default Gravatar image to use if the user/group/blog has no avatar or gravatar */
    160         $bp->grav_default->user = apply_filters( 'bp_user_gravatar_default', get_site_option( 'user-avatar-default' ) );
     156        $bp->grav_default->user = apply_filters( 'bp_user_gravatar_default', $bp->site_options['user-avatar-default'] );
    161157        $bp->grav_default->group = apply_filters( 'bp_group_gravatar_default', 'identicon' );
    162158        $bp->grav_default->blog = apply_filters( 'bp_blog_gravatar_default', 'identicon' );
     
    183179}
    184180add_action( 'bp_setup_globals', 'bp_core_setup_globals' );
    185 add_action( '_admin_menu', 'bp_core_setup_globals', 2 ); // must be _admin_menu hook.
    186 
    187181
    188182/**
     
    202196        bp_core_add_root_component( BP_ACTIVATION_SLUG );
    203197        bp_core_add_root_component( BP_SEARCH_SLUG );
    204         bp_core_add_root_component( BP_HOME_BLOG_SLUG );
    205198}
    206199add_action( 'plugins_loaded', 'bp_core_setup_root_uris', 2 );
     
    274267
    275268        /* Need to check db tables exist, activate hook no-worky in mu-plugins folder. */
    276         if ( get_site_option('bp-core-db-version') < BP_CORE_DB_VERSION )
     269        if ( $bp->site_options['bp-core-db-version'] < BP_CORE_DB_VERSION )
    277270                bp_core_install();
    278271}
     
    558551        return apply_filters( 'bp_core_get_user_domain', $domain );
    559552}
    560 /* DEPRECATED */
    561 function bp_core_get_userurl( $uid ) { return bp_core_get_user_domain( $uid ); }
    562553
    563554/**
     
    10771068 * @return str The link text based on passed parameters.
    10781069 */
    1079 function bp_core_get_userlink( $user_id, $no_anchor = false, $just_link = false, $deprecated = false, $with_s = false ) {
     1070function bp_core_get_userlink( $user_id, $no_anchor = false, $just_link = false ) {
    10801071        $display_name = bp_core_get_user_displayname( $user_id );
    10811072
     
    10831074                return false;
    10841075
    1085         if ( $with_s )
    1086                 $display_name = sprintf( __( "%s's", 'buddypress' ), $display_name );
    1087 
    10881076        if ( $no_anchor )
    10891077                return $display_name;
     
    10951083                return $url;
    10961084
    1097         return apply_filters( 'bp_core_get_userlink', '<a href="' . $url . '">' . $display_name . '</a>', $user_id );
     1085        return apply_filters( 'bp_core_get_userlink', '<a href="' . $url . '" title="' . $display_name . '">' . $display_name . '</a>', $user_id );
    10981086}
    10991087
     
    15331521
    15341522        return apply_filters( 'bp_core_get_site_path', $site_path );
     1523}
     1524
     1525/**
     1526 * bp_core_get_site_options()
     1527 *
     1528 * BuddyPress uses site options to store configuration settings. Many of these settings are needed
     1529 * at run time. Instead of fetching them all and adding many initial queries to each page load, let's fetch
     1530 * them all in one go.
     1531 *
     1532 * @package BuddyPress Core
     1533 */
     1534function bp_core_get_site_options() {
     1535        global $bp, $wpdb;
     1536
     1537        $options = apply_filters( 'bp_core_site_options', array(
     1538                'bp-core-db-version',
     1539                'bp-activity-db-version',
     1540                'bp-blogs-db-version',
     1541                'bp-friends-db-version',
     1542                'bp-groups-db-version',
     1543                'bp-messages-db-version',
     1544                'bp-xprofile-db-version',
     1545                'bp-deactivated-components',
     1546                'bp-blogs-first-install',
     1547                'bp-disable-blog-forum-comments',
     1548                'bp-xprofile-base-group-name',
     1549                'bp-xprofile-fullname-field-name',
     1550                'bp-hide-loggedout-adminbar',
     1551                'bp-disable-profile-sync',
     1552                'bp-disable-avatar-uploads',
     1553                'bp-disable-account-deletion',
     1554                'bp-disable-forum-directory',
     1555                'bp-disable-blogforum-comments',
     1556                'bb-config-location',
     1557
     1558                /* Useful WordPress settings used often */
     1559                'user-avatar-default',
     1560                'tags_blog_id',
     1561                'registration',
     1562                'fileupload_maxk'
     1563        ) );
     1564
     1565        $meta_keys = "'" . implode( "','", (array)$options ) ."'";
     1566
     1567        if ( bp_core_is_multisite() )
     1568                $meta = $wpdb->get_results( "SELECT meta_key AS name, meta_value AS value FROM {$wpdb->sitemeta} WHERE meta_key IN ({$meta_keys})" );
     1569        else
     1570                $meta = $wpdb->get_results( "SELECT option_name AS name, option_value AS value FROM {$wpdb->options} WHERE option_name IN ({$meta_keys})" );
     1571
     1572        $site_options = array();
     1573        if ( !empty( $meta ) ) {
     1574                foreach( (array)$meta as $meta_item )
     1575                        $site_options[$meta_item->name] = $meta_item->value;
     1576        }
     1577
     1578        return apply_filters( 'bp_core_get_site_options', $site_options );
    15351579}
    15361580
Note: See TracChangeset for help on using the changeset viewer.