Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support template for WP_Widget settings #160

Merged
merged 1 commit into from
Apr 14, 2024
Merged

Support template for WP_Widget settings #160

merged 1 commit into from
Apr 14, 2024

Conversation

lipemat
Copy link
Contributor

@lipemat lipemat commented Feb 13, 2024

The WP_Widget class supports passing an "$instance" array around which contains the value of the current widget settings.

Without a PHPStan template, adding a type to the $instance array results in warnings like "should be contravariant with parameter" for the following methods:

  • form
  • update
  • widget

Having a template available allows using @extends to pass the array shape around.

As a bonus, this pull request also includes the full shape of the $args passed to WP_Widget::widget

- Support passing the shape for the widget settings.
- Add type for the widget arguments registered from `register_sidebar`.
lipemat added a commit to lipemat/advanced-sidebar-menu that referenced this pull request Feb 13, 2024
- Include basic definitions for widget settings.
- Fix inconsistencies found from the new types.

Note: If this pull request gets merged a bunch of ignored phpstan items can be
removed.

php-stubs/wordpress-stubs#160
lipemat added a commit to lipemat/phpstan-wordpress that referenced this pull request Feb 13, 2024
Submitted a pull request but in the meantime we're going to use the
template to move forward.

php-stubs/wordpress-stubs#160
lipemat added a commit to lipemat/advanced-sidebar-menu that referenced this pull request Feb 13, 2024
- Include basic definitions for widget settings.
- Fix inconsistencies found from the new types.

Note: If this pull request gets merged a bunch of ignored phpstan items can be
removed.

php-stubs/wordpress-stubs#160
@szepeviktor
Copy link
Member

@lipemat Are we ready to merge this PR?

@lipemat
Copy link
Contributor Author

lipemat commented Apr 14, 2024

@lipemat Are we ready to merge this PR?

Yes. I've been adding the definitions to various projects and using/testing them there. Merging this in will allow me to cleanup the other projects.

@szepeviktor
Copy link
Member

All right.

@szepeviktor szepeviktor merged commit d866d5d into php-stubs:master Apr 14, 2024
2 checks passed
@lipemat lipemat deleted the wp_widget branch April 15, 2024 00:14
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.

2 participants