Changeset 13177
- Timestamp:
- 12/11/2021 01:40:24 PM (3 years ago)
- Location:
- trunk/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/bp-core-avatars.php
r13176 r13177 1177 1177 * 1178 1178 * @since 2.3.0 1179 * @since 10.0.0 Adds the `$return` param to eventually return the crop result. 1179 1180 * 1180 1181 * @param string $data Base64 encoded image. 1181 1182 * @param int $item_id Item to associate. 1182 * @return bool True on success, false on failure. 1183 */ 1184 function bp_avatar_handle_capture( $data = '', $item_id = 0 ) { 1183 * @param string $return Whether to get the crop `array` or a `boolean`. Defaults to `boolean`. 1184 * @return array|bool True on success, false on failure. 1185 */ 1186 function bp_avatar_handle_capture( $data = '', $item_id = 0, $return = 'boolean' ) { 1185 1187 if ( empty( $data ) || empty( $item_id ) ) { 1186 1188 return false; … … 1238 1240 $crop_args = array( 'item_id' => $item_id, 'original_file' => $avatar_to_crop, 'crop_x' => 0, 'crop_y' => 0 ); 1239 1241 1242 if ( 'array' === $return ) { 1243 return bp_core_avatar_handle_crop( $crop_args, 'array' ); 1244 } 1245 1240 1246 return bp_core_avatar_handle_crop( $crop_args ); 1241 1247 } else { … … 1248 1254 * 1249 1255 * @since 1.1.0 1256 * @since 10.0.0 Adds the `$return` param to eventually return the crop result. 1250 1257 * 1251 1258 * @param array|string $args { … … 1266 1273 * @type int $crop_y The vertical starting point of the crop. Default: 0. 1267 1274 * } 1268 * @return bool True on success, false on failure. 1269 */ 1270 function bp_core_avatar_handle_crop( $args = '' ) { 1275 * @param string $return Whether to get the crop `array` or a `boolean`. Defaults to `boolean`. 1276 * @return array|bool True or the crop result on success, false on failure. 1277 */ 1278 function bp_core_avatar_handle_crop( $args = '', $return = 'boolean' ) { 1271 1279 1272 1280 $r = bp_parse_args( … … 1307 1315 } 1308 1316 1317 if ( 'array' === $return ) { 1318 return $cropped; 1319 } 1320 1309 1321 return true; 1310 1322 } … … 1353 1365 } 1354 1366 1355 if ( ! bp_avatar_handle_capture( $webcam_avatar, $avatar_data['item_id'] ) ) { 1367 $cropped_webcam_avatar = bp_avatar_handle_capture( $webcam_avatar, $avatar_data['item_id'], 'array' ); 1368 1369 if ( ! $cropped_webcam_avatar ) { 1356 1370 wp_send_json_error( array( 1357 1371 'feedback_code' => 1 … … 1360 1374 } else { 1361 1375 $return = array( 1362 'avatar' => esc_url( bp_core_fetch_avatar( array( 1363 'object' => $avatar_data['object'], 1364 'item_id' => $avatar_data['item_id'], 1365 'html' => false, 1366 'type' => 'full', 1367 ) ) ), 1376 'avatar' => esc_url( 1377 bp_core_fetch_avatar( 1378 array( 1379 'object' => $avatar_data['object'], 1380 'item_id' => $avatar_data['item_id'], 1381 'html' => false, 1382 'type' => 'full', 1383 ) 1384 ) 1385 ), 1368 1386 'feedback_code' => 2, 1369 1387 'item_id' => $avatar_data['item_id'], … … 1377 1395 * 1378 1396 * @since 6.0.0 1397 * @since 10.0.0 Adds a new param: an array containing the full, thumb avatar and the timestamp. 1379 1398 * 1380 * @param string $item_id Inform about the user id the avatar was set for. 1381 * @param string $type Inform about the way the avatar was set ('camera'). 1382 * @param array $avatar_data Array of parameters passed to the avatar handler. 1399 * @param string $item_id Inform about the user id the avatar was set for. 1400 * @param string $type Inform about the way the avatar was set ('camera'). 1401 * @param array $avatar_data Array of parameters passed to the crop handler. 1402 * @param array $cropped_webcam_avatar Array containing the full, thumb avatar and the timestamp. 1383 1403 */ 1384 do_action( 'bp_members_avatar_uploaded', (int) $avatar_data['item_id'], $avatar_data['type'], $avatar_data );1404 do_action( 'bp_members_avatar_uploaded', (int) $avatar_data['item_id'], $avatar_data['type'], $avatar_data, $cropped_webcam_avatar ); 1385 1405 1386 1406 wp_send_json_success( $return ); … … 1414 1434 1415 1435 // Handle crop. 1416 if ( bp_core_avatar_handle_crop( $r ) ) { 1436 $cropped_avatar = bp_core_avatar_handle_crop( $r, 'array' ); 1437 1438 if ( $cropped_avatar ) { 1417 1439 $return = array( 1418 'avatar' => esc_url( bp_core_fetch_avatar( array( 1419 'object' => $avatar_data['object'], 1420 'item_id' => $avatar_data['item_id'], 1421 'html' => false, 1422 'type' => 'full', 1423 ) ) ), 1440 'avatar' => esc_url( 1441 bp_core_fetch_avatar( 1442 array( 1443 'object' => $avatar_data['object'], 1444 'item_id' => $avatar_data['item_id'], 1445 'html' => false, 1446 'type' => 'full', 1447 ) 1448 ) 1449 ), 1424 1450 'feedback_code' => 2, 1425 1451 'item_id' => $avatar_data['item_id'], … … 1431 1457 1432 1458 /** This action is documented in bp-core/bp-core-avatars.php */ 1433 do_action( 'bp_members_avatar_uploaded', (int) $avatar_data['item_id'], $avatar_data['type'], $r );1459 do_action( 'bp_members_avatar_uploaded', (int) $avatar_data['item_id'], $avatar_data['type'], $r, $cropped_avatar ); 1434 1460 } elseif ( 'group' === $avatar_data['object'] ) { 1435 1461 /** This action is documented in bp-groups/bp-groups-screens.php */ 1436 do_action( 'groups_avatar_uploaded', (int) $avatar_data['item_id'], $avatar_data['type'], $r );1462 do_action( 'groups_avatar_uploaded', (int) $avatar_data['item_id'], $avatar_data['type'], $r, $cropped_avatar ); 1437 1463 } 1438 1464 -
trunk/src/bp-groups/actions/create.php
r12433 r13177 271 271 ); 272 272 273 if ( ! bp_core_avatar_handle_crop( $args ) ) { 273 $cropped_avatar = bp_core_avatar_handle_crop( $args, 'array' ); 274 275 if ( ! $cropped_avatar ) { 274 276 bp_core_add_message( __( 'There was an error saving the group profile photo, please try uploading again.', 'buddypress' ), 'error' ); 275 277 } else { … … 278 280 * 279 281 * @since 2.8.0 282 * @since 10.0.0 Adds a new param: an array containing the full, thumb avatar and the timestamp. 280 283 * 281 * @param int $group_id ID of the group. 282 * @param string $type Avatar type. 'crop' or 'full'. 283 * @param array $args Array of parameters passed to the avatar handler. 284 * @param int $group_id ID of the group. 285 * @param string $type Avatar type. 'crop' or 'camera'. 286 * @param array $args Array of parameters passed to the crop handler. 287 * @param array $cropped_avatar Array containing the full, thumb avatar and the timestamp. 284 288 */ 285 do_action( 'groups_avatar_uploaded', bp_get_current_group_id(), 'crop', $args );289 do_action( 'groups_avatar_uploaded', bp_get_current_group_id(), 'crop', $args, $cropped_avatar ); 286 290 287 291 bp_core_add_message( __( 'The group profile photo was uploaded successfully.', 'buddypress' ) ); -
trunk/src/bp-groups/screens/single/admin/group-avatar.php
r11923 r13177 75 75 ); 76 76 77 if ( !bp_core_avatar_handle_crop( $args ) ) { 77 $cropped_avatar = bp_core_avatar_handle_crop( $args, 'array' ); 78 79 if ( ! $cropped_avatar ) { 78 80 bp_core_add_message( __( 'There was a problem cropping the group profile photo.', 'buddypress' ), 'error' ); 79 81 } else { … … 82 84 * 83 85 * @since 2.8.0 86 * @since 10.0.0 Adds a new param: an array containing the full, thumb avatar and the timestamp. 84 87 * 85 * @param int $group_id ID of the group. 86 * @param string $type Avatar type. 'crop' or 'full'. 87 * @param array $args Array of parameters passed to the avatar handler. 88 * @param int $group_id ID of the group. 89 * @param string $type Avatar type. 'crop' or 'camera'. 90 * @param array $args Array of parameters passed to the avatar handler. 91 * @param array $cropped_avatar Array containing the full, thumb avatar and the timestamp. 88 92 */ 89 do_action( 'groups_avatar_uploaded', bp_get_current_group_id(), 'crop', $args );93 do_action( 'groups_avatar_uploaded', bp_get_current_group_id(), 'crop', $args, $cropped_avatar ); 90 94 bp_core_add_message( __( 'The new group profile photo was uploaded successfully.', 'buddypress' ) ); 91 95 } -
trunk/src/bp-members/bp-members-activity.php
r13155 r13177 167 167 * 168 168 * @since 8.0.0 169 * 170 * @param int $user_id The user id the avatar was set for. 171 */ 172 function bp_members_new_avatar_activity( $user_id = 0 ) { 169 * @since 10.0.0 Adds the `$type`, `$crop_data` and `$cropped_avatar` parameters. 170 * 171 * @param int $user_id The user id the avatar was set for. 172 * @param string $type The way the avatar was set ('camera' or `crop`). 173 * @param array $crop_data Array of parameters passed to the crop handler. 174 * @param array $cropped_avatar Array containing the full, thumb avatar and the timestamp. 175 */ 176 function bp_members_new_avatar_activity( $user_id = 0, $type = '', $crop_data = array(), $cropped_avatar = array() ) { 173 177 174 178 // Bail if activity component is not active. … … 231 235 } 232 236 237 $recorded_time = ''; 238 if ( isset( $cropped_avatar['timestamp'] ) && $cropped_avatar['timestamp'] ) { 239 $recorded_time = date( 'Y-m-d H:i:s', $cropped_avatar['timestamp'] ); 240 } 241 233 242 // Add the activity. 234 bp_activity_add(243 $activity_id = bp_activity_add( 235 244 array( 236 'user_id' => $user_id, 237 'component' => $bp->members->id, 238 'type' => 'new_avatar', 245 'user_id' => $user_id, 246 'component' => $bp->members->id, 247 'type' => 'new_avatar', 248 'recorded_time' => $recorded_time, 239 249 ) 240 250 ); 241 251 } 242 add_action( 'bp_members_avatar_uploaded', 'bp_members_new_avatar_activity' );252 add_action( 'bp_members_avatar_uploaded', 'bp_members_new_avatar_activity', 10, 4 ); -
trunk/src/bp-members/screens/change-avatar.php
r12557 r13177 62 62 ); 63 63 64 if ( ! bp_core_avatar_handle_crop( $args ) ) { 64 // Handle crop. 65 $cropped_avatar = bp_core_avatar_handle_crop( $r, 'array' ); 66 67 if ( ! $cropped_avatar ) { 65 68 bp_core_add_message( __( 'There was a problem cropping your profile photo.', 'buddypress' ), 'error' ); 66 69 } else { … … 73 76 * 74 77 * @since 6.0.0 78 * @since 10.0.0 Adds a new param: an array containing the full, thumb avatar and the timestamp. 75 79 * 76 * @param string $item_id Inform about the user id the avatar was set for. 77 * @param string $value Inform about the way the avatar was set ('crop'). 80 * @param string $item_id Inform about the user id the avatar was set for. 81 * @param string $type Inform about the way the avatar was set ('camera'). 82 * @param array $args Array of parameters passed to the crop handler. 83 * @param array $cropped_avatar Array containing the full, thumb avatar and the timestamp. 78 84 */ 79 do_action( 'bp_members_avatar_uploaded', (int) $args['item_id'], 'crop' );85 do_action( 'bp_members_avatar_uploaded', (int) $args['item_id'], 'crop', $args, $cropped_avatar ); 80 86 81 87 bp_core_add_message( __( 'Your new profile photo was uploaded successfully.', 'buddypress' ) );
Note: See TracChangeset
for help on using the changeset viewer.