Make WordPress Core

Changeset 32727


Ignore:
Timestamp:
06/12/2015 01:04:04 PM (11 years ago)
Author:
boonebgorges
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post-template.php

    r32617 r32727  
    991991 * @since 2.1.0
    992992 * @since 4.2.0 The `$value_field` argument was added.
     993 * @since 4.3.0 The `$class` argument was added.
    993994 *
    994995 * @param array|string $args {
    … …  
    10031004 *                                               Default 'page_id'.
    10041005 *     @type string       $id                    Value for the 'id' attribute of the select element.
     1006 *     @type string       $class                 Value for the 'class' attribute of the select element. Default: none.
    10051007 *                                               Defaults to the value of `$name`.
    10061008 *     @type string       $show_option_none      Text to display for showing no pages. Default empty (does not display).
    … …  
    10171019                'selected' => 0, 'echo' => 1,
    10181020                'name' => 'page_id', 'id' => '',
     1021                'class' => '',
    10191022                'show_option_none' => '', 'show_option_no_change' => '',
    10201023                'option_none_value' => '',
    … …  
    10321035
    10331036        if ( ! empty( $pages ) ) {
    1034                 $output = "<select name='" . esc_attr( $r['name'] ) . "' id='" . esc_attr( $r['id'] ) . "'>\n";
     1037                $class = '';
     1038                if ( ! empty( $r['class'] ) ) {
     1039                        $class = " class='" . esc_attr( $r['class'] ) . "'";
     1040                }
     1041
     1042                $output = "<select name='" . esc_attr( $r['name'] ) . "'" . $class . " id='" . esc_attr( $r['id'] ) . "'>\n";
    10351043                if ( $r['show_option_no_change'] ) {
    10361044                        $output .= "\t<option value=\"-1\">" . $r['show_option_no_change'] . "</option>\n";
  • trunk/tests/phpunit/tests/post/template.php

    r31531 r32727  
    200200
    201201        /**
     202         * @ticket 30082
     203         */
     204        public function test_wp_dropdown_pages_should_not_contain_class_attribute_when_no_class_is_passed() {
     205                $p = $this->factory->post->create( array(
     206                        'post_type' => 'page',
     207                        'post_name' => 'foo',
     208                ) );
     209
     210                $found = wp_dropdown_pages( array(
     211                        'echo' => 0,
     212                ) );
     213
     214                $this->assertNotRegExp( '/<select[^>]+class=\'/', $found );
     215        }
     216
     217        /**
     218         * @ticket 30082
     219         */
     220        public function test_wp_dropdown_pages_should_obey_class_parameter() {
     221                $p = $this->factory->post->create( array(
     222                        'post_type' => 'page',
     223                        'post_name' => 'foo',
     224                ) );
     225
     226                $found = wp_dropdown_pages( array(
     227                        'echo' => 0,
     228                        'class' => 'bar',
     229                ) );
     230
     231                $this->assertRegExp( '/<select[^>]+class=\'bar\'/', $found );
     232        }
     233
     234        /**
    202235         * @ticket 31389
    203236         */
Note: See TracChangeset for help on using the changeset viewer.