functions.php 7.4 KB

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