array( 'default' => '', 'value' => $body_font, 'type' => 'font', ), 'headings_font' => array( 'default' => '', 'value' => $headings_font, 'type' => 'font', ), 'headings_weight' => array( 'default' => '700', 'value' => $headings_weight, 'type' => 'font', ), 'headings_case' => array( 'default' => 'normal', 'value' => $headings_case, 'type' => 'font', ), 'headings_spacing' => array( 'default' => 'normal', 'value' => $headings_spacing, 'suffix' => 'em', 'type' => 'font', ), 'background' => array( 'default' => '#ffffff', 'value' => $background, 'type' => 'color', ), 'primary' => array( 'default' => '#1a1b1f', 'value' => $primary, 'type' => 'color', ), 'headings' => array( 'default' => '#1a1b1f', 'value' => $headings, 'type' => 'color', ), 'buttons_background' => array( 'default' => $buttons_background_default, 'value' => $buttons_background, 'type' => 'color', ), 'buttons_text' => array( 'default' => $background, 'value' => $buttons_text, 'type' => 'color', ), 'accent' => array( 'default' => '#007c89', 'value' => $accent, 'type' => 'color', ), ) ); /* CSS Elements ------------------ */ $css_elements = self::get_css_elements_array( $type ); /* Loop over the CSS elements ---- */ foreach ( $css_elements as $key => $definitions ) { $property = $properties[ $key ]; // Only proceeed if the value is set and not the default one // if ( ! $property['value'] || ( $property['default'] && $property['default'] == $property['value'] ) ) { // continue; // } // Add the specified prefix and/or suffix to the value $value = $property['value']; $value = isset( $property['prefix'] ) && $property['prefix'] ? $property['prefix'] . $value : $value; $value = isset( $property['suffix'] ) && $property['suffix'] ? $value . $property['suffix'] : $value; foreach ( $definitions as $elements_property => $elements ) { // No elements, no output if ( empty( $elements ) ) { continue; } // Convert to array, to support multiple sets of elements for each property. This gets // us around edgecases where browsers will break if it hits an urecognized selector. // For example, vendor specific ::placeholder selectors need to be styled separately, // or the browser will skip the entire CSS rule. if ( ! is_array( $elements ) ) $elements = array( $elements ); foreach ( $elements as $elements_set ) { // Generate CSS for the elements $css .= self::generate_css( $elements_set, $elements_property, $value ); } } } /* Minify the results ------------ */ $css = self::minify_css( $css ); /* Return the results ------------ */ return $css; } /* ----------------------------------------------------------------------------------------------- GET THE CSS ELEMENTS Stores an array of all elements to apply custom CSS to. @param $type string Whether to return elements for 'front-end', 'block-editor', --------------------------------------------------------------------------------------------------- */ public static function get_css_elements_array( $type = 'front-end' ) { /* Helper Variables -------------- */ // Type specific helper variables switch ( $type ) { case 'front-end' : $headings_targets = apply_filters( 'alux_headings_targets_front_end', 'h1, h2, h3, h4, h5, h6' ); $buttons_targets = apply_filters( 'alux_buttons_targets_front_end', 'button, .button, .wp-block-button__link, :root .wp-block-file a.wp-block-file__button, input[type=\'button\'], input[type=\'reset\'], input[type=\'submit\']' ); break; case 'block-editor' : $headings_targets = apply_filters( 'alux_headings_targets_block_editor', ':root .wp-block h1, :root h1.wp-block, :root .wp-block h2, :root h2.wp-block, :root .wp-block h3, :root h3.wp-block, :root .wp-block h4, :root h4.wp-block, :root .wp-block h5, :root h5.wp-block, :root .wp-block h6, :root h6.wp-block, .editor-post-title__block .editor-post-title__input, .editor-post-title__block .editor-post-title__input:focus' ); $buttons_targets = apply_filters( 'alux_buttons_targets_block_editor', '.wp-block-button__link, .editor-styles-wrapper :root .wp-block-file a.wp-block-file__button' ); break; } /* Build the array --------------- */ $elements = array( 'front-end' => array( // Typography 'body_font' => array( 'font-family' => 'body', ), 'headings_font' => array( 'font-family' => $headings_targets, ), 'headings_weight' => array( 'font-weight' => $headings_targets, ), 'headings_case' => array( 'text-transform' => $headings_targets, ), 'headings_spacing' => array( 'letter-spacing' => $headings_targets, ), // Colors 'primary' => array( 'background-color' => ' ', 'border-color' => ' ', 'color' => '.color-primary, .color-primary-hover:hover, body p', //'fill' => '.fill-children-primary, .fill-children-primary *', ), 'headings' => array( 'color' => $headings_targets, ), 'accent' => array( 'background-color' => ' ' . $buttons_targets, 'border-color' => ' blockquote', 'color' => ' a ', //'fill' => '.fill-children-accent, .fill-children-accent *', ), 'buttons_background' => array( 'background-color' => $buttons_targets . ' ', 'color' => '.is-style-outline .wp-block-button__link:not(.has-text-color), .wp-block-button__link.is-style-outline', ), 'buttons_text' => array( 'background-color' => ' ', 'color' => $buttons_targets . ' .wp-block-button__link ', ), ), 'block-editor' => array( // Typography 'body_font' => array( 'font-family' => '.editor-styles-wrapper > *, .editor-post-title__block .editor-post-title__input', ), 'headings_font' => array( 'font-family' => $headings_targets, ), 'headings_weight' => array( 'font-weight' => $headings_targets, ), 'headings_case' => array( 'text-transform' => $headings_targets, ), 'headings_spacing' => array( 'letter-spacing' => $headings_targets, ), // Colors 'primary' => array( 'background-color' => ' ', 'color' => ' .editor-styles-wrapper > *', ), 'headings' => array( 'color' => $headings_targets, ), 'accent' => array( 'background-color' => ' ' . $buttons_targets, 'border-color' => '.editor-styles-wrapper blockquote, .editor-styles-wrapper .wp-block-quote,', 'color' => '.editor-styles-wrapper .editor-block-list__layout a, .editor-styles-wrapper .block-editor-block-list__layout a, .wp-block-button.is-style-outline, .wp-block-button__link.is-style-outline', ), 'buttons_background' => array( 'background-color' => $buttons_targets, 'color' => '.wp-block-button.is-style-outline, .wp-block-button__link.is-style-outline, .is-style-outline>.wp-block-button__link:not(.has-text-color) ', 'border-color' => '.is-style-outline .wp-block-button__link ', ), 'buttons_text' => array( 'color' => $buttons_targets, ), ), ); /** * Filter the array of elements and return the array * * @param array Array of elements * @param string The type of elements selected (front-end, block-editor) */ return apply_filters( 'alux_get_css_elements_array', $elements[$type], $type ); } } endif; /* --------------------------------------------------------------------------------------------- Generate Blocks Defualt Colors Button --------------------------------------------------------------------------------------------- */ add_filter( 'generateblocks_defaults', function( $defaults ) { $defaults['button']['backgroundColor'] = get_theme_mod( 'alux_buttons_background_color' ); $defaults['button']['backgroundColorHover'] = get_theme_mod( 'alux_accent_color' ); $defaults['button']['textColor'] = get_theme_mod( 'alux_buttons_text_color' ); //$defaults['button']['textColorHover'] = $color_settings['form_button_text_color_hover']; $defaults['button']['paddingTop'] = '10'; $defaults['button']['paddingRight'] = '20'; $defaults['button']['paddingBottom'] = '10'; $defaults['button']['paddingLeft'] = '20'; return $defaults; } );