functions.php 6.0 KB

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