Introduce 'value_field' parameter to wp_dropdown_pages().

This parameter allows developers to choose the post field that will be used to
fill in the 'option' attribute of the generated dropdown markup.

See [31006] #30306 for a parallel enhancement in `wp_dropdown_categories()`.

Props jfarthing84.
Fixes #12494.

git-svn-id: https://develop.svn.wordpress.org/trunk@31338 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges
2015-02-05 19:03:52 +00:00
parent a710c0451c
commit c9c9af5df8
2 changed files with 78 additions and 6 deletions
+67 -1
View File
@@ -131,4 +131,70 @@ NO;
) );
$this->assertEquals( $option_no_change, $output );
}
}
/**
* @ticket 12494
*/
public function test_wp_dropdown_pages_value_field_should_default_to_ID() {
$p = $this->factory->post->create( array(
'post_type' => 'page',
) );
$found = wp_dropdown_pages( array(
'echo' => 0,
) );
// Should contain page ID by default.
$this->assertContains( 'value="' . $p . '"', $found );
}
/**
* @ticket 12494
*/
public function test_wp_dropdown_pages_value_field_ID() {
$p = $this->factory->post->create( array(
'post_type' => 'page',
) );
$found = wp_dropdown_pages( array(
'echo' => 0,
'value_field' => 'ID',
) );
$this->assertContains( 'value="' . $p . '"', $found );
}
/**
* @ticket 12494
*/
public function test_wp_dropdown_pages_value_field_post_name() {
$p = $this->factory->post->create( array(
'post_type' => 'page',
'post_name' => 'foo',
) );
$found = wp_dropdown_pages( array(
'echo' => 0,
'value_field' => 'post_name',
) );
$this->assertContains( 'value="foo"', $found );
}
/**
* @ticket 12494
*/
public function test_wp_dropdown_pages_value_field_should_fall_back_on_ID_when_an_invalid_value_is_provided() {
$p = $this->factory->post->create( array(
'post_type' => 'page',
'post_name' => 'foo',
) );
$found = wp_dropdown_pages( array(
'echo' => 0,
'value_field' => 'foo',
) );
$this->assertContains( 'value="' . $p . '"', $found );
}
}