206 posts
  • Has sold $40,000+ on Envato Market
  • Has been part of the Envato Community for over 5 years
  • Has referred 10+ members
  • Located in Australia
+3 more
ThemeChills
says

Hi all,

Perhaps you can help me out. I’m in the process of creating a WP theme which has certain elements that require RGBA support.

From what I have researched online, this doesn’t appear to be native to the Theme Customizer – currently only hex values are supported.

Because of this, I’m a bit stuck…would anyone have any recommendations on how I can get around this?

Thanks,

Leo

15 posts
  • Has been part of the Envato Community for over 6 years
  • Has referred 1+ members
  • Has collected 1+ items on Envato Market
  • Located in Romania
acosmin
says
You could use this for the php part:

function ac_hex2rgb($hex, $opacity = "1") {
   $hex = str_replace("#", "", $hex);

   if(strlen($hex) == 3) {
      $r = hexdec(substr($hex,0,1).substr($hex,0,1));
      $g = hexdec(substr($hex,1,1).substr($hex,1,1));
      $b = hexdec(substr($hex,2,1).substr($hex,2,1));
   } else {
      $r = hexdec(substr($hex,0,2));
      $g = hexdec(substr($hex,2,2));
      $b = hexdec(substr($hex,4,2));
   }

   echo $r . ',' . $g . ',' . $b . ',' . $opacity;
}

I don’t know if it will help you, but …

1867 posts The Last Man Standing
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $125,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Helped several times protecting Envato Market against copyright violations
+9 more
ImanGM
Moderator
says

You could use this for the php part:

+1

I would recommend to add a Hex fallback for RGBA colors too :)

15 posts
  • Has been part of the Envato Community for over 6 years
  • Has referred 1+ members
  • Has collected 1+ items on Envato Market
  • Located in Romania
acosmin
says

And here you have an example in jQuery: http://jsfiddle.net/ekinertac/3Evx5/1/

206 posts
  • Has sold $40,000+ on Envato Market
  • Has been part of the Envato Community for over 5 years
  • Has referred 10+ members
  • Located in Australia
+3 more
ThemeChills
says

You could use this for the php part:

function ac_hex2rgb($hex, $opacity = "1") {
   $hex = str_replace("#", "", $hex);

   if(strlen($hex) == 3) {
      $r = hexdec(substr($hex,0,1).substr($hex,0,1));
      $g = hexdec(substr($hex,1,1).substr($hex,1,1));
      $b = hexdec(substr($hex,2,1).substr($hex,2,1));
   } else {
      $r = hexdec(substr($hex,0,2));
      $g = hexdec(substr($hex,2,2));
      $b = hexdec(substr($hex,4,2));
   }

   echo $r . ',' . $g . ',' . $b . ',' . $opacity;
}
I don’t know if it will help you, but …

Thanks, though don’t quite understand where I would integrate this in the theme customizer…

554 posts
  • Had an item featured in an Envato Bundle
  • Won a Most Wanted contest
  • Has sold $10,000+ on Envato Market
  • Has been part of the Envato Community for over 6 years
+4 more
QBKL
says

You don’t need to use it IN the customizer. You use it as a function to convert the hex value in the customizer to your RGBA needs, when/where you need it. The value in the customizer still remains HEX.

In your customizer you’d have to offer the user two fields to set up, the HEX color and the opacity level, which you later process through the function.

206 posts
  • Has sold $40,000+ on Envato Market
  • Has been part of the Envato Community for over 5 years
  • Has referred 10+ members
  • Located in Australia
+3 more
ThemeChills
says

Ok, thanks everyone. I’ll look into it further.

by
by
by
by
by
by