Esempio n. 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 
    }
Esempio n. 2
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
         */
        protected 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 = '';
            }
            /**
             * Execute code before the taxonomy meta box content outputs to the page.
             *
             * @since 2.0.0
             *
             * @param stdClass $tax  The current taxonomy object.
             * @param WP_Post  $post The current post object.
             * @param string   $type The taxonomy list type ('checklist' or 'dropdown').
             */
            do_action('ext-taxos/meta_box/before', $tax, $post, $type);
            ?>
		<div id="taxonomy-<?php 
            echo esc_attr($taxonomy);
            ?>
" class="categorydiv">

			<?php 
            switch ($type) {
                case 'dropdown':
                    wp_dropdown_categories(array('option_none_value' => is_taxonomy_hierarchical($taxonomy) ? '-1' : '', 'show_option_none' => $none, 'hide_empty' => false, 'hierarchical' => true, 'show_count' => false, 'orderby' => 'name', 'selected' => reset($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 esc_attr($taxonomy);
                    ?>
-0 {
							color: #888;
							border-top: 1px solid #eee;
							margin-top: 5px;
							padding-top: 5px;
						}
					</style>

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

					<ul id="<?php 
                    echo esc_attr($taxonomy);
                    ?>
checklist" class="list:<?php 
                    echo esc_attr($taxonomy);
                    ?>
 categorychecklist form-no-clear">
						<?php 
                    # Standard WP Walker_Category_Checklist does not cut it
                    if (empty($walker) || !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;
                        // WPCS: XSS ok.
                    }
                    ?>

					</ul>

					<?php 
                    break;
            }
            ?>

		</div>
		<?php 
            /**
             * Execute code after the taxonomy meta box content outputs to the page.
             *
             * @since 2.0.0
             *
             * @param stdClass $tax  The current taxonomy object.
             * @param WP_Post  $post The current post object.
             * @param string   $type The taxonomy list type ('checklist' or 'dropdown').
             */
            do_action('ext-taxos/meta_box/after', $tax, $post, $type);
        }