Skip to content

Commit 6c3f1ae

Browse files
committed
Account for dominant_color not being prefixed by hash
1 parent be57225 commit 6c3f1ae

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

plugins/dominant-color-images/hooks.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,20 @@ function dominant_color_prepare_attachment_for_js( $response, WP_Post $attachmen
261261
}
262262

263263
$response['dominantColor'] = '';
264-
if ( isset( $meta['dominant_color'] ) && str_starts_with( '#', $meta['dominant_color'] ) ) {
265-
$response['dominantColor'] = sanitize_hex_color( $meta['dominant_color'] );
264+
if (
265+
isset( $meta['dominant_color'] )
266+
&&
267+
1 === preg_match( '/^[0-9A-F]+$/', $meta['dominant_color'] ) // See format returned by dominant_color_rgb_to_hex().
268+
) {
269+
$response['dominantColor'] = $meta['dominant_color'];
266270
}
267271
$response['hasTransparency'] = '';
268272
if ( isset( $meta['has_transparency'] ) ) {
269273
$response['hasTransparency'] = (bool) $meta['has_transparency'];
270274
}
271275

276+
$response['testMeta'] = $meta;
277+
272278
return $response;
273279
}
274280
add_filter( 'wp_prepare_attachment_for_js', 'dominant_color_prepare_attachment_for_js', 10, 3 );

0 commit comments

Comments
 (0)