Plugin Directory: Detect wp_add_dashboard_widget() during import#625
Plugin Directory: Detect wp_add_dashboard_widget() during import#625dd32 wants to merge 8 commits intoWordPress:trunkfrom
Conversation
…r the dashboard-widgets section. Scans imported plugin source for wp_add_dashboard_widget() calls, assigns the dashboard-widgets plugin_section term, and stores each detected widget label as dashboard_widget_name post meta. The label is extracted as the first string literal inside the second argument, so wrappers like __(), _x(), and esc_html__() are handled. Includes a CLI backfill script that walks candidate slugs from a CSV and re-imports them, plus the section term seeding for the local dev environment. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…t string array. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
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. |
Add explicit visibility to find_dashboard_widgets_in_file() and clean up the backfill script for the new-file PHPCS scan: split the multi-assignment, rename a local that overrode a WordPress global, and switch echo to fwrite(STDOUT, ...). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds dashboard-widget detection to the Plugin Directory importer so plugins that register dashboard widgets can be automatically categorized and have widget labels recorded during import.
Changes:
- Collects
wp_add_dashboard_widget()labels from imported plugin PHP files and passes them through the importer parse pipeline. - Assigns/removes the
dashboard-widgetsplugin_sectionterm and stores detected labels indashboard_widget_namepost meta during import. - Seeds and internationalizes the “Dashboard Widgets” section name in local environment + translation strings, and adds a convenience backfill script.
Reviewed changes
Copilot reviewed 2 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php |
Adds PHP scanning + import-time taxonomy/meta updates for dashboard widgets. |
wordpress.org/public_html/wp-content/plugins/plugin-directory/class-i18n.php |
Adds translatable string for the new section name. |
wordpress.org/public_html/wp-content/plugins/plugin-directory/bin/process-dashboard-widgets.php |
Adds a CLI helper script to backfill by re-importing candidate plugins. |
environments/plugin-directory/bin/after-start.sh |
Seeds the dashboard-widgets section in local environments. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| delete_post_meta( $plugin->ID, 'dashboard_widget_name' ); | ||
| foreach ( $dashboard_widgets as $widget_name ) { | ||
| add_post_meta( $plugin->ID, 'dashboard_widget_name', $widget_name, false ); | ||
| } |
| // Find dashboard widget registrations (wp_add_dashboard_widget calls). | ||
| $dashboard_widgets = array(); | ||
| foreach ( Filesystem::list_files( $base_dir, true, '!\.php$!i' ) as $filename ) { | ||
| foreach ( self::find_dashboard_widgets_in_file( $filename ) as $widget ) { | ||
| $dashboard_widgets[] = $widget; | ||
| } | ||
| } |
| // Match wp_add_dashboard_widget( <first arg>, <second arg up to next top-level comma or close-paren> ). | ||
| if ( preg_match_all( | ||
| '#wp_add_dashboard_widget\s*\(\s*[^,]{1,200},\s*([^;]{1,500}?)(?:,|\))#ms', | ||
| $contents, | ||
| $matches, | ||
| PREG_SET_ORDER |
| // Pull the first quoted string out of the second argument. | ||
| if ( preg_match( '#[\'"]([^\'"]+)[\'"]#', $match[1], $title_match ) ) { | ||
| $widgets[] = $title_match[1]; |
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…scanner. Skip files under any /vendor/ path during the dashboard widget scan, and move the array_unique() into the file-scanner return so the helper hands back a clean list. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Thanks for the review. Triage:
|
The backfill is a one-shot operation that does not need to live in the repo. It can run as an ad-hoc script outside the tree. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
| $dashboard_widgets[] = $widget; | ||
| } | ||
| } | ||
|
|
| wp_add_object_terms( $plugin->ID, 'dashboard-widgets', 'plugin_section' ); | ||
|
|
| // Pull the first quoted string out of the second argument. | ||
| if ( preg_match( '#[\'"]([^\'"]+)[\'"]#', $match[1], $title_match ) ) { | ||
| $widgets[] = $title_match[1]; |
Summary
find_dashboard_widgets_in_file()to the plugin importer, scanning PHP files forwp_add_dashboard_widget()calls.dashboard-widgetsplugin_sectionterm to plugins where any call is detected, and stores each detected widget label asdashboard_widget_namepost meta.__(),_x(), andesc_html__()are handled.Context: https://wordpress.slack.com/archives/C0ATCQF2PMM/p1778193159754749
Notes
dashboard-widgetsterm is assumed to exist on production (manual creation, same approach asfeatured,popular,block). The local environment seeds it viaenvironments/plugin-directory/bin/after-start.sh.bin/process-dashboard-widgets.php, is included for convenience. It pulls candidate slugs from a Veloria CSV export and re-imports them. This script likely does not need to be merged and can be dropped from the PR if preferred.find_blocks_in_file().Test plan
bin/import-plugin.php elementor(or another known dashboard-widget plugin) in a dev environment and confirm thedashboard-widgetsplugin_sectionterm is set anddashboard_widget_namemeta is populated./plugins/browse/dashboard-widgets/and confirm the plugin lists.wp_add_dashboard_widget()calls does not gain the section.🤖 Generated with Claude Code