Skip to content

Commit

Permalink
Content: Remove variation selector code from arrow emoji.
Browse files Browse the repository at this point in the history
The variation selector code is causing Safari to render these arrows as [?]. Rather than chase that down, we can remove the variation selector code, in favor of adding the `wp-exclude-emoji` class to the arrow wrapper span. This fixes the arrows in Safari, while still preventing the emoji replacement.

See WordPress/wporg-mu-plugins#578
  • Loading branch information
ryelle committed Mar 8, 2024
1 parent 1bda3a0 commit 5885209
Showing 1 changed file with 1 addition and 17 deletions.
18 changes: 1 addition & 17 deletions source/wp-content/themes/wporg-parent-2021/functions.php
Expand Up @@ -18,8 +18,6 @@
add_filter( 'author_link', __NAMESPACE__ . '\use_wporg_profile_for_author_link', 10, 3 );
add_filter( 'render_block_core/pattern', __NAMESPACE__ . '\add_aria_hidden_to_arrows', 19 );
add_filter( 'the_content', __NAMESPACE__ . '\add_aria_hidden_to_arrows', 19 );
add_filter( 'render_block_core/pattern', __NAMESPACE__ . '\prevent_arrow_emoji', 20 );
add_filter( 'the_content', __NAMESPACE__ . '\prevent_arrow_emoji', 20 );
add_filter( 'wp_theme_json_data_theme', __NAMESPACE__ . '\merge_parent_child_theme_json' );

// Enable embeds in patterns.
Expand Down Expand Up @@ -108,21 +106,7 @@ function use_wporg_profile_for_author_link( $link, $author_id, $author_nicename
* @return string The updated content.
*/
function add_aria_hidden_to_arrows( $content ) {
return preg_replace( '/([←↑→↓↔↕↖↗↘↙])/u', '<span aria-hidden="true">\1</span>', $content );
}

/**
* Add the variation-selector unicode character to any arrow. This will force
* the twemoji script to skip these characters, leaving them as text.
*
* Can be removed once the `wp-exclude-emoji` issue is fixed.
* See https://core.trac.wordpress.org/ticket/52219.
*
* @param string $content Content of the current post.
* @return string The updated content.
*/
function prevent_arrow_emoji( $content ) {
return preg_replace( '/([←↑→↓↔↕↖↗↘↙])/u', '\1&#65038;', $content );
return preg_replace( '/([←↑→↓↔↕↖↗↘↙])/u', '<span aria-hidden="true" class="wp-exclude-emoji">\1</span>', $content );
}

/**
Expand Down

0 comments on commit 5885209

Please sign in to comment.