functions.php 6.7 KB

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