WordPress / WordPress/Documentation-Issue-Tracker
[DevHub] Zero and one argument for add_filter being "the same"
Nobody has claimed this yet.
- Dominant language
- Shell
- Stars
- 109
- Forks
- 73
- PR merge metrics
- No merged PRs in 30d
Description
Issue Description
In the following remarks:
callbacks bound to it can accept none (the same as 1) of the arguments or up to four
If no arguments were accepted by the callback that is considered to be the same as accepting 1 argument.
Accepting zero/one arguments.
It is not precisely clear what it means for none/no/zero arguments to be "the same as 1" argument.
If it means that functions with 0 arguments may be used as callbacks for filters with 1 argument, it is true for filters with 2, 3, and 4 arguments as well. E.g., this does work all right:
function test_callback () {
return true;
}
add_filter('http_request_host_is_external', 'test_callback', 7, 0);
add_filter('http_request_host_is_external', 'test_callback', 8, 1);
add_filter('http_request_host_is_external', 'test_callback', 9, 3);
If it means that functions with 1 argument may be used as callbacks for filters with 0 arguments, it is not true. E.g., this :
function test_callback ($allow) {
error_log('Worked' . $allow);
return false;
}
add_filter('http_request_host_is_external', 'test_callback', 7, 0);
produces error
Too few arguments to function test_callback(), 0 passed [..] and exactly 1 expected
If it means that there is no difference whether you add filter with $accepted_args = 0 or $accepted_args = 1, it is not true either:
function test_callback ($allow = null) {
error_log(var_export(['$allow' => $allow], true));
return false;
}
add_filter('http_request_host_is_external', 'Lvlv_auth\test_callback', 7, 1);
add_filter('http_request_host_is_external', 'Lvlv_auth\test_callback', 8, 0);
produces output (the value is not the same):
array (
'$allow' => false,
)
array (
'$allow' => NULL,
)
URL of the Page with the Issue
https://developer.wordpress.org/reference/functions/add_filter/
Section of Page with the issue
Description
Why is this a problem?
The remark about zero arguments is ambiguous and/or unclear and/or unnecessary.
Suggested Fix
One option would be to just delete the remarks about 0 arguments being the same as 1 argument.
Or if not then reword the remark somehow, but I have no suggestion for that as it's not clear to me what is meant.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Open the add_filter reference page and inspect the Description section containing the remarks about zero and one accepted arguments. Compare that wording with the supplied PHP examples, then remove or clarify the ambiguous remarks so they accurately describe the behavior; the page should no longer imply that accepted_args values of 0 and 1 are equivalent.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100