functions.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php
  2. /**
  3. * Child Theme Functions and definitions
  4. *
  5. * @link https://developer.wordpress.org/themes/basics/theme-functions/
  6. *
  7. * @package WordPress
  8. * @since 1.0.0
  9. */
  10. if ( ! function_exists( 'redhill_theme_setup' ) ) :
  11. /**
  12. * Sets up theme defaults and registers support for various WordPress features.
  13. *
  14. * Note that this function is hooked into the after_setup_theme hook, which
  15. * runs before the init hook. The init hook is too late for some features, such
  16. * as indicating support for post thumbnails.
  17. */
  18. function redhill_theme_setup() {
  19. // Add child theme editor styles, compiled from `style-child-theme-editor.scss`.
  20. add_editor_style( 'style-editor.css' );
  21. // Remove parent theme font sizes
  22. remove_theme_support( 'editor-font-sizes' );
  23. // Add child theme editor font sizes to match Sass-map variables in `_config-child-theme-deep.scss`.
  24. add_theme_support(
  25. 'editor-font-sizes',
  26. array(
  27. array(
  28. 'name' => __( 'Small', 'redhill' ),
  29. 'shortName' => __( 'S', 'redhill' ),
  30. 'size' => 16.66,
  31. 'slug' => 'small',
  32. ),
  33. array(
  34. 'name' => __( 'Normal', 'redhill' ),
  35. 'shortName' => __( 'N', 'redhill' ),
  36. 'size' => 20,
  37. 'slug' => 'normal',
  38. ),
  39. array(
  40. 'name' => __( 'Medium', 'redhill' ),
  41. 'shortName' => __( 'M', 'redhill' ),
  42. 'size' => 24,
  43. 'slug' => 'medium',
  44. ),
  45. array(
  46. 'name' => __( 'Large', 'redhill' ),
  47. 'shortName' => __( 'L', 'redhill' ),
  48. 'size' => 28.8,
  49. 'slug' => 'large',
  50. ),
  51. array(
  52. 'name' => __( 'Huge', 'redhill' ),
  53. 'shortName' => __( 'XL', 'redhill' ),
  54. 'size' => 34.56,
  55. 'slug' => 'huge',
  56. ),
  57. )
  58. );
  59. /*
  60. * Get customizer colors and add them to the editor color palettes
  61. *
  62. * - if the customizer color is empty, use the default
  63. */
  64. $colors_array = get_theme_mod( 'colors_manager' ); // color annotations array()
  65. $primary = is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) ? $colors_array['colors']['link'] : '#CA2017'; // $config-global--color-primary-default;
  66. $secondary = is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) ? $colors_array['colors']['fg1'] : '#007FDB'; // $config-global--color-secondary-default;
  67. $background = is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) ? $colors_array['colors']['bg'] : '#FFFFFF'; // $config-global--color-background-default;
  68. $foreground = is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) ? $colors_array['colors']['txt'] : '#222222'; // $config-global--color-foreground-default;
  69. $foreground_light = ( is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) && $colors_array['colors']['txt'] != '#222222' ) ? $colors_array['colors']['txt'] : '#666666'; // $config-global--color-foreground-light-default;
  70. $foreground_dark = ( is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) && $colors_array['colors']['txt'] != '#222222' ) ? $colors_array['colors']['txt'] : '#111111'; // $config-global--color-foreground-dark-default;
  71. // Editor color palette.
  72. add_theme_support(
  73. 'editor-color-palette',
  74. array(
  75. array(
  76. 'name' => __( 'Primary', 'redhill' ),
  77. 'slug' => 'primary',
  78. 'color' => $primary,
  79. ),
  80. array(
  81. 'name' => __( 'Secondary', 'redhill' ),
  82. 'slug' => 'secondary',
  83. 'color' => $secondary,
  84. ),
  85. array(
  86. 'name' => __( 'Background', 'redhill' ),
  87. 'slug' => 'background',
  88. 'color' => $background,
  89. ),
  90. array(
  91. 'name' => __( 'Foreground', 'redhill' ),
  92. 'slug' => 'foreground',
  93. 'color' => $foreground,
  94. ),
  95. array(
  96. 'name' => __( 'Foreground Light', 'redhill' ),
  97. 'slug' => 'foreground-light',
  98. 'color' => $foreground_light,
  99. ),
  100. array(
  101. 'name' => __( 'Foreground Dark', 'redhill' ),
  102. 'slug' => 'foreground-dark',
  103. 'color' => $foreground_dark,
  104. ),
  105. )
  106. );
  107. // Add child theme support for core custom logo.
  108. add_theme_support(
  109. 'custom-logo',
  110. array(
  111. 'height' => 120,
  112. 'width' => 100,
  113. 'flex-width' => true,
  114. 'flex-height' => true,
  115. 'header-text' => array( 'site-title', 'site-description' ),
  116. )
  117. );
  118. }
  119. endif;
  120. add_action( 'after_setup_theme', 'redhill_theme_setup', 12 );
  121. /**
  122. * Set the content width in pixels, based on the child-theme's design and stylesheet.
  123. *
  124. * Priority 0 to make it available to lower priority callbacks.
  125. *
  126. * @global int $content_width Content width.
  127. */
  128. function redhill_theme_content_width() {
  129. // This variable is intended to be overruled from themes.
  130. // Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
  131. // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
  132. $GLOBALS['content_width'] = apply_filters( 'redhill_theme_content_width', 740 );
  133. }
  134. add_action( 'after_setup_theme', 'redhill_theme_content_width', 0 );
  135. /**
  136. * Enqueue scripts and styles.
  137. */
  138. function redhill_theme_scripts() {
  139. // dequeue parent styles
  140. wp_dequeue_style( 'varia-style' );
  141. // enqueue child styles
  142. wp_enqueue_style( 'redhill-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ) );
  143. // enqueue child RTL styles
  144. wp_style_add_data( 'redhill-style', 'rtl', 'replace' );
  145. }
  146. add_action( 'wp_enqueue_scripts', 'redhill_theme_scripts', 99 );
  147. /**
  148. * Enqueue theme styles for the block editor.
  149. */
  150. function redhill_editor_styles() {
  151. // Hide duplicate palette colors
  152. $colors_array = get_theme_mod( 'colors_manager' );
  153. if ( ! empty( $colors_array ) && $colors_array['colors']['txt'] != '#666666' ) { // $config-global--color-foreground-light-default;
  154. $inline_palette_css = '.components-circular-option-picker__option-wrapper:nth-child(5),
  155. .components-circular-option-picker__option-wrapper:nth-child(6) {
  156. display: none;
  157. }';
  158. wp_add_inline_style( 'wp-edit-blocks', $inline_palette_css );
  159. }
  160. }
  161. add_action( 'enqueue_block_editor_assets', 'redhill_editor_styles' );