bp_core_avatar_handle_crop( array|string $args = '' )

Crop an uploaded avatar.


Description Description


Parameters 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: ''


Top ↑

Return Return

(bool) True on success, false on failure.


Top ↑

Source Source

File: bp-core/bp-core-avatars.php

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 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;
}

Top ↑

Changelog Changelog

Changelog
Version Description
1.1.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.