| cli_token | widget | |||||||
|---|---|---|---|---|---|---|---|---|
| aliases |
|
|||||||
| include_when |
|
|||||||
| do_not_include_when |
|
|||||||
| depends_on | ||||||||
| often_with | ||||||||
| copied_files |
|
|||||||
| boilerplate_class |
Copy the legacy widget package: a WP_Widget class plus admin and front views.
On current plugin-boilerplate (PSR-4, no views/ at zip root), this token does nothing useful: the command prints that widgets are unsupported and skips folder creation. Prefer a Gutenberg block (docs/components/_always-included.md).
Only with a boilerplate that still contains widgets:
composer scaffold-plugin beapi-promo-widget widget --boilerplate-version=2.x.x(Use a real tag that still has views/ and classes/widgets/.)
On Latest/master:
composer scaffold-plugin beapi-promo-widget widget→ error line, no widget files; other tokens still copy.
- Ticket explicitly requires a classic widget
- You pinned
--boilerplate-versionto a zip that includesviews/
Do not pass widget for:
- New plugins on current boilerplate
- “Block in the widget area” (that is still a block)
- Shortcodes
None. Widgets are independent. For new UI, use Blocks (always copied on PSR-4 ≥ 3.2) instead of this token.
The scaffold always mkdir classes/widgets/ (legacy path) even on PSR-4 when views exist — not PSR-4 Widgets/.
Shipped files (legacy layout):
| File | Role |
|---|---|
classes/widgets/main.php |
Widget class (extend / rename after search-replace). |
views/admin/widget.php |
Form in Appearance → Widgets. |
views/client/widget.php |
Front-end output. |
Typical WordPress widget API (in that class, depending on boilerplate version):
| Member | Role |
|---|---|
| constructor | id_base, name, WP_Widget options. |
widget( $args, $instance ) |
Echo front view ($args = before_widget, etc.). |
form( $instance ) |
Admin fields. |
update( $new_instance, $old_instance ) |
Sanitize and return instance. |
Load views via Helpers::locate_template() when Helpers is available.
- Confirm
views/andclasses/widgets/exist after the command. If not, drop the token and implement a block. - Register the widget on
widgets_initfromMain. - Replace dummy strings; keep admin vs client views split.
- Do not add this token “just in case”.
- Do pin boilerplate version if you truly need widgets.
- Don’t confuse widgets with
Dynamic_Block. - Don’t expect PSR-4
classes/Widgets/on current scaffold logic.
widget, WP_Widget, sidebar, Appearance → Widgets. If the user says “Gutenberg” or “bloc”, do not pass widget.