Walker_ExtendedTaxonomyCheckboxes::start_el PHP Method

start_el() public method

Start the element output.
public start_el ( string &$output, object $object, integer $depth, array $args = [], integer $current_object_id )
$output string Passed by reference. Used to append additional content.
$object object Term data object.
$depth integer Depth of term in reference to parents.
$args array Optional arguments.
$current_object_id integer Current object ID.
        public function start_el(&$output, $object, $depth = 0, $args = array(), $current_object_id = 0)
        {
            $tax = get_taxonomy($args['taxonomy']);
            if ($this->field) {
                $value = $object->{$this->field};
            } else {
                $value = $tax->hierarchical ? $object->term_id : $object->name;
            }
            if (empty($object->term_id) && !$tax->hierarchical) {
                $value = '';
            }
            $output .= "\n<li id='{$args['taxonomy']}-{$object->term_id}'>" . '<label class="selectit">' . '<input value="' . esc_attr($value) . '" type="checkbox" name="tax_input[' . esc_attr($args['taxonomy']) . '][]" ' . 'id="in-' . esc_attr($args['taxonomy']) . '-' . intval($object->term_id) . '"' . checked(in_array($object->term_id, (array) $args['selected_cats']), true, false) . disabled(empty($args['disabled']), false, false) . ' /> ' . esc_html(apply_filters('the_category', $object->name)) . '</label>';
        }

Usage Example

Example #1
0
    /**
     * Display a meta box on the post editing screen.
     *
     * @param object $post The post object
     * @param object $walker An optional term walker
     * @param bool $show_none Whether to include a 'none' item in the term list
     * @param string $type The taxonomy list type (checklist or dropdown)
     * @return null
     */
    function do_meta_box(WP_Post $post, Walker $walker = null, $show_none = false, $type = 'checklist')
    {
        $taxonomy = $this->taxo->taxonomy;
        $tax = get_taxonomy($taxonomy);
        $selected = wp_get_object_terms($post->ID, $taxonomy, array('fields' => 'ids'));
        if ($show_none) {
            if (isset($tax->labels->no_item)) {
                $none = $tax->labels->no_item;
            } else {
                $none = __('Not Specified', 'ext_taxos');
            }
        } else {
            $none = '';
        }
        ?>
		<div id="taxonomy-<?php 
        echo $taxonomy;
        ?>
" class="categorydiv">

			<?php 
        switch ($type) {
            case 'dropdown':
                wp_dropdown_categories(array('show_option_none' => $none, 'hide_empty' => false, 'hierarchical' => true, 'show_count' => false, 'orderby' => 'name', 'selected' => $selected, 'id' => "{$taxonomy}dropdown", 'name' => "tax_input[{$taxonomy}]", 'taxonomy' => $taxonomy, 'walker' => $walker));
                break;
            case 'checklist':
            default:
                ?>
					<style type="text/css">
						/* Style for the 'none' item: */
						#<?php 
                echo $taxonomy;
                ?>
-0 {
							color: #888;
							border-top: 1px solid #eee;
							margin-top: 5px;
						}
					</style>

					<input type="hidden" name="tax_input[<?php 
                echo $taxonomy;
                ?>
][]" value="0" />

					<ul id="<?php 
                echo $taxonomy;
                ?>
checklist" class="list:<?php 
                echo $taxonomy;
                ?>
 categorychecklist form-no-clear">
						<?php 
                # Standard WP Walker_Category_Checklist does not cut it
                if (empty($walker) or !is_a($walker, 'Walker')) {
                    $walker = new Walker_ExtendedTaxonomyCheckboxes();
                }
                # Output the terms:
                wp_terms_checklist($post->ID, array('taxonomy' => $taxonomy, 'walker' => $walker, 'selected_cats' => $selected, 'checked_ontop' => $this->args['checked_ontop']));
                # Output the 'none' item:
                if ($show_none) {
                    $output = '';
                    $o = (object) array('term_id' => 0, 'name' => $none, 'slug' => 'none');
                    if (empty($selected)) {
                        $_selected = array(0);
                    } else {
                        $_selected = $selected;
                    }
                    $args = array('taxonomy' => $taxonomy, 'selected_cats' => $_selected, 'disabled' => false);
                    $walker->start_el($output, $o, 1, $args);
                    $walker->end_el($output, $o, 1, $args);
                    echo $output;
                }
                ?>

					</ul>

					<?php 
                break;
        }
        ?>

		</div>
		<?php 
    }
All Usage Examples Of Walker_ExtendedTaxonomyCheckboxes::start_el