Make WordPress Core


Ignore:
Timestamp:
10/29/2019 04:40:34 PM (5 years ago)
Author:
desrosj
Message:

Bundled Themes: Update Twenty Twenty.

This brings Twenty Twenty in-sync with GitHub.

For a complete list of changes since [46571], see https://github.com/WordPress/twentytwenty/compare/4549fd9...dea9290.

Reviewed by ianbelanger, SergeyBiryukov, desrosj.
Props anlino, ianbelanger, poena, williampatton, collet, erikkroes, torres126, intimez, byalextran, mehidi258, swapnild, nielslange.
Merges [46613] to the 5.3 branch.
Fixes #48450.

Location:
branches/5.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/5.3

  • branches/5.3/src/wp-content/themes/twentytwenty/functions.php

    r46571 r46614  
    6565
    6666    // Custom logo.
    67     $logo_id     = get_theme_mod( 'custom_logo' );
    6867    $logo_width  = 120;
    6968    $logo_height = 90;
    7069
    7170    // If the retina setting is active, double the recommended width and height.
    72     if ( get_theme_mod( 'twentytwenty_retina_logo', false ) ) {
     71    if ( get_theme_mod( 'retina_logo', false ) ) {
    7372        $logo_width  = floor( $logo_width * 2 );
    7473        $logo_height = floor( $logo_height * 2 );
     
    8281            'flex-height' => true,
    8382            'flex-width'  => true,
    84             'header-text' => array( 'site-title', 'site-description' ),
    8583        )
    8684    );
     
    164162require get_template_directory() . '/classes/class-twentytwenty-script-loader.php';
    165163
     164// Non-latin language handling.
     165require get_template_directory() . '/classes/class-twentytwenty-non-latin-languages.php';
     166
    166167// Custom CSS.
    167168require get_template_directory() . '/inc/custom-css.php';
     
    207208
    208209add_action( 'wp_enqueue_scripts', 'twentytwenty_register_scripts' );
     210
     211/**
     212 * Fix skip link focus in IE11.
     213 *
     214 * This does not enqueue the script because it is tiny and because it is only for IE11,
     215 * thus it does not warrant having an entire dedicated blocking script being loaded.
     216 *
     217 * @link https://git.io/vWdr2
     218 */
     219function twentytwenty_skip_link_focus_fix() {
     220    // The following is minified via `terser --compress --mangle -- assets/js/skip-link-focus-fix.js`.
     221    ?>
     222    <script>
     223    /(trident|msie)/i.test(navigator.userAgent)&&document.getElementById&&window.addEventListener&&window.addEventListener("hashchange",function(){var t,e=location.hash.substring(1);/^[A-z0-9_-]+$/.test(e)&&(t=document.getElementById(e))&&(/^(?:a|select|input|button|textarea)$/i.test(t.tagName)||(t.tabIndex=-1),t.focus())},!1);
     224    </script>
     225    <?php
     226}
     227add_action( 'wp_print_footer_scripts', 'twentytwenty_skip_link_focus_fix' );
     228
     229/** Enqueue non-latin language styles
     230 *
     231 * @since 1.0.0
     232 *
     233 * @return void
     234 */
     235function twentytwenty_non_latin_languages() {
     236    $custom_css = TwentyTwenty_Non_Latin_Languages::get_non_latin_css( 'front-end' );
     237
     238    if ( $custom_css ) {
     239        wp_add_inline_style( 'twentytwenty-style', $custom_css );
     240    }
     241}
     242
     243add_action( 'wp_enqueue_scripts', 'twentytwenty_non_latin_languages' );
    209244
    210245/**
     
    263298            );
    264299
     300            // Add a style attribute with the height, or append the height to the style attribute if the style attribute already exists.
     301            if ( strpos( $html, ' style=' ) === false ) {
     302                $search[]  = '/(src=)/';
     303                $replace[] = "style=\"height: {$logo_height}px;\" src=";
     304            } else {
     305                $search[]  = '/(style="[^"]*)/';
     306                $replace[] = "$1 height: {$logo_height}px;";
     307            }
     308
    265309            $html = preg_replace( $search, $replace, $html );
     310
    266311        }
    267312    }
     
    349394    wp_add_inline_style( 'twentytwenty-block-editor-styles', twentytwenty_get_customizer_css( 'block-editor' ) );
    350395
     396    // Add inline style for non-latin fonts.
     397    wp_add_inline_style( 'twentytwenty-block-editor-styles', TwentyTwenty_Non_Latin_Languages::get_non_latin_css( 'block-editor' ) );
     398
    351399    // Enqueue the editor script.
    352400    wp_enqueue_script( 'twentytwenty-block-editor-script', get_theme_file_uri( '/assets/js/editor-script-block.js' ), array( 'wp-blocks', 'wp-dom' ), wp_get_theme()->get( 'Version' ), true );
     
    393441
    394442add_filter( 'tiny_mce_before_init', 'twentytwenty_add_classic_editor_customizer_styles' );
     443
     444/**
     445 * Output non-latin font styles in the classic editor.
     446 * Adds styles to the head of the TinyMCE iframe. Kudos to @Otto42 for the original solution.
     447 *
     448 * @param array $mce_init TinyMCE styles.
     449 *
     450 * @return array $mce_init TinyMCE styles.
     451 */
     452function twentytwenty_add_classic_editor_non_latin_styles( $mce_init ) {
     453
     454    $styles = TwentyTwenty_Non_Latin_Languages::get_non_latin_css( 'classic-editor' );
     455
     456    // Return if there are no styles to add.
     457    if ( ! $styles ) {
     458        return $mce_init;
     459    }
     460
     461    if ( ! isset( $mce_init['content_style'] ) ) {
     462        $mce_init['content_style'] = $styles . ' ';
     463    } else {
     464        $mce_init['content_style'] .= ' ' . $styles . ' ';
     465    }
     466
     467    return $mce_init;
     468
     469}
     470
     471add_filter( 'tiny_mce_before_init', 'twentytwenty_add_classic_editor_non_latin_styles' );
    395472
    396473/**
     
    481558
    482559add_action( 'after_setup_theme', 'twentytwenty_block_editor_settings' );
     560
     561/**
     562 * Overwrite default more tag with styling and screen reader markup.
     563 *
     564 * @param string $html The default output HTML for the more tag.
     565 *
     566 * @return string $html
     567 */
     568function twentytwenty_read_more_tag( $html ) {
     569    return preg_replace( '/<a.*>(.*)<\/a>/iU', sprintf( '<span class="faux-button">$1</span> <span class="screen-reader-text">"%1$s"</span>', get_the_title( get_the_ID() ) ), $html );
     570}
     571
     572add_filter( 'the_content_more_link', 'twentytwenty_read_more_tag' );
    483573
    484574/**
Note: See TracChangeset for help on using the changeset viewer.