Skip to content

Commit 3f96e3f

Browse files
pbearnewestonruter
andauthored
Update plugins/dominant-color-images/hooks.php
Co-authored-by: Weston Ruter <[email protected]>
1 parent 7de9e68 commit 3f96e3f

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

plugins/dominant-color-images/hooks.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,15 @@ function dominant_color_admin_script(): void {
225225
let replaced = match.replace( /\sclass="/, " class=\"{{ data.hasTransparency ? \'has-transparency\' : \'not-transparent\' }} " );
226226
replaced += ' data-dominant-color="{{ data.dominantColor }}"';
227227
replaced += ' data-has-transparency="{{ data.hasTransparency }}"';
228-
replaced += ' style="--dominant-color: #{{ data.dominantColor }};"'; // TODO: Potentially there could be a style attribute as well!
228+
let hasStyleAttr = false;
229+
const colorStyle = '--dominant-color: #{{ data.dominantColor }};';
230+
replaced = replaced.replace( /\sstyle="/, ( styleMatch ) => {
231+
hasStyleAttr = true;
232+
return styleMatch + colorStyle;
233+
} );
234+
if ( ! hasStyleAttr ) {
235+
replaced += ` style="${colorStyle}"`;
236+
}
229237
return replaced;
230238
} );
231239
}

0 commit comments

Comments
 (0)