Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#49391 closed defect (bug) (duplicate)

small notice in add_query_arg

Reported by: quasibrodo's profile quasibrodo Owned by:
Milestone: Priority: normal
Severity: trivial Version: 5.2.5
Component: General Keywords:
Focuses: Cc:

Description (last modified by SergeyBiryukov)

Admittedly I noticed this problem on wp 5.2.5 and I do see that the function has been updated in 5.3 but in in add_query_arg(), this snippet:

if ( is_array( $args[0] ) ) {
	foreach ( $args[0] as $k => $v ) {
		$qs[ $k ] = $v;
	}
} else {
	$qs[ $args[0] ] = $args[1]; //this is line 964
}

produces the following error.

Notice: Undefined offset: 1 in /home/centerforpublich/public_html/wp-includes/functions.php on line 964

though I see that line is now 1114 on 5.3.2

I'm not certain if its a flaw with the logic of the function or if its being called without the proper arguments but a simple fix that I implemented to remove the notice was changing the above snippet to the following:

if ( is_array( $args[0] ) ) {	
	foreach ( $args[0] as $k => $v ) {	
		$qs[ $k ] = $v;	
	}	
} else if ( isset( $args[1] ) ) {	
	$qs[ $args[0] ] = $args[1];	
}

It seems that for some reason it cannot be assumed that $args[1] will always be set.

I hope this helps.

Change History (2)

#1 @SergeyBiryukov
5 years ago

  • Description modified (diff)

#2 @SergeyBiryukov
5 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Hi there, welcome to WordPress Trac!

Thanks for the report, we're already tracking this issue in #48272.

Note: See TracTickets for help on using tickets.