functions.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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 Balasana
  10. * @since 1.0.0
  11. */
  12. if ( ! function_exists( 'balasana_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 balasana_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', 'balasana' ),
  29. 'shortName' => __( 'S', 'balasana' ),
  30. 'size' => 16.666,
  31. 'slug' => 'small',
  32. ),
  33. array(
  34. 'name' => __( 'Normal', 'balasana' ),
  35. 'shortName' => __( 'M', 'balasana' ),
  36. 'size' => 20,
  37. 'slug' => 'normal',
  38. ),
  39. array(
  40. 'name' => __( 'Large', 'balasana' ),
  41. 'shortName' => __( 'L', 'balasana' ),
  42. 'size' => 28.8,
  43. 'slug' => 'large',
  44. ),
  45. array(
  46. 'name' => __( 'Huge', 'balasana' ),
  47. 'shortName' => __( 'XL', 'balasana' ),
  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'] : '#19744C'; // $config-global--color-primary-default;
  60. $secondary = is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) ? $colors_array['colors']['fg1'] : '#BC2213'; // $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'] : '#303030'; // $config-global--color-foreground-default;
  63. $foreground_light = ( is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) && $colors_array['colors']['txt'] != '#303030' ) ? $colors_array['colors']['txt'] : '#505050'; // $config-global--color-foreground-light-default;
  64. $foreground_dark = ( is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) && $colors_array['colors']['txt'] != '#303030' ) ? $colors_array['colors']['txt'] : '#101010'; // $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', 'balasana' ),
  71. 'slug' => 'primary',
  72. 'color' => $primary,
  73. ),
  74. array(
  75. 'name' => __( 'Secondary', 'balasana' ),
  76. 'slug' => 'secondary',
  77. 'color' => $secondary,
  78. ),
  79. array(
  80. 'name' => __( 'Background', 'balasana' ),
  81. 'slug' => 'background',
  82. 'color' => $background,
  83. ),
  84. array(
  85. 'name' => __( 'Foreground', 'balasana' ),
  86. 'slug' => 'foreground',
  87. 'color' => $foreground,
  88. ),
  89. array(
  90. 'name' => __( 'Foreground Light', 'balasana' ),
  91. 'slug' => 'foreground-light',
  92. 'color' => $foreground_light,
  93. ),
  94. array(
  95. 'name' => __( 'Foreground Dark', 'balasana' ),
  96. 'slug' => 'foreground-dark',
  97. 'color' => $foreground_dark,
  98. ),
  99. )
  100. );
  101. // Add child theme support for core custom logo.
  102. add_theme_support(
  103. 'custom-logo',
  104. array(
  105. 'height' => 96,
  106. 'width' => 96,
  107. 'flex-width' => true,
  108. 'flex-height' => true,
  109. 'header-text' => array( 'site-title', 'site-description' ),
  110. )
  111. );
  112. }
  113. endif;
  114. add_action( 'after_setup_theme', 'balasana_setup', 12 );
  115. /**
  116. * Filter the content_width in pixels, based on the child-theme's design and stylesheet.
  117. */
  118. function balasana_content_width() {
  119. return 750;
  120. }
  121. add_filter( 'varia_content_width', 'balasana_content_width' );
  122. /**
  123. * Add Google webfonts
  124. *
  125. * - See: http://themeshaper.com/2014/08/13/how-to-add-google-fonts-to-wordpress-themes/
  126. */
  127. function balasana_fonts_url() {
  128. $fonts_url = '';
  129. /* Translators: If there are characters in your language that are not
  130. * supported by Roboto Condensed, translate this to 'off'. Do not translate
  131. * into your own language.
  132. */
  133. $roboto_condensed = esc_html_x( 'on', 'Roboto Condensed font: on or off', 'balasana' );
  134. /* Translators: If there are characters in your language that are not
  135. * supported by Roboto, translate this to 'off'. Do not translate
  136. * into your own language.
  137. */
  138. $roboto = esc_html_x( 'on', 'Roboto font: on or off', 'balasana' );
  139. if ( 'off' !== $roboto_condensed || 'off' !== $roboto ) {
  140. $font_families = array();
  141. if ( 'off' !== $roboto_condensed ) {
  142. $font_families[] = 'Roboto Condensed:400,400i,700,700i';
  143. }
  144. if ( 'off' !== $roboto ) {
  145. $font_families[] = 'Roboto:400,400i,700,700i';
  146. }
  147. /**
  148. * A filter to enable child themes to add/change/omit font families.
  149. *
  150. * @param array $font_families An array of font families to be imploded for the Google Font API
  151. */
  152. $font_families = apply_filters( 'included_google_font_families', $font_families );
  153. $query_args = array(
  154. 'family' => urlencode( implode( '|', $font_families ) ),
  155. 'subset' => urlencode( 'latin,latin-ext' ),
  156. );
  157. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  158. }
  159. return esc_url_raw( $fonts_url );
  160. }
  161. /**
  162. * Enqueue scripts and styles.
  163. */
  164. function balasana_scripts() {
  165. // enqueue Google fonts
  166. wp_enqueue_style( 'balasana-fonts', balasana_fonts_url(), array(), null );
  167. // dequeue parent styles
  168. wp_dequeue_style( 'varia-style' );
  169. // enqueue child styles
  170. wp_enqueue_style( 'balasana-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ) );
  171. // enqueue child RTL styles
  172. wp_style_add_data( 'balasana-style', 'rtl', 'replace' );
  173. }
  174. add_action( 'wp_enqueue_scripts', 'balasana_scripts', 99 );
  175. /**
  176. * Enqueue theme styles for the block editor.
  177. */
  178. function balasana_editor_styles() {
  179. // Enqueue Google fonts in the editor
  180. wp_enqueue_style( 'balasana-editor-fonts', balasana_fonts_url(), array(), null );
  181. // Hide duplicate palette colors
  182. $colors_array = get_theme_mod( 'colors_manager', array( 'colors' => true ) ); // color annotations array()
  183. if ( ! empty( $colors_array ) && $colors_array['colors']['txt'] != '#394d55' ) { // $config-global--color-foreground-light-default;
  184. $inline_palette_css = '.components-circular-option-picker__option-wrapper:nth-child(5),
  185. .components-circular-option-picker__option-wrapper:nth-child(6) {
  186. display: none;
  187. }';
  188. wp_add_inline_style( 'wp-edit-blocks', $inline_palette_css );
  189. }
  190. }
  191. add_action( 'enqueue_block_editor_assets', 'balasana_editor_styles' );