diff -r 3d4e9c994f10 -r a86126ab1dd4 wp/wp-admin/includes/template.php --- a/wp/wp-admin/includes/template.php Tue Oct 22 16:11:46 2019 +0200 +++ b/wp/wp-admin/includes/template.php Tue Dec 15 13:49:49 2020 +0100 @@ -9,13 +9,13 @@ */ /** Walker_Category_Checklist class */ -require_once( ABSPATH . 'wp-admin/includes/class-walker-category-checklist.php' ); +require_once ABSPATH . 'wp-admin/includes/class-walker-category-checklist.php'; /** WP_Internal_Pointers class */ -require_once( ABSPATH . 'wp-admin/includes/class-wp-internal-pointers.php' ); +require_once ABSPATH . 'wp-admin/includes/class-wp-internal-pointers.php'; // -// Category Checklists +// Category Checklists. // /** @@ -32,7 +32,7 @@ * @param int[] $selected_cats Optional. Array of category IDs to mark as checked. Default false. * @param int[] $popular_cats Optional. Array of category IDs to receive the "popular-category" class. * Default false. - * @param object $walker Optional. Walker object to use to build the output. + * @param Walker $walker Optional. Walker object to use to build the output. * Default is a Walker_Category_Checklist instance. * @param bool $checked_ontop Optional. Whether to move checked items out of the hierarchy and to * the top of the list. Default true. @@ -68,7 +68,7 @@ * @type int[] $selected_cats Array of category IDs to mark as checked. Default false. * @type int[] $popular_cats Array of category IDs to receive the "popular-category" class. * Default false. - * @type object $walker Walker object to use to build the output. + * @type Walker $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 @@ -76,6 +76,7 @@ * @type bool $echo Whether to echo the generated markup. False to return the markup instead * of echoing it. Default true. * } + * @return string HTML list of input elements. */ function wp_terms_checklist( $post_id = 0, $args = array() ) { $defaults = array( @@ -100,37 +101,38 @@ */ $params = apply_filters( 'wp_terms_checklist_args', $args, $post_id ); - $r = wp_parse_args( $params, $defaults ); + $parsed_args = wp_parse_args( $params, $defaults ); - if ( empty( $r['walker'] ) || ! ( $r['walker'] instanceof Walker ) ) { + if ( empty( $parsed_args['walker'] ) || ! ( $parsed_args['walker'] instanceof Walker ) ) { $walker = new Walker_Category_Checklist; } else { - $walker = $r['walker']; + $walker = $parsed_args['walker']; } - $taxonomy = $r['taxonomy']; - $descendants_and_self = (int) $r['descendants_and_self']; + $taxonomy = $parsed_args['taxonomy']; + $descendants_and_self = (int) $parsed_args['descendants_and_self']; $args = array( 'taxonomy' => $taxonomy ); $tax = get_taxonomy( $taxonomy ); $args['disabled'] = ! current_user_can( $tax->cap->assign_terms ); - $args['list_only'] = ! empty( $r['list_only'] ); + $args['list_only'] = ! empty( $parsed_args['list_only'] ); - if ( is_array( $r['selected_cats'] ) ) { - $args['selected_cats'] = $r['selected_cats']; + if ( is_array( $parsed_args['selected_cats'] ) ) { + $args['selected_cats'] = array_map( 'intval', $parsed_args['selected_cats'] ); } elseif ( $post_id ) { $args['selected_cats'] = wp_get_object_terms( $post_id, $taxonomy, array_merge( $args, array( 'fields' => 'ids' ) ) ); } else { $args['selected_cats'] = array(); } - if ( is_array( $r['popular_cats'] ) ) { - $args['popular_cats'] = $r['popular_cats']; + + if ( is_array( $parsed_args['popular_cats'] ) ) { + $args['popular_cats'] = array_map( 'intval', $parsed_args['popular_cats'] ); } else { $args['popular_cats'] = get_terms( - $taxonomy, array( + 'taxonomy' => $taxonomy, 'fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', @@ -139,10 +141,11 @@ ) ); } + if ( $descendants_and_self ) { $categories = (array) get_terms( - $taxonomy, array( + 'taxonomy' => $taxonomy, 'child_of' => $descendants_and_self, 'hierarchical' => 0, 'hide_empty' => 0, @@ -151,30 +154,36 @@ $self = get_term( $descendants_and_self, $taxonomy ); array_unshift( $categories, $self ); } else { - $categories = (array) get_terms( $taxonomy, array( 'get' => 'all' ) ); + $categories = (array) get_terms( + array( + 'taxonomy' => $taxonomy, + 'get' => 'all', + ) + ); } $output = ''; - if ( $r['checked_ontop'] ) { - // Post process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all posts (for any query cache) + if ( $parsed_args['checked_ontop'] ) { + // Post-process $categories rather than adding an exclude to the get_terms() query + // to keep the query the same across all posts (for any query cache). $checked_categories = array(); $keys = array_keys( $categories ); foreach ( $keys as $k ) { - if ( in_array( $categories[ $k ]->term_id, $args['selected_cats'] ) ) { + if ( in_array( $categories[ $k ]->term_id, $args['selected_cats'], true ) ) { $checked_categories[] = $categories[ $k ]; unset( $categories[ $k ] ); } } - // Put checked cats on top - $output .= call_user_func_array( array( $walker, 'walk' ), array( $checked_categories, 0, $args ) ); + // Put checked categories on top. + $output .= $walker->walk( $checked_categories, 0, $args ); } - // Then the rest of them - $output .= call_user_func_array( array( $walker, 'walk' ), array( $categories, 0, $args ) ); + // Then the rest of them. + $output .= $walker->walk( $categories, 0, $args ); - if ( $r['echo'] ) { + if ( $parsed_args['echo'] ) { echo $output; } @@ -192,10 +201,10 @@ * @since 2.5.0 * * @param string $taxonomy Taxonomy to retrieve terms from. - * @param int $default Not used. - * @param int $number Number of terms to retrieve. Defaults to 10. - * @param bool $echo Optionally output the list as well. Defaults to true. - * @return array List of popular term IDs. + * @param int $default Not used. + * @param int $number Number of terms to retrieve. Defaults to 10. + * @param bool $echo Optionally output the list as well. Defaults to true. + * @return int[] Array of popular term IDs. */ function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $echo = true ) { $post = get_post(); @@ -207,8 +216,8 @@ } $terms = get_terms( - $taxonomy, array( + 'taxonomy' => $taxonomy, 'orderby' => 'count', 'order' => 'DESC', 'number' => $number, @@ -219,13 +228,14 @@ $tax = get_taxonomy( $taxonomy ); $popular_ids = array(); + foreach ( (array) $terms as $term ) { $popular_ids[] = $term->term_id; if ( ! $echo ) { // Hack for Ajax use. continue; } $id = "popular-$taxonomy-$term->term_id"; - $checked = in_array( $term->term_id, $checked_terms ) ? 'checked="checked"' : ''; + $checked = in_array( $term->term_id, $checked_terms, true ) ? 'checked="checked"' : ''; ?> '; } } @@ -302,7 +312,6 @@ $title = esc_textarea( trim( $post->post_title ) ); - /** This filter is documented in wp-admin/edit-tag-form.php */ echo '