Member Avatar

Schema Schema

The schema defines all the fields that exist for a member avatar object.

Note: The Member Avatar endpoints will only be available if the xProfile component is active on the community site.
full

string,
uri
Full size of the image file.
Read only
Context: viewedit
thumb

string,
uri
Thumb size of the image file.
Read only
Context: viewedit

Top ↑

Retrieve the Avatar of a Member Retrieve the Avatar of a Member

Arguments Arguments

NameTypeDescription
user_idintegerA unique numeric ID for the Member.
contextstringScope under which the request is made; determines fields present in response.
Default: view
One of: view, edit
htmlbooleanWhether to return an <img> HTML element, vs a raw URL to an avatar.
altstringThe alt attribute for the <img> element.
no_gravbooleanWhether to disable the default Gravatar fallback.

Top ↑

Definition Definition

GET /buddypress/v1/members/<user_id>/avatar

Top ↑

Example of use Example of use

Alert: To use the bp.apiRequest function, you need to enqueue the bp-api-request JavaScript or use it as a dependency of your script. Refer to this page to know more about loading JavaScript files in WordPress.

bp.apiRequest( {
  path: 'buddypress/v1/members/43/avatar',
  type: 'GET',
  data: {
    context: 'view'
  }
} ).done( function( data ) {
  return data;
} ).fail( function( error ) {
  return error;
} );

Top ↑

Attach an Avatar to a Member Attach an Avatar to a Member

Top ↑

Arguments Arguments

NameTypeDescription
user_idintegerA unique numeric ID for the Member.

Alert: The file input name to use to upload the file must be file and the form action must be bp_avatar_upload.

Top ↑

Definition Definition

POST /buddypress/v1/members/<user_id>/avatar

Top ↑

Example of use Example of use

Alert: To use the bp.apiRequest function, you need to enqueue the bp-api-request JavaScript or use it as a dependency of your script. Refer to this page to know more about loading JavaScript files in WordPress.

( function( $ ){
    // Listen to the injected File Input's change.
    $( '#main article .entry-content' ).on( 'change', 'input[type="file"]', function( event ) {
        var formData = new FormData();

        if ( ! event.currentTarget.files || ! event.currentTarget.files[0] ) {
            return;
        }

        formData.append( 'context', 'edit' );

        // The `action` is required and must be `bp_avatar_upload`.
        formData.append( 'action', 'bp_avatar_upload' );

        // The `file` is required and must be an image.
        formData.append( 'file', event.currentTarget.files[0] );

        bp.apiRequest( {
            path: 'buddypress/v1/members/98/avatar',
            type: 'POST',
            data: formData,
            contentType: false,
            processData: false,
        } ).done( function( data ) {
            console.log( data );
        } ).fail( function( error ) {
            console.log( error );
        } );
    } );

    /**
     * Inject a File input
     *
     * PS: Active WordPress Theme for the test is Twenty Nineteen.
     */
    $( document ).ready( function() {
        $( '#main article .entry-content' ).append(
            $( '<input></input>' ).prop( {
                type: 'file',
                accept: 'image/jpg'
            } )
        );
    } );
}( jQuery ) );

Top ↑

Delete the Avatar of a Member Delete the Avatar of a Member

Top ↑

Arguments Arguments

NameTypeDescription
user_idintegerA unique numeric ID for the Member.

Top ↑

Definition Definition

DELETE /buddypress/v1/members/<user_id>/avatar

Top ↑

Example of use Example of use

Alert: To use the bp.apiRequest function, you need to enqueue the bp-api-request JavaScript or use it as a dependency of your script. Refer to this page to know more about loading JavaScript files in WordPress.

bp.apiRequest( {
  path: 'buddypress/v1/members/43/avatar',
  type: 'DELETE',
  data: {
    context: 'edit'
  }
} ).done( function( data ) {
  return data;
} ).fail( function( error ) {
  return error;
} );