Created
June 26, 2019 09:56
-
-
Save tiborp/7d1435b3e3ae17593753c889bac6fcf6 to your computer and use it in GitHub Desktop.
Extract colors from a CSS or Sass file
This file contains 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 | |
/** | |
* Extract colors from a CSS or Sass file | |
* | |
* @param string $path the path to your CSS variables file | |
*/ | |
function get_colors( $path ) { | |
$dir = get_stylesheet_directory(); | |
if ( file_exists( $dir . $path ) ) { | |
$css_vars = file_get_contents( $dir . $path ); // phpcs:ignore WordPress.WP.AlternativeFunctions | |
preg_match_all( ' /#([a-f]|[A-F]|[0-9]){3}(([a-f]|[A-F]|[0-9]){3})?\b/', $css_vars, $matches ); | |
return $matches[0]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment