[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-content/themes/twentyfifteen/inc/ -> custom-header.php (source)

   1  <?php
   2  /**
   3   * Custom Header functionality for Twenty Fifteen
   4   *
   5   * @package WordPress
   6   * @subpackage Twenty_Fifteen
   7   * @since Twenty Fifteen 1.0
   8   */
   9  
  10  /**
  11   * Set up the WordPress core custom header feature.
  12   *
  13   * @uses twentyfifteen_header_style()
  14   */
  15  function twentyfifteen_custom_header_setup() {
  16      $color_scheme       = twentyfifteen_get_color_scheme();
  17      $default_text_color = trim( $color_scheme[4], '#' );
  18  
  19      /**
  20       * Filter Twenty Fifteen custom-header support arguments.
  21       *
  22       * @since Twenty Fifteen 1.0
  23       *
  24       * @param array $args {
  25       *     An array of custom-header support arguments.
  26       *
  27       *     @type string $default_text_color     Default color of the header text.
  28       *     @type int    $width                  Width in pixels of the custom header image. Default 954.
  29       *     @type int    $height                 Height in pixels of the custom header image. Default 1300.
  30       *     @type string $wp-head-callback       Callback function used to styles the header image and text
  31       *                                          displayed on the blog.
  32       * }
  33       */
  34      add_theme_support(
  35          'custom-header',
  36          apply_filters(
  37              'twentyfifteen_custom_header_args',
  38              array(
  39                  'default-text-color' => $default_text_color,
  40                  'width'              => 954,
  41                  'height'             => 1300,
  42                  'wp-head-callback'   => 'twentyfifteen_header_style',
  43              )
  44          )
  45      );
  46  }
  47  add_action( 'after_setup_theme', 'twentyfifteen_custom_header_setup' );
  48  
  49  /**
  50   * Convert HEX to RGB.
  51   *
  52   * @since Twenty Fifteen 1.0
  53   *
  54   * @param string $color The original color, in 3- or 6-digit hexadecimal form.
  55   * @return array Array containing RGB (red, green, and blue) values for the given
  56   *               HEX code, empty array otherwise.
  57   */
  58  function twentyfifteen_hex2rgb( $color ) {
  59      $color = trim( $color, '#' );
  60  
  61      if ( strlen( $color ) == 3 ) {
  62          $r = hexdec( substr( $color, 0, 1 ) . substr( $color, 0, 1 ) );
  63          $g = hexdec( substr( $color, 1, 1 ) . substr( $color, 1, 1 ) );
  64          $b = hexdec( substr( $color, 2, 1 ) . substr( $color, 2, 1 ) );
  65      } elseif ( strlen( $color ) == 6 ) {
  66          $r = hexdec( substr( $color, 0, 2 ) );
  67          $g = hexdec( substr( $color, 2, 2 ) );
  68          $b = hexdec( substr( $color, 4, 2 ) );
  69      } else {
  70          return array();
  71      }
  72  
  73      return array(
  74          'red'   => $r,
  75          'green' => $g,
  76          'blue'  => $b,
  77      );
  78  }
  79  
  80  if ( ! function_exists( 'twentyfifteen_header_style' ) ) :
  81      /**
  82       * Styles the header image and text displayed on the blog.
  83       *
  84       * @since Twenty Fifteen 1.0
  85       *
  86       * @see twentyfifteen_custom_header_setup()
  87       */
  88  	function twentyfifteen_header_style() {
  89          $header_image = get_header_image();
  90  
  91          // If no custom options for text are set, let's bail.
  92          if ( empty( $header_image ) && display_header_text() ) {
  93              return;
  94          }
  95  
  96          // If we get this far, we have custom styles. Let's do this.
  97          ?>
  98          <style type="text/css" id="twentyfifteen-header-css">
  99          <?php
 100          // Short header for when there is no Custom Header and Header Text is hidden.
 101          if ( empty( $header_image ) && ! display_header_text() ) :
 102              ?>
 103          .site-header {
 104              padding-top: 14px;
 105              padding-bottom: 14px;
 106          }
 107  
 108          .site-branding {
 109              min-height: 42px;
 110          }
 111  
 112          @media screen and (min-width: 46.25em) {
 113              .site-header {
 114                  padding-top: 21px;
 115                  padding-bottom: 21px;
 116              }
 117              .site-branding {
 118                  min-height: 56px;
 119              }
 120          }
 121          @media screen and (min-width: 55em) {
 122              .site-header {
 123                  padding-top: 25px;
 124                  padding-bottom: 25px;
 125              }
 126              .site-branding {
 127                  min-height: 62px;
 128              }
 129          }
 130          @media screen and (min-width: 59.6875em) {
 131              .site-header {
 132                  padding-top: 0;
 133                  padding-bottom: 0;
 134              }
 135              .site-branding {
 136                  min-height: 0;
 137              }
 138          }
 139              <?php
 140          endif;
 141  
 142          // Has a Custom Header been added?
 143          if ( ! empty( $header_image ) ) :
 144              ?>
 145          .site-header {
 146  
 147              /*
 148               * No shorthand so the Customizer can override individual properties.
 149               * @see https://core.trac.wordpress.org/ticket/31460
 150               */
 151              background-image: url(<?php header_image(); ?>);
 152              background-repeat: no-repeat;
 153              background-position: 50% 50%;
 154              -webkit-background-size: cover;
 155              -moz-background-size:    cover;
 156              -o-background-size:      cover;
 157              background-size:         cover;
 158          }
 159  
 160          @media screen and (min-width: 59.6875em) {
 161              body:before {
 162  
 163                  /*
 164                   * No shorthand so the Customizer can override individual properties.
 165                   * @see https://core.trac.wordpress.org/ticket/31460
 166                   */
 167                  background-image: url(<?php header_image(); ?>);
 168                  background-repeat: no-repeat;
 169                  background-position: 100% 50%;
 170                  -webkit-background-size: cover;
 171                  -moz-background-size:    cover;
 172                  -o-background-size:      cover;
 173                  background-size:         cover;
 174                  border-right: 0;
 175              }
 176  
 177              .site-header {
 178                  background: transparent;
 179              }
 180          }
 181              <?php
 182          endif;
 183  
 184          // Has the text been hidden?
 185          if ( ! display_header_text() ) :
 186              ?>
 187          .site-title,
 188          .site-description {
 189              clip: rect(1px, 1px, 1px, 1px);
 190              position: absolute;
 191          }
 192      <?php endif; ?>
 193      </style>
 194          <?php
 195      }
 196  endif; // twentyfifteen_header_style
 197  
 198  /**
 199   * Enqueues front-end CSS for the header background color.
 200   *
 201   * @since Twenty Fifteen 1.0
 202   *
 203   * @see wp_add_inline_style()
 204   */
 205  function twentyfifteen_header_background_color_css() {
 206      $color_scheme            = twentyfifteen_get_color_scheme();
 207      $default_color           = $color_scheme[1];
 208      $header_background_color = get_theme_mod( 'header_background_color', $default_color );
 209  
 210      // Don't do anything if the current color is the default.
 211      if ( $header_background_color === $default_color ) {
 212          return;
 213      }
 214  
 215      $css = '
 216          /* Custom Header Background Color */
 217          body:before,
 218          .site-header {
 219              background-color: %1$s;
 220          }
 221  
 222          @media screen and (min-width: 59.6875em) {
 223              .site-header,
 224              .secondary {
 225                  background-color: transparent;
 226              }
 227  
 228              .widget button,
 229              .widget input[type="button"],
 230              .widget input[type="reset"],
 231              .widget input[type="submit"],
 232              .widget_calendar tbody a,
 233              .widget_calendar tbody a:hover,
 234              .widget_calendar tbody a:focus {
 235                  color: %1$s;
 236              }
 237          }
 238      ';
 239  
 240      wp_add_inline_style( 'twentyfifteen-style', sprintf( $css, $header_background_color ) );
 241  }
 242  add_action( 'wp_enqueue_scripts', 'twentyfifteen_header_background_color_css', 11 );
 243  
 244  /**
 245   * Enqueues front-end CSS for the sidebar text color.
 246   *
 247   * @since Twenty Fifteen 1.0
 248   */
 249  function twentyfifteen_sidebar_text_color_css() {
 250      $color_scheme       = twentyfifteen_get_color_scheme();
 251      $default_color      = $color_scheme[4];
 252      $sidebar_link_color = get_theme_mod( 'sidebar_textcolor', $default_color );
 253  
 254      // Don't do anything if the current color is the default.
 255      if ( $sidebar_link_color === $default_color ) {
 256          return;
 257      }
 258  
 259      // If we get this far, we have custom styles. Let's do this.
 260      $sidebar_link_color_rgb     = twentyfifteen_hex2rgb( $sidebar_link_color );
 261      $sidebar_text_color         = vsprintf( 'rgba( %1$s, %2$s, %3$s, 0.7)', $sidebar_link_color_rgb );
 262      $sidebar_border_color       = vsprintf( 'rgba( %1$s, %2$s, %3$s, 0.1)', $sidebar_link_color_rgb );
 263      $sidebar_border_focus_color = vsprintf( 'rgba( %1$s, %2$s, %3$s, 0.3)', $sidebar_link_color_rgb );
 264  
 265      $css = '
 266          /* Custom Sidebar Text Color */
 267          .site-title a,
 268          .site-description,
 269          .secondary-toggle:before {
 270              color: %1$s;
 271          }
 272  
 273          .site-title a:hover,
 274          .site-title a:focus {
 275              color: %1$s; /* Fallback for IE7 and IE8 */
 276              color: %2$s;
 277          }
 278  
 279          .secondary-toggle {
 280              border-color: %1$s; /* Fallback for IE7 and IE8 */
 281              border-color: %3$s;
 282          }
 283  
 284          .secondary-toggle:hover,
 285          .secondary-toggle:focus {
 286              border-color: %1$s; /* Fallback for IE7 and IE8 */
 287              border-color: %4$s;
 288          }
 289  
 290          .site-title a {
 291              outline-color: %1$s; /* Fallback for IE7 and IE8 */
 292              outline-color: %4$s;
 293          }
 294  
 295          @media screen and (min-width: 59.6875em) {
 296              .secondary a,
 297              .dropdown-toggle:after,
 298              .widget-title,
 299              .widget blockquote cite,
 300              .widget blockquote small {
 301                  color: %1$s;
 302              }
 303  
 304              .widget button,
 305              .widget input[type="button"],
 306              .widget input[type="reset"],
 307              .widget input[type="submit"],
 308              .widget_calendar tbody a {
 309                  background-color: %1$s;
 310              }
 311  
 312              .textwidget a {
 313                  border-color: %1$s;
 314              }
 315  
 316              .secondary a:hover,
 317              .secondary a:focus,
 318              .main-navigation .menu-item-description,
 319              .widget,
 320              .widget blockquote,
 321              .widget .wp-caption-text,
 322              .widget .gallery-caption {
 323                  color: %2$s;
 324              }
 325  
 326              .widget button:hover,
 327              .widget button:focus,
 328              .widget input[type="button"]:hover,
 329              .widget input[type="button"]:focus,
 330              .widget input[type="reset"]:hover,
 331              .widget input[type="reset"]:focus,
 332              .widget input[type="submit"]:hover,
 333              .widget input[type="submit"]:focus,
 334              .widget_calendar tbody a:hover,
 335              .widget_calendar tbody a:focus {
 336                  background-color: %2$s;
 337              }
 338  
 339              .widget blockquote {
 340                  border-color: %2$s;
 341              }
 342  
 343              .main-navigation ul,
 344              .main-navigation li,
 345              .secondary-toggle,
 346              .widget input,
 347              .widget textarea,
 348              .widget table,
 349              .widget th,
 350              .widget td,
 351              .widget pre,
 352              .widget li,
 353              .widget_categories .children,
 354              .widget_nav_menu .sub-menu,
 355              .widget_pages .children,
 356              .widget abbr[title] {
 357                  border-color: %3$s;
 358              }
 359  
 360              .dropdown-toggle:hover,
 361              .dropdown-toggle:focus,
 362              .widget hr {
 363                  background-color: %3$s;
 364              }
 365  
 366              .widget input:focus,
 367              .widget textarea:focus {
 368                  border-color: %4$s;
 369              }
 370  
 371              .sidebar a:focus,
 372              .dropdown-toggle:focus {
 373                  outline-color: %4$s;
 374              }
 375          }
 376      ';
 377  
 378      wp_add_inline_style( 'twentyfifteen-style', sprintf( $css, $sidebar_link_color, $sidebar_text_color, $sidebar_border_color, $sidebar_border_focus_color ) );
 379  }
 380  add_action( 'wp_enqueue_scripts', 'twentyfifteen_sidebar_text_color_css', 11 );


Generated: Sun Sep 15 01:00:03 2019 Cross-referenced by PHPXref 0.7.1