Advertisement
srikat

Untitled

May 21st, 2016
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. <?php
  2. /**
  3. * Genesis Sample.
  4. *
  5. * This file adds the required CSS to the front end to the Genesis Sample Theme.
  6. *
  7. * @package Genesis Sample
  8. * @author StudioPress
  9. * @license GPL-2.0+
  10. * @link http://www.studiopress.com/
  11. */
  12.  
  13. add_action( 'wp_enqueue_scripts', 'genesis_sample_css' );
  14. /**
  15. * Checks the settings for the link color, and accent color.
  16. * If any of these value are set the appropriate CSS is output.
  17. *
  18. * @since 2.2.3
  19. */
  20. function genesis_sample_css() {
  21.  
  22. $handle = defined( 'CHILD_THEME_NAME' ) && CHILD_THEME_NAME ? sanitize_title_with_dashes( CHILD_THEME_NAME ) : 'child-theme';
  23.  
  24. $color_link = get_theme_mod( 'genesis_sample_link_color', genesis_sample_customizer_get_default_link_color() );
  25. $color_accent = get_theme_mod( 'genesis_sample_accent_color', genesis_sample_customizer_get_default_accent_color() );
  26.  
  27. $css = '';
  28.  
  29. //* Calculate Color Contrast
  30. function genesis_sample_color_contrast( $color ) {
  31.  
  32. $hexcolor = str_replace( '#', '', $color );
  33.  
  34. $red = hexdec( substr( $hexcolor, 0, 2 ) );
  35. $green = hexdec( substr( $hexcolor, 2, 2 ) );
  36. $blue = hexdec( substr( $hexcolor, 4, 2 ) );
  37.  
  38. $luminosity = ( ( $red * 0.2126 ) + ( $green * 0.7152 ) + ( $blue * 0.0722 ) );
  39.  
  40. return ( $luminosity > 128 ) ? '#333333' : '#ffffff';
  41.  
  42. }
  43.  
  44. //* Calculate Color Brightness
  45. function genesis_sample_color_brightness( $color, $change ) {
  46.  
  47. $hexcolor = str_replace( '#', '', $color );
  48.  
  49. $red = hexdec( substr( $hexcolor, 0, 2 ) );
  50. $green = hexdec( substr( $hexcolor, 2, 2 ) );
  51. $blue = hexdec( substr( $hexcolor, 4, 2 ) );
  52.  
  53. $red = max( 0, min( 255, $red + $change ) );
  54. $green = max( 0, min( 255, $green + $change ) );
  55. $blue = max( 0, min( 255, $blue + $change ) );
  56.  
  57. return '#'.dechex( $red ).dechex( $green ).dechex( $blue );
  58.  
  59. }
  60.  
  61. $css .= ( genesis_sample_customizer_get_default_link_color() !== $color_link ) ? sprintf( '
  62.  
  63. a,
  64. .entry-title a:focus,
  65. .entry-title a:hover,
  66. .genesis-nav-menu a:focus,
  67. .genesis-nav-menu a:hover,
  68. .genesis-nav-menu .current-menu-item > a,
  69. .genesis-nav-menu .sub-menu .current-menu-item > a:focus,
  70. .genesis-nav-menu .sub-menu .current-menu-item > a:hover,
  71. .js nav button:focus,
  72. .js .menu-toggle:focus {
  73. color: %1$s;
  74. }
  75. ', $color_link ) : '';
  76.  
  77. $css .= ( genesis_sample_customizer_get_default_accent_color() !== $color_accent ) ? sprintf( '
  78.  
  79. button:focus,
  80. button:hover,
  81. input:focus[type="button"],
  82. input:focus[type="reset"],
  83. input:focus[type="submit"],
  84. input:hover[type="button"],
  85. input:hover[type="reset"],
  86. input:hover[type="submit"],
  87. .archive-pagination li a:focus,
  88. .archive-pagination li a:hover,
  89. .archive-pagination .active a,
  90. .button:focus,
  91. .button:hover,
  92. .sidebar .enews-widget input[type="submit"] {
  93. background-color: %s;
  94. color: %s;
  95. }
  96. ', $color_accent, genesis_sample_color_contrast( $color_accent ) ) : '';
  97.  
  98. if ( $css ) {
  99. wp_add_inline_style( $handle, $css );
  100. }
  101.  
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement