123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- <?php
- if ( ! function_exists( 'twentytwenty_generate_css' ) ) {
-
- function twentytwenty_generate_css( $selector, $style, $value, $prefix = '', $suffix = '', $echo = true ) {
- $return = '';
-
- if ( ! $value || ! $selector ) {
- return;
- }
- $return = sprintf( '%s { %s: %s; }', $selector, $style, $prefix . $value . $suffix );
- if ( $echo ) {
- echo $return;
- }
- return $return;
- }
- }
- if ( ! function_exists( 'twentytwenty_get_customizer_css' ) ) {
-
- function twentytwenty_get_customizer_css( $type = 'front-end' ) {
-
- $body = sanitize_hex_color( twentytwenty_get_color_for_area( 'content', 'text' ) );
- $body_default = '#000000';
- $secondary = sanitize_hex_color( twentytwenty_get_color_for_area( 'content', 'secondary' ) );
- $secondary_default = '#6d6d6d';
- $borders = sanitize_hex_color( twentytwenty_get_color_for_area( 'content', 'borders' ) );
- $borders_default = '#dcd7ca';
- $accent = sanitize_hex_color( twentytwenty_get_color_for_area( 'content', 'accent' ) );
- $accent_default = '#cd2653';
-
- $header_footer_background = sanitize_hex_color( twentytwenty_get_color_for_area( 'header-footer', 'background' ) );
- $header_footer_background_default = '#ffffff';
-
- $cover = sanitize_hex_color( get_theme_mod( 'cover_template_overlay_text_color' ) );
- $cover_default = '#ffffff';
-
- $background = sanitize_hex_color_no_hash( get_theme_mod( 'background_color' ) );
- $background_default = 'f5efe0';
- ob_start();
-
-
- if ( 'front-end' === $type ) {
-
- $elements_definitions = twentytwenty_get_elements_array();
- foreach ( $elements_definitions as $context => $props ) {
- foreach ( $props as $key => $definitions ) {
- foreach ( $definitions as $property => $elements ) {
-
- if ( ! is_array( $elements ) || empty( $elements ) ) {
- continue;
- }
- $val = twentytwenty_get_color_for_area( $context, $key );
- if ( $val ) {
- twentytwenty_generate_css( implode( ',', $elements ), $property, $val );
- }
- }
- }
- }
- if ( $cover && $cover !== $cover_default ) {
- twentytwenty_generate_css( '.overlay-header .header-inner', 'color', $cover );
- twentytwenty_generate_css( '.cover-header .entry-header *', 'color', $cover );
- }
-
- } elseif ( 'block-editor' === $type ) {
-
-
- if ( $accent && $accent !== $accent_default ) {
- twentytwenty_generate_css( '.has-accent-color, .editor-styles-wrapper .editor-block-list__layout a, .editor-styles-wrapper .has-drop-cap:not(:focus)::first-letter, .editor-styles-wrapper .wp-block-button.is-style-outline .wp-block-button__link, .editor-styles-wrapper .wp-block-pullquote::before, .editor-styles-wrapper .wp-block-file .wp-block-file__textlink', 'color', $accent );
- twentytwenty_generate_css( '.editor-styles-wrapper .wp-block-quote', 'border-color', $accent, '' );
- twentytwenty_generate_css( '.has-accent-background-color, .editor-styles-wrapper .wp-block-button__link, .editor-styles-wrapper .wp-block-file__button', 'background-color', $accent );
- }
-
- if ( $background && $background !== $background_default ) {
- twentytwenty_generate_css( '.editor-styles-wrapper', 'background-color', '#' . $background );
- twentytwenty_generate_css( '.has-background.has-primary-background-color:not(.has-text-color),.has-background.has-primary-background-color *:not(.has-text-color),.has-background.has-accent-background-color:not(.has-text-color),.has-background.has-accent-background-color *:not(.has-text-color)', 'color', '#' . $background );
- }
-
- if ( $borders && $borders !== $borders_default ) {
- twentytwenty_generate_css( '.editor-styles-wrapper .wp-block-code, .editor-styles-wrapper pre, .editor-styles-wrapper .wp-block-preformatted pre, .editor-styles-wrapper .wp-block-verse pre, .editor-styles-wrapper fieldset, .editor-styles-wrapper .wp-block-table, .editor-styles-wrapper .wp-block-table *, .editor-styles-wrapper .wp-block-table.is-style-stripes, .editor-styles-wrapper .wp-block-latest-posts.is-grid li', 'border-color', $borders );
- twentytwenty_generate_css( '.editor-styles-wrapper .wp-block-table caption, .editor-styles-wrapper .wp-block-table.is-style-stripes tbody tr:nth-child(odd)', 'background-color', $borders );
- }
-
- if ( $body && $body !== $body_default ) {
- twentytwenty_generate_css( 'body .editor-styles-wrapper, .editor-post-title__block .editor-post-title__input, .editor-post-title__block .editor-post-title__input:focus', 'color', $body );
- }
-
- if ( $secondary && $secondary !== $secondary_default ) {
- twentytwenty_generate_css( '.editor-styles-wrapper figcaption, .editor-styles-wrapper cite, .editor-styles-wrapper .wp-block-quote__citation, .editor-styles-wrapper .wp-block-quote cite, .editor-styles-wrapper .wp-block-quote footer, .editor-styles-wrapper .wp-block-pullquote__citation, .editor-styles-wrapper .wp-block-pullquote cite, .editor-styles-wrapper .wp-block-pullquote footer, .editor-styles-wrapper ul.wp-block-archives li, .editor-styles-wrapper ul.wp-block-categories li, .editor-styles-wrapper ul.wp-block-latest-posts li, .editor-styles-wrapper ul.wp-block-categories__list li, .editor-styles-wrapper .wp-block-latest-comments time, .editor-styles-wrapper .wp-block-latest-posts time', 'color', $secondary );
- }
-
- if ( $header_footer_background && $header_footer_background !== $header_footer_background_default ) {
- twentytwenty_generate_css( '.editor-styles-wrapper .wp-block-pullquote::before', 'background-color', $header_footer_background );
- }
- } elseif ( 'classic-editor' === $type ) {
-
-
- if ( $accent && $accent !== $accent_default ) {
- twentytwenty_generate_css( 'body#tinymce.wp-editor.content a, body#tinymce.wp-editor.content a:focus, body#tinymce.wp-editor.content a:hover', 'color', $accent );
- twentytwenty_generate_css( 'body#tinymce.wp-editor.content blockquote, body#tinymce.wp-editor.content .wp-block-quote', 'border-color', $accent, '', ' !important' );
- twentytwenty_generate_css( 'body#tinymce.wp-editor.content button, body#tinymce.wp-editor.content .faux-button, body#tinymce.wp-editor.content .wp-block-button__link, body#tinymce.wp-editor.content .wp-block-file__button, body#tinymce.wp-editor.content input[type=\'button\'], body#tinymce.wp-editor.content input[type=\'reset\'], body#tinymce.wp-editor.content input[type=\'submit\']', 'background-color', $accent );
- }
-
- if ( $background && $background !== $background_default ) {
- twentytwenty_generate_css( 'body#tinymce.wp-editor.content', 'background-color', '#' . $background );
- }
-
- if ( $body && $body !== $body_default ) {
- twentytwenty_generate_css( 'body#tinymce.wp-editor.content', 'color', $body );
- }
-
- if ( $secondary && $secondary !== $secondary_default ) {
- twentytwenty_generate_css( 'body#tinymce.wp-editor.content hr:not(.is-style-dots), body#tinymce.wp-editor.content cite, body#tinymce.wp-editor.content figcaption, body#tinymce.wp-editor.content .wp-caption-text, body#tinymce.wp-editor.content .wp-caption-dd, body#tinymce.wp-editor.content .gallery-caption', 'color', $secondary );
- }
-
- if ( $borders && $borders !== $borders_default ) {
- twentytwenty_generate_css( 'body#tinymce.wp-editor.content pre, body#tinymce.wp-editor.content hr, body#tinymce.wp-editor.content fieldset,body#tinymce.wp-editor.content input, body#tinymce.wp-editor.content textarea', 'border-color', $borders );
- }
- }
-
- return ob_get_clean();
- }
- }
|