Skip to:
Content

BuddyPress.org

Changeset 4378


Ignore:
Timestamp:
05/16/2011 10:22:39 PM (14 years ago)
Author:
boonebgorges
Message:

Refactors user_meta key filtering to remove overhead in the bp global. Fixes #2952. Props nacin.

Location:
trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity/bp-activity-classes.php

    r4372 r4378  
    524524
    525525    function total_favorite_count( $user_id ) {
    526         if ( !$favorite_activity_entries = get_user_meta( $user_id, bp_get_user_meta_key( 'favorite_activities' ), true ) )
     526        if ( !$favorite_activity_entries = get_user_meta( $user_id, bp_get_user_meta_key( 'bp_favorite_activities' ), true ) )
    527527            return 0;
    528528
  • trunk/bp-activity/bp-activity-functions.php

    r4372 r4378  
    191191
    192192    // Get favorites for user
    193     $favs = get_user_meta( $user_id, bp_get_user_meta_key( 'favorite_activities' ), true );
     193    $favs = get_user_meta( $user_id, bp_get_user_meta_key( 'bp_favorite_activities' ), true );
    194194
    195195    return apply_filters( 'bp_activity_get_user_favorites', $favs );
     
    216216
    217217    // Update the user's personal favorites
    218     $my_favs   = get_user_meta( $bp->loggedin_user->id, bp_get_user_meta_key( 'favorite_activities' ), true );
     218    $my_favs   = get_user_meta( $bp->loggedin_user->id, bp_get_user_meta_key( 'bp_favorite_activities' ), true );
    219219    $my_favs[] = $activity_id;
    220220
     
    224224
    225225    // Update user meta
    226     update_user_meta( $bp->loggedin_user->id, bp_get_user_meta_key( 'favorite_activities' ), $my_favs );
     226    update_user_meta( $bp->loggedin_user->id, bp_get_user_meta_key( 'bp_favorite_activities' ), $my_favs );
    227227
    228228    // Update activity meta counts
     
    256256
    257257    // Remove the fav from the user's favs
    258     $my_favs = get_user_meta( $user_id, bp_get_user_meta_key( 'favorite_activities' ), true );
     258    $my_favs = get_user_meta( $user_id, bp_get_user_meta_key( 'bp_favorite_activities' ), true );
    259259    $my_favs = array_flip( (array) $my_favs );
    260260    unset( $my_favs[$activity_id] );
     
    268268
    269269            // Update users favorites
    270             if ( update_user_meta( $user_id, bp_get_user_meta_key( 'favorite_activities' ), $my_favs ) ) {
     270            if ( update_user_meta( $user_id, bp_get_user_meta_key( 'bp_favorite_activities' ), $my_favs ) ) {
    271271
    272272                // Execute additional code
     
    500500
    501501    // Remove any usermeta
    502     delete_user_meta( $user_id, bp_get_user_meta_key( 'latest_update' ) );
    503     delete_user_meta( $user_id, bp_get_user_meta_key( 'favorite_activities' ) );
     502    delete_user_meta( $user_id, bp_get_user_meta_key( 'bp_latest_update' ) );
     503    delete_user_meta( $user_id, bp_get_user_meta_key( 'bp_favorite_activities' ) );
    504504
    505505    // Execute additional code
     
    676676
    677677    // Add this update to the "latest update" usermeta so it can be fetched anywhere.
    678     update_user_meta( $bp->loggedin_user->id, bp_get_user_meta_key( 'latest_update' ), array( 'id' => $activity_id, 'content' => wp_filter_kses( $content ) ) );
     678    update_user_meta( $bp->loggedin_user->id, bp_get_user_meta_key( 'bp_latest_update' ), array( 'id' => $activity_id, 'content' => wp_filter_kses( $content ) ) );
    679679
    680680    // Require the notifications code so email notifications can be set on the 'bp_activity_posted_update' action.
     
    808808    do_action( 'bp_before_activity_delete', $args );
    809809
    810     $latest_update = get_user_meta( $user_id, bp_get_user_meta_key( 'latest_update' ), true );
     810    $latest_update = get_user_meta( $user_id, bp_get_user_meta_key( 'bp_latest_update' ), true );
    811811    if ( !empty( $latest_update ) ) {
    812812        if ( in_array( (int)$latest_update['id'], (array)$activity_ids_deleted ) )
    813             delete_user_meta( $user_id, bp_get_user_meta_key( 'latest_update' ) );
     813            delete_user_meta( $user_id, bp_get_user_meta_key( 'bp_latest_update' ) );
    814814    }
    815815
  • trunk/bp-activity/bp-activity-loader.php

    r4372 r4378  
    6868            'table_name_meta' => $bp->table_prefix . 'bp_activity_meta',
    6969        );
    70        
    71         // User meta keys
    72         $user_meta_keys = array(
    73             'new_mention_count'             => 'bp_new_mention_count',
    74             'new_mentions'              => 'bp_new_mentions',
    75             'favorite_activities'           => 'bp_favorite_activities',
    76             'latest_update'             => 'bp_latest_update',
    77             'notification_activity_new_mention' => 'notification_activity_new_mention',
    78             'notification_activity_new_reply'   => 'notification_activity_new_reply'
    79         );
    8070
    8171        // All globals for activity component.
     
    8676            'root_slug'             => isset( $bp->pages->activity->slug ) ? $bp->pages->activity->slug : BP_ACTIVITY_SLUG,
    8777            'search_string'         => __( 'Search Activity...', 'buddypress' ),
    88             'global_tables'         => $global_tables,
    89             'user_meta_keys'    => $user_meta_keys
     78            'global_tables'         => $global_tables
    9079        );
    9180
  • trunk/bp-activity/bp-activity-template.php

    r4376 r4378  
    9494
    9595        // Get an array of the logged in user's favorite activities
    96         $this->my_favs = maybe_unserialize( get_user_meta( $bp->loggedin_user->id, bp_get_user_meta_key( 'favorite_activities' ), true ) );
     96        $this->my_favs = maybe_unserialize( get_user_meta( $bp->loggedin_user->id, bp_get_user_meta_key( 'bp_favorite_activities' ), true ) );
    9797
    9898        // Fetch specific activity items based on ID's
     
    10261026            $user_id = $bp->displayed_user->id;
    10271027
    1028         if ( !$update = get_user_meta( $user_id, bp_get_user_meta_key( 'latest_update' ), true ) )
     1028        if ( !$update = get_user_meta( $user_id, bp_get_user_meta_key( 'bp_latest_update' ), true ) )
    10291029            return false;
    10301030
     
    11441144        global $bp;
    11451145       
    1146         return apply_filters( 'bp_get_total_mention_count_for_user', get_user_meta( $user_id, bp_get_user_meta_key( 'new_mention_count' ), true ) );
     1146        return apply_filters( 'bp_get_total_mention_count_for_user', get_user_meta( $user_id, bp_get_user_meta_key( 'bp_new_mention_count' ), true ) );
    11471147    }
    11481148
  • trunk/bp-core/bp-core-classes.php

    r4372 r4378  
    432432
    433433        // Fetch the user's latest update
    434         $user_update = $wpdb->get_results( "SELECT user_id as id, meta_value as latest_update FROM " . CUSTOM_USER_META_TABLE . " WHERE meta_key = 'bp_latest_update' AND user_id IN ( {$user_ids} )" );
     434        $user_update = $wpdb->get_results( "SELECT user_id as id, meta_value as latest_update FROM " . CUSTOM_USER_META_TABLE . " WHERE meta_key = '" . bp_get_user_meta_key( 'bp_latest_update' ) . "' AND user_id IN ( {$user_ids} )" );
    435435        for ( $i = 0; $i < count( $paged_users ); $i++ ) {
    436436            foreach ( (array)$user_update as $update ) {
  • trunk/bp-core/bp-core-component.php

    r4372 r4378  
    9595     * @uses apply_filters() Calls 'bp_{@link bp_Component::name}_id'
    9696     * @uses apply_filters() Calls 'bp_{@link bp_Component::name}_slug'
    97      * @uses apply_filters() Calls 'bp_user_meta_keys_$key_name'
    9897     *
    9998     * @param arr $args Used to
     
    109108            'notification_callback' => '',
    110109            'search_string'         => '',
    111             'global_tables'         => '',
    112             'user_meta_keys'    => array()
     110            'global_tables'         => ''
    113111        );
    114112        $r = wp_parse_args( $args, $defaults );
     
    130128            foreach ( $r['global_tables'] as $global_name => $table_name )
    131129                $this->$global_name = $table_name;
    132            
    133         // User meta keys
    134         if ( !empty( $r['user_meta_keys'] ) ) {
    135             foreach ( $r['user_meta_keys'] as $key_name => $key_value )
    136                 $bp->user_meta_keys->$key_name = apply_filters( "bp_user_meta_keys_$key_name", $key_value );
    137         }
    138130       
    139131        /** BuddyPress ********************************************************/
  • trunk/bp-core/bp-core-functions.php

    r4372 r4378  
    2828
    2929    $page_blog_id = $is_enable_multiblog ? get_current_blog_id() : BP_ROOT_BLOG;
    30    
     30
    3131    // Upgrading from an earlier version of BP pre-1.3
    3232    if ( empty( $page_ids ) || isset( $page_ids['members'] ) ) {       
     
    10011001 * BuddyPress stores a number of pieces of userdata in the WordPress central usermeta table. In
    10021002 * order to allow plugins to enable multiple instances of BuddyPress on a single WP installation,
    1003  * BP's usermeta keys are abstracted and stored in the $bp global, at $bp->user_meta_keys.
     1003 * BP's usermeta keys are filtered with this function, so that they can be altered on the fly.
    10041004 *
    10051005 * Plugin authors who access or modify metadata created by BuddyPress should use
     
    10091009 *
    10101010 * If your plugin introduces custom user metadata that might change between multiple BP instances
    1011  * on a single WP installation, you are strongly recommended to register your meta keys in the $bp
    1012  * global (see BP_Core_Component::setup_globals()), and use this function when storing and
     1011 * on a single WP installation, you are strongly recommended to use this function when storing and
    10131012 * retrieving metadata.
    10141013 *
    10151014 * @package BuddyPress
    10161015 * @since 1.3
    1017  * @see BP_Core_Component::_setup_globals()
    10181016 *
    10191017 * @uses apply_filters() Filter bp_get_user_meta_key to modify keys individually
    1020  * @param str $name
     1018 * @param str $key
    10211019 * @return str $key
    10221020 */
    1023 function bp_get_user_meta_key( $name = false ) {
    1024     global $bp;
    1025    
    1026     if ( !$name )
    1027         return false;
    1028    
    1029     $key = isset( $bp->user_meta_keys->$name ) ? $bp->user_meta_keys->$name : false;
    1030    
    1031     return apply_filters( 'bp_get_user_meta_key', $key, $name );
     1021function bp_get_user_meta_key( $key = false ) {
     1022    return apply_filters( 'bp_get_user_meta_key', $key );
    10321023}
    10331024
  • trunk/bp-core/bp-core-loader.php

    r4372 r4378  
    150150        // The user ID of the user who is currently logged in.
    151151        $bp->loggedin_user->id   = $current_user->ID;
    152        
    153         // Keys for BP user_meta
    154         $bp->user_meta_keys->last_activity  = apply_filters( 'bp_user_meta_key_last_activity', 'last_activity' );
    155         $bp->user_meta_keys->closed_notices     = apply_filters( 'bp_user_meta_key_closed_notices', 'closed_notices' );
    156152
    157153        /** Avatars ***********************************************************/
  • trunk/bp-friends/bp-friends-loader.php

    r4372 r4378  
    7171            'table_name_meta' => $bp->table_prefix . 'bp_friends_meta',
    7272        );
    73        
    74         // User meta keys
    75         $user_meta_keys = array(
    76             'total_friend_count'                => 'total_friend_count',
    77             'notification_friends_friendship_request'   => 'notification_friends_friendship_request',
    78             'notification_friends_friendship_accepted'  => 'notification_friends_friendship_accepted'
    79         );
    8073
    8174        // All globals for the friends component.
     
    8679            'search_string'         => __( 'Search Friends...', 'buddypress' ),
    8780            'notification_callback' => 'friends_format_notifications',
    88             'global_tables'         => $global_tables,
    89             'user_meta_keys'    => $user_meta_keys
     81            'global_tables'         => $global_tables
    9082        );
    9183
  • trunk/bp-groups/bp-groups-functions.php

    r4372 r4378  
    249249
    250250    // Modify user's group memberhip count
    251     update_user_meta( $user_id, $bp->user_meta_keys->total_group_count, (int) get_user_meta( $user_id, bp_get_user_meta_key( 'total_group_count' ), true ) - 1 );
     251    update_user_meta( $user_id, bp_get_user_meta_key( 'total_group_count' ), (int) get_user_meta( $user_id, bp_get_user_meta_key( 'total_group_count' ), true ) - 1 );
    252252
    253253    /**
  • trunk/bp-groups/bp-groups-loader.php

    r4372 r4378  
    7474            'table_name_groupmeta' => $bp->table_prefix . 'bp_groups_groupmeta'
    7575        );
    76        
    77         // User meta_keys
    78         $user_meta_keys = array(
    79             'total_group_count'                     => 'total_group_count',
    80             'notification_groups_group_updated'         => 'notification_groups_group_updated',
    81             'notification_groups_membership_request'    => 'notification_groups_membership_request',
    82             'notification_membership_request_completed' => 'notification_membership_request_completed',
    83             'notification_groups_invite'            => 'notification_groups_invite',
    84             'notification_groups_admin_promotion'       => 'notification_groups_admin_promotion'
    85         );
    8676
    8777        // All globals for messaging component.
     
    9282            'notification_callback' => 'groups_format_notifications',
    9383            'search_string'         => __( 'Search Groups...', 'buddypress' ),
    94             'global_tables'         => $global_tables,
    95             'user_meta_keys'    => $user_meta_keys
     84            'global_tables'         => $global_tables
    9685        );
    9786
  • trunk/bp-messages/bp-messages-loader.php

    r4372 r4378  
    7171        );
    7272       
    73         $user_meta_keys = array(
    74             'notification_messages_new_message' => 'notification_messages_new_message',
    75             'notification_messages_new_notice'  => 'notification_messages_new_notice'
    76         );
    77 
    7873        // All globals for messaging component.
    7974        // Note that global_tables is included in this array.
     
    8277            'notification_callback' => 'messages_format_notifications',
    8378            'search_string'         => __( 'Search Messages...', 'buddypress' ),
    84             'global_tables'         => $global_tables,
    85             'user_meta_keys'    => $user_meta_keys
     79            'global_tables'         => $global_tables
    8680        );
    8781
  • trunk/bp-xprofile/bp-xprofile-loader.php

    r4372 r4378  
    9393        );
    9494
    95         $user_meta_keys = array(
    96             'profile_last_updated' => 'profile_last_updated'
    97         );
    98 
    9995        $globals = array(
    10096            'slug'                  => BP_XPROFILE_SLUG,
    10197            'root_slug'             => isset( $bp->pages->xprofile->slug ) ? $bp->pages->xprofile->slug : BP_XPROFILE_SLUG,
    10298            'notification_callback' => 'xprofile_format_notifications',
    103             'global_tables'         => $global_tables,
    104             'user_meta_keys'    => $user_meta_keys
     99            'global_tables'         => $global_tables
    105100        );
    106101
Note: See TracChangeset for help on using the changeset viewer.