Skip to content

Utilities

Nick Haskins edited this page Nov 28, 2013 · 1 revision

Soren offers a library of utilities ranging from simple template functions, to full on color automation with PHP (that's balls awesome).

Color Sync

This function provides a level of color automation in cases where LESS isn't possible. A use case is providing a custom color control, but wanting to automatically style other items based on that users input. This function also has a built in brightness guard, that will automatically return a contrasting color if the input is greater than 128 rgba, which is roughly the breaking point of black and white.

soren_color_sync($key = '', $lum = 2);

Args

$key - hexidecimal color code
$lum - int - controls brightness cutoff - ligher is < 2, darker is > 2

Here's a basic example. Here were are using the function in it's basic form. It returns a matching color, automatically. This would through inline styles or style tag in wp_head.

border-bottom: 2px solid <?php echo soren_color_sync($storybasecolor, 1.7);?>;

Here's an expanded example. Here, we're taking a color from a users set color through post meta. We're passing this into the color sync function, and we're telling it to return a color a little lighter than the color they set.

$storybasecolor = get_post_meta(get_the_ID(),'aesop_article_bg', true); 
border-bottom: 2px solid <?php echo soren_color_sync($storybasecolor, 1.7);?>;

2 is the brightness break point. 1.7 is a little lighter. 2.2 is a little darker. Play with these values to suit your needs. Remember, users can use custom css if they absolutely have to. This just provides some level of color automation for PHP and inline styles.


Clone this wiki locally