functions.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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 Dalston
  9. * @since 1.0.0
  10. */
  11. if ( ! function_exists( 'dalston_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 dalston_setup() {
  20. // Add child theme editor styles, compiled from `style-child-theme-editor.scss`.
  21. add_editor_style( 'style-editor.css' );
  22. // Add child theme editor font sizes to match Sass-map variables in `_config-child-theme-deep.scss`.
  23. add_theme_support(
  24. 'editor-font-sizes',
  25. array(
  26. array(
  27. 'name' => __( 'Small', 'dalston' ),
  28. 'shortName' => __( 'S', 'dalston' ),
  29. 'size' => 16.5,
  30. 'slug' => 'small',
  31. ),
  32. array(
  33. 'name' => __( 'Normal', 'dalston' ),
  34. 'shortName' => __( 'M', 'dalston' ),
  35. 'size' => 19,
  36. 'slug' => 'normal',
  37. ),
  38. array(
  39. 'name' => __( 'Large', 'dalston' ),
  40. 'shortName' => __( 'L', 'dalston' ),
  41. 'size' => 25.1275,
  42. 'slug' => 'large',
  43. ),
  44. array(
  45. 'name' => __( 'Huge', 'dalston' ),
  46. 'shortName' => __( 'XL', 'dalston' ),
  47. 'size' => 28.9,
  48. 'slug' => 'huge',
  49. ),
  50. )
  51. );
  52. /*
  53. * Get customizer colors and add them to the editor color palettes
  54. *
  55. * - if the customizer color is empty, use the default
  56. */
  57. $colors_array = get_theme_mod( 'colors_manager' ); // color annotations array()
  58. $primary = is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) ? $colors_array['colors']['link'] : '#0073AA'; // $config-global--color-primary-default;
  59. $secondary = is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) ? $colors_array['colors']['fg1'] : '#0D1B24'; // $config-global--color-secondary-default;
  60. $background = is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) ? $colors_array['colors']['bg'] : '#FFFFFF'; // $config-global--color-background-default;
  61. $foreground = is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) ? $colors_array['colors']['txt'] : '#1E1E1E'; // $config-global--color-foreground-default;
  62. $foreground_light = ( is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) && $colors_array['colors']['txt'] != '#1E1E1E' ) ? $colors_array['colors']['txt'] : '#767676'; // $config-global--color-foreground-light-default;
  63. $foreground_dark = ( is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) && $colors_array['colors']['txt'] != '#1E1E1E' ) ? $colors_array['colors']['txt'] : '#000000'; // $config-global--color-foreground-dark-default;
  64. // Editor color palette.
  65. add_theme_support(
  66. 'editor-color-palette',
  67. array(
  68. array(
  69. 'name' => __( 'Primary', 'dalston' ),
  70. 'slug' => 'primary',
  71. 'color' => $primary,
  72. ),
  73. array(
  74. 'name' => __( 'Secondary', 'dalston' ),
  75. 'slug' => 'secondary',
  76. 'color' => $secondary,
  77. ),
  78. array(
  79. 'name' => __( 'Foreground', 'dalston' ),
  80. 'slug' => 'foreground',
  81. 'color' => $foreground,
  82. ),
  83. array(
  84. 'name' => __( 'Background', 'dalston' ),
  85. 'slug' => 'background',
  86. 'color' => $background,
  87. ),
  88. array(
  89. 'name' => __( 'Foreground Light', 'dalston' ),
  90. 'slug' => 'foreground-light',
  91. 'color' => $foreground_light,
  92. ),
  93. array(
  94. 'name' => __( 'Foreground Dark', 'dalston' ),
  95. 'slug' => 'foreground-dark',
  96. 'color' => $foreground_dark,
  97. ),
  98. )
  99. );
  100. /**
  101. * Add support for core custom logo.
  102. *
  103. * @link https://codex.wordpress.org/Theme_Logo
  104. */
  105. add_theme_support(
  106. 'custom-logo',
  107. array(
  108. 'height' => 96,
  109. 'width' => 100,
  110. 'flex-width' => true,
  111. 'flex-height' => true,
  112. 'header-text' => array( 'site-title' ),
  113. )
  114. );
  115. // Setup nav on side toggle support.
  116. if ( function_exists( 'varia_mobile_nav_on_side_setup' ) ) {
  117. varia_mobile_nav_on_side_setup();
  118. }
  119. }
  120. endif;
  121. add_action( 'after_setup_theme', 'dalston_setup', 12 );
  122. /**
  123. * Filter the content_width in pixels, based on the child-theme's design and stylesheet.
  124. */
  125. function dalston_content_width() {
  126. return 750;
  127. }
  128. add_filter( 'varia_content_width', 'dalston_content_width' );
  129. /**
  130. * Add Google webfonts, if necessary
  131. *
  132. * - See: http://themeshaper.com/2014/08/13/how-to-add-google-fonts-to-wordpress-themes/
  133. */
  134. function dalston_fonts_url() {
  135. $fonts_url = '';
  136. /**
  137. * Translators: If there are characters in your language that are not
  138. * supported by Open Sans, translate this to 'off'. Do not translate
  139. * into your own language.
  140. */
  141. $crimson_text = esc_html_x( 'on', 'Crimson Text font: on or off', 'dalston' );
  142. if ( 'off' !== $crimson_text ) {
  143. $font_families = array();
  144. if ( 'off' !== $crimson_text ) {
  145. $font_families[] = 'Crimson Text:400,600,700,400italic,600italic';
  146. }
  147. /**
  148. * A filter to enable child themes to add/change/omit font families.
  149. *
  150. * @param array $font_families An array of font families to be imploded for the Google Font API
  151. */
  152. $font_families = apply_filters( 'included_google_font_families', $font_families );
  153. $query_args = array(
  154. 'family' => urlencode( implode( '|', $font_families ) ),
  155. 'subset' => urlencode( 'latin,latin-ext' ),
  156. );
  157. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  158. }
  159. return esc_url_raw( $fonts_url );
  160. }
  161. /**
  162. * Enqueue scripts and styles.
  163. */
  164. function dalston_scripts() {
  165. // enqueue Google fonts, if necessary
  166. wp_enqueue_style( 'dalston-fonts', dalston_fonts_url(), array(), null );
  167. // dequeue parent styles
  168. wp_dequeue_style( 'varia-style' );
  169. // enqueue child styles
  170. wp_enqueue_style( 'dalston-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ) );
  171. // enqueue child RTL styles
  172. wp_style_add_data( 'dalston-style', 'rtl', 'replace' );
  173. }
  174. add_action( 'wp_enqueue_scripts', 'dalston_scripts', 99 );
  175. /**
  176. * Enqueue theme styles for the block editor.
  177. */
  178. function dalston_editor_styles() {
  179. // Enqueue Google fonts in the editor, if necessary
  180. wp_enqueue_style( 'dalston-editor-fonts', dalston_fonts_url(), array(), null );
  181. // Hide duplicate palette colors
  182. $colors_array = get_theme_mod( 'colors_manager', array( 'colors' => true ) ); // color annotations array()
  183. if ( ! empty( $colors_array ) && $colors_array['colors']['txt'] != '#1E1E1E' ) { // $config-global--color-foreground-light-default;
  184. $inline_palette_css = '.components-circular-option-picker__option-wrapper:nth-child(5),
  185. .components-circular-option-picker__option-wrapper:nth-child(6) {
  186. display: none;
  187. }';
  188. wp_add_inline_style( 'wp-edit-blocks', $inline_palette_css );
  189. }
  190. }
  191. add_action( 'enqueue_block_editor_assets', 'dalston_editor_styles' );
  192. /**
  193. * Enqueue Custom Cover Block Scripts
  194. */
  195. function dalston_block_extends() {
  196. // Bail out early while in AMP endpoint.
  197. if ( dalston_is_amp() ) {
  198. return;
  199. }
  200. // Cover Block Tweaks
  201. wp_enqueue_script(
  202. 'dalston-extend-cover-block',
  203. get_stylesheet_directory_uri() . '/block-extends/extend-cover-block.js',
  204. array( 'wp-blocks' )
  205. );
  206. // Columns Block Tweaks
  207. wp_enqueue_script(
  208. 'dalston-extend-columns-block',
  209. get_stylesheet_directory_uri() . '/block-extends/extend-columns-block.js',
  210. array( 'wp-blocks' )
  211. );
  212. // Media & Text Block Tweaks
  213. wp_enqueue_script(
  214. 'dalston-extend-media-text-block',
  215. get_stylesheet_directory_uri() . '/block-extends/extend-media-text-block.js',
  216. array( 'wp-blocks' )
  217. );
  218. }
  219. add_action( 'enqueue_block_editor_assets', 'dalston_block_extends' );
  220. /**
  221. * Enqueue Custom Cover Block Styles
  222. */
  223. function dalston_block_extends_styles() {
  224. wp_enqueue_style(
  225. 'dalston-extend-cover-block-style',
  226. get_stylesheet_directory_uri() . '/block-extends/extend-cover-block.css'
  227. );
  228. wp_enqueue_style(
  229. 'dalston-extend-cover-columns-style',
  230. get_stylesheet_directory_uri() . '/block-extends/extend-columns-block.css'
  231. );
  232. wp_enqueue_style(
  233. 'dalston-extend-cover-media-text-style',
  234. get_stylesheet_directory_uri() . '/block-extends/extend-media-text-block.css'
  235. );
  236. }
  237. add_action( 'enqueue_block_assets', 'dalston_block_extends_styles' );
  238. /**
  239. * Whether this is an AMP endpoint.
  240. *
  241. * @see https://github.com/Automattic/amp-wp/blob/e4472bfa5c304b6c1b968e533819e3fa96579ad4/includes/amp-helper-functions.php#L248
  242. * @return bool
  243. */
  244. function dalston_is_amp() {
  245. return function_exists( 'is_amp_endpoint' ) && is_amp_endpoint();
  246. }