WordPress.org

Make WordPress Core


Ignore:
Timestamp:
02/05/2015 07:03:52 PM (7 years ago)
Author:
boonebgorges
Message:

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.

File:
1 edited

Legend:

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

    r31337 r31338  
    972972        'name' => 'page_id', 'id' => '',
    973973        'show_option_none' => '', 'show_option_no_change' => '',
    974         'option_none_value' => ''
     974        'option_none_value' => '',
     975        'value_field' => 'ID',
    975976    );
    976977
     
    14261427     *
    14271428     * @param string $output Passed by reference. Used to append additional content.
    1428      * @param object $page Page data object.
    1429      * @param int $depth Depth of page in reference to parent pages. Used for padding.
    1430      * @param array $args Uses 'selected' argument for selected page to set selected HTML attribute for option element.
     1429     * @param object $page   Page data object.
     1430     * @param int    $depth  Depth of page in reference to parent pages. Used for padding.
     1431     * @param array  $args   Uses 'selected' argument for selected page to set selected HTML attribute for option
     1432     *              element. Uses 'value_field' argument to fill "value" attribute. See {@see wp_dropdown_pages()}.
    14311433     * @param int $id
    14321434     */
     
    14341436        $pad = str_repeat(' ', $depth * 3);
    14351437
    1436         $output .= "\t<option class=\"level-$depth\" value=\"$page->ID\"";
     1438        if ( ! isset( $args['value_field'] ) || ! isset( $page->{$args['value_field']} ) ) {
     1439            $args['value_field'] = 'ID';
     1440        }
     1441
     1442        $output .= "\t<option class=\"level-$depth\" value=\"" . esc_attr( $page->{$args['value_field']} ) . "\"";
    14371443        if ( $page->ID == $args['selected'] )
    14381444            $output .= ' selected="selected"';
Note: See TracChangeset for help on using the changeset viewer.