functions.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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 Leven
  9. * @since 1.0.0
  10. */
  11. if ( ! function_exists( 'leven_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 leven_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', 'leven' ),
  28. 'shortName' => __( 'S', 'leven' ),
  29. 'size' => 15,
  30. 'slug' => 'small',
  31. ),
  32. array(
  33. 'name' => __( 'Normal', 'leven' ),
  34. 'shortName' => __( 'M', 'leven' ),
  35. 'size' => 18,
  36. 'slug' => 'normal',
  37. ),
  38. array(
  39. 'name' => __( 'Large', 'leven' ),
  40. 'shortName' => __( 'L', 'leven' ),
  41. 'size' => 32,
  42. 'slug' => 'large',
  43. ),
  44. array(
  45. 'name' => __( 'Huge', 'leven' ),
  46. 'shortName' => __( 'XL', 'leven' ),
  47. 'size' => 47.17,
  48. 'slug' => 'huge',
  49. ),
  50. )
  51. );
  52. /*
  53. * Get customizer colors and add them to the editor color palettes
  54. *
  55. * - if the customizer color is empty, use the default
  56. */
  57. $colors_array = get_theme_mod( 'colors_manager' ); // color annotations array()
  58. $primary = is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) ? $colors_array['colors']['link'] : '#FF302C'; // $config-global--color-primary-default;
  59. $secondary = is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) ? $colors_array['colors']['fg1'] : '#1285CE'; // $config-global--color-secondary-default;
  60. $background = is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) ? $colors_array['colors']['bg'] : '#F7F7F6'; // $config-global--color-background-default;
  61. $foreground = is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) ? $colors_array['colors']['txt'] : '#444444'; // $config-global--color-foreground-default;
  62. $foreground_light = ( is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) && $colors_array['colors']['txt'] != '#444444' ) ? $colors_array['colors']['txt'] : '#767676'; // $config-global--color-foreground-light-default;
  63. $foreground_dark = ( is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) && $colors_array['colors']['txt'] != '#444444' ) ? $colors_array['colors']['txt'] : '#111111'; // $config-global--color-foreground-dark-default;
  64. // Editor color palette.
  65. add_theme_support(
  66. 'editor-color-palette',
  67. array(
  68. array(
  69. 'name' => __( 'Primary', 'leven' ),
  70. 'slug' => 'primary',
  71. 'color' => $primary,
  72. ),
  73. array(
  74. 'name' => __( 'Secondary', 'leven' ),
  75. 'slug' => 'secondary',
  76. 'color' => $secondary,
  77. ),
  78. array(
  79. 'name' => __( 'Foreground', 'leven' ),
  80. 'slug' => 'foreground',
  81. 'color' => $foreground,
  82. ),
  83. array(
  84. 'name' => __( 'Background', 'leven' ),
  85. 'slug' => 'background',
  86. 'color' => $background,
  87. ),
  88. array(
  89. 'name' => __( 'Foreground Light', 'leven' ),
  90. 'slug' => 'foreground-light',
  91. 'color' => $foreground_light,
  92. ),
  93. array(
  94. 'name' => __( 'Foreground Dark', 'leven' ),
  95. 'slug' => 'foreground-dark',
  96. 'color' => $foreground_dark,
  97. ),
  98. )
  99. );
  100. }
  101. endif;
  102. add_action( 'after_setup_theme', 'leven_setup', 12 );
  103. /**
  104. * Set the content width in pixels, based on the child-theme's design and stylesheet.
  105. *
  106. * Priority 0 to make it available to lower priority callbacks.
  107. *
  108. * @global int $content_width Content width.
  109. */
  110. function leven_content_width() {
  111. // This variable is intended to be overruled from themes.
  112. // Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
  113. // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
  114. $GLOBALS['content_width'] = apply_filters( 'leven_content_width', 640 );
  115. }
  116. add_action( 'after_setup_theme', 'leven_content_width', 0 );
  117. /**
  118. * Add Google webfonts, if necessary
  119. *
  120. * - See: http://themeshaper.com/2014/08/13/how-to-add-google-fonts-to-wordpress-themes/
  121. */
  122. function leven_fonts_url() {
  123. $fonts_url = '';
  124. /* Translators: If there are characters in your language that are not
  125. * supported by Lora, translate this to 'off'. Do not translate
  126. * into your own language.
  127. */
  128. $crimson_text = esc_html_x( 'on', 'Crimson Text font: on or off', 'leven' );
  129. if ( 'off' !== $crimson_text ) {
  130. $font_families = array();
  131. if ( 'off' !== $crimson_text ) {
  132. $font_families[] = 'Crimson Text:400,400i';
  133. }
  134. /**
  135. * A filter to enable child themes to add/change/omit font families.
  136. *
  137. * @param array $font_families An array of font families to be imploded for the Google Font API
  138. */
  139. $font_families = apply_filters( 'included_google_font_families', $font_families );
  140. $query_args = array(
  141. 'family' => urlencode( implode( '|', $font_families ) ),
  142. 'subset' => urlencode( 'latin,latin-ext' ),
  143. );
  144. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  145. }
  146. return esc_url_raw( $fonts_url );
  147. }
  148. /**
  149. * Enqueue scripts and styles.
  150. */
  151. function leven_scripts() {
  152. // enqueue Google fonts, if necessary
  153. wp_enqueue_style( 'leven-fonts', leven_fonts_url(), array(), null );
  154. // dequeue parent styles
  155. wp_dequeue_style( 'varia-style' );
  156. // enqueue child styles
  157. wp_enqueue_style( 'leven-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ) );
  158. // enqueue child RTL styles
  159. wp_style_add_data( 'leven-style', 'rtl', 'replace' );
  160. }
  161. add_action( 'wp_enqueue_scripts', 'leven_scripts', 99 );
  162. /**
  163. * Enqueue theme styles for the block editor.
  164. */
  165. function leven_editor_styles() {
  166. // Enqueue Google fonts in the editor, if necessary
  167. wp_enqueue_style( 'leven-editor-fonts', leven_fonts_url(), array(), null );
  168. // Hide duplicate palette colors
  169. $colors_array = get_theme_mod( 'colors_manager' );
  170. if ( ! empty( $colors_array ) && $colors_array['colors']['txt'] != '#767676' ) { // $config-global--color-foreground-light-default;
  171. $inline_palette_css = '.components-circular-option-picker__option-wrapper:nth-child(5),
  172. .components-circular-option-picker__option-wrapper:nth-child(6) {
  173. display: none;
  174. }';
  175. wp_add_inline_style( 'wp-edit-blocks', $inline_palette_css );
  176. }
  177. }
  178. add_action( 'enqueue_block_editor_assets', 'leven_editor_styles' );