Make WordPress Core

Ticket #20167: post-template.wp_pages_checklist-post_types.diff

File post-template.wp_pages_checklist-post_types.diff, 2.6 KB (added by jackreichert, 13 years ago)
  • post-template.php

     
    761761//
    762762
    763763/**
     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 */
     771function 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/**
    764794 * Retrieve or display list of pages as a dropdown (select list).
    765795 *
    766796 * @since 2.1.0
     
    969999}
    9701000
    9711001/**
     1002 * Retrieve HTML checklist of pages for page list.
     1003 *
     1004 * @uses Walker_Page_Checklist to create  checklist of pages.
     1005 * @since
     1006 */
     1007function walk_page_checklist_tree() {
     1008        $args = func_get_args();
     1009        if ( empty($args[2]['walker']) ) // the user's options are the third parameter
     1010                $walker = new Walker_Page_Checklist;
     1011        else
     1012                $walker = $args[2]['walker'];
     1013
     1014        return call_user_func_array(array(&$walker, 'walk'), $args);
     1015}
     1016
     1017/**
    9721018 * Create HTML list of pages.
    9731019 *
    9741020 * @package WordPress
     
    11191165        }
    11201166}
    11211167
     1168/**
     1169 * Creates a checklist of pages.
     1170 *
     1171 * @package WordPress
     1172 * @since
     1173 * @uses Walker
     1174 */
     1175class 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
    11221204//
    11231205// Attachments
    11241206//