functions.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 Exford
  10. * @since 1.0.0
  11. */
  12. if ( ! function_exists( 'exford_setup' ) ) :
  13. /**
  14. * Sets up theme defaults and registers support for various WordPress features.
  15. *
  16. * Note that this function is hooked into the after_setup_theme hook, which
  17. * runs before the init hook. The init hook is too late for some features, such
  18. * as indicating support for post thumbnails.
  19. */
  20. function exford_setup() {
  21. // Add child theme editor styles, compiled from `style-child-theme-editor.scss`.
  22. add_editor_style( 'style-editor.css' );
  23. // Add child theme editor font sizes to match Sass-map variables in `_config-child-theme-deep.scss`.
  24. add_theme_support(
  25. 'editor-font-sizes',
  26. array(
  27. array(
  28. 'name' => __( 'Small', 'exford' ),
  29. 'shortName' => __( 'S', 'exford' ),
  30. 'size' => 16.6,
  31. 'slug' => 'small',
  32. ),
  33. array(
  34. 'name' => __( 'Normal', 'exford' ),
  35. 'shortName' => __( 'M', 'exford' ),
  36. 'size' => 20,
  37. 'slug' => 'normal',
  38. ),
  39. array(
  40. 'name' => __( 'Large', 'exford' ),
  41. 'shortName' => __( 'L', 'exford' ),
  42. 'size' => 28.8,
  43. 'slug' => 'large',
  44. ),
  45. array(
  46. 'name' => __( 'Huge', 'exford' ),
  47. 'shortName' => __( 'XL', 'exford' ),
  48. 'size' => 34.56,
  49. 'slug' => 'huge',
  50. ),
  51. )
  52. );
  53. /*
  54. * Get customizer colors and add them to the editor color palettes
  55. *
  56. * - if the customizer color is empty, use the default
  57. */
  58. $colors_array = get_theme_mod( 'colors_manager' ); // color annotations array()
  59. $primary = is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) ? $colors_array['colors']['link'] : '#23883D'; // $config-global--color-primary-default;
  60. $secondary = is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) ? $colors_array['colors']['fg1'] : '#0963C4'; // $config-global--color-secondary-default;
  61. $background = is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) ? $colors_array['colors']['bg'] : '#FFFFFF'; // $config-global--color-background-default;
  62. $foreground = is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) ? $colors_array['colors']['txt'] : '#111111'; // $config-global--color-foreground-default;
  63. $foreground_light = ( is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) && $colors_array['colors']['txt'] != '#111111' ) ? $colors_array['colors']['txt'] : '#6E6E6E'; // $config-global--color-foreground-light-default;
  64. $foreground_dark = ( is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) && $colors_array['colors']['txt'] != '#111111' ) ? $colors_array['colors']['txt'] : '#020202'; // $config-global--color-foreground-dark-default;
  65. // Editor color palette.
  66. add_theme_support(
  67. 'editor-color-palette',
  68. array(
  69. array(
  70. 'name' => __( 'Primary', 'exford' ),
  71. 'slug' => 'primary',
  72. 'color' => $primary,
  73. ),
  74. array(
  75. 'name' => __( 'Secondary', 'exford' ),
  76. 'slug' => 'secondary',
  77. 'color' => $secondary,
  78. ),
  79. array(
  80. 'name' => __( 'Foreground', 'exford' ),
  81. 'slug' => 'foreground',
  82. 'color' => $foreground,
  83. ),
  84. array(
  85. 'name' => __( 'Background', 'exford' ),
  86. 'slug' => 'background',
  87. 'color' => $background,
  88. ),
  89. array(
  90. 'name' => __( 'Foreground Light', 'exford' ),
  91. 'slug' => 'foreground-light',
  92. 'color' => $foreground_light,
  93. ),
  94. array(
  95. 'name' => __( 'Foreground Dark', 'exford' ),
  96. 'slug' => 'foreground-dark',
  97. 'color' => $foreground_dark,
  98. ),
  99. )
  100. );
  101. // Enable Full Site Editing
  102. add_theme_support( 'full-site-editing' );
  103. }
  104. endif;
  105. add_action( 'after_setup_theme', 'exford_setup', 12 );
  106. /**
  107. * Filter the content_width in pixels, based on the child-theme's design and stylesheet.
  108. */
  109. function exford_content_width() {
  110. return 750;
  111. }
  112. add_filter( 'varia_content_width', 'exford_content_width' );
  113. /**
  114. * Add Google webfonts, if necessary
  115. *
  116. * - See: http://themeshaper.com/2014/08/13/how-to-add-google-fonts-to-wordpress-themes/
  117. */
  118. function exford_fonts_url() {
  119. $fonts_url = '';
  120. /* Translators: If there are characters in your language that are not
  121. * supported by Source Serif Pro, translate this to 'off'. Do not translate
  122. * into your own language.
  123. */
  124. $source_serif_pro = esc_html_x( 'on', 'Source Serif Pro font: on or off', 'exford' );
  125. /* Translators: If there are characters in your language that are not
  126. * supported by Source Sans Pro, translate this to 'off'. Do not translate
  127. * into your own language.
  128. */
  129. $source_sans_pro = esc_html_x( 'on', 'Source Sans Pro font: on or off', 'exford' );
  130. if ( 'off' !== $source_serif_pro || 'off' !== $source_sans_pro ) {
  131. $font_families = array();
  132. if ( 'off' !== $source_serif_pro ) {
  133. $font_families[] = 'Source Serif Pro:400,700,400i,700i';
  134. }
  135. if ( 'off' !== $source_sans_pro ) {
  136. $font_families[] = 'Source Sans Pro:400,700,400i,700i';
  137. }
  138. /**
  139. * A filter to enable child themes to add/change/omit font families.
  140. *
  141. * @param array $font_families An array of font families to be imploded for the Google Font API
  142. */
  143. $font_families = apply_filters( 'included_google_font_families', $font_families );
  144. $query_args = array(
  145. 'family' => urlencode( implode( '|', $font_families ) ),
  146. 'subset' => urlencode( 'latin,latin-ext' ),
  147. );
  148. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  149. }
  150. return esc_url_raw( $fonts_url );
  151. }
  152. /**
  153. * Enqueue scripts and styles.
  154. */
  155. function exford_scripts() {
  156. // enqueue Google fonts, if necessary
  157. wp_enqueue_style( 'exford-fonts', exford_fonts_url(), array(), null );
  158. // dequeue parent styles
  159. wp_dequeue_style( 'varia-style' );
  160. // enqueue child styles
  161. wp_enqueue_style( 'exford-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ) );
  162. // enqueue child RTL styles
  163. wp_style_add_data( 'exford-style', 'rtl', 'replace' );
  164. }
  165. add_action( 'wp_enqueue_scripts', 'exford_scripts', 99 );
  166. /**
  167. * Enqueue theme styles for the block editor.
  168. */
  169. function exford_editor_styles() {
  170. // Enqueue Google fonts in the editor, if necessary
  171. wp_enqueue_style( 'exford-editor-fonts', exford_fonts_url(), array(), null );
  172. // Hide duplicate palette colors
  173. $colors_array = get_theme_mod( 'colors_manager' );
  174. if ( ! empty( $colors_array ) && $colors_array['colors']['txt'] != '#6E6E6E' ) { // $config-global--color-foreground-light-default;
  175. $inline_palette_css = '.components-circular-option-picker__option-wrapper:nth-child(5),
  176. .components-circular-option-picker__option-wrapper:nth-child(6) {
  177. display: none;
  178. }';
  179. wp_add_inline_style( 'wp-edit-blocks', $inline_palette_css );
  180. }
  181. }
  182. add_action( 'enqueue_block_editor_assets', 'exford_editor_styles' );