Make WordPress Core

Opened 4 weeks ago

Last modified 4 weeks ago

#65843 new enhancement

Expand the Tools screen with Import, Export, and Code Editing cards & adding a message when there are no tools to display

Reported by: abdulawal39 Owned by:
Priority: normal Milestone: Awaiting Review
Component: Administration Version:
Severity: normal Keywords: needs-design-feedback has-patch has-screenshots
Cc: Focuses: administration

Description

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. Users have to already know those screens exist in the submenu.

This adds three cards in the existing .card style used by the converter, each
listing the options available on its screen and linking to it:

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

Each card is gated independently on the capability its target screen enforces
(import, export, edit_themes, edit_plugins), so the screen only
advertises what the user can actually reach. The Plugin File Editor entry follows
menu.php and is hidden on multisite, and the Code Editing card disappears entirely
under DISALLOW_FILE_EDIT.

When nothing at all renders — including nothing hooked to tool_box — the screen
shows "No tools are available for your account." instead of being blank.

Relationship to #42486

This resolves the blank Tools screen reported in #42486, but by filling the page
rather than by removing the menu item.

The patches on that ticket all hide the Tools menu when it would be empty. That
approach stalled because hiding Tools breaks plugins that add submenus for users
without import (comment 48), and because of the capability asymmetry dd32
listed in comment 4 (can import but not export, and vice versa). Per-card gating
handles both. Filling the page was suggested on that ticket by dd32 in comment 4
and by Clorith in comment 38.

Note this deliberately keeps the Tools menu item. If this lands, the menu.php change
proposed in #42486 may no longer be needed, but that is a separate decision and this
patch does not touch menu.php.

Backward compatibility

tool_box fires unchanged — same name, no arguments, same position. Its output is
buffered only so that a plugin card suppresses the empty-state message; the output is
echoed unmodified.

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:

  • 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 — the
editor descriptions come from theme-editor.php and plugin-editor.php, the export list
from export.php, and the importer names and descriptions from
wp_get_popular_importers().

Testing

  • Administrator: all four cards
  • export but not import or file editing: only the Export card
  • Author/Contributor: the "No tools are available for your account." message
  • Author/Contributor with a plugin hooked to tool_box: the plugin card renders, no message
  • A custom post type with can_export => true appears in the Export list; can_export => false does not

Attachments (2)

new-tools-screen-with-cards.png (1.3 MB ) - added by abdulawal39 4 weeks ago.
New Tools page view for admins
no-tools-contributor-role-account.png (987.7 KB ) - added by abdulawal39 4 weeks ago.
Tools page for users with no available tools. a contributor role in this case

Change History (4)

@abdulawal39
4 weeks ago

New Tools page view for admins

@abdulawal39
4 weeks ago

Tools page for users with no available tools. a contributor role in this case

This ticket was mentioned in PR #12955 on WordPress/wordpress-develop by @abdulawal39.


4 weeks ago
#1

  • Keywords has-patch added

## 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.

#2 @abdulawal39
4 weeks ago

  • Keywords has-screenshots added
Note: See TracTickets for help on using tickets.