functions.php 6.8 KB

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