functions.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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 Brompton
  10. * @since 1.0.0
  11. */
  12. if ( ! function_exists( 'brompton_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 brompton_setup() {
  21. // Add child theme editor styles, compiled from `style-child-theme-editor.scss`.
  22. add_editor_style( 'style-editor.css' );
  23. // Remove parent theme font sizes
  24. remove_theme_support( 'editor-font-sizes' );
  25. // Add child theme editor font sizes to match Sass-map variables in `_config-child-theme-deep.scss`.
  26. add_theme_support(
  27. 'editor-font-sizes',
  28. array(
  29. array(
  30. 'name' => __( 'Small', 'brompton' ),
  31. 'shortName' => __( 'S', 'brompton' ),
  32. 'size' => 16.66,
  33. 'slug' => 'small',
  34. ),
  35. array(
  36. 'name' => __( 'Normal', 'brompton' ),
  37. 'shortName' => __( 'N', 'brompton' ),
  38. 'size' => 20,
  39. 'slug' => 'normal',
  40. ),
  41. array(
  42. 'name' => __( 'Medium', 'brompton' ),
  43. 'shortName' => __( 'M', 'brompton' ),
  44. 'size' => 24,
  45. 'slug' => 'medium',
  46. ),
  47. array(
  48. 'name' => __( 'Large', 'brompton' ),
  49. 'shortName' => __( 'L', 'brompton' ),
  50. 'size' => 28.8,
  51. 'slug' => 'large',
  52. ),
  53. array(
  54. 'name' => __( 'Huge', 'brompton' ),
  55. 'shortName' => __( 'XL', 'brompton' ),
  56. 'size' => 34.56,
  57. 'slug' => 'huge',
  58. ),
  59. )
  60. );
  61. /*
  62. * Get customizer colors and add them to the editor color palettes
  63. *
  64. * - if the customizer color is empty, use the default
  65. */
  66. $colors_array = get_theme_mod( 'colors_manager' ); // color annotations array()
  67. $primary = is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) ? $colors_array['colors']['link'] : '#C04239'; // $config-global--color-primary-default;
  68. $secondary = is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) ? $colors_array['colors']['fg1'] : '#FFFFFF'; // $config-global--color-secondary-default;
  69. $background = is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) ? $colors_array['colors']['bg'] : '#E8E4DD'; // $config-global--color-background-default;
  70. $foreground = is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) ? $colors_array['colors']['txt'] : '#252E36'; // $config-global--color-foreground-default;
  71. $foreground_light = ( is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) && $colors_array['colors']['txt'] != '#252E36' ) ? $colors_array['colors']['txt'] : '#666666'; // $config-global--color-foreground-light-default;
  72. $foreground_dark = ( is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) && $colors_array['colors']['txt'] != '#252E36' ) ? $colors_array['colors']['txt'] : '#474747'; // $config-global--color-foreground-dark-default;
  73. // Editor color palette.
  74. add_theme_support(
  75. 'editor-color-palette',
  76. array(
  77. array(
  78. 'name' => __( 'Primary', 'brompton' ),
  79. 'slug' => 'primary',
  80. 'color' => $primary,
  81. ),
  82. array(
  83. 'name' => __( 'Secondary', 'brompton' ),
  84. 'slug' => 'secondary',
  85. 'color' => $secondary,
  86. ),
  87. array(
  88. 'name' => __( 'Background', 'barnsbury' ),
  89. 'slug' => 'background',
  90. 'color' => $background,
  91. ),
  92. array(
  93. 'name' => __( 'Foreground', 'barnsbury' ),
  94. 'slug' => 'foreground',
  95. 'color' => $foreground,
  96. ),
  97. array(
  98. 'name' => __( 'Foreground Light', 'barnsbury' ),
  99. 'slug' => 'foreground-light',
  100. 'color' => $foreground_light,
  101. ),
  102. array(
  103. 'name' => __( 'Foreground Dark', 'barnsbury' ),
  104. 'slug' => 'foreground-dark',
  105. 'color' => $foreground_dark,
  106. ),
  107. )
  108. );
  109. }
  110. endif;
  111. add_action( 'after_setup_theme', 'brompton_setup', 12 );
  112. /**
  113. * Set the content width in pixels, based on the child-theme's design and stylesheet.
  114. *
  115. * Priority 0 to make it available to lower priority callbacks.
  116. *
  117. * @global int $content_width Content width.
  118. */
  119. function brompton_content_width() {
  120. // This variable is intended to be overruled from themes.
  121. // Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
  122. // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
  123. $GLOBALS['content_width'] = apply_filters( 'brompton_content_width', 740 );
  124. }
  125. add_action( 'after_setup_theme', 'brompton_content_width', 0 );
  126. /**
  127. * Add Google webfonts, if necessary
  128. *
  129. * - See: http://themeshaper.com/2014/08/13/how-to-add-google-fonts-to-wordpress-themes/
  130. */
  131. function brompton_fonts_url() {
  132. $fonts_url = '';
  133. /* Translators: If there are characters in your language that are not
  134. * supported by Lora, translate this to 'off'. Do not translate
  135. * into your own language.
  136. */
  137. $lora = esc_html_x( 'on', 'Lora font: on or off', 'brompton' );
  138. /* Translators: If there are characters in your language that are not
  139. * supported by Nunito Sans, translate this to 'off'. Do not translate
  140. * into your own language.
  141. */
  142. $nunito = esc_html_x( 'on', 'Nunito Sans font: on or off', 'brompton' );
  143. if ( 'off' !== $lora || 'off' !== $nunito ) {
  144. $font_families = array();
  145. if ( 'off' !== $lora ) {
  146. $font_families[] = 'Lora:400,400i,700,700i';
  147. }
  148. if ( 'off' !== $nunito ) {
  149. $font_families[] = 'Nunito Sans:400,400i,700,700i,900,900i';
  150. }
  151. /**
  152. * A filter to enable child themes to add/change/omit font families.
  153. *
  154. * @param array $font_families An array of font families to be imploded for the Google Font API
  155. */
  156. $font_families = apply_filters( 'included_google_font_families', $font_families );
  157. $query_args = array(
  158. 'family' => urlencode( implode( '|', $font_families ) ),
  159. 'subset' => urlencode( 'latin,latin-ext' ),
  160. );
  161. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  162. }
  163. return esc_url_raw( $fonts_url );
  164. }
  165. /**
  166. * Enqueue scripts and styles.
  167. */
  168. function brompton_scripts() {
  169. // enqueue Google fonts, if necessary
  170. wp_enqueue_style( 'brompton-fonts', brompton_fonts_url(), array(), null );
  171. // dequeue parent styles
  172. wp_dequeue_style( 'varia-style' );
  173. // enqueue child styles
  174. wp_enqueue_style( 'brompton-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ) );
  175. // enqueue child RTL styles
  176. wp_style_add_data( 'brompton-style', 'rtl', 'replace' );
  177. }
  178. add_action( 'wp_enqueue_scripts', 'brompton_scripts', 99 );
  179. /**
  180. * Enqueue theme styles for the block editor.
  181. */
  182. function brompton_editor_styles() {
  183. // Enqueue Google fonts in the editor, if necessary
  184. wp_enqueue_style( 'brompton-editor-fonts', brompton_fonts_url(), array(), null );
  185. // Hide duplicate palette colors
  186. $colors_array = get_theme_mod( 'colors_manager', array( 'colors' => true ) ); // color annotations array()
  187. if ( ! empty( $colors_array ) && $colors_array['colors']['txt'] != '#505050' ) { // $config-global--color-foreground-light-default;
  188. $inline_palette_css = '.components-circular-option-picker__option-wrapper:nth-child(5),
  189. .components-circular-option-picker__option-wrapper:nth-child(6) {
  190. display: none;
  191. }';
  192. wp_add_inline_style( 'wp-edit-blocks', $inline_palette_css );
  193. }
  194. }
  195. add_action( 'enqueue_block_editor_assets', 'brompton_editor_styles' );