Administration: Expand the Tools screen with Import, Export, and Code Editing cards - #12955
Administration: Expand the Tools screen with Import, Export, and Code Editing cards#12955abdulawal39 wants to merge 1 commit into
Conversation
… Editing cards. The Tools screen shows a single card, the Categories and Tags Converter, even though Tools is the home of Import, Export and, for block themes, the Theme and Plugin File Editors. Add three cards in the existing card style, each listing the options available on its screen and linking to it. Every card is gated on the capability its target screen enforces, so the screen only advertises what the user can reach. When nothing renders at all, including nothing hooked to `tool_box`, show a message rather than an empty page. Props abdulawal39. See #42486. Fixes #65843.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the 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. |
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. |
Trac ticket: https://core.trac.wordpress.org/ticket/65843
What
The Tools screen currently shows a single card, the Categories and Tags Converter, even though Tools is the home of Import, Export and — for block themes — the Theme and Plugin File Editors. This adds three cards in the existing
.cardstyle, each listing the options available on its screen and linking to it.wp_get_popular_importers(), listed only for users who caninstall_plugins(matchingimport.php)export.php, including any custom post type registered withcan_exportWhen nothing renders at all — including nothing hooked to
tool_box— the screen showsNo tools are available for your account.instead of being blank.Capability gating
Each card is gated on the capability its target screen enforces, so the screen never advertises a page that would
wp_die()on arrival:import+ (manage_categories||manage_post_tags) — unchangedimport; the list additionally needsinstall_pluginsexportwp_is_block_theme() && ! is_multisite(), thenedit_themes/edit_pluginsThe Code Editing gate mirrors
_add_themes_utility_last()and_add_plugin_file_editor_to_tools()inmenu.php: with a classic theme those editors live under Appearance and Plugins, and on multisite neither is added to a site's menu.edit_themes/edit_pluginsare already stripped bymap_meta_cap()underDISALLOW_FILE_EDIT, so the card self-hides there too.Relationship to #42486
This resolves the blank Tools screen reported in #42486, but by filling the page rather than by removing the menu item. It deliberately keeps the Tools menu item and does not touch
menu.php.See the Trac ticket for the full rationale.
Backward compatibility
tool_boxfires unchanged — same name, no arguments, same position, output echoed unmodified. It is wrapped in an output buffer only so that a plugin card suppresses the empty-state message.The Categories and Tags Converter card, its markup, and its help tab ID are unchanged.
Three new filters let plugins adjust or remove each new card. Returning an empty array hides that card:
tools_screen_import_optionstools_screen_export_optionstools_screen_code_editing_optionsHappy to drop these if new hooks are not wanted — the cards work without them.
Strings
Four new strings:
Import Tools,Export Tools,Code Editing Tools, andNo tools are available for your account.Everything else reuses existing translations — editor descriptions fromtheme-editor.phpandplugin-editor.php, the export list fromexport.php, help tab content fromimport.php/export.php, and importer names and descriptions fromwp_get_popular_importers().Testing instructions
can_export => true. It appears in the Export list. Withcan_export => falseit does not.import,install_plugins,edit_themes,edit_pluginsviauser_has_cap. Only the Export card remains.exportas well. The screen showsNo tools are available for your account.tool_box. The plugin card renders and the message is suppressed.Verified against
php -landphpcs --standard=phpcs.xml.dist.