Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
10/26/2012 05:13:59 PM (12 years ago)
Author:
johnjamesjacoby
Message:

Avatars:

  • Obey 'show_avatars' option, and bail early if avatars are totally disabled.
  • Replace $bp global with buddypress() usage in bp-core-avatars.php.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-avatars.php

    r6342 r6468  
    1212 */
    1313function bp_core_set_avatar_constants() {
    14     global $bp;
    1514
    1615    if ( !defined( 'BP_AVATAR_THUMB_WIDTH' ) )
     
    3029
    3130    if ( !defined( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE' ) ) {
     31
     32        $bp = buddypress();
     33
    3234        if ( !isset( $bp->site_options['fileupload_maxk'] ) ) {
    3335            define( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE', 5120000 ); // 5mb
     
    4648
    4749function bp_core_set_avatar_globals() {
    48     global $bp;
     50    $bp = buddypress();
    4951
    5052    $bp->avatar        = new stdClass;
     
    8890 * default, but can be extended to include your own custom components too.
    8991 *
    90  * @global BuddyPress $bp The one true BuddyPress instance
    9192 * @global $current_blog WordPress global containing information and settings for the current blog being viewed.
    9293 * @param array $args Determine the output of this function
     
    9495 */
    9596function bp_core_fetch_avatar( $args = '' ) {
    96     global $bp, $current_blog;
     97
     98    // If avatars are disabled for the root site, obey that request and bail
     99    if ( ! bp_get_option( 'show_avatars' ) )
     100        return;
     101
     102    global $current_blog;
     103
     104    $bp = buddypress();
    97105
    98106    // Set a few default variables
     
    373381    // No avatar was found, and we've been told not to use a gravatar.
    374382    } else {
    375         $gravatar = apply_filters( "bp_core_default_avatar_$object", BP_PLUGIN_URL . 'bp-core/images/mystery-man.jpg', $params );
     383        $gravatar = urlencode( apply_filters( "bp_core_default_avatar_$object", BP_PLUGIN_URL . 'bp-core/images/mystery-man.jpg', $params ) );
    376384    }
    377385
    378386    if ( true === $html )
    379         return apply_filters( 'bp_core_fetch_avatar', '<img src="' . $gravatar . '" alt="' . esc_attr( $alt ) . '" class="' . esc_attr( $class ) . '"' . $css_id . $html_width . $html_height . $title . ' />', $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir );
     387        return apply_filters( 'bp_core_fetch_avatar', '<img src="' . esc_attr( $gravatar ) . '" alt="' . esc_attr( $alt ) . '" class="' . esc_attr( $class ) . '"' . $css_id . $html_width . $html_height . $title . ' />', $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir );
    380388    else
    381389        return apply_filters( 'bp_core_fetch_avatar_url', $gravatar );
     
    390398 *  avatar_dir - The directory where the avatars to be uploaded.
    391399 *
    392  * @global object $bp BuddyPress global settings
    393400 * @param mixed $args
    394401 * @return bool Success/failure
    395402 */
    396403function bp_core_delete_existing_avatar( $args = '' ) {
    397     global $bp;
    398404
    399405    $defaults = array(
     
    410416            $item_id = bp_displayed_user_id();
    411417        else if ( 'group' == $object )
    412             $item_id = $bp->groups->current_group->id;
     418            $item_id = buddypress()->groups->current_group->id;
    413419        else if ( 'blog' == $object )
    414420            $item_id = $current_blog->id;
     
    459465 * If everything checks out, crop the image and move it to its real location.
    460466 *
    461  * @global object $bp BuddyPress global settings
    462467 * @param array $file The appropriate entry the from $_FILES superglobal.
    463468 * @param string $upload_dir_filter A filter to be applied to upload_dir
     
    467472 */
    468473function bp_core_avatar_handle_upload( $file, $upload_dir_filter ) {
    469     global $bp;
    470474
    471475    /***
     
    505509    // Filter the upload location
    506510    add_filter( 'upload_dir', $upload_dir_filter, 10, 0 );
     511
     512    $bp = buddypress();
    507513
    508514    $bp->avatar_admin->original = wp_handle_upload( $file['file'], array( 'action'=> 'bp_avatar_upload' ) );
     
    736742 */
    737743function bp_core_avatar_upload_path() {
    738     global $bp;
     744    $bp = buddypress();
    739745
    740746    // See if the value has already been calculated and stashed in the $bp global
     
    782788 */
    783789function bp_core_avatar_url() {
    784     global $bp;
     790    $bp = buddypress();
    785791
    786792    // See if the value has already been calculated and stashed in the $bp global
     
    850856 */
    851857function bp_core_avatar_dimension( $type = 'thumb', $h_or_w = 'height' ) {
    852     global $bp;
    853 
     858    $bp  = buddypress();
    854859    $dim = isset( $bp->avatar->{$type}->{$h_or_w} ) ? (int) $bp->avatar->{$type}->{$h_or_w} : false;
    855860
     
    914919 */
    915920function bp_core_avatar_original_max_width() {
    916     global $bp;
    917 
    918     return apply_filters( 'bp_core_avatar_original_max_width', (int) $bp->avatar->original_max_width );
     921    return apply_filters( 'bp_core_avatar_original_max_width', (int) buddypress()->avatar->original_max_width );
    919922}
    920923
     
    928931 */
    929932function bp_core_avatar_original_max_filesize() {
    930     global $bp;
    931 
    932     return apply_filters( 'bp_core_avatar_original_max_filesize', (int) $bp->avatar->original_max_filesize );
     933    return apply_filters( 'bp_core_avatar_original_max_filesize', (int) buddypress()->avatar->original_max_filesize );
    933934}
    934935
     
    942943 */
    943944function bp_core_avatar_default() {
    944     global $bp;
    945 
    946     return apply_filters( 'bp_core_avatar_default', $bp->avatar->full->default );
     945    return apply_filters( 'bp_core_avatar_default', buddypress()->avatar->full->default );
    947946}
    948947
     
    956955 */
    957956function bp_core_avatar_default_thumb() {
    958     global $bp;
    959 
    960     return apply_filters( 'bp_core_avatar_thumb', $bp->avatar->thumb->default );
    961 }
     957    return apply_filters( 'bp_core_avatar_thumb', buddypress()->avatar->thumb->default );
     958}
Note: See TracChangeset for help on using the changeset viewer.