| 764 | * Retrieve or display list of pages as a checklist. |
| 765 | * |
| 766 | * @since |
| 767 | * |
| 768 | * @param array|string $args Optional. Override default arguments. |
| 769 | * @return string HTML content, if not displaying. |
| 770 | */ |
| 771 | function wp_pages_checklist($args = '') { |
| 772 | $defaults = array('depth' => 0, 'checked' => 0, 'echo' => 1, 'post_type' => 'page'); |
| 773 | |
| 774 | $r = wp_parse_args( $args, $defaults ); |
| 775 | extract( $r, EXTR_SKIP ); |
| 776 | |
| 777 | $pages = get_posts($r); |
| 778 | |
| 779 | // Back-compat with old system where both id and name were based on $name argument |
| 780 | if ( empty($id) ) |
| 781 | $id = $name; |
| 782 | |
| 783 | if ( ! empty($pages) ) { |
| 784 | $output = walk_page_checklist_tree($pages, $depth, $r); |
| 785 | } |
| 786 | |
| 787 | if ( $echo ) |
| 788 | echo $output; |
| 789 | |
| 790 | return $output; |
| 791 | } |
| 792 | |
| 793 | /** |
| 1168 | /** |
| 1169 | * Creates a checklist of pages. |
| 1170 | * |
| 1171 | * @package WordPress |
| 1172 | * @since |
| 1173 | * @uses Walker |
| 1174 | */ |
| 1175 | class Walker_Page_Checklist extends Walker { |
| 1176 | |
| 1177 | var $tree_type = 'page'; |
| 1178 | |
| 1179 | var $db_fields = array ('parent' => 'post_parent', 'id' => 'ID'); |
| 1180 | |
| 1181 | function start_lvl( &$output, $depth = 0, $args = array() ) { |
| 1182 | $indent = str_repeat("\t", $depth); |
| 1183 | $output .= "$indent<ul class='children'>\n"; |
| 1184 | } |
| 1185 | function end_lvl( &$output, $depth = 0, $args = array() ) { |
| 1186 | $indent = str_repeat("\t", $depth); |
| 1187 | $output .= "$indent</ul>\n"; |
| 1188 | } |
| 1189 | |
| 1190 | function start_el(&$output, $page, $depth, $args, $id = 0) { |
| 1191 | |
| 1192 | $output .= "\t<li class=\"level-$depth\"><label class=\"selectit\"><input type=\"checkbox\" value=\"$page->ID\""; |
| 1193 | if ( $page->ID == $args['checked'] ) |
| 1194 | $output .= ' checked="checked"'; |
| 1195 | $output .= '>'; |
| 1196 | $title = apply_filters( 'list_pages', $page->post_title, $page ); |
| 1197 | $output .= esc_html( $title ); |
| 1198 | } |
| 1199 | function end_el( &$output, $category, $depth = 0, $args = array() ) { |
| 1200 | $output .= "</label></li>\n"; |
| 1201 | } |
| 1202 | } |
| 1203 | |