Ticket #19556: 19556.2.diff
File 19556.2.diff, 22.4 KB (added by , 9 years ago) |
---|
-
deleted file src/wp-admin/includes/class-walker-category-checklist.php
diff --git src/wp-admin/includes/class-walker-category-checklist.php src/wp-admin/includes/class-walker-category-checklist.php deleted file mode 100644 index cd38bfc..0000000
+ - 1 <?php2 /**3 * Taxonomy API: Walker_Category_Checklist class4 *5 * @package WordPress6 * @subpackage Administration7 * @since 4.4.08 */9 10 /**11 * Core walker class to output an unordered list of category checkbox input elements.12 *13 * @since 2.5.114 *15 * @see Walker16 * @see wp_category_checklist()17 * @see wp_terms_checklist()18 */19 class Walker_Category_Checklist extends Walker {20 public $tree_type = 'category';21 public $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this22 23 /**24 * Starts the list before the elements are added.25 *26 * @see Walker:start_lvl()27 *28 * @since 2.5.129 *30 * @param string $output Passed by reference. Used to append additional content.31 * @param int $depth Depth of category. Used for tab indentation.32 * @param array $args An array of arguments. @see wp_terms_checklist()33 */34 public function start_lvl( &$output, $depth = 0, $args = array() ) {35 $indent = str_repeat("\t", $depth);36 $output .= "$indent<ul class='children'>\n";37 }38 39 /**40 * Ends the list of after the elements are added.41 *42 * @see Walker::end_lvl()43 *44 * @since 2.5.145 *46 * @param string $output Passed by reference. Used to append additional content.47 * @param int $depth Depth of category. Used for tab indentation.48 * @param array $args An array of arguments. @see wp_terms_checklist()49 */50 public function end_lvl( &$output, $depth = 0, $args = array() ) {51 $indent = str_repeat("\t", $depth);52 $output .= "$indent</ul>\n";53 }54 55 /**56 * Start the element output.57 *58 * @see Walker::start_el()59 *60 * @since 2.5.161 *62 * @param string $output Passed by reference. Used to append additional content.63 * @param object $category The current term object.64 * @param int $depth Depth of the term in reference to parents. Default 0.65 * @param array $args An array of arguments. @see wp_terms_checklist()66 * @param int $id ID of the current term.67 */68 public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {69 if ( empty( $args['taxonomy'] ) ) {70 $taxonomy = 'category';71 } else {72 $taxonomy = $args['taxonomy'];73 }74 75 if ( $taxonomy == 'category' ) {76 $name = 'post_category';77 } else {78 $name = 'tax_input[' . $taxonomy . ']';79 }80 81 $args['popular_cats'] = empty( $args['popular_cats'] ) ? array() : $args['popular_cats'];82 $class = in_array( $category->term_id, $args['popular_cats'] ) ? ' class="popular-category"' : '';83 84 $args['selected_cats'] = empty( $args['selected_cats'] ) ? array() : $args['selected_cats'];85 86 if ( ! empty( $args['list_only'] ) ) {87 $aria_cheched = 'false';88 $inner_class = 'category';89 90 if ( in_array( $category->term_id, $args['selected_cats'] ) ) {91 $inner_class .= ' selected';92 $aria_cheched = 'true';93 }94 95 /** This filter is documented in wp-includes/category-template.php */96 $output .= "\n" . '<li' . $class . '>' .97 '<div class="' . $inner_class . '" data-term-id=' . $category->term_id .98 ' tabindex="0" role="checkbox" aria-checked="' . $aria_cheched . '">' .99 esc_html( apply_filters( 'the_category', $category->name ) ) . '</div>';100 } else {101 /** This filter is documented in wp-includes/category-template.php */102 $output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" .103 '<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="'.$name.'[]" id="in-'.$taxonomy.'-' . $category->term_id . '"' .104 checked( in_array( $category->term_id, $args['selected_cats'] ), true, false ) .105 disabled( empty( $args['disabled'] ), false, false ) . ' /> ' .106 esc_html( apply_filters( 'the_category', $category->name ) ) . '</label>';107 }108 }109 110 /**111 * Ends the element output, if needed.112 *113 * @see Walker::end_el()114 *115 * @since 2.5.1116 *117 * @param string $output Passed by reference. Used to append additional content.118 * @param object $category The current term object.119 * @param int $depth Depth of the term in reference to parents. Default 0.120 * @param array $args An array of arguments. @see wp_terms_checklist()121 */122 public function end_el( &$output, $category, $depth = 0, $args = array() ) {123 $output .= "</li>\n";124 }125 } -
src/wp-admin/includes/template.php
diff --git src/wp-admin/includes/template.php src/wp-admin/includes/template.php index 08a366f..75b9b7f 100644
8 8 * @subpackage Administration 9 9 */ 10 10 11 /** Walker_Category_Checklist class */12 require_once( ABSPATH . 'wp-admin/includes/class-walker-category-checklist.php' );13 14 11 /** WP_Internal_Pointers class */ 15 12 require_once( ABSPATH . 'wp-admin/includes/class-wp-internal-pointers.php' ); 16 13 … … require_once( ABSPATH . 'wp-admin/includes/class-wp-internal-pointers.php' ); 19 16 // 20 17 21 18 /** 22 * Output an unordered list of checkbox input elements labeled with category names.23 *24 * @since 2.5.125 *26 * @see wp_terms_checklist()27 *28 * @param int $post_id Optional. Post to generate a categories checklist for. Default 0.29 * $selected_cats must not be an array. Default 0.30 * @param int $descendants_and_self Optional. ID of the category to output along with its descendants.31 * Default 0.32 * @param array $selected_cats Optional. List of categories to mark as checked. Default false.33 * @param array $popular_cats Optional. List of categories to receive the "popular-category" class.34 * Default false.35 * @param object $walker Optional. Walker object to use to build the output.36 * Default is a Walker_Category_Checklist instance.37 * @param bool $checked_ontop Optional. Whether to move checked items out of the hierarchy and to38 * the top of the list. Default true.39 */40 function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false, $popular_cats = false, $walker = null, $checked_ontop = true ) {41 wp_terms_checklist( $post_id, array(42 'taxonomy' => 'category',43 'descendants_and_self' => $descendants_and_self,44 'selected_cats' => $selected_cats,45 'popular_cats' => $popular_cats,46 'walker' => $walker,47 'checked_ontop' => $checked_ontop48 ) );49 }50 51 /**52 * Output an unordered list of checkbox input elements labelled with term names.53 *54 * Taxonomy-independent version of wp_category_checklist().55 *56 * @since 3.0.057 * @since 4.4.0 Introduced the `$echo` argument.58 *59 * @param int $post_id Optional. Post ID. Default 0.60 * @param array|string $args {61 * Optional. Array or string of arguments for generating a terms checklist. Default empty array.62 *63 * @type int $descendants_and_self ID of the category to output along with its descendants.64 * Default 0.65 * @type array $selected_cats List of categories to mark as checked. Default false.66 * @type array $popular_cats List of categories to receive the "popular-category" class.67 * Default false.68 * @type object $walker Walker object to use to build the output.69 * Default is a Walker_Category_Checklist instance.70 * @type string $taxonomy Taxonomy to generate the checklist for. Default 'category'.71 * @type bool $checked_ontop Whether to move checked items out of the hierarchy and to72 * the top of the list. Default true.73 * @type bool $echo Whether to echo the generated markup. False to return the markup instead74 * of echoing it. Default true.75 * }76 */77 function wp_terms_checklist( $post_id = 0, $args = array() ) {78 $defaults = array(79 'descendants_and_self' => 0,80 'selected_cats' => false,81 'popular_cats' => false,82 'walker' => null,83 'taxonomy' => 'category',84 'checked_ontop' => true,85 'echo' => true,86 );87 88 /**89 * Filter the taxonomy terms checklist arguments.90 *91 * @since 3.4.092 *93 * @see wp_terms_checklist()94 *95 * @param array $args An array of arguments.96 * @param int $post_id The post ID.97 */98 $params = apply_filters( 'wp_terms_checklist_args', $args, $post_id );99 100 $r = wp_parse_args( $params, $defaults );101 102 if ( empty( $r['walker'] ) || ! ( $r['walker'] instanceof Walker ) ) {103 $walker = new Walker_Category_Checklist;104 } else {105 $walker = $r['walker'];106 }107 108 $taxonomy = $r['taxonomy'];109 $descendants_and_self = (int) $r['descendants_and_self'];110 111 $args = array( 'taxonomy' => $taxonomy );112 113 $tax = get_taxonomy( $taxonomy );114 $args['disabled'] = ! current_user_can( $tax->cap->assign_terms );115 116 $args['list_only'] = ! empty( $r['list_only'] );117 118 if ( is_array( $r['selected_cats'] ) ) {119 $args['selected_cats'] = $r['selected_cats'];120 } elseif ( $post_id ) {121 $args['selected_cats'] = wp_get_object_terms( $post_id, $taxonomy, array_merge( $args, array( 'fields' => 'ids' ) ) );122 } else {123 $args['selected_cats'] = array();124 }125 if ( is_array( $r['popular_cats'] ) ) {126 $args['popular_cats'] = $r['popular_cats'];127 } else {128 $args['popular_cats'] = get_terms( $taxonomy, array(129 'fields' => 'ids',130 'orderby' => 'count',131 'order' => 'DESC',132 'number' => 10,133 'hierarchical' => false134 ) );135 }136 if ( $descendants_and_self ) {137 $categories = (array) get_terms( $taxonomy, array(138 'child_of' => $descendants_and_self,139 'hierarchical' => 0,140 'hide_empty' => 0141 ) );142 $self = get_term( $descendants_and_self, $taxonomy );143 array_unshift( $categories, $self );144 } else {145 $categories = (array) get_terms( $taxonomy, array( 'get' => 'all' ) );146 }147 148 $output = '';149 150 if ( $r['checked_ontop'] ) {151 // 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)152 $checked_categories = array();153 $keys = array_keys( $categories );154 155 foreach ( $keys as $k ) {156 if ( in_array( $categories[$k]->term_id, $args['selected_cats'] ) ) {157 $checked_categories[] = $categories[$k];158 unset( $categories[$k] );159 }160 }161 162 // Put checked cats on top163 $output .= call_user_func_array( array( $walker, 'walk' ), array( $checked_categories, 0, $args ) );164 }165 // Then the rest of them166 $output .= call_user_func_array( array( $walker, 'walk' ), array( $categories, 0, $args ) );167 168 if ( $r['echo'] ) {169 echo $output;170 }171 172 return $output;173 }174 175 /**176 19 * Retrieve a list of the most popular terms from the specified taxonomy. 177 20 * 178 21 * If the $echo argument is true then the elements for a list of checkbox -
src/wp-includes/category-template.php
diff --git src/wp-includes/category-template.php src/wp-includes/category-template.php index b989ed5..a2452db 100644
function has_term( $term = '', $taxonomy = '', $post = null ) { 1328 1328 1329 1329 return $r; 1330 1330 } 1331 1332 1333 /** 1334 * Output an unordered list of checkbox input elements labeled with category names. 1335 * 1336 * @since 2.5.1 1337 * 1338 * @see wp_terms_checklist() 1339 * 1340 * @param int $post_id Optional. Post to generate a categories checklist for. Default 0. 1341 * $selected_cats must not be an array. Default 0. 1342 * @param int $descendants_and_self Optional. ID of the category to output along with its descendants. 1343 * Default 0. 1344 * @param array $selected_cats Optional. List of categories to mark as checked. Default false. 1345 * @param array $popular_cats Optional. List of categories to receive the "popular-category" class. 1346 * Default false. 1347 * @param object $walker Optional. Walker object to use to build the output. 1348 * Default is a Walker_Category_Checklist instance. 1349 * @param bool $checked_ontop Optional. Whether to move checked items out of the hierarchy and to 1350 * the top of the list. Default true. 1351 */ 1352 function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false, $popular_cats = false, $walker = null, $checked_ontop = true ) { 1353 wp_terms_checklist( $post_id, array( 1354 'taxonomy' => 'category', 1355 'descendants_and_self' => $descendants_and_self, 1356 'selected_cats' => $selected_cats, 1357 'popular_cats' => $popular_cats, 1358 'walker' => $walker, 1359 'checked_ontop' => $checked_ontop 1360 ) ); 1361 } 1362 1363 /** 1364 * Output an unordered list of checkbox input elements labelled with term names. 1365 * 1366 * Taxonomy-independent version of wp_category_checklist(). 1367 * 1368 * @since 3.0.0 1369 * @since 4.4.0 Introduced the `$echo` argument. 1370 * @since 4.5.0 Introduced the `$name` argument. 1371 * 1372 * @param int $post_id Optional. Post ID. Default 0. 1373 * @param array|string $args { 1374 * Optional. Array or string of arguments for generating a terms checklist. Default empty array. 1375 * 1376 * @type int $descendants_and_self ID of the category to output along with its descendants. 1377 * Default 0. 1378 * @type array $selected_cats List of categories to mark as checked. Default false. 1379 * @type array $popular_cats List of categories to receive the "popular-category" class. 1380 * Default false. 1381 * @type object $walker Walker object to use to build the output. 1382 * Default is a Walker_Category_Checklist instance. 1383 * @type string $taxonomy Taxonomy to generate the checklist for. Default 'category'. 1384 * @type bool $checked_ontop Whether to move checked items out of the hierarchy and to 1385 * the top of the list. Default true. 1386 * @type bool $echo Whether to echo the generated markup. False to return the markup instead 1387 * of echoing it. Default true. 1388 * @type string $name HTML name attribute for the form inputs. Default 'post_category' for 1389 * category taxonomy or `tax_input[ $taxonomy ]` for other taxonomies. 1390 * } 1391 */ 1392 function wp_terms_checklist( $post_id = 0, $args = array() ) { 1393 $defaults = array( 1394 'descendants_and_self' => 0, 1395 'selected_cats' => false, 1396 'popular_cats' => false, 1397 'walker' => null, 1398 'taxonomy' => 'category', 1399 'checked_ontop' => true, 1400 'echo' => true, 1401 ); 1402 1403 /** 1404 * Filter the taxonomy terms checklist arguments. 1405 * 1406 * @since 3.4.0 1407 * 1408 * @see wp_terms_checklist() 1409 * 1410 * @param array $args An array of arguments. 1411 * @param int $post_id The post ID. 1412 */ 1413 $params = apply_filters( 'wp_terms_checklist_args', $args, $post_id ); 1414 1415 $r = wp_parse_args( $params, $defaults ); 1416 1417 if ( empty( $r['walker'] ) || ! ( $r['walker'] instanceof Walker ) ) { 1418 $walker = new Walker_Category_Checklist; 1419 } else { 1420 $walker = $r['walker']; 1421 } 1422 1423 $taxonomy = $r['taxonomy']; 1424 $descendants_and_self = (int) $r['descendants_and_self']; 1425 1426 $args = array( 'taxonomy' => $taxonomy ); 1427 1428 $tax = get_taxonomy( $taxonomy ); 1429 $args['disabled'] = ! current_user_can( $tax->cap->assign_terms ); 1430 1431 $args['list_only'] = ! empty( $r['list_only'] ); 1432 1433 if ( is_array( $r['selected_cats'] ) ) { 1434 $args['selected_cats'] = $r['selected_cats']; 1435 } elseif ( $post_id ) { 1436 $args['selected_cats'] = wp_get_object_terms( $post_id, $taxonomy, array_merge( $args, array( 'fields' => 'ids' ) ) ); 1437 } else { 1438 $args['selected_cats'] = array(); 1439 } 1440 if ( is_array( $r['popular_cats'] ) ) { 1441 $args['popular_cats'] = $r['popular_cats']; 1442 } else { 1443 $args['popular_cats'] = get_terms( $taxonomy, array( 1444 'fields' => 'ids', 1445 'orderby' => 'count', 1446 'order' => 'DESC', 1447 'number' => 10, 1448 'hierarchical' => false 1449 ) ); 1450 } 1451 if ( $descendants_and_self ) { 1452 $categories = (array) get_terms( $taxonomy, array( 1453 'child_of' => $descendants_and_self, 1454 'hierarchical' => 0, 1455 'hide_empty' => 0 1456 ) ); 1457 $self = get_term( $descendants_and_self, $taxonomy ); 1458 array_unshift( $categories, $self ); 1459 } else { 1460 $categories = (array) get_terms( $taxonomy, array( 'get' => 'all' ) ); 1461 } 1462 1463 $output = ''; 1464 1465 if ( $r['checked_ontop'] ) { 1466 // 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) 1467 $checked_categories = array(); 1468 $keys = array_keys( $categories ); 1469 1470 foreach ( $keys as $k ) { 1471 if ( in_array( $categories[$k]->term_id, $args['selected_cats'] ) ) { 1472 $checked_categories[] = $categories[$k]; 1473 unset( $categories[$k] ); 1474 } 1475 } 1476 1477 // Put checked cats on top 1478 $output .= call_user_func_array( array( $walker, 'walk' ), array( $checked_categories, 0, $args ) ); 1479 } 1480 // Then the rest of them 1481 $output .= call_user_func_array( array( $walker, 'walk' ), array( $categories, 0, $args ) ); 1482 1483 if ( $r['echo'] ) { 1484 echo $output; 1485 } 1486 1487 return $output; 1488 } -
new file src/wp-includes/class-walker-category-checklist.php
diff --git src/wp-includes/class-walker-category-checklist.php src/wp-includes/class-walker-category-checklist.php new file mode 100644 index 0000000..ad71c1a
- + 1 <?php 2 /** 3 * Taxonomy API: Walker_Category_Checklist class 4 * 5 * @package WordPress 6 * @subpackage Administration 7 * @since 4.4.0 8 */ 9 10 /** 11 * Core walker class to output an unordered list of category checkbox input elements. 12 * 13 * @since 2.5.1 14 * 15 * @see Walker 16 * @see wp_category_checklist() 17 * @see wp_terms_checklist() 18 */ 19 class Walker_Category_Checklist extends Walker { 20 public $tree_type = 'category'; 21 public $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); //TODO: decouple this 22 23 /** 24 * Starts the list before the elements are added. 25 * 26 * @see Walker:start_lvl() 27 * 28 * @since 2.5.1 29 * 30 * @param string $output Passed by reference. Used to append additional content. 31 * @param int $depth Depth of category. Used for tab indentation. 32 * @param array $args An array of arguments. @see wp_terms_checklist() 33 */ 34 public function start_lvl( &$output, $depth = 0, $args = array() ) { 35 $indent = str_repeat("\t", $depth); 36 $output .= "$indent<ul class='children'>\n"; 37 } 38 39 /** 40 * Ends the list of after the elements are added. 41 * 42 * @see Walker::end_lvl() 43 * 44 * @since 2.5.1 45 * 46 * @param string $output Passed by reference. Used to append additional content. 47 * @param int $depth Depth of category. Used for tab indentation. 48 * @param array $args An array of arguments. @see wp_terms_checklist() 49 */ 50 public function end_lvl( &$output, $depth = 0, $args = array() ) { 51 $indent = str_repeat("\t", $depth); 52 $output .= "$indent</ul>\n"; 53 } 54 55 /** 56 * Start the element output. 57 * 58 * @see Walker::start_el() 59 * 60 * @since 2.5.1 61 * 62 * @param string $output Passed by reference. Used to append additional content. 63 * @param object $category The current term object. 64 * @param int $depth Depth of the term in reference to parents. Default 0. 65 * @param array $args An array of arguments. @see wp_terms_checklist() 66 * @param int $id ID of the current term. 67 */ 68 public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) { 69 if ( empty( $args['taxonomy'] ) ) { 70 $taxonomy = 'category'; 71 } else { 72 $taxonomy = $args['taxonomy']; 73 } 74 75 if ( $taxonomy == 'category' ) { 76 $name = 'post_category'; 77 } else { 78 $name = 'tax_input[' . $taxonomy . ']'; 79 } 80 81 if ( isset( $args['name'] ) ) { 82 $name = esc_attr( $args['name'] ); 83 } 84 85 $args['popular_cats'] = empty( $args['popular_cats'] ) ? array() : $args['popular_cats']; 86 $class = in_array( $category->term_id, $args['popular_cats'] ) ? ' class="popular-category"' : ''; 87 88 $args['selected_cats'] = empty( $args['selected_cats'] ) ? array() : $args['selected_cats']; 89 90 if ( ! empty( $args['list_only'] ) ) { 91 $aria_cheched = 'false'; 92 $inner_class = 'category'; 93 94 if ( in_array( $category->term_id, $args['selected_cats'] ) ) { 95 $inner_class .= ' selected'; 96 $aria_cheched = 'true'; 97 } 98 99 /** This filter is documented in wp-includes/category-template.php */ 100 $output .= "\n" . '<li' . $class . '>' . 101 '<div class="' . $inner_class . '" data-term-id=' . $category->term_id . 102 ' tabindex="0" role="checkbox" aria-checked="' . $aria_cheched . '">' . 103 esc_html( apply_filters( 'the_category', $category->name ) ) . '</div>'; 104 } else { 105 /** This filter is documented in wp-includes/category-template.php */ 106 $output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" . 107 '<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="'.$name.'[]" id="in-'.$taxonomy.'-' . $category->term_id . '"' . 108 checked( in_array( $category->term_id, $args['selected_cats'] ), true, false ) . 109 disabled( empty( $args['disabled'] ), false, false ) . ' /> ' . 110 esc_html( apply_filters( 'the_category', $category->name ) ) . '</label>'; 111 } 112 } 113 114 /** 115 * Ends the element output, if needed. 116 * 117 * @see Walker::end_el() 118 * 119 * @since 2.5.1 120 * 121 * @param string $output Passed by reference. Used to append additional content. 122 * @param object $category The current term object. 123 * @param int $depth Depth of the term in reference to parents. Default 0. 124 * @param array $args An array of arguments. @see wp_terms_checklist() 125 */ 126 public function end_el( &$output, $category, $depth = 0, $args = array() ) { 127 $output .= "</li>\n"; 128 } 129 } -
src/wp-settings.php
diff --git src/wp-settings.php src/wp-settings.php index ef1d2cd..b270b30 100644
require( ABSPATH . WPINC . '/post-thumbnail-template.php' ); 149 149 require( ABSPATH . WPINC . '/category.php' ); 150 150 require( ABSPATH . WPINC . '/class-walker-category.php' ); 151 151 require( ABSPATH . WPINC . '/class-walker-category-dropdown.php' ); 152 require( ABSPATH . WPINC . '/class-walker-category-checklist.php' ); 152 153 require( ABSPATH . WPINC . '/category-template.php' ); 153 154 require( ABSPATH . WPINC . '/comment.php' ); 154 155 require( ABSPATH . WPINC . '/class-wp-comment.php' );