WordPress.org

Make WordPress Core


Ignore:
Timestamp:
05/15/2014 01:11:21 AM (7 years ago)
Author:
wonderboymusic
Message:

Eliminate use of extract() in wp_dropdown_pages().

Adds unit tests to: tests/post/template.php.
There was previously only one wimpy assertion for wp_dropdown_pages().

See #22400.

File:
1 edited

Legend:

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

    r28398 r28399  
    919919 * @return string HTML content, if not displaying.
    920920 */
    921 function wp_dropdown_pages($args = '') {
     921function wp_dropdown_pages( $args = '' ) {
    922922    $defaults = array(
    923923        'depth' => 0, 'child_of' => 0,
     
    929929
    930930    $r = wp_parse_args( $args, $defaults );
    931     extract( $r, EXTR_SKIP );
    932 
    933     $pages = get_pages($r);
     931
     932    $pages = get_pages( $r );
    934933    $output = '';
    935934    // Back-compat with old system where both id and name were based on $name argument
    936     if ( empty($id) )
    937         $id = $name;
    938 
    939     if ( ! empty($pages) ) {
    940         $output = "<select name='" . esc_attr( $name ) . "' id='" . esc_attr( $id ) . "'>\n";
    941         if ( $show_option_no_change )
    942             $output .= "\t<option value=\"-1\">$show_option_no_change</option>";
    943         if ( $show_option_none )
    944             $output .= "\t<option value=\"" . esc_attr($option_none_value) . "\">$show_option_none</option>\n";
    945         $output .= walk_page_dropdown_tree($pages, $depth, $r);
     935    if ( empty( $r['id'] ) ) {
     936        $r['id'] = $r['name'];
     937    }
     938
     939    if ( ! empty( $pages ) ) {
     940        $output = "<select name='" . esc_attr( $r['name'] ) . "' id='" . esc_attr( $r['id'] ) . "'>\n";
     941        if ( $r['show_option_no_change'] ) {
     942            $output .= "\t<option value=\"-1\">" . $r['show_option_no_change'] . "</option>\n";
     943        }
     944        if ( $r['show_option_none'] ) {
     945            $output .= "\t<option value=\"" . esc_attr( $r['option_none_value'] ) . '">' . $r['show_option_none'] . "</option>\n";
     946        }
     947        $output .= walk_page_dropdown_tree( $pages, $r['depth'], $r );
    946948        $output .= "</select>\n";
    947949    }
     
    952954     * @since 2.1.0
    953955     *
    954      * @param string $output HTML output for drop down list of pages.
    955      */
    956     $output = apply_filters( 'wp_dropdown_pages', $output );
    957 
    958     if ( $echo )
    959         echo $output;
    960 
    961     return $output;
     956     * @param string $html HTML output for drop down list of pages.
     957     */
     958    $html = apply_filters( 'wp_dropdown_pages', $output );
     959
     960    if ( $r['echo'] ) {
     961        echo $html;
     962    }
     963    return $html;
    962964}
    963965
Note: See TracChangeset for help on using the changeset viewer.