Last active
October 7, 2020 23:21
-
-
Save cameronjonesweb/1ffbfca7563a787fd59a000f9746b86f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function cameronjonesweb_colour_scheme() { | |
return array( | |
array( | |
'name' => 'White', | |
'slug' => 'white', | |
'color' => '#ffffff', | |
), | |
array( | |
'name' => 'Black', | |
'slug' => 'black', | |
'color' => '#222222', | |
), | |
array( | |
'name' => 'Grey', | |
'slug' => 'grey', | |
'color' => '#f4f4f4', | |
), | |
); | |
} | |
/** | |
* Generate CSS rules for the colour scheme | |
* | |
* @return string | |
*/ | |
function cameronjonesweb_generate_colour_scheme_styles() { | |
$colours = cameronjonesweb_colour_scheme(); | |
$styles = ''; | |
if ( ! empty( $colours ) ) { | |
foreach ( $colours as $colour ) { | |
$styles .= sprintf( | |
'.has-%1$s-color { color: %2$s; } .has-%1$s-background-color { background-color: %2$s; }', | |
$colour['slug'], | |
$colour['color'] | |
); | |
} | |
} | |
return $styles; | |
} | |
/** | |
* Render style tag with the colour scheme styles | |
*/ | |
function cameronjonesweb_render_colour_scheme_styles() { | |
wp_add_inline_style( 'wp-block-library', cameronjonesweb_generate_colour_scheme_styles(); | |
} | |
add_action( 'init', 'cameronjonesweb_render_colour_scheme_styles' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment