Changeset 3635 for trunk/bp-core/bp-core-avatars.php
- Timestamp:
- 01/01/2011 06:26:18 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-core/bp-core-avatars.php
r3592 r3635 53 53 * default, but can be extended to include your own custom components too. 54 54 * 55 * @global object $bp56 * @global object $current_blog55 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() 56 * @global $current_blog WordPress global containing information and settings for the current blog being viewed. 57 57 * @param array $args Determine the output of this function 58 58 * @return string Formatted HTML <img> element, or raw avatar URL based on $html arg … … 62 62 63 63 // Set a few default variables 64 $def_object 65 $def_type 66 $def_class 67 $def_alt 64 $def_object = 'user'; 65 $def_type = 'thumb'; 66 $def_class = 'avatar'; 67 $def_alt = __( 'Avatar Image', 'buddypress' ); 68 68 69 69 // Set the default variables array 70 70 $defaults = array( 71 'item_id' => false, 72 'object' => $def_object, // user/group/blog/custom type (if you use filters) 73 'type' => $def_type, // thumb or full 74 'avatar_dir' => false, // Specify a custom avatar directory for your object 75 'width' => false, // Custom width (int) 76 'height' => false, // Custom height (int) 77 'class' => $def_class, // Custom <img> class (string) 78 'css_id' => false, // Custom <img> ID (string) 79 'alt' => $def_alt, // Custom <img> alt (string) 80 'email' => false, // Pass the user email (for gravatar) to prevent querying the DB for it 81 'no_grav' => false, // If there is no avatar found, return false instead of a grav? 82 'html' => true // Wrap the return img URL in <img /> 71 'item_id' => false, 72 'object' => $def_object, // user/group/blog/custom type (if you use filters) 73 'type' => $def_type, // thumb or full 74 'avatar_dir' => false, // Specify a custom avatar directory for your object 75 'width' => false, // Custom width (int) 76 'height' => false, // Custom height (int) 77 'class' => $def_class, // Custom <img> class (string) 78 'css_id' => false, // Custom <img> ID (string) 79 'alt' => $def_alt, // Custom <img> alt (string) 80 'email' => false, // Pass the user email (for gravatar) to prevent querying the DB for it 81 'no_grav' => false, // If there is no avatar found, return false instead of a grav? 82 'html' => true, // Wrap the return img URL in <img /> 83 'title' => '' // Custom <img> title (string) 83 84 ); 84 85 … … 98 99 $item_id = apply_filters( 'bp_core_avatar_item_id', $item_id, $object ); 99 100 100 if ( !$item_id ) return false; 101 if ( !$item_id ) 102 return false; 101 103 } 102 104 … … 112 114 $avatar_dir = apply_filters( 'bp_core_avatar_dir', $avatar_dir, $object ); 113 115 114 if ( !$avatar_dir ) return false; 116 if ( !$avatar_dir ) 117 return false; 115 118 } 116 119 117 120 // Add an identifying class to each item 118 121 $class .= ' ' . $object . '-' . $item_id . '-avatar'; 122 123 // Get item name for alt/title tags 124 $item_name = ''; 125 126 if ( 'user' == $object ) 127 $item_name = bp_core_get_user_displayname( $item_id ); 128 elseif ( 'group' == $object ) 129 $item_name = bp_get_group_name( new BP_Groups_Group( $item_id ) ); 130 elseif ( 'blog' == $object ) 131 $item_name = get_blog_option( $item_id, 'blogname' ); 132 133 $alt = sprintf( $alt, apply_filters( 'bp_core_avatar_alt', $item_name, $item_id, $object ) ); 134 135 // Set title tag 136 if ( $title ) 137 $title = " title='" . esc_attr( apply_filters( 'bp_core_avatar_title', $title, $item_id, $object ) ) . "'"; 138 elseif ( $item_name ) 139 $title = " title='" . esc_attr( apply_filters( 'bp_core_avatar_title', $item_name, $item_id, $object ) ) . "'"; 119 140 120 141 // Set CSS ID if passed … … 196 217 // Return it wrapped in an <img> element 197 218 if ( true === $html ) { 198 return apply_filters( 'bp_core_fetch_avatar', '<img src="' . $avatar_url . '" alt="' . $alt . '" class="' . $class . '"' . $css_id . $html_width . $html_height. ' />', $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir );219 return apply_filters( 'bp_core_fetch_avatar', '<img src="' . $avatar_url . '" 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 ); 199 220 200 221 // ...or only the URL … … 247 268 // Return gravatar wrapped in <img /> 248 269 if ( true === $html ) 249 return apply_filters( 'bp_core_fetch_avatar', '<img src="' . $gravatar . '" alt="' . $alt . '" class="' . $class . '"' . $css_id . $html_width . $html_height. ' />', $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir );270 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 ); 250 271 251 272 // ...or only return the gravatar URL … … 506 527 return !empty( $avatar ) ? $avatar : $default; 507 528 529 if ( !$alt ) 530 $alt = __( 'Avatar of %s', 'buddypress' ); 531 508 532 // Let BuddyPress handle the fetching of the avatar 509 533 $bp_avatar = bp_core_fetch_avatar( array( 'item_id' => $id, 'width' => $size, 'height' => $size, 'alt' => $alt ) );
Note: See TracChangeset
for help on using the changeset viewer.