Make WordPress Core

Opened 12 years ago

Closed 12 years ago

#23026 closed defect (bug) (fixed)

parent_dropdown() should verify that a post has been fetched

Reported by: mweichert's profile mweichert Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 3.6 Priority: normal
Severity: minor Version: 3.5
Component: Warnings/Notices Keywords: has-patch
Focuses: Cc:

Description

If you call parent_dropdown() and no post has been provided or populated, then an E_NOTICE will be emitted in template.php:683 because $post is null.

The fix is to adjust line 681 from:

if ( $items ) {

to...

if ($post && $items) {

I've attached a patch.

To reproduce:

  1. Ensure that your server is configured to show E_NOTICE errors.
  2. Install NextGEN Gallery
  3. Go to the Manage Galleries Page
  4. Click on a gallery.
  5. Voila. ;)

Attachments (2)

parent_dropdown_fix.patch (597 bytes) - added by mweichert 12 years ago.
Patch for template.php
23026.patch (491 bytes) - added by SergeyBiryukov 12 years ago.

Download all attachments as: .zip

Change History (11)

@mweichert
12 years ago

Patch for template.php

#1 follow-up: @SergeyBiryukov
12 years ago

  • Component changed from Template to Warnings/Notices
  • Version changed from trunk to 1.5

#2 @charliespider
12 years ago

another issue is that this function can not be used outside of the loop such as within the wp-admin.

A simple fix is to change the function argument declarations from

function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) {

to:

function parent_dropdown( $default = 0, $parent = 0, $level = 0, $post = array() ) {

and then also change:

$post = get_post();

to

	if ( empty( $post )) {
		$post = get_post();
	}	

which would allow a WP post object to be passed into the function.

Sorry I am unable to provide an SVN patch.

#3 follow-up: @SergeyBiryukov
12 years ago

  • Milestone changed from Awaiting Review to 3.6

parent_dropdown_fix.patch looks sane.

Let's leave the enhancement from comment:2 for another ticket.

#4 in reply to: ↑ 1 ; follow-up: @charliespider
12 years ago

Replying to SergeyBiryukov:
Why was this changed to Version 1.5???

That was released like 8 years ago!!!

#5 in reply to: ↑ 3 @charliespider
12 years ago

Replying to SergeyBiryukov:

parent_dropdown_fix.patch looks sane.

Let's leave the enhancement from comment:2 for another ticket.

OK I will create one

#6 in reply to: ↑ 4 ; follow-up: @SergeyBiryukov
12 years ago

Replying to charliespider:

Why was this changed to Version 1.5???

Version number indicates when the issue was initially introduced/reported.

parent_dropdown() (with that particular piece of code) was introduced in 1.5: [1747].

#7 in reply to: ↑ 6 @charliespider
12 years ago

Replying to SergeyBiryukov:

Replying to charliespider:

Why was this changed to Version 1.5???

Version number indicates when the issue was initially introduced/reported.

parent_dropdown() (with that particular piece of code) was introduced in 1.5: [1747].

ahhh ok

thank you for explaining

I have created a new ticket for my issue: http://core.trac.wordpress.org/ticket/23162

Version 0, edited 12 years ago by charliespider (next)

#8 @SergeyBiryukov
12 years ago

  • Version changed from 1.5 to 3.5

Actually, this wasn't an issue before [21735], where !empty( $post_ID ) check was removed.

parent_dropdown_fix.patch introduces a change in the behaviour: it makes parent_dropdown() return false rather than still display the dropdown when being called outside of the loop.

23026.patch keeps the current behaviour and just fixes the notice.

#9 @SergeyBiryukov
12 years ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 23351:

Make sure the post exists before checking its ID. fixes #23026.

Note: See TracTickets for help on using tickets.