Make WordPress Core

Opened 5 months ago

Closed 4 months ago

Last modified 3 months ago

#65310 closed defect (bug) (fixed)

Emoji detection script not being printed in admin

Reported by: westonruter Owned by: westonruter
Priority: normal Milestone: 7.0.1
Component: Emoji Version: 6.9
Severity: normal Keywords: has-patch has-unit-tests fixed-major dev-reviewed
Cc: Focuses:

Description

This is a follow-up to an issue introduced in r60902 (​3cba156) to fix #63842 and #64076 in the 6.9 release.

The change to print the emoji detection script in the footer instead of the head was only accounting for its use on the frontend. It neglected to account for the hooks in the admin, where the wp_print_footer_scripts action never fires. Instead, the admin_print_footer_scripts action fires. The following change is needed:

  • src/wp-includes/formatting.php

    a b function print_emoji_detection_script() {  
    59075907
    59085908        $printed = true;
    59095909
    5910         if ( did_action( 'wp_print_footer_scripts' ) ) {
    5911                 _print_emoji_detection_script();
     5910        if ( is_admin() ) {
     5911                if ( did_action( 'admin_print_footer_scripts' ) ) {
     5912                        _print_emoji_detection_script();
     5913                } else {
     5914                        add_action( 'admin_print_footer_scripts', '_print_emoji_detection_script' );
     5915                }
    59125916        } else {
    5913                 add_action( 'wp_print_footer_scripts', '_print_emoji_detection_script' );
     5917                if ( did_action( 'wp_print_footer_scripts' ) ) {
     5918                        _print_emoji_detection_script();
     5919                } else {
     5920                        add_action( 'wp_print_footer_scripts', '_print_emoji_detection_script' );
     5921                }
    59145922        }
    59155923}

Related: #65260

Change History (12)

#1 @westonruter
5 months ago

  • Owner set to westonruter
  • Status new → accepted

This ticket was mentioned in ​PR #11931 on ​WordPress/wordpress-develop by ​@westonruter.


5 months ago
#2

  • Keywords has-patch has-unit-tests added

This fixes the emoji detection script not being printed in the admin.

This is a follow-up to a regression introduced in ​3cba156 (r60902), which fixed #63842 and #64076 in the 6.9 release. That change moved the emoji detection script from the document head to the footer, but only accounted for the front end: it hooked _print_emoji_detection_script onto the wp_print_footer_scripts action, which never fires in the admin. The admin_print_footer_scripts action fires there instead, so the script was never printed in the admin.

print_emoji_detection_script() now branches on is_admin() and uses the appropriate footer action for each context.

### Changes

  • Fix print_emoji_detection_script() to hook _print_emoji_detection_script onto admin_print_footer_scripts in the admin and wp_print_footer_scripts on the front end, and to print directly when that action has already fired.
  • Add tests covering all four branches of print_emoji_detection_script() — hooking onto the correct footer action, and printing the script directly when that action has already fired — in both admin and front-end contexts.
  • Add missing parameter/return types to the get_echo() test helper.

## Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 4.7
Used for: Authoring the PHPUnit tests for print_emoji_detection_script(). All AI-generated code was reviewed, directed, and edited by me.

​@westonruter commented on ​PR #11931:


5 months ago
#3

Testing:

  1. Create a post with the title: 🦬 BISON!
  2. Go to the post list table.
  3. Verify that the 🦬 is rendered via Twemoji.

Before | After

--

https://github.com/user-attachments/assets/f95199c8-b47e-411d-91e1-796f8b680189 | https://github.com/user-attachments/assets/9c66bdfa-d913-4959-8a6d-04d2d25bf15f

#4 @jonsurrell
5 months ago

  • Keywords commit added

​@westonruter commented on ​PR #11931:


5 months ago
#5

It also seems to fix https://core.trac.wordpress.org/ticket/65260 in my testing in Firefox

This is surprising!

#6 @westonruter
5 months ago

  • Resolution → fixed
  • Status accepted → closed

In 62410:

Emoji: Use the admin_print_footer_scripts action for printing the emoji detection script in the admin.

This corrects an oversight in an optimization made to print_emoji_detection_script() which moved the emoji detection script to the wp_print_footer_scripts action. Since this action doesn't fire in the admin, no script was printed. Now in the admin, the script is printed at the admin_print_footer_scripts action. Existing sites that wish to omit emoji can continue to do remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ).

Tests are added covering all four branches of print_emoji_detection_script(): hooking the script onto the appropriate footer action, and printing it directly when that action has already fired, in both the admin and the frontend.

Missing parameter and return types are added to the get_echo() test helper.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/11931.
Follow-up to r60902.

Props westonruter, jonsurrell.
See #64076, #65260.
Fixes #65310.

#7 @westonruter
5 months ago

  • Keywords fixed-major dev-feedback added
  • Resolution fixed
  • Status closed → reopened

Re-opening for 7.0.1 consideration, especially if r62410 also fixes #65260.

#8 @jonsurrell
4 months ago

  • Keywords dev-reviewed added; dev-feedback removed

Approving r62410 for 7.0.1 backport.

#9 @westonruter
4 months ago

#65363 was marked as a duplicate.

This ticket was mentioned in ​Slack in #core by masteradhoc. ​View the logs.


4 months ago

#11 @cbravobernal
4 months ago

  • Resolution → fixed
  • Status reopened → closed

In 62560:

Emoji: Use the admin_print_footer_scripts action for printing the emoji detection script in the admin.

This corrects an oversight in an optimization made to print_emoji_detection_script() which moved the emoji detection script to the wp_print_footer_scripts action. Since this action doesn't fire in the admin, no script was printed. Now in the admin, the script is printed at the admin_print_footer_scripts action. Existing sites that wish to omit emoji can continue to do remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ).

Tests are added covering all four branches of print_emoji_detection_script(): hooking the script onto the appropriate footer action, and printing it directly when that action has already fired, in both the admin and the frontend.

Missing parameter and return types are added to the get_echo() test helper.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/11931.
Follow-up to r60902.

Reviewed by jonsurrell.
Merges [62410] to the 7.0 branch.

Props westonruter, jonsurrell.
See #64076, #65260.
Fixes #65310.

#12 @cbravobernal
3 months ago

  • Keywords commit removed
Note: See TracTickets for help on using tickets.