@@ -132,6 +132,18 @@ public function register_color_schemes() {
132132 'default ' => '' ,
133133 )
134134 );
135+
136+ register_setting (
137+ 'stackable_global_settings ' ,
138+ 'stackable_use_v3_16_0_color_scheme_inheritance ' ,
139+ array (
140+ 'type ' => 'boolean ' ,
141+ 'description ' => __ ( 'Stackable Global Color Scheme v3.16.0 Color Scheme Inheritance ' , STACKABLE_I18N ),
142+ 'sanitize_callback ' => 'sanitize_text_field ' ,
143+ 'show_in_rest ' => true ,
144+ 'default ' => false ,
145+ )
146+ );
135147 }
136148
137149 // Make this function static so it can be used when
@@ -182,6 +194,20 @@ public static function get_color_scheme_properties( $values = null ) {
182194 /**-----------------------------------------------------------------------------
183195 * Global Color Scheme functions
184196 *-----------------------------------------------------------------------------*/
197+
198+ public static function get_color_schemes_array () {
199+ $ schemes_array = is_array ( get_option ( 'stackable_global_color_schemes ' ) ) ? get_option ( 'stackable_global_color_schemes ' ) : [];
200+
201+ // Get all color schemes, including custom color schemes if any
202+ $ all_color_schemes = apply_filters ( 'stackable_global_color_schemes/get_color_schemes ' , $ schemes_array );
203+
204+ if ( ! is_array ( $ all_color_schemes ) ) {
205+ return false ;
206+ }
207+
208+ return self ::convert_to_assoc_array ( $ all_color_schemes );
209+ }
210+
185211 /**
186212 * Add the default global color schemes in the frontend (Base, Default Background, Default Container).
187213 * Other color schemes used by blocks will be added on `render_block` filter.
@@ -201,16 +227,13 @@ public function add_global_color_schemes_styles( $current_css ) {
201227 }
202228
203229 // Generate the CSS for the color schemes if there is no cached CSS
204- $ schemes_array = is_array ( get_option ( 'stackable_global_color_schemes ' ) ) ? get_option ( 'stackable_global_color_schemes ' ) : [];
205-
206- // Get all color schemes, including custom color schemes if any
207- $ all_color_schemes = apply_filters ( 'stackable_global_color_schemes/get_color_schemes ' , $ schemes_array );
230+ $ all_color_schemes = $ this ::get_color_schemes_array ();
208231
209- if ( ! is_array ( $ all_color_schemes ) ) {
232+ if ( ! $ all_color_schemes ) {
210233 return $ current_css ;
211234 }
212235
213- $ this ->color_schemes = $ this -> convert_to_assoc_array ( $ all_color_schemes ) ;
236+ $ this ->color_schemes = $ all_color_schemes ;
214237
215238 $ base_default = isset ( $ this ->color_schemes [ get_option ( 'stackable_global_base_color_scheme ' ) ] ) ? get_option ( 'stackable_global_base_color_scheme ' ) : 'scheme-default-1 ' ;
216239 $ background_default = isset ( $ this ->color_schemes [ get_option ( 'stackable_global_background_mode_color_scheme ' ) ] ) ? get_option ( 'stackable_global_background_mode_color_scheme ' ) : 'scheme-default-2 ' ;
@@ -274,6 +297,11 @@ public function add_global_color_schemes_styles( $current_css ) {
274297 $ styles = $ this ->generate_color_scheme_styles ( $ styles , $ scheme );
275298 }
276299
300+ // This fixes the issue wherein if there is a background scheme and no container/base scheme, the container inherits the background scheme which may cause the text to be unreadable
301+ if ( isset ( $ this ->color_schemes [ $ container_default ] ) && $ this ::is_scheme_empty ( $ this ->color_schemes [ $ container_default ] ) ) {
302+ $ styles = $ this ->getDefaultContainerColors ( $ styles , $ default_color_schemes [ 2 ] );
303+ }
304+
277305 $ color_scheme_css = '' ;
278306 $ generated_css = wp_style_engine_get_stylesheet_from_css_rules ( $ styles );
279307 if ( $ generated_css != '' ) {
@@ -320,7 +348,7 @@ public function add_body_class_color_schemes( $classes ) {
320348 * @param Array $schemes_array
321349 * @return Array
322350 */
323- public function convert_to_assoc_array ( $ schemes_array ) {
351+ public static function convert_to_assoc_array ( $ schemes_array ) {
324352 return array_column ( $ schemes_array , 'colorScheme ' , 'key ' );
325353 }
326354
@@ -402,6 +430,18 @@ public function has_value( $scheme, $property, $state ) {
402430 return true ;
403431 }
404432
433+ public static function is_scheme_empty ( $ scheme ) {
434+ foreach ( $ scheme as $ property => $ values ) {
435+ if ( is_array ( $ values ) ) {
436+ foreach ( $ values as $ device_state => $ value ) {
437+ if ( $ value ) return false ;
438+ }
439+ }
440+ }
441+
442+ return true ;
443+ }
444+
405445 public function is_gradient ( $ scheme , $ property , $ state ) {
406446 if ( ! $ this ->has_value ( $ scheme , $ property , $ state ) ) {
407447 return false ;
@@ -410,6 +450,37 @@ public function is_gradient( $scheme, $property, $state ) {
410450 return strpos ( $ value , 'linear- ' ) !== false || strpos ( $ value , 'radial- ' ) !== false ;
411451 }
412452
453+ // These colors are used when there are color schemes but the default container scheme is empty
454+ public function getDefaultContainerColors ( $ styles , $ scheme ) {
455+ $ selectors = $ scheme [ 'selectors ' ];
456+
457+ $ default_styles = array ();
458+ $ default_styles [] = array (
459+ 'selector ' => $ selectors [ 'desktop ' ],
460+ 'declarations ' => array (
461+ '--stk-background-color ' => 'var(--stk-default-container-background-color, #fff) ' ,
462+ '--stk-heading-color ' => 'var(--stk-default-heading-color, initial) ' ,
463+ '--stk-text-color ' => 'var(--stk-container-color, initial) ' ,
464+ '--stk-link-color ' => 'var(--stk-default-link-color, var(--stk-text-color, initial)) ' ,
465+ '--stk-accent-color ' => '#ddd ' ,
466+ '--stk-subtitle-color ' => '#39414d ' ,
467+ '--stk-default-icon-color ' => 'var(--stk-icon-color) ' ,
468+ '--stk-button-background-color ' => 'var(--stk-default-button-background-color, #008de4) ' ,
469+ '--stk-button-text-color ' => 'var(--stk-default-button-text-color, #fff) ' ,
470+ '--stk-button-outline-color ' => 'var(--stk-default-button-background-color, #008de4) '
471+ )
472+ );
473+
474+ $ default_styles = apply_filters ( 'stackable.global-settings.global-color-schemes.default-container-scheme ' , $ default_styles );
475+
476+ foreach ( $ default_styles as $ styles ) {
477+ $ styles [] = $ default_styles ;
478+ }
479+
480+
481+ return $ styles ;
482+ }
483+
413484 /**
414485 * This returns the CSS declarations for the CSS rules.
415486 *
@@ -436,6 +507,11 @@ public function generate_css_rules( $scheme, $mode = '' ) {
436507 foreach ( $ properties as $ property => $ css_property ) {
437508 if ( $ this ->has_value ( $ scheme , $ property , $ state ) ) {
438509 $ decls [ $ state ][ $ css_property ] = $ scheme [ $ property ][ $ state ];
510+
511+ if ( $ property === 'accentColor ' ) {
512+ $ suffix = $ state === 'desktopHover ' ? '-hover ' : '' ;
513+ $ decls [ $ state ][ "--stk-subtitle-color $ suffix " ] = $ scheme [ $ property ][ $ state ];
514+ }
439515 }
440516
441517 /**
0 commit comments