Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions modules/images/dominant-color-images/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,18 @@ function dominant_color_set_image_editors( $editors ) {
* Computes the dominant color of the given attachment image and whether it has transparency.
*
* @since 1.2.0
* @since n.e.x.t Function renamed to remove the `_` prefix.
* @access private
*
* @param int $attachment_id The attachment ID.
* @return array|WP_Error Array with the dominant color and has transparency values or WP_Error on error.
*/
function _dominant_color_get_dominant_color_data( $attachment_id ) {
function dominant_color_get_dominant_color_data( $attachment_id ) {
$mime_type = get_post_mime_type( $attachment_id );
if ( 'application/pdf' === $mime_type ) {
return new WP_Error( 'no_image_found', __( 'Unable to load image.', 'performance-lab' ) );
}
$file = wp_get_attachment_file_path( $attachment_id );
$file = dominant_color_get_attachment_file_path( $attachment_id );
if ( ! $file ) {
$file = get_attached_file( $attachment_id );
}
Expand Down Expand Up @@ -90,12 +91,13 @@ function _dominant_color_get_dominant_color_data( $attachment_id ) {
* Gets file path of image based on size.
*
* @since 1.2.0
* @since n.e.x.t Function renamed to change `wp_` prefix to `dominant_color_`.
*
* @param int $attachment_id Attachment ID for image.
* @param string $size Optional. Image size. Default 'medium'.
* @return false|string Path to an image or false if not found.
*/
function wp_get_attachment_file_path( $attachment_id, $size = 'medium' ) {
function dominant_color_get_attachment_file_path( $attachment_id, $size = 'medium' ) {
$imagedata = wp_get_attachment_metadata( $attachment_id );
if ( ! is_array( $imagedata ) ) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion modules/images/dominant-color-images/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* @return array $metadata The attachment metadata.
*/
function dominant_color_metadata( $metadata, $attachment_id ) {
$dominant_color_data = _dominant_color_get_dominant_color_data( $attachment_id );
$dominant_color_data = dominant_color_get_dominant_color_data( $attachment_id );
if ( ! is_wp_error( $dominant_color_data ) ) {
if ( isset( $dominant_color_data['dominant_color'] ) ) {
$metadata['dominant_color'] = $dominant_color_data['dominant_color'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function test_get_dominant_color( $image_path, $expected_color, $expected
$attachment_id = self::factory()->attachment->create_upload_object( $image_path );
wp_maybe_generate_attachment_metadata( get_post( $attachment_id ) );

$dominant_color_data = _dominant_color_get_dominant_color_data( $attachment_id );
$dominant_color_data = dominant_color_get_dominant_color_data( $attachment_id );

$this->assertContains( $dominant_color_data['dominant_color'], $expected_color );
$this->assertSame( $dominant_color_data['has_transparency'], $expected_transparency );
Expand All @@ -53,7 +53,7 @@ public function test_get_dominant_color_invalid( $image_path, $expected_color, $
$attachment_id = self::factory()->attachment->create_upload_object( $image_path );
wp_maybe_generate_attachment_metadata( get_post( $attachment_id ) );

$dominant_color_data = _dominant_color_get_dominant_color_data( $attachment_id );
$dominant_color_data = dominant_color_get_dominant_color_data( $attachment_id );

$this->assertWPError( $dominant_color_data );
$this->assertStringContainsString( 'image_no_editor', $dominant_color_data->get_error_code() );
Expand All @@ -71,7 +71,7 @@ public function test_get_dominant_color_none_images( $image_path ) {
$attachment_id = self::factory()->attachment->create_upload_object( $image_path );
wp_maybe_generate_attachment_metadata( get_post( $attachment_id ) );

$dominant_color_data = _dominant_color_get_dominant_color_data( $attachment_id );
$dominant_color_data = dominant_color_get_dominant_color_data( $attachment_id );

$this->assertWPError( $dominant_color_data );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function test_get_dominant_color( $image_path, $expected_color, $expected
$attachment_id = self::factory()->attachment->create_upload_object( $image_path );
wp_maybe_generate_attachment_metadata( get_post( $attachment_id ) );

$dominant_color_data = _dominant_color_get_dominant_color_data( $attachment_id );
$dominant_color_data = dominant_color_get_dominant_color_data( $attachment_id );

$this->assertContains( $dominant_color_data['dominant_color'], $expected_color );
$this->assertSame( $dominant_color_data['has_transparency'], $expected_transparency );
Expand All @@ -55,7 +55,7 @@ public function test_get_dominant_color_invalid( $image_path, $expected_color, $
$attachment_id = self::factory()->attachment->create_upload_object( $image_path );
wp_maybe_generate_attachment_metadata( get_post( $attachment_id ) );

$dominant_color_data = _dominant_color_get_dominant_color_data( $attachment_id );
$dominant_color_data = dominant_color_get_dominant_color_data( $attachment_id );

$this->assertContains( $dominant_color_data['dominant_color'], $expected_color );
$this->assertSame( $dominant_color_data['has_transparency'], $expected_transparency );
Expand All @@ -73,7 +73,7 @@ public function test_get_dominant_color_none_images( $image_path ) {
$attachment_id = self::factory()->attachment->create_upload_object( $image_path );
wp_maybe_generate_attachment_metadata( get_post( $attachment_id ) );

$dominant_color_data = _dominant_color_get_dominant_color_data( $attachment_id );
$dominant_color_data = dominant_color_get_dominant_color_data( $attachment_id );

$this->assertWPError( $dominant_color_data );
}
Expand Down