functions.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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 = ! empty( $colors_array ) ? $colors_array['colors']['link'] : '#CAAB57'; // $config-global--color-primary-default;
  63. $secondary = ! empty( $colors_array ) ? $colors_array['colors']['fg1'] : '#EE4266'; // $config-global--color-secondary-default;
  64. $background = ! empty( $colors_array ) ? $colors_array['colors']['bg'] : '#060f29'; // $config-global--color-background-default;
  65. $foreground = ! empty( $colors_array ) ? $colors_array['colors']['txt'] : '#F2F2F2'; // $config-global--color-foreground-default;
  66. $foreground_light = ( ! empty( $colors_array ) && $colors_array['colors']['txt'] != '#F2F2F2' ) ? $colors_array['colors']['txt'] : '#FFFFFF'; // $config-global--color-foreground-light-default;
  67. $foreground_dark = ( ! empty( $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. }
  107. endif;
  108. add_action( 'after_setup_theme', 'rivington_setup', 12 );
  109. /**
  110. * Filter the content_width in pixels, based on the child-theme's design and stylesheet.
  111. */
  112. function rivington_content_width() {
  113. return 750;
  114. }
  115. add_filter( 'varia_content_width', 'rivington_content_width' );
  116. /**
  117. * Add Google webfonts, if necessary
  118. *
  119. * - See: http://themeshaper.com/2014/08/13/how-to-add-google-fonts-to-wordpress-themes/
  120. */
  121. function rivington_fonts_url() {
  122. $fonts_url = '';
  123. /* Translators: If there are characters in your language that are not
  124. * supported by Poppins, translate this to 'off'. Do not translate
  125. * into your own language.
  126. */
  127. $poppins = esc_html_x( 'on', 'Poppins font: on or off', 'rivington' );
  128. if ( 'off' !== $poppins ) {
  129. $font_families = array();
  130. $font_families[] = 'Poppins:400,400i,600,600i';
  131. $query_args = array(
  132. 'family' => urlencode( implode( '|', $font_families ) ),
  133. 'subset' => urlencode( 'latin,latin-ext' ),
  134. );
  135. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  136. }
  137. return esc_url_raw( $fonts_url );
  138. }
  139. /**
  140. * Enqueue scripts and styles.
  141. */
  142. function rivington_scripts() {
  143. // enqueue Google fonts, if necessary
  144. // wp_enqueue_style( 'rivington-fonts', rivington_fonts_url(), array(), null );
  145. // dequeue parent styles
  146. wp_dequeue_style( 'varia-style' );
  147. // enqueue child styles
  148. wp_enqueue_style('rivington-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ));
  149. // enqueue child RTL styles
  150. wp_style_add_data( 'rivington-style', 'rtl', 'replace' );
  151. }
  152. add_action( 'wp_enqueue_scripts', 'rivington_scripts', 99 );
  153. /**
  154. * Enqueue theme styles for the block editor.
  155. */
  156. function rivington_editor_styles() {
  157. // Enqueue Google fonts in the editor, if necessary
  158. wp_enqueue_style( 'rivington-editor-fonts', rivington_fonts_url(), array(), null );
  159. }
  160. add_action( 'enqueue_block_editor_assets', 'rivington_editor_styles' );