| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Twenty Twenty Custom CSS 4 * 5 * @package WordPress 6 * @subpackage Twenty_Twenty 7 * @since Twenty Twenty 1.0 8 */ 9 10 if ( ! function_exists( 'twentytwenty_generate_css' ) ) { 11 12 /** 13 * Generates CSS. 14 * 15 * @since Twenty Twenty 1.0 16 * 17 * @param string $selector The CSS selector. 18 * @param string $style The CSS style. 19 * @param string $value The CSS value. 20 * @param string $prefix The CSS prefix. 21 * @param string $suffix The CSS suffix. 22 * @param bool $display Print the styles. 23 * @return string Generated CSS. 24 */ 25 function twentytwenty_generate_css( $selector, $style, $value, $prefix = '', $suffix = '', $display = true ) { 26 /* 27 * Bail early if we have no $selector elements or properties and $value. 28 */ 29 if ( ! $value || ! $selector ) { 30 return ''; 31 } 32 33 $return = sprintf( '%s { %s: %s; }', $selector, $style, $prefix . $value . $suffix ); 34 35 if ( $display ) { 36 37 echo $return; 38 39 } 40 41 return $return; 42 } 43 } 44 45 if ( ! function_exists( 'twentytwenty_get_customizer_css' ) ) { 46 47 /** 48 * Gets CSS Built from Customizer Options. 49 * Builds CSS reflecting colors, fonts and other options set in the Customizer, and returns them for output. 50 * 51 * @since Twenty Twenty 1.0 52 * 53 * @param string $type Whether to return CSS for the "front-end", "block-editor", or "classic-editor". 54 * @return string CSS styles built from Customizer options. 55 */ 56 function twentytwenty_get_customizer_css( $type = 'front-end' ) { 57 58 // Get variables. 59 $body = sanitize_hex_color( twentytwenty_get_color_for_area( 'content', 'text' ) ); 60 $body_default = '#000000'; 61 $secondary = sanitize_hex_color( twentytwenty_get_color_for_area( 'content', 'secondary' ) ); 62 $secondary_default = '#6d6d6d'; 63 $borders = sanitize_hex_color( twentytwenty_get_color_for_area( 'content', 'borders' ) ); 64 $borders_default = '#dcd7ca'; 65 $accent = sanitize_hex_color( twentytwenty_get_color_for_area( 'content', 'accent' ) ); 66 $accent_default = '#cd2653'; 67 68 // Header. 69 $header_footer_background = sanitize_hex_color( twentytwenty_get_color_for_area( 'header-footer', 'background' ) ); 70 $header_footer_background_default = '#ffffff'; 71 72 // Cover. 73 $cover = sanitize_hex_color( get_theme_mod( 'cover_template_overlay_text_color' ) ); 74 $cover_default = '#ffffff'; 75 76 // Background. 77 $background = sanitize_hex_color_no_hash( get_theme_mod( 'background_color' ) ); 78 $background_default = 'f5efe0'; 79 80 ob_start(); 81 82 /* 83 * Note – Styles are applied in this order: 84 * 1. Element specific 85 * 2. Helper classes 86 * 87 * This enables all helper classes to overwrite base element styles, 88 * meaning that any color classes applied in the block editor will 89 * have a higher priority than the base element styles. 90 */ 91 92 // Front-End Styles. 93 if ( 'front-end' === $type ) { 94 95 // Auto-calculated colors. 96 $elements_definitions = twentytwenty_get_elements_array(); 97 foreach ( $elements_definitions as $context => $props ) { 98 foreach ( $props as $key => $definitions ) { 99 foreach ( $definitions as $property => $elements ) { 100 /* 101 * If we don't have an elements array or it is empty 102 * then skip this iteration early; 103 */ 104 if ( ! is_array( $elements ) || empty( $elements ) ) { 105 continue; 106 } 107 $val = twentytwenty_get_color_for_area( $context, $key ); 108 if ( $val ) { 109 twentytwenty_generate_css( implode( ',', $elements ), $property, $val ); 110 } 111 } 112 } 113 } 114 115 if ( $cover && $cover !== $cover_default ) { 116 twentytwenty_generate_css( '.overlay-header .header-inner', 'color', $cover ); 117 twentytwenty_generate_css( '.cover-header .entry-header *', 'color', $cover ); 118 } 119 120 // Block Editor Styles. 121 } elseif ( 'block-editor' === $type ) { 122 123 // Colors. 124 // Accent color. 125 if ( $accent && $accent !== $accent_default ) { 126 twentytwenty_generate_css( ':root .has-accent-color, .editor-styles-wrapper 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 ); 127 twentytwenty_generate_css( '.editor-styles-wrapper .wp-block-quote', 'border-color', $accent, '' ); 128 twentytwenty_generate_css( '.has-accent-background-color, .editor-styles-wrapper .wp-block-button__link, .editor-styles-wrapper .wp-block-file__button', 'background-color', $accent ); 129 } 130 131 // Background color. 132 if ( $background && $background !== $background_default ) { 133 twentytwenty_generate_css( '.editor-styles-wrapper', 'background-color', '#' . $background ); 134 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 ); 135 } 136 137 // Borders color. 138 if ( $borders && $borders !== $borders_default ) { 139 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 ); 140 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 ); 141 } 142 143 // Text color. 144 if ( $body && $body !== $body_default ) { 145 twentytwenty_generate_css( 'html .editor-styles-wrapper, .editor-post-title__block .editor-post-title__input, .editor-post-title__block .editor-post-title__input:focus', 'color', $body ); 146 } 147 148 // Secondary color. 149 if ( $secondary && $secondary !== $secondary_default ) { 150 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 ); 151 } 152 153 // Header Footer Background Color. 154 if ( $header_footer_background && $header_footer_background !== $header_footer_background_default ) { 155 twentytwenty_generate_css( '.editor-styles-wrapper .wp-block-pullquote::before', 'background-color', $header_footer_background ); 156 } 157 } elseif ( 'classic-editor' === $type ) { 158 159 // Colors. 160 // Accent color. 161 if ( $accent && $accent !== $accent_default ) { 162 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 ); 163 twentytwenty_generate_css( 'body#tinymce.wp-editor.content blockquote, body#tinymce.wp-editor.content .wp-block-quote', 'border-color', $accent, '', ' !important' ); 164 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 ); 165 } 166 167 // Background color. 168 if ( $background && $background !== $background_default ) { 169 twentytwenty_generate_css( 'body#tinymce.wp-editor.content', 'background-color', '#' . $background ); 170 } 171 172 // Text color. 173 if ( $body && $body !== $body_default ) { 174 twentytwenty_generate_css( 'body#tinymce.wp-editor.content', 'color', $body ); 175 } 176 177 // Secondary color. 178 if ( $secondary && $secondary !== $secondary_default ) { 179 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 ); 180 } 181 182 // Borders color. 183 if ( $borders && $borders !== $borders_default ) { 184 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 ); 185 } 186 } 187 188 // Return the results. 189 return ob_get_clean(); 190 } 191 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Sun Sep 6 08:20:27 2026 | Cross-referenced by PHPXref |