2015-09-16 17:35:23 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2015-09-22 16:33:48 +02:00
|
|
|
* Taxonomy API: Walker_Category_Checklist class
|
2015-09-16 17:35:23 +02:00
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Administration
|
|
|
|
* @since 4.4.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2015-09-22 16:33:48 +02:00
|
|
|
* Core walker class to output an unordered list of category checkbox input elements.
|
2015-09-16 17:35:23 +02:00
|
|
|
*
|
|
|
|
* @since 2.5.1
|
|
|
|
*
|
|
|
|
* @see Walker
|
|
|
|
* @see wp_category_checklist()
|
|
|
|
* @see wp_terms_checklist()
|
|
|
|
*/
|
|
|
|
class Walker_Category_Checklist extends Walker {
|
|
|
|
public $tree_type = 'category';
|
2017-12-01 00:11:00 +01:00
|
|
|
public $db_fields = array(
|
|
|
|
'parent' => 'parent',
|
|
|
|
'id' => 'term_id',
|
2020-01-29 01:45:18 +01:00
|
|
|
); // TODO: Decouple this.
|
2015-09-16 17:35:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Starts the list before the elements are added.
|
|
|
|
*
|
|
|
|
* @see Walker:start_lvl()
|
|
|
|
*
|
|
|
|
* @since 2.5.1
|
|
|
|
*
|
2017-10-03 00:14:46 +02:00
|
|
|
* @param string $output Used to append additional content (passed by reference).
|
2015-09-16 17:35:23 +02:00
|
|
|
* @param int $depth Depth of category. Used for tab indentation.
|
2023-08-24 11:01:16 +02:00
|
|
|
* @param array $args An array of arguments. See {@see wp_terms_checklist()}.
|
2015-09-16 17:35:23 +02:00
|
|
|
*/
|
|
|
|
public function start_lvl( &$output, $depth = 0, $args = array() ) {
|
2017-12-01 00:11:00 +01:00
|
|
|
$indent = str_repeat( "\t", $depth );
|
2015-09-16 17:35:23 +02:00
|
|
|
$output .= "$indent<ul class='children'>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ends the list of after the elements are added.
|
|
|
|
*
|
|
|
|
* @see Walker::end_lvl()
|
|
|
|
*
|
|
|
|
* @since 2.5.1
|
|
|
|
*
|
2017-10-03 00:14:46 +02:00
|
|
|
* @param string $output Used to append additional content (passed by reference).
|
2015-09-16 17:35:23 +02:00
|
|
|
* @param int $depth Depth of category. Used for tab indentation.
|
2023-08-24 11:01:16 +02:00
|
|
|
* @param array $args An array of arguments. See {@see wp_terms_checklist()}.
|
2015-09-16 17:35:23 +02:00
|
|
|
*/
|
|
|
|
public function end_lvl( &$output, $depth = 0, $args = array() ) {
|
2017-12-01 00:11:00 +01:00
|
|
|
$indent = str_repeat( "\t", $depth );
|
2015-09-16 17:35:23 +02:00
|
|
|
$output .= "$indent</ul>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start the element output.
|
|
|
|
*
|
|
|
|
* @see Walker::start_el()
|
|
|
|
*
|
|
|
|
* @since 2.5.1
|
Code Modernization: Fix last parameter name mismatches for parent/child classes in `Walker::start_el()`.
The parent class uses `$current_object_id` while most of the child classes use `$id`. As the parent class' is more descriptive, renaming the last parameter in each of child class.
Why? PHP 8 introduces the ability to pass named arguments to function/method calls. This means the child and parent method signatures (i.e. parameter names) need to match.
Changes for readability:
- `@since` clearly specifies the original parameter name and its new name as well as why the change happened.
- In methods longer than a single line, the generic parameter is reassigned to the original parameter restoring it for context for use within the method. An inline comment is added to explain why this reassignment is made.
- In cases where the original parameter name was too generic or misleading, renamed (when reassigning) to a more descriptive name for use within the method.
Follow-up to [7737], [8900], [8970], [14248], [15077], [16100], [25642], [25644], [37051], [37054], [37056], [46271], [47189], [51739].
Props jrf, hellofromTonya, sergeybiryukov, azaozz, desrosj, johnbillion.
See #51553.
Built from https://develop.svn.wordpress.org/trunk@51779
git-svn-id: http://core.svn.wordpress.org/trunk@51386 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-09-09 14:39:59 +02:00
|
|
|
* @since 5.9.0 Renamed `$category` to `$data_object` and `$id` to `$current_object_id`
|
|
|
|
* to match parent class for PHP 8 named parameter support.
|
2015-09-16 17:35:23 +02:00
|
|
|
*
|
Code Modernization: Fix last parameter name mismatches for parent/child classes in `Walker::start_el()`.
The parent class uses `$current_object_id` while most of the child classes use `$id`. As the parent class' is more descriptive, renaming the last parameter in each of child class.
Why? PHP 8 introduces the ability to pass named arguments to function/method calls. This means the child and parent method signatures (i.e. parameter names) need to match.
Changes for readability:
- `@since` clearly specifies the original parameter name and its new name as well as why the change happened.
- In methods longer than a single line, the generic parameter is reassigned to the original parameter restoring it for context for use within the method. An inline comment is added to explain why this reassignment is made.
- In cases where the original parameter name was too generic or misleading, renamed (when reassigning) to a more descriptive name for use within the method.
Follow-up to [7737], [8900], [8970], [14248], [15077], [16100], [25642], [25644], [37051], [37054], [37056], [46271], [47189], [51739].
Props jrf, hellofromTonya, sergeybiryukov, azaozz, desrosj, johnbillion.
See #51553.
Built from https://develop.svn.wordpress.org/trunk@51779
git-svn-id: http://core.svn.wordpress.org/trunk@51386 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-09-09 14:39:59 +02:00
|
|
|
* @param string $output Used to append additional content (passed by reference).
|
|
|
|
* @param WP_Term $data_object The current term object.
|
|
|
|
* @param int $depth Depth of the term in reference to parents. Default 0.
|
2023-08-24 11:01:16 +02:00
|
|
|
* @param array $args An array of arguments. See {@see wp_terms_checklist()}.
|
Code Modernization: Fix last parameter name mismatches for parent/child classes in `Walker::start_el()`.
The parent class uses `$current_object_id` while most of the child classes use `$id`. As the parent class' is more descriptive, renaming the last parameter in each of child class.
Why? PHP 8 introduces the ability to pass named arguments to function/method calls. This means the child and parent method signatures (i.e. parameter names) need to match.
Changes for readability:
- `@since` clearly specifies the original parameter name and its new name as well as why the change happened.
- In methods longer than a single line, the generic parameter is reassigned to the original parameter restoring it for context for use within the method. An inline comment is added to explain why this reassignment is made.
- In cases where the original parameter name was too generic or misleading, renamed (when reassigning) to a more descriptive name for use within the method.
Follow-up to [7737], [8900], [8970], [14248], [15077], [16100], [25642], [25644], [37051], [37054], [37056], [46271], [47189], [51739].
Props jrf, hellofromTonya, sergeybiryukov, azaozz, desrosj, johnbillion.
See #51553.
Built from https://develop.svn.wordpress.org/trunk@51779
git-svn-id: http://core.svn.wordpress.org/trunk@51386 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-09-09 14:39:59 +02:00
|
|
|
* @param int $current_object_id Optional. ID of the current term. Default 0.
|
2015-09-16 17:35:23 +02:00
|
|
|
*/
|
Code Modernization: Fix last parameter name mismatches for parent/child classes in `Walker::start_el()`.
The parent class uses `$current_object_id` while most of the child classes use `$id`. As the parent class' is more descriptive, renaming the last parameter in each of child class.
Why? PHP 8 introduces the ability to pass named arguments to function/method calls. This means the child and parent method signatures (i.e. parameter names) need to match.
Changes for readability:
- `@since` clearly specifies the original parameter name and its new name as well as why the change happened.
- In methods longer than a single line, the generic parameter is reassigned to the original parameter restoring it for context for use within the method. An inline comment is added to explain why this reassignment is made.
- In cases where the original parameter name was too generic or misleading, renamed (when reassigning) to a more descriptive name for use within the method.
Follow-up to [7737], [8900], [8970], [14248], [15077], [16100], [25642], [25644], [37051], [37054], [37056], [46271], [47189], [51739].
Props jrf, hellofromTonya, sergeybiryukov, azaozz, desrosj, johnbillion.
See #51553.
Built from https://develop.svn.wordpress.org/trunk@51779
git-svn-id: http://core.svn.wordpress.org/trunk@51386 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-09-09 14:39:59 +02:00
|
|
|
public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_id = 0 ) {
|
Code Modernization: Fix reserved keyword and parameter name mismatches for parent/child classes in `Walker::start_el()`.
In the parent class, renames the parameter `$object` to `$data_object`.
Why? `object` is a PHP reserved keyword.
In each child class: renames the corresponding parameter to match the parent's method signature.
Why?
PHP 8 introduces the ability to pass named arguments to function/method calls. This means the child and parent method signatures (i.e. parameter names) need to match.
Changes for readability:
- `@since` clearly specifies the original parameter name and its new name as well as why the change happened.
- in methods longer than a single line, the generic parameter is reassigned to the original parameter restoring it for context for use within the method. An inline comment is added to explain why this reassignment is made.
- in cases where the original parameter name was too generic, renamed (when reassigning) to a more descriptive name for use within the method.
Follow-up to [7737], [8900], [8970], [14248], [15077], [16100], [25642], [25644], [37051], [37054], [37056], [46271], [47189].
Props jrf, hellofromTonya, sergeybiryukov, azaozz, desrosj, johnbillion.
See #51553.
Built from https://develop.svn.wordpress.org/trunk@51739
git-svn-id: http://core.svn.wordpress.org/trunk@51347 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-09-08 17:36:59 +02:00
|
|
|
// Restores the more descriptive, specific name for use within this method.
|
|
|
|
$category = $data_object;
|
|
|
|
|
2015-09-16 17:35:23 +02:00
|
|
|
if ( empty( $args['taxonomy'] ) ) {
|
|
|
|
$taxonomy = 'category';
|
|
|
|
} else {
|
|
|
|
$taxonomy = $args['taxonomy'];
|
|
|
|
}
|
|
|
|
|
2020-02-09 17:55:09 +01:00
|
|
|
if ( 'category' === $taxonomy ) {
|
2015-09-16 17:35:23 +02:00
|
|
|
$name = 'post_category';
|
|
|
|
} else {
|
|
|
|
$name = 'tax_input[' . $taxonomy . ']';
|
|
|
|
}
|
|
|
|
|
2020-08-27 04:48:06 +02:00
|
|
|
$args['popular_cats'] = ! empty( $args['popular_cats'] ) ? array_map( 'intval', $args['popular_cats'] ) : array();
|
2020-04-05 05:02:11 +02:00
|
|
|
|
2020-04-09 17:43:10 +02:00
|
|
|
$class = in_array( $category->term_id, $args['popular_cats'], true ) ? ' class="popular-category"' : '';
|
2015-09-16 17:35:23 +02:00
|
|
|
|
2020-08-27 04:48:06 +02:00
|
|
|
$args['selected_cats'] = ! empty( $args['selected_cats'] ) ? array_map( 'intval', $args['selected_cats'] ) : array();
|
2015-09-16 17:35:23 +02:00
|
|
|
|
|
|
|
if ( ! empty( $args['list_only'] ) ) {
|
2017-03-29 13:22:47 +02:00
|
|
|
$aria_checked = 'false';
|
2017-12-01 00:11:00 +01:00
|
|
|
$inner_class = 'category';
|
2015-09-16 17:35:23 +02:00
|
|
|
|
2020-04-09 17:43:10 +02:00
|
|
|
if ( in_array( $category->term_id, $args['selected_cats'], true ) ) {
|
2015-09-16 17:35:23 +02:00
|
|
|
$inner_class .= ' selected';
|
2017-03-29 13:22:47 +02:00
|
|
|
$aria_checked = 'true';
|
2015-09-16 17:35:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$output .= "\n" . '<li' . $class . '>' .
|
|
|
|
'<div class="' . $inner_class . '" data-term-id=' . $category->term_id .
|
2017-03-29 13:22:47 +02:00
|
|
|
' tabindex="0" role="checkbox" aria-checked="' . $aria_checked . '">' .
|
2019-09-10 21:23:55 +02:00
|
|
|
/** This filter is documented in wp-includes/category-template.php */
|
2017-08-03 18:13:44 +02:00
|
|
|
esc_html( apply_filters( 'the_category', $category->name, '', '' ) ) . '</div>';
|
2015-09-16 17:35:23 +02:00
|
|
|
} else {
|
2020-04-09 17:43:10 +02:00
|
|
|
$is_selected = in_array( $category->term_id, $args['selected_cats'], true );
|
|
|
|
$is_disabled = ! empty( $args['disabled'] );
|
|
|
|
|
2015-09-16 17:35:23 +02:00
|
|
|
$output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" .
|
2017-12-01 00:11:00 +01:00
|
|
|
'<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="' . $name . '[]" id="in-' . $taxonomy . '-' . $category->term_id . '"' .
|
2020-04-09 17:43:10 +02:00
|
|
|
checked( $is_selected, true, false ) .
|
|
|
|
disabled( $is_disabled, true, false ) . ' /> ' .
|
2019-09-10 21:23:55 +02:00
|
|
|
/** This filter is documented in wp-includes/category-template.php */
|
2017-08-03 18:13:44 +02:00
|
|
|
esc_html( apply_filters( 'the_category', $category->name, '', '' ) ) . '</label>';
|
2015-09-16 17:35:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ends the element output, if needed.
|
|
|
|
*
|
|
|
|
* @see Walker::end_el()
|
|
|
|
*
|
|
|
|
* @since 2.5.1
|
Code Modernization: Fix reserved keyword and parameter name mismatches for parent/child classes in `Walker::end_el()`.
In the parent class, renames the parameter `$object` to `$data_object`.
Why? `object` is a PHP reserved keyword. The parameter name is selected for consistency with `Walker::start_el()`.
In each child class: renames the parameter to match the parent's method signature.
Why? PHP 8 introduces the ability to pass named arguments to function/method calls. This means the child and parent method signatures (i.e. parameter names) need to match.
Changes for readability:
- `@since` clearly specifies the original parameter name and its new name as well as why the change happened.
Follow-up to [7737], [8900], [8970], [14248], [16100], [25642], [25644], [37051], [37056].
Props jrf, hellofromTonya, sergeybiryukov, azaozz, desrosj, johnbillion.
See #51553.
Built from https://develop.svn.wordpress.org/trunk@51780
git-svn-id: http://core.svn.wordpress.org/trunk@51387 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-09-09 15:03:55 +02:00
|
|
|
* @since 5.9.0 Renamed `$category` to `$data_object` to match parent class for PHP 8 named parameter support.
|
2015-09-16 17:35:23 +02:00
|
|
|
*
|
Code Modernization: Fix reserved keyword and parameter name mismatches for parent/child classes in `Walker::end_el()`.
In the parent class, renames the parameter `$object` to `$data_object`.
Why? `object` is a PHP reserved keyword. The parameter name is selected for consistency with `Walker::start_el()`.
In each child class: renames the parameter to match the parent's method signature.
Why? PHP 8 introduces the ability to pass named arguments to function/method calls. This means the child and parent method signatures (i.e. parameter names) need to match.
Changes for readability:
- `@since` clearly specifies the original parameter name and its new name as well as why the change happened.
Follow-up to [7737], [8900], [8970], [14248], [16100], [25642], [25644], [37051], [37056].
Props jrf, hellofromTonya, sergeybiryukov, azaozz, desrosj, johnbillion.
See #51553.
Built from https://develop.svn.wordpress.org/trunk@51780
git-svn-id: http://core.svn.wordpress.org/trunk@51387 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-09-09 15:03:55 +02:00
|
|
|
* @param string $output Used to append additional content (passed by reference).
|
|
|
|
* @param WP_Term $data_object The current term object.
|
|
|
|
* @param int $depth Depth of the term in reference to parents. Default 0.
|
2023-08-24 11:01:16 +02:00
|
|
|
* @param array $args An array of arguments. See {@see wp_terms_checklist()}.
|
2015-09-16 17:35:23 +02:00
|
|
|
*/
|
Code Modernization: Fix reserved keyword and parameter name mismatches for parent/child classes in `Walker::end_el()`.
In the parent class, renames the parameter `$object` to `$data_object`.
Why? `object` is a PHP reserved keyword. The parameter name is selected for consistency with `Walker::start_el()`.
In each child class: renames the parameter to match the parent's method signature.
Why? PHP 8 introduces the ability to pass named arguments to function/method calls. This means the child and parent method signatures (i.e. parameter names) need to match.
Changes for readability:
- `@since` clearly specifies the original parameter name and its new name as well as why the change happened.
Follow-up to [7737], [8900], [8970], [14248], [16100], [25642], [25644], [37051], [37056].
Props jrf, hellofromTonya, sergeybiryukov, azaozz, desrosj, johnbillion.
See #51553.
Built from https://develop.svn.wordpress.org/trunk@51780
git-svn-id: http://core.svn.wordpress.org/trunk@51387 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-09-09 15:03:55 +02:00
|
|
|
public function end_el( &$output, $data_object, $depth = 0, $args = array() ) {
|
2015-09-16 17:35:23 +02:00
|
|
|
$output .= "</li>\n";
|
|
|
|
}
|
|
|
|
}
|