From dba2b6a9c02326790c34a3c10f28097e95e2e7e9 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Fri, 12 Jun 2015 13:04:04 +0000 Subject: [PATCH] Introduce `class` argument to `wp_dropdown_pages()`. This new argument allows devs to specify the 'class' attribute of the select element. Props ramiy, voldemortensen. Fixes #30082. git-svn-id: https://develop.svn.wordpress.org/trunk@32727 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/post-template.php | 10 +++++++- tests/phpunit/tests/post/template.php | 33 +++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/post-template.php b/src/wp-includes/post-template.php index fe3afdd510..f190ad0b9f 100644 --- a/src/wp-includes/post-template.php +++ b/src/wp-includes/post-template.php @@ -990,6 +990,7 @@ function the_meta() { * * @since 2.1.0 * @since 4.2.0 The `$value_field` argument was added. + * @since 4.3.0 The `$class` argument was added. * * @param array|string $args { * Optional. Array or string of arguments to generate a pages drop-down element. @@ -1002,6 +1003,7 @@ function the_meta() { * @type string $name Value for the 'name' attribute of the select element. * Default 'page_id'. * @type string $id Value for the 'id' attribute of the select element. + * @type string $class Value for the 'class' attribute of the select element. Default: none. * Defaults to the value of `$name`. * @type string $show_option_none Text to display for showing no pages. Default empty (does not display). * @type string $show_option_no_change Text to display for "no change" option. Default empty (does not display). @@ -1016,6 +1018,7 @@ function wp_dropdown_pages( $args = '' ) { 'depth' => 0, 'child_of' => 0, 'selected' => 0, 'echo' => 1, 'name' => 'page_id', 'id' => '', + 'class' => '', 'show_option_none' => '', 'show_option_no_change' => '', 'option_none_value' => '', 'value_field' => 'ID', @@ -1031,7 +1034,12 @@ function wp_dropdown_pages( $args = '' ) { } if ( ! empty( $pages ) ) { - $output = "\n"; if ( $r['show_option_no_change'] ) { $output .= "\t\n"; } diff --git a/tests/phpunit/tests/post/template.php b/tests/phpunit/tests/post/template.php index 052884d018..41c2be7bbc 100644 --- a/tests/phpunit/tests/post/template.php +++ b/tests/phpunit/tests/post/template.php @@ -198,6 +198,39 @@ NO; $this->assertContains( 'value="' . $p . '"', $found ); } + /** + * @ticket 30082 + */ + public function test_wp_dropdown_pages_should_not_contain_class_attribute_when_no_class_is_passed() { + $p = $this->factory->post->create( array( + 'post_type' => 'page', + 'post_name' => 'foo', + ) ); + + $found = wp_dropdown_pages( array( + 'echo' => 0, + ) ); + + $this->assertNotRegExp( '/]+class=\'/', $found ); + } + + /** + * @ticket 30082 + */ + public function test_wp_dropdown_pages_should_obey_class_parameter() { + $p = $this->factory->post->create( array( + 'post_type' => 'page', + 'post_name' => 'foo', + ) ); + + $found = wp_dropdown_pages( array( + 'echo' => 0, + 'class' => 'bar', + ) ); + + $this->assertRegExp( '/]+class=\'bar\'/', $found ); + } + /** * @ticket 31389 */