functions.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. // Add child theme editor color pallete to match Sass-map variables in `_config-child-theme-deep.scss`.
  61. add_theme_support(
  62. 'editor-color-palette',
  63. array(
  64. array(
  65. 'name' => __( 'Primary', 'brompton' ),
  66. 'slug' => 'primary',
  67. 'color' => '#C04239',
  68. ),
  69. array(
  70. 'name' => __( 'Secondary', 'brompton' ),
  71. 'slug' => 'secondary',
  72. 'color' => '#FFFFFF',
  73. ),
  74. array(
  75. 'name' => __( 'Dark Gray', 'brompton' ),
  76. 'slug' => 'foreground-dark',
  77. 'color' => '#474747',
  78. ),
  79. array(
  80. 'name' => __( 'Gray', 'brompton' ),
  81. 'slug' => 'foreground',
  82. 'color' => '#505050',
  83. ),
  84. array(
  85. 'name' => __( 'Light Gray', 'brompton' ),
  86. 'slug' => 'foreground-light',
  87. 'color' => '#666666',
  88. ),
  89. array(
  90. 'name' => __( 'Dark Ivory', 'varia' ),
  91. 'slug' => 'background-dark',
  92. 'color' => '#B9B6B2',
  93. ),
  94. array(
  95. 'name' => __( 'Ivory', 'varia' ),
  96. 'slug' => 'background-light',
  97. 'color' => '#CFCDC7',
  98. ),
  99. array(
  100. 'name' => __( 'Light Ivory', 'brompton' ),
  101. 'slug' => 'background',
  102. 'color' => '#E8E4DD',
  103. ),
  104. )
  105. );
  106. }
  107. endif;
  108. add_action( 'after_setup_theme', 'brompton_setup', 12 );
  109. /**
  110. * Set the content width in pixels, based on the child-theme's design and stylesheet.
  111. *
  112. * Priority 0 to make it available to lower priority callbacks.
  113. *
  114. * @global int $content_width Content width.
  115. */
  116. function brompton_content_width() {
  117. // This variable is intended to be overruled from themes.
  118. // Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
  119. // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
  120. $GLOBALS['content_width'] = apply_filters( 'brompton_content_width', 740 );
  121. }
  122. add_action( 'after_setup_theme', 'brompton_content_width', 0 );
  123. /**
  124. * Add Google webfonts, if necessary
  125. *
  126. * - See: http://themeshaper.com/2014/08/13/how-to-add-google-fonts-to-wordpress-themes/
  127. */
  128. function brompton_fonts_url() {
  129. $fonts_url = '';
  130. /* Translators: If there are characters in your language that are not
  131. * supported by Lora, translate this to 'off'. Do not translate
  132. * into your own language.
  133. */
  134. $lora = esc_html_x( 'on', 'Lora font: on or off', 'brompton' );
  135. /* Translators: If there are characters in your language that are not
  136. * supported by Nunito Sans, translate this to 'off'. Do not translate
  137. * into your own language.
  138. */
  139. $nunito = esc_html_x( 'on', 'Nunito Sans font: on or off', 'brompton' );
  140. if ( 'off' !== $lora || 'off' !== $nunito ) {
  141. $font_families = array();
  142. if ( 'off' !== $lora ) {
  143. $font_families[] = 'Lora:400,400i,700,700i';
  144. }
  145. if ( 'off' !== $nunito ) {
  146. $font_families[] = 'Nunito Sans:400,400i,700,700i,900,900i';
  147. }
  148. $query_args = array(
  149. 'family' => urlencode( implode( '|', $font_families ) ),
  150. 'subset' => urlencode( 'latin,latin-ext' ),
  151. );
  152. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  153. }
  154. return esc_url_raw( $fonts_url );
  155. }
  156. /**
  157. * Enqueue scripts and styles.
  158. */
  159. function brompton_scripts() {
  160. // enqueue Google fonts, if necessary
  161. wp_enqueue_style( 'brompton-fonts', brompton_fonts_url(), array(), null );
  162. // dequeue parent styles
  163. wp_dequeue_style( 'varia-style' );
  164. // enqueue child styles
  165. wp_enqueue_style('brompton-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ));
  166. // enqueue child RTL styles
  167. wp_style_add_data( 'brompton-style', 'rtl', 'replace' );
  168. }
  169. add_action( 'wp_enqueue_scripts', 'brompton_scripts', 99 );
  170. /**
  171. * Enqueue theme styles for the block editor.
  172. */
  173. function brompton_editor_styles() {
  174. // Enqueue Google fonts in the editor, if necessary
  175. wp_enqueue_style( 'brompton-editor-fonts', brompton_fonts_url(), array(), null );
  176. }
  177. add_action( 'enqueue_block_editor_assets', 'brompton_editor_styles' );