Opened 9 years ago
Closed 5 years ago
#38825 closed defect (bug) (worksforme)
wp_get_post_revisions default $args value
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | 2.6 |
| Component: | Revisions | Keywords: | reporter-feedback close |
| Focuses: | Cc: |
Description
function wp_get_post_revisions( $post_id = 0, $args = null ) {
wp-includes/revision.php
$args should be array() or [], not null, otherwise array merge returns null every time $args is null.
Change History (4)
#3
in reply to:
↑ 1
@
9 years ago
Replying to ocean90:
Hello @natostanco, do you have some code which is currently failing for you? Because of the
wp_parse_args()call$argsshould never benull.
<?php $args = null; $defaults = [ 'foo' => 'bar' ]; $args = wp_parse_args( $args, $defaults ); var_dump( $args ); // array(1) { ["foo"]=> string(3) "bar" }Introduced in [7987].
yes wp_parse_args() should return not null, this is another case of null =/= ''. If $args is null parse_str() does not touch $r which is then left undefined/null, then array_merge fails. For pars_str() to work and set $r to empty array $args must be empty string '', not null
#4
@
5 years ago
- Milestone Awaiting Review deleted
- Resolution set to worksforme
- Status changed from new to closed
I was unable to reproduce the reported issue. As it's marked as a close candidate, I'm closing it. Why?
Let's talk about what's happening in the code.
When invoking wp_get_post_revisions without passing the 2nd argument, $args is set to null within the function. This is its initial state.
function wp_get_post_revisions( $post_id = 0, $args = null ) {
When null is passed to wp_parse_args, the $defaults array is returned as demonstrated here.
$defaults = array(
'order' => 'DESC',
'orderby' => 'date ID',
'check_enabled' => true,
);
$args = wp_parse_args( $args, $defaults );
After the above code, $args is set to the default array and is no longer null.
When the code gets to the array_merge, $args is an array and not null.
What could be happening?
There's a filter in wp_parse_str():
function wp_parse_str( $string, &$array ) {
parse_str( $string, $array );
/**
* Filters the array of variables derived from a parsed string.
*
* @since 2.3.0
*
* @param array $array The array populated with variables.
*/
$array = apply_filters( 'wp_parse_str', $array );
}
A callback may be incorrectly running null instead of an array. Searching core, there is not a callback registered to this hook.
I suspect there's a callback in a plugin, must use script, or theme that is returning null to cause the problem @natostanco is reporting.

Hello @natostanco, do you have some code which is currently failing for you? Because of the
wp_parse_args()call$argsshould never benull.Introduced in [7987].