mirror of
https://github.com/WordPress/WordPress.git
synced 2025-03-03 11:59:23 +00:00
This update applies the following changes: - Improve menu UI to support keyboard, click and touch interactions - Improve variable scoping and js performance in menu interaction javascript - Improve custom-colors for selected text, buttons and menu hover styles - Improve margins structure for more consistency between editor and frontend - Improve discussion avatars for simpler wording and better performance - Improve fonts in list widgets and list blocks - Improve comment responsive spacing and avatar display - Improve various block styles to make them consistent between the editor and frontend - Add tabbed browsing support for ie11 - Add backwards compatibility support for older versions of WordPress - Add fallback styles for older versions of WP where Gutenberg is activated and then deactivated (backwards compatibility) - Add `sizes` attribute for featured images to improve responsive performance - Add focus-within polyfill - Add a footer menu for secondary page links - Fix editor styles to prevent conflicts with plugins that add meta boxes to the editor - Fix columns block issues on small screens - Fix empty-space font text cursor issue in Gutenberg editor - Fix RTL floating styles so that left/right floats are honored - Fix cover image block margins/padding - Fix invalid rgba style - Fix php warning when returning attributes - Fix gallery widget margins to improve gallery grids - Fix .entry-content selectors to prevent shortcodes, plugins and other unknown content from breaking the layout - Remove translation escaping to follow code standards in previous default themes - Remove custom color output in the fronten header when default color is selected - Remove fly-out sub-sub-sub-menu behavior on desktop to prevent sub-menus from falling off the screen - General code clean up and coding standards improvements Initial development occurred on GitHub. See: https://github.com/WordPress/twentynineteen Props allancole, karmatosed, kjellr, yingling017, mrasharirfan, milana_cap, fabiankaegy, westonruter, aaronjorbin, netweb, b-07, khleomix, blowery, dereksmart, jasmussen, audrasjb, nielslange, mmaumio, dimadin, joyously, anevins12, peterwilsoncc, dannycooper, icaleb, siriokun, technosiren, travel_girl, azchughtai, ianbelanger, nadim1992, ismailelkorchi, nativeinside, chetan200891, icaleb, grapplerulrich, ocean90, joshfeck, frankew, abdulwahab610, mendezcode, eliorivero, melchoyce, joen, laurelfulford, mdawaffe, kraftbj, dsmart, mukeshpanchal27, burhandodhy, crunnells, Ismail-elkorchi, aryaprakasa, @tlxo, @themeroots, @whizbangik, @yingles, @youthkee, @brentswisher, @smy315, @ahmadawais, @desi-developer. Built from https://develop.svn.wordpress.org/branches/5.0@43892 git-svn-id: http://core.svn.wordpress.org/branches/5.0@43721 1a063a9b-81f0-0310-95a4-ce76da25c4cd
259 lines
7.7 KiB
PHP
259 lines
7.7 KiB
PHP
<?php
|
|
/**
|
|
* Twenty Nineteen functions and definitions
|
|
*
|
|
* @link https://developer.wordpress.org/themes/basics/theme-functions/
|
|
*
|
|
* @package WordPress
|
|
* @subpackage Twenty_Nineteen
|
|
* @since 1.0.0
|
|
*/
|
|
|
|
/**
|
|
* Twenty Nineteen only works in WordPress 4.7 or later.
|
|
*/
|
|
if ( version_compare( $GLOBALS['wp_version'], '4.7', '<' ) ) {
|
|
require get_template_directory() . '/inc/back-compat.php';
|
|
return;
|
|
}
|
|
|
|
if ( ! function_exists( 'twentynineteen_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 twentynineteen_setup() {
|
|
/*
|
|
* Make theme available for translation.
|
|
* Translations can be filed in the /languages/ directory.
|
|
* If you're building a theme based on Twenty Nineteen, use a find and replace
|
|
* to change 'twentynineteen' to the name of your theme in all the template files.
|
|
*/
|
|
load_theme_textdomain( 'twentynineteen', get_template_directory() . '/languages' );
|
|
|
|
// Add default posts and comments RSS feed links to head.
|
|
add_theme_support( 'automatic-feed-links' );
|
|
|
|
/*
|
|
* Let WordPress manage the document title.
|
|
* By adding theme support, we declare that this theme does not use a
|
|
* hard-coded <title> tag in the document head, and expect WordPress to
|
|
* provide it for us.
|
|
*/
|
|
add_theme_support( 'title-tag' );
|
|
|
|
/*
|
|
* Enable support for Post Thumbnails on posts and pages.
|
|
*
|
|
* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
|
|
*/
|
|
add_theme_support( 'post-thumbnails' );
|
|
set_post_thumbnail_size( 1568, 9999 );
|
|
|
|
// This theme uses wp_nav_menu() in two locations.
|
|
register_nav_menus(
|
|
array(
|
|
'menu-1' => __( 'Primary', 'twentynineteen' ),
|
|
'footer' => __( 'Footer Menu', 'twentynineteen' ),
|
|
'social' => __( 'Social Links Menu', 'twentynineteen' ),
|
|
)
|
|
);
|
|
|
|
/*
|
|
* Switch default core markup for search form, comment form, and comments
|
|
* to output valid HTML5.
|
|
*/
|
|
add_theme_support(
|
|
'html5',
|
|
array(
|
|
'search-form',
|
|
'comment-form',
|
|
'comment-list',
|
|
'gallery',
|
|
'caption',
|
|
)
|
|
);
|
|
|
|
/**
|
|
* Add support for core custom logo.
|
|
*
|
|
* @link https://codex.wordpress.org/Theme_Logo
|
|
*/
|
|
add_theme_support(
|
|
'custom-logo',
|
|
array(
|
|
'height' => 190,
|
|
'width' => 190,
|
|
'flex-width' => false,
|
|
'flex-height' => false,
|
|
)
|
|
);
|
|
|
|
// Add theme support for selective refresh for widgets.
|
|
add_theme_support( 'customize-selective-refresh-widgets' );
|
|
|
|
// Add support for Block Styles.
|
|
add_theme_support( 'wp-block-styles' );
|
|
|
|
// Add support for full and wide align images.
|
|
add_theme_support( 'align-wide' );
|
|
|
|
// Add support for editor styles.
|
|
add_theme_support( 'editor-styles' );
|
|
|
|
// Enqueue editor styles.
|
|
add_editor_style( 'style-editor.css' );
|
|
|
|
// Editor color palette.
|
|
add_theme_support(
|
|
'editor-color-palette',
|
|
array(
|
|
array(
|
|
'name' => __( 'Primary Color', 'twentynineteen' ),
|
|
'slug' => 'primary',
|
|
'color' => twentynineteen_hsl_hex( 'default' === get_theme_mod( 'colorscheme' ) ? 199 : get_theme_mod( 'colorscheme_primary_hue', 199 ), 100, 33 ),
|
|
),
|
|
)
|
|
);
|
|
|
|
// Add support for responsive embedded content.
|
|
add_theme_support( 'responsive-embeds' );
|
|
|
|
}
|
|
endif;
|
|
add_action( 'after_setup_theme', 'twentynineteen_setup' );
|
|
|
|
/**
|
|
* Register widget area.
|
|
*
|
|
* @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
|
|
*/
|
|
function twentynineteen_widgets_init() {
|
|
|
|
register_sidebar(
|
|
array(
|
|
'name' => __( 'Footer', 'twentynineteen' ),
|
|
'id' => 'sidebar-1',
|
|
'description' => __( 'Add widgets here to appear in your footer.', 'twentynineteen' ),
|
|
'before_widget' => '<section id="%1$s" class="widget %2$s">',
|
|
'after_widget' => '</section>',
|
|
'before_title' => '<h2 class="widget-title">',
|
|
'after_title' => '</h2>',
|
|
)
|
|
);
|
|
|
|
}
|
|
add_action( 'widgets_init', 'twentynineteen_widgets_init' );
|
|
|
|
/**
|
|
* Set the content width in pixels, based on the theme's design and stylesheet.
|
|
*
|
|
* Priority 0 to make it available to lower priority callbacks.
|
|
*
|
|
* @global int $content_width Content width.
|
|
*/
|
|
function twentynineteen_content_width() {
|
|
// This variable is intended to be overruled from themes.
|
|
// Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
|
|
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
|
|
$GLOBALS['content_width'] = apply_filters( 'twentynineteen_content_width', 640 );
|
|
}
|
|
add_action( 'after_setup_theme', 'twentynineteen_content_width', 0 );
|
|
|
|
/**
|
|
* Enqueue scripts and styles.
|
|
*/
|
|
function twentynineteen_scripts() {
|
|
wp_enqueue_style( 'twentynineteen-style', get_stylesheet_uri() );
|
|
|
|
wp_style_add_data( 'twentynineteen-style', 'rtl', 'replace' );
|
|
|
|
wp_enqueue_script( 'twentynineteen-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20151215', true );
|
|
|
|
if ( has_nav_menu( 'menu-1' ) ) {
|
|
wp_enqueue_script( 'twentynineteen-priority-menu', get_theme_file_uri( '/js/priority-menu.js' ), array(), '1.0', true );
|
|
wp_enqueue_script( 'twentynineteen-touch-navigation', get_theme_file_uri( '/js/touch-keyboard-navigation.js' ), array(), '1.0', true );
|
|
}
|
|
|
|
wp_enqueue_style( 'twentynineteen-print-style', get_template_directory_uri() . '/print.css', array(), wp_get_theme()->get( 'Version' ), 'print' );
|
|
|
|
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
|
|
wp_enqueue_script( 'comment-reply' );
|
|
}
|
|
}
|
|
add_action( 'wp_enqueue_scripts', 'twentynineteen_scripts' );
|
|
|
|
/**
|
|
* Enqueue supplemental block editor styles.
|
|
*/
|
|
function twentynineteen_editor_customizer_styles() {
|
|
|
|
wp_enqueue_style( 'twentynineteen-editor-customizer-styles', get_theme_file_uri( '/style-editor-customizer.css' ), false, '1.0', 'all' );
|
|
|
|
if ( 'custom' === get_theme_mod( 'colorscheme' ) ) {
|
|
// Include color patterns
|
|
require_once get_parent_theme_file_path( '/inc/color-patterns.php' );
|
|
wp_add_inline_style( 'twentynineteen-editor-customizer-styles', twentynineteen_custom_colors_css() );
|
|
}
|
|
}
|
|
add_action( 'enqueue_block_editor_assets', 'twentynineteen_editor_customizer_styles' );
|
|
|
|
/**
|
|
* Display custom color CSS in customizer and on frontend.
|
|
*/
|
|
function twentynineteen_colors_css_wrap() {
|
|
|
|
// Only include custom colors in customizer or frontend.
|
|
if ( ( ! is_customize_preview() && 'default' === get_theme_mod( 'colorscheme', 'default' ) ) || is_admin() ) {
|
|
return;
|
|
}
|
|
|
|
require_once get_parent_theme_file_path( '/inc/color-patterns.php' );
|
|
|
|
if ( 'default' === get_theme_mod( 'colorscheme', 'default' ) ) {
|
|
$primary_color = 199;
|
|
} else {
|
|
$primary_color = absint( get_theme_mod( 'colorscheme_primary_hue', 199 ) );
|
|
}
|
|
?>
|
|
|
|
<style type="text/css" id="custom-theme-colors" <?php echo is_customize_preview() ? 'data-hue="' . $primary_color . '"' : ''; ?>>
|
|
<?php echo twentynineteen_custom_colors_css(); ?>
|
|
</style>
|
|
<?php
|
|
}
|
|
add_action( 'wp_head', 'twentynineteen_colors_css_wrap' );
|
|
|
|
/**
|
|
* SVG Icons class.
|
|
*/
|
|
require get_template_directory() . '/classes/class-twentynineteen-svg-icons.php';
|
|
|
|
/**
|
|
* Custom Comment Walker template.
|
|
*/
|
|
require get_template_directory() . '/classes/class-twentynineteen-walker-comment.php';
|
|
|
|
/**
|
|
* Enhance the theme by hooking into WordPress.
|
|
*/
|
|
require get_template_directory() . '/inc/template-functions.php';
|
|
|
|
/**
|
|
* SVG Icons related functions.
|
|
*/
|
|
require get_template_directory() . '/inc/icon-functions.php';
|
|
|
|
/**
|
|
* Custom template tags for the theme.
|
|
*/
|
|
require get_template_directory() . '/inc/template-tags.php';
|
|
|
|
/**
|
|
* Customizer additions.
|
|
*/
|
|
require get_template_directory() . '/inc/customizer.php';
|