X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/76aea3697c6043c1613370f172395b4f65ee71f0..refs/tags/wordpress-4.4:/wp-admin/includes/template.php diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index e132733e..e65c7d0f 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -1,252 +1,221 @@ 'category', + 'descendants_and_self' => $descendants_and_self, + 'selected_cats' => $selected_cats, + 'popular_cats' => $popular_cats, + 'walker' => $walker, + 'checked_ontop' => $checked_ontop + ) ); } -function _cat_rows( $categories, &$count, $parent = 0, $level = 0, $page = 1, $per_page = 20 ) { - if ( empty($categories) ) { - $args = array('hide_empty' => 0); - if ( !empty($_GET['s']) ) - $args['search'] = $_GET['s']; - $categories = get_categories( $args ); - } - - if ( !$categories ) - return false; - - $children = _get_term_hierarchy('category'); - - $start = ($page - 1) * $per_page; - $end = $start + $per_page; - $i = -1; - ob_start(); - foreach ( $categories as $category ) { - if ( $count >= $end ) - break; - - $i++; - - if ( $category->parent != $parent ) - continue; - - // If the page starts in a subtree, print the parents. - if ( $count == $start && $category->parent > 0 ) { - $my_parents = array(); - $my_parent = $category->parent; - while ( $my_parent) { - $my_parent = get_category($my_parent); - $my_parents[] = $my_parent; - if ( !$my_parent->parent ) - break; - $my_parent = $my_parent->parent; - } - $num_parents = count($my_parents); - while( $my_parent = array_pop($my_parents) ) { - echo "\t" . _cat_row( $my_parent, $level - $num_parents ); - $num_parents--; - } - } - - if ( $count >= $start ) - echo "\t" . _cat_row( $category, $level ); - - unset($categories[$i]); // Prune the working set - $count++; +/** + * Output an unordered list of checkbox input elements labelled with term names. + * + * Taxonomy-independent version of wp_category_checklist(). + * + * @since 3.0.0 + * @since 4.4.0 Introduced the `$echo` argument. + * + * @param int $post_id Optional. Post ID. Default 0. + * @param array|string $args { + * Optional. Array or string of arguments for generating a terms checklist. Default empty array. + * + * @type int $descendants_and_self ID of the category to output along with its descendants. + * Default 0. + * @type array $selected_cats List of categories to mark as checked. Default false. + * @type array $popular_cats List of categories to receive the "popular-category" class. + * Default false. + * @type object $walker Walker object to use to build the output. + * Default is a Walker_Category_Checklist instance. + * @type string $taxonomy Taxonomy to generate the checklist for. Default 'category'. + * @type bool $checked_ontop Whether to move checked items out of the hierarchy and to + * the top of the list. Default true. + * @type bool $echo Whether to echo the generated markup. False to return the markup instead + * of echoing it. Default true. + * } + */ +function wp_terms_checklist( $post_id = 0, $args = array() ) { + $defaults = array( + 'descendants_and_self' => 0, + 'selected_cats' => false, + 'popular_cats' => false, + 'walker' => null, + 'taxonomy' => 'category', + 'checked_ontop' => true, + 'echo' => true, + ); + + /** + * Filter the taxonomy terms checklist arguments. + * + * @since 3.4.0 + * + * @see wp_terms_checklist() + * + * @param array $args An array of arguments. + * @param int $post_id The post ID. + */ + $params = apply_filters( 'wp_terms_checklist_args', $args, $post_id ); - if ( isset($children[$category->term_id]) ) - _cat_rows( $categories, $count, $category->term_id, $level + 1, $page, $per_page ); + $r = wp_parse_args( $params, $defaults ); + if ( empty( $r['walker'] ) || ! ( $r['walker'] instanceof Walker ) ) { + $walker = new Walker_Category_Checklist; + } else { + $walker = $r['walker']; } - $output = ob_get_contents(); - ob_end_clean(); - - $output = apply_filters('cat_rows', $output); - - echo $output; -} - -function _cat_row( $category, $level, $name_override = false ) { - global $class; + $taxonomy = $r['taxonomy']; + $descendants_and_self = (int) $r['descendants_and_self']; - $category = get_category( $category ); + $args = array( 'taxonomy' => $taxonomy ); - $pad = str_repeat( '— ', $level ); - $name = ( $name_override ? $name_override : $pad . ' ' . $category->name ); - if ( current_user_can( 'manage_categories' ) ) { - $edit = "name)) . "'>$name"; - } else { - $edit = $name; - } + $tax = get_taxonomy( $taxonomy ); + $args['disabled'] = ! current_user_can( $tax->cap->assign_terms ); - $class = " class='alternate'" == $class ? '' : " class='alternate'"; + $args['list_only'] = ! empty( $r['list_only'] ); - $category->count = number_format_i18n( $category->count ); - $posts_count = ( $category->count > 0 ) ? "$category->count" : $category->count; - $output = "
+ | - |
---|
-