Allow child themes to override parent colors.json

This is used to set up the Customizer color inputs.
This commit is contained in:
Tetrakern 2024-08-01 10:00:48 +02:00
parent 1b4e3530bb
commit ee6048c7bd
2 changed files with 10 additions and 4 deletions

View File

@ -66,12 +66,18 @@ function fictioneer_add_color_theme_option( $manager, $args ) {
global $fictioneer_colors; global $fictioneer_colors;
if ( empty( $fictioneer_colors ) && ! is_array( $fictioneer_colors ) ) { if ( empty( $fictioneer_colors ) && ! is_array( $fictioneer_colors ) ) {
$json_path = get_template_directory() . '/includes/functions/colors.json'; $parent_colors = @json_decode( file_get_contents( get_template_directory() . '/includes/colors.json' ), true );
$fictioneer_colors = @json_decode( file_get_contents( $json_path ), true ); $child_colors = @json_decode( file_get_contents( get_stylesheet_directory() . '/includes/colors.json' ), true );
if ( ! is_array( $fictioneer_colors ) ) { if ( ! is_array( $parent_colors ) ) {
$fictioneer_colors = []; $parent_colors = [];
} }
if ( ! is_array( $child_colors ) ) {
$child_colors = [];
}
$fictioneer_colors = array_merge( $parent_colors, $child_colors );
} }
$default = $args['default'] ?? $fictioneer_colors[ $args['setting'] ]['hex'] ?? ''; $default = $args['default'] ?? $fictioneer_colors[ $args['setting'] ]['hex'] ?? '';