WordPress.org

Make WordPress Core

Opened 20 months ago

Last modified 20 months ago

#38825 new defect (bug)

wp_get_post_revisions default $args value

Reported by: natostanco Owned by:
Milestone: Awaiting Review 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 (3)

#1 follow-up: @ocean90
20 months ago

  • Keywords reporter-feedback added
  • Version changed from trunk to 2.6

Hello @natostanco, do you have some code which is currently failing for you? Because of the wp_parse_args() call $args should never be null.

<?php
$args     = null;
$defaults = [ 'foo' => 'bar' ];
$args     = wp_parse_args( $args, $defaults );
var_dump( $args ); // array(1) { ["foo"]=> string(3) "bar" }

Introduced in [7987].

#2 @adamsilverstein
20 months ago

  • Keywords close added

I tested wp_get_post_revisions passing null (or no $args) and everything worked as expected.

https://cl.ly/3W3s2j38163T/1._adamsilversteinAdams-MacBook-Pro-2_develop.svn.wordpress.orgtrunksrc_zsh_2016-11-16_10-53-38.jpg

#3 in reply to: ↑ 1 @natostanco
20 months ago

Replying to ocean90:

Hello @natostanco, do you have some code which is currently failing for you? Because of the wp_parse_args() call $args should never be null.

<?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

Note: See TracTickets for help on using tickets.