Usage
nebula()->get_color($color, $specific_location, $default)
Parameters
$color
(Optional) (String) Which color to get
Default: primary
$specific_location
(Optional) (String) Only look in a single location for this color
Default: false
$default
(Optional) (String (color)) The color to return if the requested is not found
Default: black
Parameter Notes
Color names will be normalized, so ‘primary_color’, ‘primary’, and ‘$primary_color’ are all equivalent.
Specific locations that can be used are ‘customizer’, ‘child’, or ‘parent’. Or leave it blank to check each in their appropriate priority.
If the color exists in the specified location, but is commented out this will return the default color or black.
Additional Notes
This function has an alias sass_color()
.
Source File
Located in /libs/Utilities/Sass.php on line 453.
1 Hook
Find these filters and actions in the source code below to hook into them. Use do_action() and add_filter() in your functions file or plugin.
Filters
"pre_get_color"Need a new filter hook? Request one here.
Actions
This function has no action hooks available. Request one?public function get_color($color='primary', $specific_location=false, $default='black'){ $override = apply_filters('pre_get_color', null, $color, $specific_location); if ( isset($override) ){return $override;} $color = $this->normalize_color_name($color); //Check the Customizer if ( empty($specific_location) || $specific_location === 'customizer' ){ $theme_mod_color = get_theme_mod('nebula_' . $color); if ( !empty($theme_mod_color) ){ return $theme_mod_color; } } //Check the child theme if ( empty($specific_location) || $specific_location === 'child' ){ if ( is_child_theme() ){ $child_theme_color = $this->get_sass_variable($color, 'child', 'color'); if ( !empty($child_theme_color) ){ return $child_theme_color; } } } //Check the parent theme if ( empty($specific_location) || $specific_location === 'parent' ){ $parent_theme_color = $this->get_sass_variable($color, 'parent', 'color'); if ( !empty($parent_theme_color) ){ return $parent_theme_color; } } return $default; //Return the default color if provided, otherwise return black }
Override
To override this PHP function, use this hook in your child theme or plugin ("my_custom" can be changed):
add_filter('pre_get_color', 'my_custom_get_color', 10, 4); //The last integer must be 1 more than the actual parameters function my_custom_get_color($null, $color, $specific_location, $default){ //$null is required, but can be ignored //Write your own code here return true; //Return true to prevent the original function from running afterwords }
You can completely disable this PHP function with a single line actions:
add_filter('pre_get_color', '__return_false');