From ee6048c7bd409dcc454a90801b447a8155cca65a Mon Sep 17 00:00:00 2001 From: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Thu, 1 Aug 2024 10:00:48 +0200 Subject: [PATCH] Allow child themes to override parent colors.json This is used to set up the Customizer color inputs. --- includes/{functions => }/colors.json | 0 includes/functions/_customizer-settings.php | 14 ++++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) rename includes/{functions => }/colors.json (100%) diff --git a/includes/functions/colors.json b/includes/colors.json similarity index 100% rename from includes/functions/colors.json rename to includes/colors.json diff --git a/includes/functions/_customizer-settings.php b/includes/functions/_customizer-settings.php index ba6ce72a..ad2e2c51 100644 --- a/includes/functions/_customizer-settings.php +++ b/includes/functions/_customizer-settings.php @@ -66,12 +66,18 @@ function fictioneer_add_color_theme_option( $manager, $args ) { global $fictioneer_colors; if ( empty( $fictioneer_colors ) && ! is_array( $fictioneer_colors ) ) { - $json_path = get_template_directory() . '/includes/functions/colors.json'; - $fictioneer_colors = @json_decode( file_get_contents( $json_path ), true ); + $parent_colors = @json_decode( file_get_contents( get_template_directory() . '/includes/colors.json' ), true ); + $child_colors = @json_decode( file_get_contents( get_stylesheet_directory() . '/includes/colors.json' ), true ); - if ( ! is_array( $fictioneer_colors ) ) { - $fictioneer_colors = []; + if ( ! is_array( $parent_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'] ?? '';