213 posts
  • Trendsetter
  • Author Level 6
  • 5 Years of Membership
  • Affiliate Level 2
+4 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

16 posts
  • 6 Years of Membership
  • Affiliate Level 1
  • Collector Level 1
  • 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 …

1891 posts The Last Man Standing
  • Weekly Top Seller
  • Author Level 8
  • Beta Tester
  • Moderator
+10 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 :)

16 posts
  • 6 Years of Membership
  • Affiliate Level 1
  • Collector Level 1
  • Romania
acosmin
says

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

213 posts
  • Trendsetter
  • Author Level 6
  • 5 Years of Membership
  • Affiliate Level 2
+4 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
  • Bundle Boss
  • Most Wanted Winner
  • Author Level 5
  • 6 Years of Membership
+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.

213 posts
  • Trendsetter
  • Author Level 6
  • 5 Years of Membership
  • Affiliate Level 2
+4 more
ThemeChills
says

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

by
by
by
by
by
by