functions.php 5.0 KB

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