functions.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 Rivington
  10. * @since 1.0.0
  11. */
  12. if ( ! function_exists( 'rivington_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 rivington_setup() {
  21. // Add child theme editor styles, compiled from `style-child-theme-editor.scss`.
  22. add_editor_style( 'style-editor.css' );
  23. add_theme_support( 'editor-styles' );
  24. // Add child theme editor font sizes to match Sass-map variables in `_config-child-theme-deep.scss`.
  25. add_theme_support(
  26. 'editor-font-sizes',
  27. array(
  28. array(
  29. 'name' => __( 'Small', 'rivington' ),
  30. 'shortName' => __( 'S', 'rivington' ),
  31. 'size' => 14.4,
  32. 'slug' => 'small',
  33. ),
  34. array(
  35. 'name' => __( 'Normal', 'rivington' ),
  36. 'shortName' => __( 'M', 'rivington' ),
  37. 'size' => 18,
  38. 'slug' => 'normal',
  39. ),
  40. array(
  41. 'name' => __( 'Large', 'rivington' ),
  42. 'shortName' => __( 'L', 'rivington' ),
  43. 'size' => 28.12,
  44. 'slug' => 'large',
  45. ),
  46. array(
  47. 'name' => __( 'Huge', 'rivington' ),
  48. 'shortName' => __( 'XL', 'rivington' ),
  49. 'size' => 35.15,
  50. 'slug' => 'huge',
  51. ),
  52. )
  53. );
  54. /*
  55. * Get customizer colors and add them to the editor color palettes
  56. *
  57. * - if the customizer color is empty, use the default
  58. */
  59. $colors_array = get_theme_mod( 'colors_manager' ); // color annotations array()
  60. $primary = is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) ? $colors_array['colors']['link'] : '#CAAB57'; // $config-global--color-primary-default;
  61. $secondary = is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) ? $colors_array['colors']['fg1'] : '#EE4266'; // $config-global--color-secondary-default;
  62. $background = is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) ? $colors_array['colors']['bg'] : '#060f29'; // $config-global--color-background-default;
  63. $foreground = is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) ? $colors_array['colors']['txt'] : '#F2F2F2'; // $config-global--color-foreground-default;
  64. $foreground_light = ( is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) && $colors_array['colors']['txt'] != '#F2F2F2' ) ? $colors_array['colors']['txt'] : '#FFFFFF'; // $config-global--color-foreground-light-default;
  65. $foreground_dark = ( is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) && $colors_array['colors']['txt'] != '#F2F2F2' ) ? $colors_array['colors']['txt'] : '#8F8F8F'; // $config-global--color-foreground-dark-default;
  66. // Editor color palette.
  67. add_theme_support(
  68. 'editor-color-palette',
  69. array(
  70. array(
  71. 'name' => __( 'Primary', 'rivington' ),
  72. 'slug' => 'primary',
  73. 'color' => $primary,
  74. ),
  75. array(
  76. 'name' => __( 'Secondary', 'rivington' ),
  77. 'slug' => 'secondary',
  78. 'color' => $secondary,
  79. ),
  80. array(
  81. 'name' => __( 'Background', 'rivington' ),
  82. 'slug' => 'background',
  83. 'color' => $background,
  84. ),
  85. array(
  86. 'name' => __( 'Foreground', 'rivington' ),
  87. 'slug' => 'foreground',
  88. 'color' => $foreground,
  89. ),
  90. array(
  91. 'name' => __( 'Foreground Light', 'rivington' ),
  92. 'slug' => 'foreground-light',
  93. 'color' => $foreground_light,
  94. ),
  95. array(
  96. 'name' => __( 'Foreground Dark', 'rivington' ),
  97. 'slug' => 'foreground-dark',
  98. 'color' => $foreground_dark,
  99. ),
  100. )
  101. );
  102. // Remove footer menu
  103. unregister_nav_menu( 'menu-2' );
  104. // Setup nav on side toggle support.
  105. if ( function_exists( 'varia_mobile_nav_on_side_setup' ) ) {
  106. varia_mobile_nav_on_side_setup();
  107. }
  108. }
  109. endif;
  110. add_action( 'after_setup_theme', 'rivington_setup', 12 );
  111. /**
  112. * Filter the content_width in pixels, based on the child-theme's design and stylesheet.
  113. */
  114. function rivington_content_width() {
  115. return 750;
  116. }
  117. add_filter( 'varia_content_width', 'rivington_content_width' );
  118. /**
  119. * Add Google webfonts, if necessary
  120. *
  121. * - See: http://themeshaper.com/2014/08/13/how-to-add-google-fonts-to-wordpress-themes/
  122. */
  123. function rivington_fonts_url() {
  124. $fonts_url = '';
  125. /* Translators: If there are characters in your language that are not
  126. * supported by Poppins, translate this to 'off'. Do not translate
  127. * into your own language.
  128. */
  129. $poppins = esc_html_x( 'on', 'Poppins font: on or off', 'rivington' );
  130. if ( 'off' !== $poppins ) {
  131. $font_families = array();
  132. $font_families[] = 'Poppins:400,400i,600,600i';
  133. /**
  134. * A filter to enable child themes to add/change/omit font families.
  135. *
  136. * @param array $font_families An array of font families to be imploded for the Google Font API
  137. */
  138. $font_families = apply_filters( 'included_google_font_families', $font_families );
  139. $query_args = array(
  140. 'family' => urlencode( implode( '|', $font_families ) ),
  141. 'subset' => urlencode( 'latin,latin-ext' ),
  142. );
  143. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  144. }
  145. return esc_url_raw( $fonts_url );
  146. }
  147. /**
  148. * Enqueue scripts and styles.
  149. */
  150. function rivington_scripts() {
  151. // enqueue Google fonts, if necessary
  152. // wp_enqueue_style( 'rivington-fonts', rivington_fonts_url(), array(), null );
  153. // dequeue parent styles
  154. wp_dequeue_style( 'varia-style' );
  155. // enqueue child styles
  156. wp_enqueue_style( 'rivington-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ) );
  157. // enqueue child RTL styles
  158. wp_style_add_data( 'rivington-style', 'rtl', 'replace' );
  159. }
  160. add_action( 'wp_enqueue_scripts', 'rivington_scripts', 99 );
  161. /**
  162. * Enqueue theme styles for the block editor.
  163. */
  164. function rivington_editor_styles() {
  165. // Enqueue Google fonts in the editor, if necessary
  166. wp_enqueue_style( 'rivington-editor-fonts', rivington_fonts_url(), array(), null );
  167. // Hide duplicate palette colors
  168. $colors_array = get_theme_mod( 'colors_manager', array( 'colors' => true ) ); // color annotations array()
  169. if ( ! empty( $colors_array ) && $colors_array['colors']['txt'] != '#F2F2F2' ) { // $config-global--color-foreground-light-default;
  170. $inline_palette_css = '.components-circular-option-picker__option-wrapper:nth-child(5),
  171. .components-circular-option-picker__option-wrapper:nth-child(6) {
  172. display: none;
  173. }';
  174. wp_add_inline_style( 'wp-edit-blocks', $inline_palette_css );
  175. }
  176. }
  177. add_action( 'enqueue_block_editor_assets', 'rivington_editor_styles' );