functions.php 5.2 KB

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