Repository navigation
Administration: Use nowdocs for title-field autofocus inline scripts - #16318
shail-mehta wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the administration autofocus updates aimed at improving CSP compatibility.
No open issues 🎉
What changed in this PR
Updates four administration autofocus scripts to use WordPress’s inline script helper for CSP compatibility, addressing the work described in Trac #66856.
Changes:
- Replaces raw
<script>tags withwp_print_inline_script_tag()and JS nowdocs. - Preserves the JavaScript and existing conditions controlling autofocus.
| File | Description |
|---|---|
src/wp-admin/edit-tags.php |
Converts the Add New Category/Tag name autofocus script. |
src/wp-admin/edit-tag-form.php |
Converts the term-editing name autofocus script. |
src/wp-admin/edit-form-comment.php |
Converts the comment author name autofocus script. |
src/wp-admin/edit-form-advanced.php |
Converts the Classic Editor title autofocus script. |
Review effort: Balanced
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
mukeshpanchal27
left a comment
There was a problem hiding this comment.
LGTM. Optional: the one-liners could be formatted like other converted scripts, as in r63545. One example inline; the same applies to the other three files.
| if ( ! wp_is_mobile() && post_type_supports( $post_type, 'title' ) && '' === $post->post_title ) { | ||
| wp_print_inline_script_tag( | ||
| <<<'JS' | ||
| try{document.post.title.focus();}catch(e){} |
There was a problem hiding this comment.
Optional formatting:
| try{document.post.title.focus();}catch(e){} | |
| try { | |
| document.post.title.focus(); | |
| } catch ( e ) {} |
What
Trac ticket: #66856
Moves the four title/name field autofocus inline scripts from raw
<script>tags towp_print_inline_script_tag()with<<<'JS'nowdocs:src/wp-admin/edit-form-advanced.phpsrc/wp-admin/edit-form-comment.phpsrc/wp-admin/edit-tag-form.phpsrc/wp-admin/edit-tags.phpThe JavaScript is unchanged.
Why
#66856 lists these four title-field autofocus one-liners as remaining work. Using
wp_print_inline_script_tag()removes raw<script>tags for CSP compatibility, and<<<'JS'nowdocs preserve IDE syntax highlighting.How
Replace each raw
<script>block withwp_print_inline_script_tag( <<<'JS' … JS ). No PHP values are interpolated, so nowp_json_encode()is needed.Testing Instructions
php -lon all four modified files and confirm no syntax errors.wp-admin/post-new.php) — confirm the title field receives focus.wp-admin/comment.php?action=editcomment&c=…) — confirm the author name field receives focus.wp-admin/edit-tags.php?taxonomy=category) — confirm the Name field in Add New Category receives focus.wp-admin/term.php?taxonomy=category&tag_ID=…) — confirm the Name field receives focus.<script>is printed cleanly with no console errors.Use of AI Tools