Skip to content

Administration: Expand the Tools screen with Import, Export, and Code Editing cards - #12955

Open
abdulawal39 wants to merge 1 commit into
WordPress:trunkfrom
abdulawal39:tools-page-revamp
Open

Administration: Expand the Tools screen with Import, Export, and Code Editing cards#12955
abdulawal39 wants to merge 1 commit into
WordPress:trunkfrom
abdulawal39:tools-page-revamp

Conversation

@abdulawal39

Copy link
Copy Markdown

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 .card style, each listing the options available on its screen and linking to it.

  • Import Tools — importers from wp_get_popular_importers(), listed only for users who can install_plugins (matching import.php)
  • Export Tools — the choices from export.php, including any custom post type registered with can_export
  • Code Editing Tools — Theme File Editor and Plugin File Editor

When nothing renders at all — including nothing hooked to tool_box — the screen shows No 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:

Card Gate
Categories and Tags Converter import + (manage_categories || manage_post_tags) — unchanged
Import Tools import; the list additionally needs install_plugins
Export Tools export
Code Editing Tools wp_is_block_theme() && ! is_multisite(), then edit_themes / edit_plugins

The Code Editing gate mirrors _add_themes_utility_last() and _add_plugin_file_editor_to_tools() in menu.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_plugins are already stripped by map_meta_cap() under DISALLOW_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_box fires 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_options
  • tools_screen_export_options
  • tools_screen_code_editing_options

Happy 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, and No tools are available for your account. Everything else reuses existing translations — editor descriptions from theme-editor.php and plugin-editor.php, the export list from export.php, help tab content from import.php / export.php, and importer names and descriptions from wp_get_popular_importers().

Testing instructions

  1. As an administrator on a block theme, visit Tools. All four cards appear; the Code Editing card links both file editors.
  2. Switch to a classic theme (e.g. Twenty Twenty-One). The Code Editing card disappears, matching the Tools submenu.
  3. Register a custom post type with can_export => true. It appears in the Export list. With can_export => false it does not.
  4. Filter caps to simulate a lower-privileged user, e.g. drop import, install_plugins, edit_themes, edit_plugins via user_has_cap. Only the Export card remains.
  5. Drop export as well. The screen shows No tools are available for your account.
  6. With those caps still dropped, hook something to tool_box. The plugin card renders and the message is suppressed.

Verified against php -l and phpcs --standard=phpcs.xml.dist.

… 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.
@github-actions

Copy link
Copy Markdown

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props abdulawal39.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant