: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* Get contrast color relative to given color.
* @param string|array $color The color.
private function get_contrast_color( $color ): string {
$rgba = is_array( $color ) ? $color : $this->get_color_as_rgb_array( $color );
$avg = (int) ( ( ( array_sum( $rgba ) ) / 3 ) * ( $rgba[3] ?? 1 ) );
return $avg < 128 ? '#ffffff' : '#000000';
* @since 1.8.8 Removed $css_vars argument.
* @param array $attr Attributes passed by integration.
private function get_size_css_vars( array $attr ): array {
$size_items = [ 'field', 'label', 'button', 'container-shadow' ];
foreach ( $size_items as $item ) {
$item_attr = preg_replace_callback(
static function ( $matches ) {
return strtoupper( $matches[1] );
$item_key = $item . '-size';
$item_constant = 'self::' . str_replace( '-', '_', strtoupper( $item ) ) . '_SIZE';
if ( empty( $attr[ $item_attr ] ) ) {
$size_css_vars[] = $this->get_complex_vars( $item_key, constant( $item_constant )[ $attr[ $item_attr ] ] );
return empty( $size_css_vars ) ? [] : array_merge( ...$size_css_vars );
* Get color as an array of RGB(A) values.
* @param string $color Color.
* @return array|bool Color as an array of RGBA values. False on error.
private function get_color_as_rgb_array( $color ) {
// Remove # from the beginning of the string and remove whitespaces.
$color = preg_replace( '/^#/', '', strtolower( trim( $color ) ) );
$color = str_replace( ' ', '', $color );
if ( $color === 'transparent' ) {
$color = 'rgba(0,0,0,0)';
// Check if color is in HEX(A) format.
$is_hex = preg_match( '/[0-9a-f]{6,8}$/', $rgba );
// Search and split HEX(A) color into an array of couples of chars.
preg_match_all( '/\w\w/', $rgba, $rgb_array );
static function ( $value ) {
return hexdec( '0x' . $value );
$rgb_array[3] = ( $rgb_array[3] ?? 255 ) / 255;
$rgba = preg_replace( '/[^\d,.]/', '', $rgba );
$rgb_array = explode( ',', $rgba );