Changeset 28399
- Timestamp:
- 05/15/2014 01:11:21 AM (11 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/post-template.php
r28398 r28399 919 919 * @return string HTML content, if not displaying. 920 920 */ 921 function wp_dropdown_pages( $args = '') {921 function wp_dropdown_pages( $args = '' ) { 922 922 $defaults = array( 923 923 'depth' => 0, 'child_of' => 0, … … 929 929 930 930 $r = wp_parse_args( $args, $defaults ); 931 extract( $r, EXTR_SKIP ); 932 933 $pages = get_pages($r); 931 932 $pages = get_pages( $r ); 934 933 $output = ''; 935 934 // 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 ); 946 948 $output .= "</select>\n"; 947 949 } … … 952 954 * @since 2.1.0 953 955 * 954 * @param string $ outputHTML 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; 962 964 } 963 965 -
trunk/tests/phpunit/tests/post/getPages.php
r27767 r28399 165 165 */ 166 166 function test_wp_dropdown_pages() { 167 $ posts = $this->factory->post->create_many( 5, array( 'post_type' => 'page' ) );167 $this->factory->post->create_many( 5, array( 'post_type' => 'page' ) ); 168 168 169 169 preg_match_all( '#<option#', wp_dropdown_pages( 'echo=0' ), $matches ); -
trunk/tests/phpunit/tests/post/template.php
r28398 r28399 73 73 $this->assertEquals( $pagelink, $output ); 74 74 } 75 76 function test_wp_dropdown_pages() { 77 $none = wp_dropdown_pages( array( 'echo' => 0 ) ); 78 $this->assertEmpty( $none ); 79 80 $bump = ' '; 81 $page_id = $this->factory->post->create( array( 'post_type' => 'page' ) ); 82 $child_id = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $page_id ) ); 83 $grandchild_id = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $child_id ) ); 84 85 $lineage =<<<LINEAGE 86 <select name='page_id' id='page_id'> 87 <option class="level-0" value="$page_id">Post title 1</option> 88 <option class="level-1" value="$child_id">{$bump}Post title 2</option> 89 <option class="level-2" value="$grandchild_id">{$bump}{$bump}Post title 3</option> 90 </select> 91 92 LINEAGE; 93 94 $output = wp_dropdown_pages( array( 'echo' => 0 ) ); 95 $this->assertEquals( $lineage, $output ); 96 97 $depth =<<<DEPTH 98 <select name='page_id' id='page_id'> 99 <option class="level-0" value="$page_id">Post title 1</option> 100 </select> 101 102 DEPTH; 103 104 $output = wp_dropdown_pages( array( 'echo' => 0, 'depth' => 1 ) ); 105 $this->assertEquals( $depth, $output ); 106 107 $option_none =<<<NONE 108 <select name='page_id' id='page_id'> 109 <option value="Woo">Hoo</option> 110 <option class="level-0" value="$page_id">Post title 1</option> 111 </select> 112 113 NONE; 114 115 $output = wp_dropdown_pages( array( 'echo' => 0, 'depth' => 1, 116 'show_option_none' => 'Hoo', 'option_none_value' => 'Woo' 117 ) ); 118 $this->assertEquals( $option_none, $output ); 119 120 $option_no_change =<<<NO 121 <select name='page_id' id='page_id'> 122 <option value="-1">Burrito</option> 123 <option value="Woo">Hoo</option> 124 <option class="level-0" value="$page_id">Post title 1</option> 125 </select> 126 127 NO; 128 $output = wp_dropdown_pages( array( 'echo' => 0, 'depth' => 1, 129 'show_option_none' => 'Hoo', 'option_none_value' => 'Woo', 130 'show_option_no_change' => 'Burrito' 131 ) ); 132 $this->assertEquals( $option_no_change, $output ); 133 } 75 134 }
Note: See TracChangeset
for help on using the changeset viewer.