[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-content/themes/twentytwenty/inc/ -> custom-css.php (source)

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


Generated : Wed Apr 24 08:20:01 2024 Cross-referenced by PHPXref