functions.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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 mayland
  9. * @since 1.0.0
  10. */
  11. if ( ! function_exists( 'mayland_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 mayland_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', 'mayland' ),
  28. 'shortName' => __( 'S', 'mayland' ),
  29. 'size' => 16.6,
  30. 'slug' => 'small',
  31. ),
  32. array(
  33. 'name' => __( 'Normal', 'mayland' ),
  34. 'shortName' => __( 'M', 'mayland' ),
  35. 'size' => 20,
  36. 'slug' => 'normal',
  37. ),
  38. array(
  39. 'name' => __( 'Large', 'mayland' ),
  40. 'shortName' => __( 'L', 'mayland' ),
  41. 'size' => 28.8,
  42. 'slug' => 'large',
  43. ),
  44. array(
  45. 'name' => __( 'Huge', 'mayland' ),
  46. 'shortName' => __( 'XL', 'mayland' ),
  47. 'size' => 34.56,
  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'] : '#000000'; // $config-global--color-primary-default;
  59. $secondary = is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) ? $colors_array['colors']['fg1'] : '#1a1a1a'; // $config-global--color-secondary-default;
  60. $background = is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) ? $colors_array['colors']['bg'] : '#FFFFFF'; // $config-global--color-background-default;
  61. $foreground = is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) ? $colors_array['colors']['txt'] : '#010101'; // $config-global--color-foreground-default;
  62. $foreground_light = ( is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) && $colors_array['colors']['txt'] != '#010101' ) ? $colors_array['colors']['txt'] : '#666666'; // $config-global--color-foreground-light-default;
  63. $foreground_dark = ( is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) && $colors_array['colors']['txt'] != '#010101' ) ? $colors_array['colors']['txt'] : '#333333'; // $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', 'mayland' ),
  70. 'slug' => 'primary',
  71. 'color' => $primary,
  72. ),
  73. array(
  74. 'name' => __( 'Secondary', 'mayland' ),
  75. 'slug' => 'secondary',
  76. 'color' => $secondary,
  77. ),
  78. array(
  79. 'name' => __( 'Background', 'mayland' ),
  80. 'slug' => 'background',
  81. 'color' => $background,
  82. ),
  83. array(
  84. 'name' => __( 'Foreground', 'mayland' ),
  85. 'slug' => 'foreground',
  86. 'color' => $foreground,
  87. ),
  88. array(
  89. 'name' => __( 'Foreground Light', 'mayland' ),
  90. 'slug' => 'foreground-light',
  91. 'color' => $foreground_light,
  92. ),
  93. array(
  94. 'name' => __( 'Foreground Dark', 'mayland' ),
  95. 'slug' => 'foreground-dark',
  96. 'color' => $foreground_dark,
  97. ),
  98. )
  99. );
  100. // Setup nav on side toggle support.
  101. if ( function_exists( 'varia_mobile_nav_on_side_setup' ) ) {
  102. varia_mobile_nav_on_side_setup();
  103. }
  104. }
  105. endif;
  106. add_action( 'after_setup_theme', 'mayland_setup', 12 );
  107. /**
  108. * Filter the content_width in pixels, based on the child-theme's design and stylesheet.
  109. */
  110. function mayland_content_width() {
  111. return 750;
  112. }
  113. add_filter( 'varia_content_width', 'mayland_content_width' );
  114. /**
  115. * Add Google webfonts, if necessary
  116. *
  117. * - See: http://themeshaper.com/2014/08/13/how-to-add-google-fonts-to-wordpress-themes/
  118. */
  119. function mayland_fonts_url() {
  120. $fonts_url = '';
  121. /* Translators: If there are characters in your language that are not
  122. * supported by Poppins, translate this to 'off'. Do not translate
  123. * into your own language.
  124. */
  125. $poppins = esc_html_x( 'on', 'Poppins font: on or off', 'mayland' );
  126. if ( 'off' !== $poppins ) {
  127. $font_families = array();
  128. $font_families[] = 'Poppins:400,400i,600,600i';
  129. /**
  130. * A filter to enable child themes to add/change/omit font families.
  131. *
  132. * @param array $font_families An array of font families to be imploded for the Google Font API
  133. */
  134. $font_families = apply_filters( 'included_google_font_families', $font_families );
  135. $query_args = array(
  136. 'family' => urlencode( implode( '|', $font_families ) ),
  137. 'subset' => urlencode( 'latin,latin-ext' ),
  138. );
  139. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  140. }
  141. return esc_url_raw( $fonts_url );
  142. }
  143. /**
  144. * Enqueue scripts and styles.
  145. */
  146. function mayland_scripts() {
  147. // enqueue Google fonts, if necessary
  148. wp_enqueue_style( 'mayland-fonts', mayland_fonts_url(), array(), null );
  149. // dequeue parent styles
  150. wp_dequeue_style( 'varia-style' );
  151. // enqueue child styles
  152. wp_enqueue_style( 'mayland-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ) );
  153. // enqueue child RTL styles
  154. wp_style_add_data( 'mayland-style', 'rtl', 'replace' );
  155. }
  156. add_action( 'wp_enqueue_scripts', 'mayland_scripts', 99 );
  157. /**
  158. * Enqueue theme styles for the block editor.
  159. */
  160. function mayland_editor_styles() {
  161. // Enqueue Google fonts in the editor, if necessary
  162. wp_enqueue_style( 'mayland-editor-fonts', mayland_fonts_url(), array(), null );
  163. // Hide duplicate palette colors
  164. $colors_array = get_theme_mod( 'colors_manager' );
  165. if ( ! empty( $colors_array ) && $colors_array['colors']['txt'] != '#666666' ) { // $config-global--color-foreground-light-default;
  166. $inline_palette_css = '.components-circular-option-picker__option-wrapper:nth-child(5),
  167. .components-circular-option-picker__option-wrapper:nth-child(6) {
  168. display: none;
  169. }';
  170. wp_add_inline_style( 'wp-edit-blocks', $inline_palette_css );
  171. }
  172. }
  173. add_action( 'enqueue_block_editor_assets', 'mayland_editor_styles' );