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