2019-08-15 15:20:03 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Child Theme Functions and definitions
|
|
|
|
*
|
|
|
|
* @link https://developer.wordpress.org/themes/basics/theme-functions/
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Dalston
|
|
|
|
* @since 1.0.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ( ! function_exists( 'dalston_setup' ) ) :
|
|
|
|
/**
|
|
|
|
* Sets up theme defaults and registers support for various WordPress features.
|
|
|
|
*
|
|
|
|
* Note that this function is hooked into the after_setup_theme hook, which
|
|
|
|
* runs before the init hook. The init hook is too late for some features, such
|
|
|
|
* as indicating support for post thumbnails.
|
|
|
|
*/
|
|
|
|
function dalston_setup() {
|
|
|
|
// Add child theme editor styles, compiled from `style-child-theme-editor.scss`.
|
|
|
|
add_editor_style( 'style-editor.css' );
|
|
|
|
|
|
|
|
// Add child theme editor font sizes to match Sass-map variables in `_config-child-theme-deep.scss`.
|
|
|
|
add_theme_support(
|
|
|
|
'editor-font-sizes',
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
'name' => __( 'Small', 'dalston' ),
|
|
|
|
'shortName' => __( 'S', 'dalston' ),
|
2019-09-24 20:21:21 +00:00
|
|
|
'size' => 16.5,
|
2019-08-15 15:20:03 +00:00
|
|
|
'slug' => 'small',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => __( 'Normal', 'dalston' ),
|
|
|
|
'shortName' => __( 'M', 'dalston' ),
|
2019-09-24 20:21:21 +00:00
|
|
|
'size' => 19,
|
2019-08-15 15:20:03 +00:00
|
|
|
'slug' => 'normal',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => __( 'Large', 'dalston' ),
|
|
|
|
'shortName' => __( 'L', 'dalston' ),
|
2019-09-24 20:21:21 +00:00
|
|
|
'size' => 25.1275,
|
2019-08-15 15:20:03 +00:00
|
|
|
'slug' => 'large',
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => __( 'Huge', 'dalston' ),
|
|
|
|
'shortName' => __( 'XL', 'dalston' ),
|
2019-09-24 20:21:21 +00:00
|
|
|
'size' => 28.9,
|
2019-08-15 15:20:03 +00:00
|
|
|
'slug' => 'huge',
|
|
|
|
),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2020-05-20 20:32:04 +00:00
|
|
|
/*
|
|
|
|
* Get customizer colors and add them to the editor color palettes
|
|
|
|
*
|
|
|
|
* - if the customizer color is empty, use the default
|
|
|
|
*/
|
2021-02-12 21:06:40 +00:00
|
|
|
$colors_array = get_theme_mod( 'colors_manager' ); // color annotations array()
|
|
|
|
$primary = is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) ? $colors_array['colors']['link'] : '#0073AA'; // $config-global--color-primary-default;
|
|
|
|
$secondary = is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) ? $colors_array['colors']['fg1'] : '#0D1B24'; // $config-global--color-secondary-default;
|
|
|
|
$background = is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) ? $colors_array['colors']['bg'] : '#FFFFFF'; // $config-global--color-background-default;
|
|
|
|
$foreground = is_array( $colors_array ) && array_key_exists( 'colors', $colors_array ) ? $colors_array['colors']['txt'] : '#1E1E1E'; // $config-global--color-foreground-default;
|
|
|
|
$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;
|
|
|
|
$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;
|
2020-05-20 20:32:04 +00:00
|
|
|
|
|
|
|
// Editor color palette.
|
2019-08-15 15:20:03 +00:00
|
|
|
add_theme_support(
|
|
|
|
'editor-color-palette',
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
'name' => __( 'Primary', 'dalston' ),
|
|
|
|
'slug' => 'primary',
|
2020-05-21 16:38:38 +00:00
|
|
|
'color' => $primary,
|
2019-08-15 15:20:03 +00:00
|
|
|
),
|
2019-08-15 17:25:10 +00:00
|
|
|
array(
|
|
|
|
'name' => __( 'Secondary', 'dalston' ),
|
|
|
|
'slug' => 'secondary',
|
2020-05-21 16:38:38 +00:00
|
|
|
'color' => $secondary,
|
2019-08-15 17:25:10 +00:00
|
|
|
),
|
2019-08-15 15:20:03 +00:00
|
|
|
array(
|
2020-05-20 20:32:04 +00:00
|
|
|
'name' => __( 'Foreground', 'dalston' ),
|
2019-08-15 15:20:03 +00:00
|
|
|
'slug' => 'foreground',
|
2020-05-21 16:38:38 +00:00
|
|
|
'color' => $foreground,
|
2019-08-15 15:20:03 +00:00
|
|
|
),
|
|
|
|
array(
|
2020-05-20 20:32:04 +00:00
|
|
|
'name' => __( 'Background', 'dalston' ),
|
2019-08-15 15:20:03 +00:00
|
|
|
'slug' => 'background',
|
2020-05-21 16:38:38 +00:00
|
|
|
'color' => $background,
|
2019-08-15 15:20:03 +00:00
|
|
|
),
|
2020-08-05 21:38:25 +00:00
|
|
|
array(
|
|
|
|
'name' => __( 'Foreground Light', 'dalston' ),
|
|
|
|
'slug' => 'foreground-light',
|
|
|
|
'color' => $foreground_light,
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => __( 'Foreground Dark', 'dalston' ),
|
|
|
|
'slug' => 'foreground-dark',
|
|
|
|
'color' => $foreground_dark,
|
|
|
|
),
|
2019-08-15 15:20:03 +00:00
|
|
|
)
|
|
|
|
);
|
2019-09-20 21:38:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add support for core custom logo.
|
|
|
|
*
|
|
|
|
* @link https://codex.wordpress.org/Theme_Logo
|
|
|
|
*/
|
|
|
|
add_theme_support(
|
|
|
|
'custom-logo',
|
|
|
|
array(
|
|
|
|
'height' => 96,
|
|
|
|
'width' => 100,
|
|
|
|
'flex-width' => true,
|
2019-12-10 22:06:03 +00:00
|
|
|
'flex-height' => true,
|
2019-09-20 21:38:17 +00:00
|
|
|
'header-text' => array( 'site-title' ),
|
|
|
|
)
|
|
|
|
);
|
2020-12-04 23:15:35 +00:00
|
|
|
|
2020-12-16 19:33:53 +00:00
|
|
|
// Setup nav on side toggle support.
|
|
|
|
if ( function_exists( 'varia_mobile_nav_on_side_setup' ) ) {
|
|
|
|
varia_mobile_nav_on_side_setup();
|
2020-12-09 06:46:12 +00:00
|
|
|
}
|
2019-08-15 15:20:03 +00:00
|
|
|
}
|
|
|
|
endif;
|
|
|
|
add_action( 'after_setup_theme', 'dalston_setup', 12 );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Filter the content_width in pixels, based on the child-theme's design and stylesheet.
|
|
|
|
*/
|
|
|
|
function dalston_content_width() {
|
|
|
|
return 750;
|
|
|
|
}
|
|
|
|
add_filter( 'varia_content_width', 'dalston_content_width' );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add Google webfonts, if necessary
|
|
|
|
*
|
|
|
|
* - See: http://themeshaper.com/2014/08/13/how-to-add-google-fonts-to-wordpress-themes/
|
|
|
|
*/
|
|
|
|
function dalston_fonts_url() {
|
|
|
|
|
|
|
|
$fonts_url = '';
|
|
|
|
|
2019-08-15 15:36:12 +00:00
|
|
|
/**
|
|
|
|
* Translators: If there are characters in your language that are not
|
|
|
|
* supported by Open Sans, translate this to 'off'. Do not translate
|
|
|
|
* into your own language.
|
|
|
|
*/
|
|
|
|
$crimson_text = esc_html_x( 'on', 'Crimson Text font: on or off', 'dalston' );
|
2019-08-15 15:20:03 +00:00
|
|
|
|
2019-08-15 15:36:12 +00:00
|
|
|
if ( 'off' !== $crimson_text ) {
|
|
|
|
$font_families = array();
|
2019-08-15 15:20:03 +00:00
|
|
|
|
2019-08-15 15:36:12 +00:00
|
|
|
if ( 'off' !== $crimson_text ) {
|
|
|
|
$font_families[] = 'Crimson Text:400,600,700,400italic,600italic';
|
2019-08-15 15:20:03 +00:00
|
|
|
}
|
|
|
|
|
2021-02-18 15:20:38 +00:00
|
|
|
/**
|
|
|
|
* A filter to enable child themes to add/change/omit font families.
|
|
|
|
*
|
|
|
|
* @param array $font_families An array of font families to be imploded for the Google Font API
|
|
|
|
*/
|
|
|
|
$font_families = apply_filters( 'included_google_font_families', $font_families );
|
|
|
|
|
2019-08-15 15:20:03 +00:00
|
|
|
$query_args = array(
|
|
|
|
'family' => urlencode( implode( '|', $font_families ) ),
|
|
|
|
'subset' => urlencode( 'latin,latin-ext' ),
|
|
|
|
);
|
|
|
|
|
|
|
|
$fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
|
|
|
|
}
|
|
|
|
|
|
|
|
return esc_url_raw( $fonts_url );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enqueue scripts and styles.
|
|
|
|
*/
|
|
|
|
function dalston_scripts() {
|
|
|
|
|
|
|
|
// enqueue Google fonts, if necessary
|
2019-08-15 15:36:12 +00:00
|
|
|
wp_enqueue_style( 'dalston-fonts', dalston_fonts_url(), array(), null );
|
2019-08-15 15:20:03 +00:00
|
|
|
|
|
|
|
// dequeue parent styles
|
|
|
|
wp_dequeue_style( 'varia-style' );
|
|
|
|
|
|
|
|
// enqueue child styles
|
2021-02-12 21:06:40 +00:00
|
|
|
wp_enqueue_style( 'dalston-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ) );
|
2019-08-15 15:20:03 +00:00
|
|
|
|
|
|
|
// enqueue child RTL styles
|
|
|
|
wp_style_add_data( 'dalston-style', 'rtl', 'replace' );
|
|
|
|
|
|
|
|
}
|
|
|
|
add_action( 'wp_enqueue_scripts', 'dalston_scripts', 99 );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enqueue theme styles for the block editor.
|
|
|
|
*/
|
|
|
|
function dalston_editor_styles() {
|
|
|
|
|
|
|
|
// Enqueue Google fonts in the editor, if necessary
|
|
|
|
wp_enqueue_style( 'dalston-editor-fonts', dalston_fonts_url(), array(), null );
|
2020-08-05 21:38:25 +00:00
|
|
|
|
|
|
|
// Hide duplicate palette colors
|
2021-02-12 21:06:40 +00:00
|
|
|
$colors_array = get_theme_mod( 'colors_manager', array( 'colors' => true ) ); // color annotations array()
|
2020-08-05 21:38:25 +00:00
|
|
|
if ( ! empty( $colors_array ) && $colors_array['colors']['txt'] != '#1E1E1E' ) { // $config-global--color-foreground-light-default;
|
2020-11-04 22:08:26 +00:00
|
|
|
$inline_palette_css = '.components-circular-option-picker__option-wrapper:nth-child(5),
|
|
|
|
.components-circular-option-picker__option-wrapper:nth-child(6) {
|
2020-08-05 21:38:25 +00:00
|
|
|
display: none;
|
|
|
|
}';
|
|
|
|
wp_add_inline_style( 'wp-edit-blocks', $inline_palette_css );
|
|
|
|
}
|
2019-08-15 15:20:03 +00:00
|
|
|
}
|
|
|
|
add_action( 'enqueue_block_editor_assets', 'dalston_editor_styles' );
|
2019-09-19 17:30:19 +00:00
|
|
|
|
|
|
|
/**
|
2021-05-11 16:31:48 +00:00
|
|
|
* Enqueue Custom Cover Block Scripts
|
2019-09-19 17:30:19 +00:00
|
|
|
*/
|
|
|
|
function dalston_block_extends() {
|
|
|
|
|
2020-08-06 15:12:41 +00:00
|
|
|
// Bail out early while in AMP endpoint.
|
|
|
|
if ( dalston_is_amp() ) {
|
|
|
|
return;
|
2020-07-06 11:06:19 +00:00
|
|
|
}
|
2019-09-19 17:30:19 +00:00
|
|
|
|
2019-09-20 16:46:23 +00:00
|
|
|
// Cover Block Tweaks
|
2021-02-12 21:06:40 +00:00
|
|
|
wp_enqueue_script(
|
|
|
|
'dalston-extend-cover-block',
|
2019-09-19 17:30:19 +00:00
|
|
|
get_stylesheet_directory_uri() . '/block-extends/extend-cover-block.js',
|
|
|
|
array( 'wp-blocks' )
|
|
|
|
);
|
|
|
|
|
2019-09-20 16:46:23 +00:00
|
|
|
// Columns Block Tweaks
|
2021-02-12 21:06:40 +00:00
|
|
|
wp_enqueue_script(
|
|
|
|
'dalston-extend-columns-block',
|
2019-09-20 16:46:23 +00:00
|
|
|
get_stylesheet_directory_uri() . '/block-extends/extend-columns-block.js',
|
|
|
|
array( 'wp-blocks' )
|
|
|
|
);
|
|
|
|
|
2021-05-11 16:31:48 +00:00
|
|
|
// Media & Text Block Tweaks
|
2021-02-12 21:06:40 +00:00
|
|
|
wp_enqueue_script(
|
|
|
|
'dalston-extend-media-text-block',
|
2019-09-20 20:48:56 +00:00
|
|
|
get_stylesheet_directory_uri() . '/block-extends/extend-media-text-block.js',
|
|
|
|
array( 'wp-blocks' )
|
|
|
|
);
|
2021-05-11 16:31:48 +00:00
|
|
|
}
|
|
|
|
add_action( 'enqueue_block_editor_assets', 'dalston_block_extends' );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enqueue Custom Cover Block Styles
|
|
|
|
*/
|
|
|
|
function dalston_block_extends_styles() {
|
|
|
|
|
|
|
|
wp_enqueue_style(
|
|
|
|
'dalston-extend-cover-block-style',
|
|
|
|
get_stylesheet_directory_uri() . '/block-extends/extend-cover-block.css'
|
|
|
|
);
|
|
|
|
|
|
|
|
wp_enqueue_style(
|
|
|
|
'dalston-extend-cover-columns-style',
|
|
|
|
get_stylesheet_directory_uri() . '/block-extends/extend-columns-block.css'
|
|
|
|
);
|
2019-09-20 20:48:56 +00:00
|
|
|
|
2021-02-12 21:06:40 +00:00
|
|
|
wp_enqueue_style(
|
|
|
|
'dalston-extend-cover-media-text-style',
|
2019-09-20 20:48:56 +00:00
|
|
|
get_stylesheet_directory_uri() . '/block-extends/extend-media-text-block.css'
|
|
|
|
);
|
2019-09-19 17:30:19 +00:00
|
|
|
}
|
2021-05-11 16:31:48 +00:00
|
|
|
add_action( 'enqueue_block_assets', 'dalston_block_extends_styles' );
|
2020-07-06 11:06:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether this is an AMP endpoint.
|
|
|
|
*
|
|
|
|
* @see https://github.com/Automattic/amp-wp/blob/e4472bfa5c304b6c1b968e533819e3fa96579ad4/includes/amp-helper-functions.php#L248
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
function dalston_is_amp() {
|
|
|
|
return function_exists( 'is_amp_endpoint' ) && is_amp_endpoint();
|
|
|
|
}
|