Make WordPress Core

Opened 12 years ago

Closed 9 years ago

Last modified 9 years ago

#23162 closed enhancement (fixed)

Allow to call parent_dropdown() for an arbitrary post

Reported by: charliespider's profile charliespider Owned by: wonderboymusic's profile wonderboymusic
Milestone: 4.4 Priority: normal
Severity: normal Version: 1.5
Component: Posts, Post Types Keywords: has-patch
Focuses: administration Cc:

Description

parent_dropdown() can no longer be used outside of the loop, such as within the wp-admin, because an E_NOTICE will be emitted in template.php:683 since $post is null.

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.

Attachments (1)

23162.diff (1.7 KB) - added by wonderboymusic 9 years ago.

Download all attachments as: .zip

Change History (8)

#1 @charliespider
12 years ago

  • Summary changed from parent_dropdown() should except WP Post object as additional argument to parent_dropdown() breaks becuause of recent changes. It should except WP Post object as additional argument

#2 @charliespider
12 years ago

  • Summary changed from parent_dropdown() breaks becuause of recent changes. It should except WP Post object as additional argument to parent_dropdown() breaks because of recent changes. It should except WP Post object as additional argument

#3 @SergeyBiryukov
12 years ago

  • Component changed from Warnings/Notices to Administration
  • Summary changed from parent_dropdown() breaks because of recent changes. It should except WP Post object as additional argument to Allow to call parent_dropdown() for an arbitrary post

an E_NOTICE will be emitted in template.php:683 since $post is null.

#23026 would fix the notice introduced in [21735].

Renaming the ticket to better reflect its purpose.

#4 @nacin
11 years ago

  • Component changed from Administration to Posts, Post Types
  • Focuses administration added

@wonderboymusic
9 years ago

#5 @wonderboymusic
9 years ago

  • Keywords has-patch added
  • Milestone changed from Awaiting Review to 4.4
  • Version set to 1.5

#6 @wonderboymusic
9 years ago

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

In 34111:

Add an argument to parent_dropdown(), $post, to allow it to be called for an arbitrary post.

Fixes #23162.

#7 @wonderboymusic
9 years ago

In 34113:

Add sanity checks in map_meta_cap(), return 'do_not_allow' when posts don't exist.

Adds unit test.

Props ocean90, nerrad, filosofo.
Fixes #23162.

Note: See TracTickets for help on using tickets.