Walker_Category_Checklist::start_el( string $output, WP_Term $data_object, int $depth, array $args = array(), int $current_object_id )

Start the element output.


Description

Top ↑

See also


Top ↑

Parameters

$output string Required
Used to append additional content (passed by reference).
$data_object WP_Term Required
The current term object.
$depth int Required
Depth of the term in reference to parents. Default 0.
$args array Optional
An array of arguments. @see wp_terms_checklist()
More Arguments from wp_terms_checklist( ... $args ) Array or string of arguments for generating a terms checklist.
  • descendants_and_self int
    ID of the category to output along with its descendants.
    Default 0.
  • selected_cats int[]
    Array of category IDs to mark as checked. Default false.
  • popular_cats int[]
    Array of category IDs to receive the "popular-category" class.
    Default false.
  • walker Walker
    Walker object to use to build the output. Default empty which results in a Walker_Category_Checklist instance being used.
  • taxonomy string
    Taxonomy to generate the checklist for. Default 'category'.
  • checked_ontop bool
    Whether to move checked items out of the hierarchy and to the top of the list. Default true.
  • echo bool
    Whether to echo the generated markup. False to return the markup instead of echoing it. Default true.

Default: array()

$current_object_id int Optional
ID of the current term. Default 0.

Top ↑

Source

File: wp-admin/includes/class-walker-category-checklist.php. View all references

public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_id = 0 ) {
	// Restores the more descriptive, specific name for use within this method.
	$category = $data_object;

	if ( empty( $args['taxonomy'] ) ) {
		$taxonomy = 'category';
	} else {
		$taxonomy = $args['taxonomy'];
	}

	if ( 'category' === $taxonomy ) {
		$name = 'post_category';
	} else {
		$name = 'tax_input[' . $taxonomy . ']';
	}

	$args['popular_cats'] = ! empty( $args['popular_cats'] ) ? array_map( 'intval', $args['popular_cats'] ) : array();

	$class = in_array( $category->term_id, $args['popular_cats'], true ) ? ' class="popular-category"' : '';

	$args['selected_cats'] = ! empty( $args['selected_cats'] ) ? array_map( 'intval', $args['selected_cats'] ) : array();

	if ( ! empty( $args['list_only'] ) ) {
		$aria_checked = 'false';
		$inner_class  = 'category';

		if ( in_array( $category->term_id, $args['selected_cats'], true ) ) {
			$inner_class .= ' selected';
			$aria_checked = 'true';
		}

		$output .= "\n" . '<li' . $class . '>' .
			'<div class="' . $inner_class . '" data-term-id=' . $category->term_id .
			' tabindex="0" role="checkbox" aria-checked="' . $aria_checked . '">' .
			/** This filter is documented in wp-includes/category-template.php */
			esc_html( apply_filters( 'the_category', $category->name, '', '' ) ) . '</div>';
	} else {
		$is_selected = in_array( $category->term_id, $args['selected_cats'], true );
		$is_disabled = ! empty( $args['disabled'] );

		$output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" .
			'<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="' . $name . '[]" id="in-' . $taxonomy . '-' . $category->term_id . '"' .
			checked( $is_selected, true, false ) .
			disabled( $is_disabled, true, false ) . ' /> ' .
			/** This filter is documented in wp-includes/category-template.php */
			esc_html( apply_filters( 'the_category', $category->name, '', '' ) ) . '</label>';
	}
}

Top ↑

Hooks



Top ↑

Changelog

Changelog
Version Description
5.9.0 Renamed $category to $data_object and $id to $current_object_id to match parent class for PHP 8 named parameter support.
2.5.1 Introduced.

Top ↑

User Contributed Notes

You must log in before being able to contribute a note or feedback.