Opened 5 months ago

Closed 4 months ago

#23026 closed defect (bug) (fixed)

parent_dropdown() should verify that a post has been fetched

Reported by: mweichert Owned by: SergeyBiryukov
Priority: normal Milestone: 3.6
Component: Warnings/Notices Version: 3.5
Severity: minor Keywords: has-patch
Cc: michael@…

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 5 months ago.
Patch for template.php
23026.patch (491 bytes) - added by SergeyBiryukov 4 months ago.

Download all attachments as: .zip

Change History (11)

Patch for template.php

comment:1 follow-up: ↓ 4   SergeyBiryukov5 months ago

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

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.

comment:3 follow-up: ↓ 5   SergeyBiryukov4 months 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.

comment:4 in reply to: ↑ 1 ; follow-up: ↓ 6   charliespider4 months ago

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

That was released like 8 years ago!!!

comment:5 in reply to: ↑ 3   charliespider4 months 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

comment:6 in reply to: ↑ 4 ; follow-up: ↓ 7   SergeyBiryukov4 months 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].

comment:7 in reply to: ↑ 6   charliespider4 months 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: #23162

Last edited 4 months ago by SergeyBiryukov (previous) (diff)
  • 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.

  • 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.