Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
09/24/2015 10:36:16 AM (11 years ago)
Author:
imath
Message:

Make sure the xprofile_avatar_uploaded action is fired once the avatar of the user is set.

In 2.3.0, we introduced a new UI to manage avatar. It now uses Ajax to upload and set the avatar. Unfortunately a confusion was made about the xprofile_avatar_uploaded action. It was firing immediately after the avatar was uploaded but before it has been set using the cropping tool.

This commit is:

  • making sure the action is fired at the right time
  • adding new parameters to the action to inform about the User ID and the way the avatar was set ("crop" or "camera")
  • making sure an activity will be generated if the avatar was set within the wp-admin/extended-profile.

Props r-a-y, landwire

Fixes #6612 (trunk)

File:
1 edited

Legend:

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

    r10108 r10135  
    992992    $name = trim( substr( $name, 0, - ( 1 + strlen( $name_parts['extension'] ) ) ) );
    993993
    994     if ( 'user' === $bp_params['object'] ) {
    995         do_action( 'xprofile_avatar_uploaded' );
    996     }
    997 
    998994    // Finally return the avatar to the editor
    999995    bp_attachments_json_response( true, $is_html4, array(
     
    10571053        // Crop to default values
    10581054        $crop_args = array( 'item_id' => $item_id, 'original_file' => $avatar_to_crop, 'crop_x' => 0, 'crop_y' => 0 );
    1059 
    1060         /**
    1061          * Fires if the new avatar was successfully captured.
    1062          *
    1063          * @since 2.3.0
    1064          */
    1065         do_action( 'xprofile_avatar_uploaded' );
    10661055
    10671056        return bp_core_avatar_handle_crop( $crop_args );
     
    12011190            );
    12021191
    1203             do_action( 'xprofile_screen_change_avatar' );
     1192            /**
     1193             * Fires if the new avatar was successfully captured.
     1194             *
     1195             * @since 1.1.0 Used to inform the avatar was successfully cropped
     1196             * @since 2.3.4 Add two new parameters to inform about the user id and
     1197             *              about the way the avatar was set (eg: 'crop' or 'camera')
     1198             *              Move the action at the right place, once the avatar is set
     1199             *
     1200             * @param string $item_id Inform about the user id the avatar was set for
     1201             * @param string $type    Inform about the way the avatar was set ('camera')
     1202             */
     1203            do_action( 'xprofile_avatar_uploaded', (int) $avatar_data['item_id'], $avatar_data['type'] );
    12041204
    12051205            wp_send_json_success( $return );
     
    12461246
    12471247        if ( 'user' === $avatar_data['object'] ) {
    1248             do_action( 'xprofile_screen_change_avatar' );
     1248            /**
     1249             * Fires if the new avatar was successfully cropped.
     1250             *
     1251             * @since 1.1.0 Used to inform the avatar was successfully cropped
     1252             * @since 2.3.4 Add two new parameters to inform about the user id and
     1253             *              about the way the avatar was set (eg: 'crop' or 'camera')
     1254             *              Move the action at the right place, once the avatar is set
     1255             *
     1256             * @param string $item_id Inform about the user id the avatar was set for
     1257             * @param string $type Inform about the way the avatar was set ('crop')
     1258             */
     1259            do_action( 'xprofile_avatar_uploaded', (int) $avatar_data['item_id'], $avatar_data['type'] );
    12491260        }
    12501261
Note: See TracChangeset for help on using the changeset viewer.