bp_core_avatar_handle_crop( array|string $args = '' )
Crop an uploaded avatar.
Description
Parameters
- $args
-
(Optional) Array of function parameters.
- 'object'
(string) Object type of the item whose avatar you're handling. 'user', 'group', 'blog', or custom. Default: 'user'. - 'avatar_dir'
(string) Subdirectory where avatar should be stored. Default: 'avatars'. - 'item_id'
(bool|int) ID of the item that the avatar belongs to. - 'original_file'
(bool|string) Absolute path to the original avatar file. - 'crop_w'
(int) Crop width. Default: the global 'full' avatar width, as retrieved by bp_core_avatar_full_width(). - 'crop_h'
(int) Crop height. Default: the global 'full' avatar height, as retrieved by bp_core_avatar_full_height(). - 'crop_x'
(int) The horizontal starting point of the crop. Default: 0. - 'crop_y'
(int) The vertical starting point of the crop. Default: 0.
Default value: ''
- 'object'
Return
(bool) True on success, false on failure.
Source
File: bp-core/bp-core-avatars.php
1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 | function bp_core_avatar_handle_crop( $args = '' ) { $r = wp_parse_args( $args , array ( 'object' => 'user' , 'avatar_dir' => 'avatars' , 'item_id' => false, 'original_file' => false, 'crop_w' => bp_core_avatar_full_width(), 'crop_h' => bp_core_avatar_full_height(), 'crop_x' => 0, 'crop_y' => 0 ) ); /** * Filters whether or not to handle cropping. * * If you want to override this function, make sure you return false. * * @since BuddyPress 1.2.4 * * @param bool $value Whether or not to crop. * @param array $r Array of parsed arguments for function. */ if ( ! apply_filters( 'bp_core_pre_avatar_handle_crop' , true, $r ) ) { return true; } // Crop the file. $avatar_attachment = new BP_Attachment_Avatar(); $cropped = $avatar_attachment ->crop( $r ); // Check for errors. if ( empty ( $cropped [ 'full' ] ) || empty ( $cropped [ 'thumb' ] ) || is_wp_error( $cropped [ 'full' ] ) || is_wp_error( $cropped [ 'thumb' ] ) ) { return false; } return true; } |
Changelog
Version | Description |
---|---|
BuddyPress 1.1.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.