functions.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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 Alves
  10. * @since 1.0.0
  11. */
  12. if ( ! function_exists( 'alves_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 alves_setup() {
  21. // Add child theme editor styles, compiled from `style-child-theme-editor.scss`.
  22. add_editor_style( 'style-editor.css' );
  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', 'alves' ),
  29. 'shortName' => __( 'S', 'alves' ),
  30. 'size' => 16.6667,
  31. 'slug' => 'small',
  32. ),
  33. array(
  34. 'name' => __( 'Normal', 'alves' ),
  35. 'shortName' => __( 'M', 'alves' ),
  36. 'size' => 20,
  37. 'slug' => 'normal',
  38. ),
  39. array(
  40. 'name' => __( 'Large', 'alves' ),
  41. 'shortName' => __( 'L', 'alves' ),
  42. 'size' => 28.8,
  43. 'slug' => 'large',
  44. ),
  45. array(
  46. 'name' => __( 'Huge', 'alves' ),
  47. 'shortName' => __( 'XL', 'alves' ),
  48. 'size' => 34.5667,
  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'] : '#3E7D98'; // $config-global--color-primary-default;
  60. $secondary = is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) ? $colors_array['colors']['fg1'] : '#9B6A36'; // $config-global--color-secondary-default;
  61. $background = is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) ? $colors_array['colors']['bg'] : '#FFFFFF'; // $config-global--color-background-default;
  62. $foreground = is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) ? $colors_array['colors']['txt'] : '#394d55'; // $config-global--color-foreground-default;
  63. $foreground_light = ( is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) && $colors_array['colors']['txt'] != '#394d55' ) ? $colors_array['colors']['txt'] : '#4d6974'; // $config-global--color-foreground-light-default;
  64. $foreground_dark = ( is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) && $colors_array['colors']['txt'] != '#394d55' ) ? $colors_array['colors']['txt'] : '#253136'; // $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', 'alves' ),
  71. 'slug' => 'primary',
  72. 'color' => $primary,
  73. ),
  74. array(
  75. 'name' => __( 'Secondary', 'alves' ),
  76. 'slug' => 'secondary',
  77. 'color' => $secondary,
  78. ),
  79. array(
  80. 'name' => __( 'Background', 'alves' ),
  81. 'slug' => 'background',
  82. 'color' => $background,
  83. ),
  84. array(
  85. 'name' => __( 'Foreground', 'alves' ),
  86. 'slug' => 'foreground',
  87. 'color' => $foreground,
  88. ),
  89. array(
  90. 'name' => __( 'Foreground Light', 'alves' ),
  91. 'slug' => 'foreground-light',
  92. 'color' => $foreground_light,
  93. ),
  94. array(
  95. 'name' => __( 'Foreground Dark', 'alves' ),
  96. 'slug' => 'foreground-dark',
  97. 'color' => $foreground_dark,
  98. ),
  99. )
  100. );
  101. // Setup nav on side toggle support.
  102. if ( function_exists( 'varia_mobile_nav_on_side_setup' ) ) {
  103. varia_mobile_nav_on_side_setup();
  104. }
  105. }
  106. endif;
  107. add_action( 'after_setup_theme', 'alves_setup', 12 );
  108. /**
  109. * Register second and third footer widget area.
  110. *
  111. * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
  112. */
  113. function alves_widgets_init() {
  114. register_sidebar(
  115. array(
  116. 'name' => __( 'Footer 2', 'alves' ),
  117. 'id' => 'sidebar-2',
  118. 'description' => __( 'Add widgets here to appear in your footer.', 'alves' ),
  119. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  120. 'after_widget' => '</section>',
  121. 'before_title' => '<h2 class="widget-title">',
  122. 'after_title' => '</h2>',
  123. )
  124. );
  125. register_sidebar(
  126. array(
  127. 'name' => __( 'Footer 3', 'alves' ),
  128. 'id' => 'sidebar-3',
  129. 'description' => __( 'Add widgets here to appear in your footer.', 'alves' ),
  130. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  131. 'after_widget' => '</section>',
  132. 'before_title' => '<h2 class="widget-title">',
  133. 'after_title' => '</h2>',
  134. )
  135. );
  136. }
  137. add_action( 'widgets_init', 'alves_widgets_init', 12 );
  138. /**
  139. * Filter the content_width in pixels, based on the child-theme's design and stylesheet.
  140. */
  141. function alves_content_width() {
  142. return 750;
  143. }
  144. add_filter( 'varia_content_width', 'alves_content_width' );
  145. /**
  146. * Add Google webfonts, if necessary
  147. *
  148. * - See: http://themeshaper.com/2014/08/13/how-to-add-google-fonts-to-wordpress-themes/
  149. */
  150. function alves_fonts_url() {
  151. $fonts_url = '';
  152. /* Translators: If there are characters in your language that are not
  153. * supported by Lora, translate this to 'off'. Do not translate
  154. * into your own language.
  155. */
  156. $lora = esc_html_x( 'on', 'Lora font: on or off', 'alves' );
  157. /* Translators: If there are characters in your language that are not
  158. * supported by Karla, translate this to 'off'. Do not translate
  159. * into your own language.
  160. */
  161. $karla = esc_html_x( 'on', 'Karla font: on or off', 'alves' );
  162. if ( 'off' !== $lora || 'off' !== $karla ) {
  163. $font_families = array();
  164. if ( 'off' !== $lora ) {
  165. $font_families[] = 'Lora:400,700,400italic,700italic';
  166. }
  167. if ( 'off' !== $karla ) {
  168. $font_families[] = 'Karla:400,700,400italic,700italic';
  169. }
  170. /**
  171. * A filter to enable child themes to add/change/omit font families.
  172. *
  173. * @param array $font_families An array of font families to be imploded for the Google Font API
  174. */
  175. $font_families = apply_filters( 'included_google_font_families', $font_families );
  176. $query_args = array(
  177. 'family' => urlencode( implode( '|', $font_families ) ),
  178. 'subset' => urlencode( 'latin,latin-ext' ),
  179. );
  180. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  181. }
  182. return esc_url_raw( $fonts_url );
  183. }
  184. /**
  185. * Enqueue scripts and styles.
  186. */
  187. function alves_scripts() {
  188. // enqueue Google fonts, if necessary
  189. wp_enqueue_style( 'alves-fonts', alves_fonts_url(), array(), null );
  190. // dequeue parent styles
  191. wp_dequeue_style( 'varia-style' );
  192. // enqueue child styles
  193. wp_enqueue_style( 'alves-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ) );
  194. // enqueue child RTL styles
  195. wp_style_add_data( 'alves-style', 'rtl', 'replace' );
  196. }
  197. add_action( 'wp_enqueue_scripts', 'alves_scripts', 99 );
  198. /**
  199. * Enqueue theme styles for the block editor.
  200. */
  201. function alves_editor_styles() {
  202. // Enqueue Google fonts in the editor, if necessary
  203. wp_enqueue_style( 'alves-editor-fonts', alves_fonts_url(), array(), null );
  204. // Hide duplicate palette colors
  205. $colors_array = get_theme_mod( 'colors_manager', array( 'colors' => true ) ); // color annotations array()
  206. if ( ! empty( $colors_array ) && $colors_array['colors']['txt'] != '#394d55' ) { // $config-global--color-foreground-light-default;
  207. $inline_palette_css = '.components-circular-option-picker__option-wrapper:nth-child(5),
  208. .components-circular-option-picker__option-wrapper:nth-child(6) {
  209. display: none;
  210. }';
  211. wp_add_inline_style( 'wp-edit-blocks', $inline_palette_css );
  212. }
  213. }
  214. add_action( 'enqueue_block_editor_assets', 'alves_editor_styles' );