It’s not a plugin problem – it’s a lack of data sanitizing in a couple of theme functions. The color string is being passed as an rgb string, not a hex string and both spacious_darkcolor and spacious_hex2rgb are assuming a hex string. Hence, both fall over when a rgb string is passed as a parameter hexdec.
Below is a version of both functions that work. No doubt, additional error checking could be added but this solves the ongoing runtime error.
Function spacious_hex2rgb can be overriden in a child theme functions file (since it’s within a function_exists wrapper), but not spacious_darkcolour where one must hack the theme function file.
/**
* Change hex code to RGB
* Source: https://css-tricks.com/snippets/php/convert-hex-to-rgb/#comment-1052011
* Extended to handle rgb codes
*/
if ( ! function_exists( 'spacious_hex2rgb' ) ) {
function spacious_hex2rgb( $hexstr ) {
if(preg_match("/^[0-9ABCDEFabcdef\#]+$/i", $hexstr)){
$int = hexdec( str_replace( '#', '', $hexstr ) );
$rgb = array( "red" => 0xFF & ( $int >> 0x10 ), "green" => 0xFF & ( $int >> 0x8 ), "blue" => 0xFF & $int );
$r = $rgb['red'];
$g = $rgb['green'];
$b = $rgb['blue'];
return "rgba(".$r.",".$g.",".$b.", 0.85)";
}elseif (preg_match("/^rgb\(/i", $hexstr)){
return str_replace(')',',0.85)',$hexstr);
}
}
}
/**
* Generate darker color
* Source: http://stackoverflow.com/questions/3512311/how-to-generate-lighter-darker-color-with-php
* Extended to handle rgb codes
*/
function spacious_darkcolor( $hex, $steps ) {
// Steps should be between -255 and 255. Negative = darker, positive = lighter
$steps = max( -255, min( 255, $steps ) );
$return = $hex;
if(preg_match("/^[0-9ABCDEFabcdef\#]+$/i", $hex)){
// Normalize into a six character long hex string
$hex = str_replace( '#', '', $hex );
if ( strlen( $hex ) == 3 ) {
$hex = str_repeat( substr( $hex, 0, 1 ), 2 ) . str_repeat( substr( $hex, 1, 1 ), 2 ) . str_repeat( substr( $hex, 2, 1 ), 2 );
}
// Split into three parts: R, G and B
$color_parts = str_split( $hex, 2 );
$return = '#';
foreach ( $color_parts as $color ) {
$color = hexdec( $color ); // Convert to decimal
$color = max( 0, min( 255, $color + $steps ) ); // Adjust color
$return .= str_pad( dechex( $color ), 2, '0', STR_PAD_LEFT ); // Make two char hex code
}
}elseif (preg_match("/^rgb\(/i", $hex)){
$hex = str_replace(array('rgb','(',')'),'',$hex);
//replace possible number separator
$hex = str_replace(array(' ',','),':',$hex);
//extract numbers
$color_parts = explode(":", $hex);
$return = '#';
foreach ( $color_parts as $color ){
//color already a decimal
$color = max( 0, min( 255, $color + $steps ) ); // Adjust color
$return .= str_pad( dechex( $color ), 2, '0', STR_PAD_LEFT ); // Make two char hex code
}
}
return $return;
}