functions.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. * @subpackage Coutoire
  10. * @since 1.0.0
  11. */
  12. if ( ! function_exists( 'coutoire_setup' ) ) :
  13. /**
  14. * Sets up theme defaults and registers support for various WordPress features.
  15. *
  16. * Note that this function is hooked into the after_setup_theme hook, which
  17. * runs before the init hook. The init hook is too late for some features, such
  18. * as indicating support for post thumbnails.
  19. */
  20. function coutoire_setup() {
  21. // Add child theme editor styles, compiled from `style-child-theme-editor.scss`.
  22. add_editor_style( 'style-editor.css' );
  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', 'coutoire' ),
  29. 'shortName' => __( 'S', 'coutoire' ),
  30. 'size' => 19.5,
  31. 'slug' => 'small',
  32. ),
  33. array(
  34. 'name' => __( 'Normal', 'coutoire' ),
  35. 'shortName' => __( 'M', 'coutoire' ),
  36. 'size' => 22,
  37. 'slug' => 'normal',
  38. ),
  39. array(
  40. 'name' => __( 'Large', 'coutoire' ),
  41. 'shortName' => __( 'L', 'coutoire' ),
  42. 'size' => 36.5,
  43. 'slug' => 'large',
  44. ),
  45. array(
  46. 'name' => __( 'Huge', 'coutoire' ),
  47. 'shortName' => __( 'XL', 'coutoire' ),
  48. 'size' => 49.5,
  49. 'slug' => 'huge',
  50. ),
  51. )
  52. );
  53. /*
  54. * Get customizer colors and add them to the editor color palettes
  55. *
  56. * - if the customizer color is empty, use the default
  57. */
  58. $colors_array = get_theme_mod( 'colors_manager' ); // color annotations array()
  59. $primary = is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) ? $colors_array['colors']['link'] : '#000000'; // $config-global--color-primary-default;
  60. $secondary = is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) ? $colors_array['colors']['fg1'] : '#FF7A5C'; // $config-global--color-secondary-default;
  61. $background = is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) ? $colors_array['colors']['bg'] : '#FFFFFF'; // $config-global--color-background-default;
  62. $foreground = is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) ? $colors_array['colors']['txt'] : '#444444'; // $config-global--color-foreground-default;
  63. $foreground_light = ( is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) && $colors_array['colors']['txt'] != '#444444' ) ? $colors_array['colors']['txt'] : '#767676'; // $config-global--color-foreground-light-default;
  64. $foreground_dark = ( is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) && $colors_array['colors']['txt'] != '#444444' ) ? $colors_array['colors']['txt'] : '#111111'; // $config-global--color-foreground-dark-default;
  65. // Editor color palette.
  66. add_theme_support(
  67. 'editor-color-palette',
  68. array(
  69. array(
  70. 'name' => __( 'Primary', 'coutoire' ),
  71. 'slug' => 'primary',
  72. 'color' => $primary,
  73. ),
  74. array(
  75. 'name' => __( 'Secondary', 'coutoire' ),
  76. 'slug' => 'secondary',
  77. 'color' => $secondary,
  78. ),
  79. array(
  80. 'name' => __( 'Background', 'coutoire' ),
  81. 'slug' => 'background',
  82. 'color' => $background,
  83. ),
  84. array(
  85. 'name' => __( 'Foreground', 'coutoire' ),
  86. 'slug' => 'foreground',
  87. 'color' => $foreground,
  88. ),
  89. array(
  90. 'name' => __( 'Foreground Light', 'coutoire' ),
  91. 'slug' => 'foreground-light',
  92. 'color' => $foreground_light,
  93. ),
  94. array(
  95. 'name' => __( 'Foreground Dark', 'coutoire' ),
  96. 'slug' => 'foreground-dark',
  97. 'color' => $foreground_dark,
  98. ),
  99. )
  100. );
  101. }
  102. endif;
  103. add_action( 'after_setup_theme', 'coutoire_setup', 12 );
  104. /**
  105. * Filter the content_width in pixels, based on the child-theme's design and stylesheet.
  106. */
  107. function coutoire_content_width() {
  108. return 1200;
  109. }
  110. add_filter( 'varia_content_width', 'coutoire_content_width' );
  111. /**
  112. * Add Google webfonts, if necessary
  113. *
  114. * - See: http://themeshaper.com/2014/08/13/how-to-add-google-fonts-to-wordpress-themes/
  115. */
  116. function coutoire_fonts_url() {
  117. $fonts_url = '';
  118. /* Translators: If there are characters in your language that are not
  119. * supported by Lora, translate this to 'off'. Do not translate
  120. * into your own language.
  121. */
  122. $work_sans = esc_html_x( 'on', 'Work Sans font: on or off', 'coutoire' );
  123. /* Translators: If there are characters in your language that are not
  124. * supported by Open Sans, translate this to 'off'. Do not translate
  125. * into your own language.
  126. */
  127. $eb_garamond = esc_html_x( 'on', 'EB Garamond font: on or off', 'coutoire' );
  128. if ( 'off' !== $work_sans || 'off' !== $eb_garamond ) {
  129. $font_families = array();
  130. if ( 'off' !== $work_sans ) {
  131. $font_families[] = 'Work Sans:300,500,600';
  132. }
  133. if ( 'off' !== $eb_garamond ) {
  134. $font_families[] = 'EB Garamond:400,400i,600';
  135. }
  136. /**
  137. * A filter to enable child themes to add/change/omit font families.
  138. *
  139. * @param array $font_families An array of font families to be imploded for the Google Font API
  140. */
  141. $font_families = apply_filters( 'included_google_font_families', $font_families );
  142. $query_args = array(
  143. 'family' => urlencode( implode( '|', $font_families ) ),
  144. 'subset' => urlencode( 'latin,latin-ext' ),
  145. );
  146. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  147. }
  148. return esc_url_raw( $fonts_url );
  149. }
  150. /**
  151. * Enqueue scripts and styles.
  152. */
  153. function coutoire_scripts() {
  154. // enqueue Google fonts, if necessary
  155. wp_enqueue_style( 'coutoire-fonts', coutoire_fonts_url(), array(), null );
  156. // dequeue parent styles
  157. wp_dequeue_style( 'varia-style' );
  158. // enqueue child styles
  159. wp_enqueue_style( 'coutoire-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ) );
  160. // enqueue child RTL styles
  161. wp_style_add_data( 'coutoire-style', 'rtl', 'replace' );
  162. if ( ! coutoire_is_amp() ) {
  163. // enqueue header spacing JS.
  164. wp_enqueue_script( 'coutoire-fixed-header-spacing', get_stylesheet_directory_uri() . '/js/fixed-header-spacing.js', array(), wp_get_theme()->get( 'Version' ), true );
  165. }
  166. }
  167. add_action( 'wp_enqueue_scripts', 'coutoire_scripts', 99 );
  168. /**
  169. * Enqueue theme styles for the block editor.
  170. */
  171. function coutoire_editor_styles() {
  172. // Enqueue Google fonts in the editor, if necessary
  173. wp_enqueue_style( 'coutoire-editor-fonts', coutoire_fonts_url(), array(), null );
  174. // Hide duplicate palette colors
  175. $colors_array = get_theme_mod( 'colors_manager', array( 'colors' => true ) ); // color annotations array()
  176. if ( ! empty( $colors_array ) && $colors_array['colors']['txt'] != '#767676' ) { // $config-global--color-foreground-light-default;
  177. $inline_palette_css = '.components-circular-option-picker__option-wrapper:nth-child(5),
  178. .components-circular-option-picker__option-wrapper:nth-child(6) {
  179. display: none;
  180. }';
  181. wp_add_inline_style( 'wp-edit-blocks', $inline_palette_css );
  182. }
  183. }
  184. add_action( 'enqueue_block_editor_assets', 'coutoire_editor_styles' );
  185. /**
  186. * Checks whether the endpoint is AMP.
  187. */
  188. function coutoire_is_amp() {
  189. return ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() );
  190. }