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

PHPDoc improvement #91

Merged
merged 2 commits into from
Jan 12, 2021
Merged

PHPDoc improvement #91

merged 2 commits into from
Jan 12, 2021

Conversation

shvlv
Copy link
Contributor

@shvlv shvlv commented Jan 8, 2021

Сlearer return type for \Brain\Monkey\Filters\has function.

inc/api.php Outdated
@@ -333,7 +333,7 @@ function expectApplied($filter)
*
* @param string $filter
* @param null $callback
* @return bool
* @return false|int Return hook priority or false if hook was not added.
Copy link
Contributor

@tfrommen tfrommen Jan 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is right.

If I do has_filter( 'the_content', 'my_filter' ), I will either get false, if the filter callback has not been added, or the priority, if it did.

However, if I don't pass a callback, and just ask for something like has_filter( 'the_content' ), I would expect to get either true or false...?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also was confused about this. But this function works as counter part of Worpdress has filter, isn't it?
https://core.trac.wordpress.org/browser/tags/5.6/src/wp-includes/plugin.php#L132

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed the proper doc should be bool|int because the function is the counter part of WordPress has_filter, and even if WordPress has_filter is documented as false|int it actually returns true when no callback is given and there's at least a callback attached.

In fact, WordPress has_filter calls WP_Hook::has_filter which, when no callback is given, calls WP_Hook::has_filters, which will return true if any callback is there.

So @shvlv would you mind to change the doc-block to bool|int so I can merge?

Thanks @tfrommen for looking into it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gmazzap Done.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @shvlv

@gmazzap gmazzap merged commit 9e9baba into Brain-WP:master Jan 12, 2021
@jrfnl jrfnl added this to the 2.6.1 milestone Sep 21, 2021
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.

None yet

4 participants