Repository navigation
Docs: Add PHPStan types for optional callback parameters #13890
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
base: trunk
Are you sure you want to change the base?
Changes from all commits
f8b11d7
bffd9e1
6103aaa
9444ff6
8e75370
8b7e501
906c4f2
3cf0176
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,15 +18,19 @@ class Custom_Background { | |
| * Callback for administration header. | ||
| * | ||
| * @since 3.0.0 | ||
| * @var callable | ||
| * @var callable|string|null | ||
| * | ||
| * @phpstan-var WP_Optional_Callback | ||
| */ | ||
| public $admin_header_callback; | ||
|
|
||
| /** | ||
| * Callback for header div. | ||
| * | ||
| * @since 3.0.0 | ||
| * @var callable | ||
| * @var callable|string|null | ||
| * | ||
| * @phpstan-var WP_Optional_Callback | ||
| */ | ||
| public $admin_image_div_callback; | ||
|
|
||
|
|
@@ -43,10 +47,13 @@ class Custom_Background { | |
| * | ||
| * @since 3.0.0 | ||
| * | ||
| * @param callable $admin_header_callback Optional. Administration header callback. | ||
| * Default empty string. | ||
| * @param callable $admin_image_div_callback Optional. Custom image div output callback. | ||
| * Default empty string. | ||
| * @param callable|string|null $admin_header_callback Optional. Administration header callback. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 Comment by Claude Opus 5.5 Nit: |
||
| * Empty string or null for none. Default empty string. | ||
| * @param callable|string|null $admin_image_div_callback Optional. Custom image div output callback. | ||
| * Empty string or null for none. Default empty string. | ||
| * | ||
| * @phpstan-param WP_Optional_Callback $admin_header_callback | ||
| * @phpstan-param WP_Optional_Callback $admin_image_div_callback | ||
| */ | ||
| public function __construct( $admin_header_callback = '', $admin_image_div_callback = '' ) { | ||
| $this->admin_header_callback = $admin_header_callback; | ||
|
|
||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -271,6 +271,12 @@ parameters: | |
| } | ||
| ''' | ||
|
|
||
| # An optional callback that is called without arguments, such as an admin page or | ||
| # custom header callback. Core treats an empty string or null as no callback. | ||
| WP_Optional_Callback: ''' | ||
| ''|(callable(): mixed)|null | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 Comment by Claude Opus 5.5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @swissspidy May I ask why
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was my suggestion in #13890 (comment) Given that PHPStan doesn't yet allow top-level There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How often is it duplicated, and how often is it expected to need an update? How many developers will now have to define it themselves? This essentially shifts the duplication to others. Perhaps this is worth reconsidering. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, why not use the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There are 13 duplications here.
Could wordpress-stubs undo the alias when reading from core, replacing Otherwise, if they are looking to use the types in their own code, either they duplicate the Or maybe phpstan-wordpress could include all of these aliases for plugins to re-use.
That probably makes sense. I think the prefix was omitted because we weren't using them on the
|
||
| ''' | ||
|
|
||
| # The properties of a block style as WP_Block_Styles_Registry stores them, which is | ||
| # more than its register() hash accepts: `name` is required for a style to be | ||
| # registered at all, and `label` is filled in from the name when the caller omits | ||
|
|
||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ I understand that
stringis needed here to account for the empty string case. Otherwise,callable|nullwould be sufficient since that includescallable-string.