functions.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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 Stow
  9. * @since 1.0.0
  10. */
  11. if ( ! function_exists( 'stow_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 stow_setup() {
  20. // Add child theme editor styles, compiled from `style-child-theme-editor.scss`.
  21. add_editor_style( 'style-editor.css' );
  22. // Add child theme editor font sizes to match Sass-map variables in `_config-child-theme-deep.scss`.
  23. add_theme_support(
  24. 'editor-font-sizes',
  25. array(
  26. array(
  27. 'name' => __( 'Small', 'stow' ),
  28. 'shortName' => __( 'S', 'stow' ),
  29. 'size' => 19.5,
  30. 'slug' => 'small',
  31. ),
  32. array(
  33. 'name' => __( 'Normal', 'stow' ),
  34. 'shortName' => __( 'M', 'stow' ),
  35. 'size' => 22,
  36. 'slug' => 'normal',
  37. ),
  38. array(
  39. 'name' => __( 'Large', 'stow' ),
  40. 'shortName' => __( 'L', 'stow' ),
  41. 'size' => 36.5,
  42. 'slug' => 'large',
  43. ),
  44. array(
  45. 'name' => __( 'Huge', 'stow' ),
  46. 'shortName' => __( 'XL', 'stow' ),
  47. 'size' => 49.5,
  48. 'slug' => 'huge',
  49. ),
  50. )
  51. );
  52. // Add child theme editor color pallete to match Sass-map variables in `_config-child-theme-deep.scss`.
  53. add_theme_support(
  54. 'editor-color-palette',
  55. array(
  56. array(
  57. 'name' => __( 'Primary', 'stow' ),
  58. 'slug' => 'primary',
  59. 'color' => '#404040',
  60. ),
  61. array(
  62. 'name' => __( 'Secondary', 'stow' ),
  63. 'slug' => 'secondary',
  64. 'color' => '#f25f70',
  65. ),
  66. array(
  67. 'name' => __( 'Dark Gray', 'stow' ),
  68. 'slug' => 'foreground-dark',
  69. 'color' => '#111111',
  70. ),
  71. array(
  72. 'name' => __( 'Gray', 'stow' ),
  73. 'slug' => 'foreground',
  74. 'color' => '#444444',
  75. ),
  76. array(
  77. 'name' => __( 'Light Gray', 'stow' ),
  78. 'slug' => 'foreground-light',
  79. 'color' => '#767676',
  80. ),
  81. array(
  82. 'name' => __( 'White Smoke', 'stow' ),
  83. 'slug' => 'background',
  84. 'color' => '#f0f0f0',
  85. ),
  86. )
  87. );
  88. }
  89. endif;
  90. add_action( 'after_setup_theme', 'stow_setup', 12 );
  91. /**
  92. * Set the content width in pixels, based on the child-theme's design and stylesheet.
  93. *
  94. * Priority 0 to make it available to lower priority callbacks.
  95. *
  96. * @global int $content_width Content width.
  97. */
  98. function stow_content_width() {
  99. // This variable is intended to be overruled from themes.
  100. // Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
  101. // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
  102. $GLOBALS['content_width'] = apply_filters( 'stow_content_width', 640 );
  103. }
  104. add_action( 'after_setup_theme', 'stow_content_width', 0 );
  105. /**
  106. * Add Google webfonts, if necessary
  107. *
  108. * - See: http://themeshaper.com/2014/08/13/how-to-add-google-fonts-to-wordpress-themes/
  109. */
  110. function stow_fonts_url() {
  111. $fonts_url = '';
  112. /* translators: If there are characters in your language that are not supported
  113. * by Source Sans Pro, translate this to 'off'. Do not translate into your own language.
  114. */
  115. $source_sans_pro = _x( 'on', 'Source Sans Pro font: on or off', 'stow' );
  116. /* translators: If there are characters in your language that are not supported
  117. * by Droid Serif, translate this to 'off'. Do not translate into your own language.
  118. */
  119. $droid_serif = _x( 'on', 'Droid Serif font: on or off', 'stow' );
  120. /* translators: If there are characters in your language that are not supported
  121. * by Oswald, translate this to 'off'. Do not translate into your own language.
  122. */
  123. $oswald = _x( 'on', 'Oswald font: on or off', 'stow' );
  124. if ( 'off' !== $source_sans_pro || 'off' !== $droid_serif || 'off' !== $oswald ) {
  125. $font_families = array();
  126. if ( 'off' !== $source_sans_pro ) {
  127. $font_families[] = 'Source Sans Pro:300,300italic,400,400italic,600';
  128. }
  129. if ( 'off' !== $droid_serif ) {
  130. $font_families[] = 'Droid Serif:400,400italic';
  131. }
  132. if ( 'off' !== $oswald ) {
  133. $font_families[] = 'Oswald:300,400';
  134. }
  135. $query_args = array(
  136. 'family' => urlencode( implode( '|', $font_families ) ),
  137. 'subset' => urlencode( 'latin,latin-ext' ),
  138. );
  139. $fonts_url = add_query_arg( $query_args, "https://fonts.googleapis.com/css" );
  140. }
  141. return esc_url_raw( $fonts_url );
  142. }
  143. /**
  144. * Enqueue scripts and styles.
  145. */
  146. function stow_scripts() {
  147. // enqueue Google fonts, if necessary
  148. wp_enqueue_style( 'stow-fonts', stow_fonts_url(), array(), null );
  149. // dequeue parent styles
  150. wp_dequeue_style( 'varia-style' );
  151. // enqueue child styles
  152. wp_enqueue_style('stow-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ));
  153. // enqueue child RTL styles
  154. wp_style_add_data( 'stow-style', 'rtl', 'replace' );
  155. }
  156. add_action( 'wp_enqueue_scripts', 'stow_scripts', 99 );
  157. /**
  158. * Enqueue theme styles for the block editor.
  159. */
  160. function stow_editor_styles() {
  161. // Enqueue Google fonts in the editor, if necessary
  162. wp_enqueue_style( 'stow-editor-fonts', stow_fonts_url(), array(), null );
  163. }
  164. add_action( 'enqueue_block_editor_assets', 'stow_editor_styles' );