123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- <?php
- if ( ! function_exists( 'blockbase_support' ) ) :
- function blockbase_support() {
- // Alignwide and alignfull classes in the block editor.
- add_theme_support( 'align-wide' );
- // Add support for experimental link color control.
- add_theme_support( 'experimental-link-color' );
- // Add support for responsive embedded content.
- // https://github.com/WordPress/gutenberg/issues/26901
- add_theme_support( 'responsive-embeds' );
- // Add support for editor styles.
- add_theme_support( 'editor-styles' );
- // Add support for post thumbnails.
- add_theme_support( 'post-thumbnails' );
- // Declare that there are no <title> tags and allow WordPress to provide them
- add_theme_support( 'title-tag' );
- // Experimental support for adding blocks inside nav menus
- add_theme_support( 'block-nav-menus' );
- // Enqueue editor styles.
- add_editor_style(
- array(
- '/assets/ponyfill.css',
- )
- );
- // Register two nav menus
- register_nav_menus(
- array(
- 'primary' => __( 'Primary Navigation', 'blockbase' ),
- 'social' => __( 'Social Navigation', 'blockbase' )
- )
- );
- add_filter(
- 'block_editor_settings_all',
- function( $settings ) {
- $settings['defaultBlockTemplate'] = '<!-- wp:group {"layout":{"inherit":true}} --><div class="wp-block-group"><!-- wp:post-content /--></div><!-- /wp:group -->';
- return $settings;
- }
- );
- // Add support for core custom logo.
- add_theme_support(
- 'custom-logo',
- array(
- 'height' => 192,
- 'width' => 192,
- 'flex-width' => true,
- 'flex-height' => true,
- )
- );
- }
- endif;
- add_action( 'after_setup_theme', 'blockbase_support', 9 );
- /**
- *
- * Enqueue scripts and styles.
- */
- function blockbase_editor_styles() {
- // Enqueue editor styles.
- add_editor_style(
- array(
- blockbase_fonts_url(),
- )
- );
- // Add the child theme CSS if it exists.
- if ( file_exists( get_stylesheet_directory() . '/assets/theme.css' ) ) {
- add_editor_style(
- '/assets/theme.css'
- );
- }
- }
- add_action( 'admin_init', 'blockbase_editor_styles' );
- /**
- *
- * Enqueue scripts and styles.
- */
- function blockbase_scripts() {
- // Enqueue Google fonts
- wp_enqueue_style( 'blockbase-fonts', blockbase_fonts_url(), array(), null );
- wp_enqueue_style( 'blockbase-ponyfill', get_template_directory_uri() . '/assets/ponyfill.css', array(), wp_get_theme()->get( 'Version' ) );
- // Add the child theme CSS if it exists.
- if ( file_exists( get_stylesheet_directory() . '/assets/theme.css' ) ) {
- wp_enqueue_style( 'blockbase-child-styles', get_stylesheet_directory_uri() . '/assets/theme.css', array('blockbase-ponyfill'), wp_get_theme()->get( 'Version' ) );
- }
- }
- add_action( 'wp_enqueue_scripts', 'blockbase_scripts' );
- /**
- * Add Google webfonts
- *
- * @return $fonts_url
- */
- function blockbase_fonts_url() {
- if ( ! class_exists( 'WP_Theme_JSON_Resolver_Gutenberg' ) ) {
- return '';
- }
- $theme_data = WP_Theme_JSON_Resolver_Gutenberg::get_merged_data()->get_settings();
- if ( empty( $theme_data ) || empty( $theme_data['typography'] ) || empty( $theme_data['typography']['fontFamilies'] ) ) {
- return '';
- }
- $font_families = [];
- if ( ! empty( $theme_data['typography']['fontFamilies']['user'] ) ) {
- foreach( $theme_data['typography']['fontFamilies']['user'] as $font ) {
- if ( ! empty( $font['google'] ) ) {
- $font_families[] = $font['google'];
- }
- }
- } else {
- if ( ! empty( $theme_data['typography']['fontFamilies']['theme'] ) ) {
- foreach( $theme_data['typography']['fontFamilies']['theme'] as $font ) {
- if ( ! empty( $font['google'] ) ) {
- $font_families[] = $font['google'];
- }
- }
- }
- }
- if ( empty( $font_families ) ) {
- return '';
- }
- // Make a single request for the theme or user fonts.
- return esc_url_raw( 'https://fonts.googleapis.com/css2?' . implode( '&', array_unique( $font_families ) ) . '&display=swap' );
- }
- /**
- * Restores the Customizer since we still rely on it.
- */
- function blockbase_restore_customizer() {
- remove_action( 'admin_menu', 'gutenberg_remove_legacy_pages' );
- }
- add_action( 'init', 'blockbase_restore_customizer' );
- /**
- * Customize Global Styles
- */
- if ( class_exists( 'WP_Theme_JSON_Resolver_Gutenberg' ) ) {
- require get_template_directory() . '/inc/customizer/wp-customize-colors.php';
- require get_template_directory() . '/inc/customizer/wp-customize-color-palettes.php';
- require get_template_directory() . '/inc/customizer/wp-customize-fonts.php';
- }
- require get_template_directory() . '/inc/social-navigation.php';
- // Force menus to reload
- add_action(
- 'customize_controls_enqueue_scripts',
- static function () {
- wp_enqueue_script(
- 'wp-customize-nav-menu-refresh',
- get_template_directory_uri() . '/inc/customizer/wp-customize-nav-menu-refresh.js',
- [ 'customize-nav-menus' ],
- wp_get_theme()->get( 'Version' ),
- true
- );
- }
- );
- /**
- * Block Styles.
- */
- require get_template_directory() . '/inc/block-styles.php';
- /**
- * Block Patterns.
- */
- require get_template_directory() . '/inc/block-patterns.php';
|