функция since 2.6.0

post_categories_meta_box()

Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.

Сигнатура

post_categories_meta_box( WP_Post $post, array $box )

Описание

Отображает поля формы рубрик записи.

Параметры

$post WP_Post обязательный
Текущий объект записи.
$box array обязательный
Categories meta box arguments. id stringMeta box 'id' attribute. title stringMeta box title. callback callableMeta box display callback. args array Extra meta box arguments. taxonomy stringTaxonomy. Default 'category'. Source function post_categories_meta_box( $post, $box ) { $defaults = array( 'taxonomy' => 'category' ); if ( ! isset( $box['args'] ) || ! is_array( $box['args'] ) ) { $args = array(); } else { $args = $box['args']; } $parsed_args = wp_parse_args( $args, $defaults ); $tax_name = esc_attr( $parsed_args['taxonomy'] ); $taxonomy = get_taxonomy( $parsed_args['taxonomy'] ); ?> <div id="taxonomy-" class="categorydiv"> <ul id="-tabs" class="category-tabs" role="tablist">
  • <a href="#-all" role="tab" aria-selected="true" aria-controls="-all">labels->all_items; ?>
  • <a href="#-pop" role="tab" aria-controls="-pop">labels->most_used ); ?>
  • <div id="-pop" class="tabs-panel" style="display: none;" role="tabpanel"> <ul id="checklist-pop" class="categorychecklist form-no-clear" >
    <div id="-all" class="tabs-panel" role="tabpanel"> <?php $name = ( 'category' === $tax_name ) ? 'post_category' : 'tax_input[' . $tax_name . ']'; // Allows for an empty term set to be sent. 0 is an invalid term ID and will be ignored by empty() checks. echo ""; ?> <ul id="checklist" data-wp-lists="list:" class="categorychecklist form-no-clear"> ID, array( 'taxonomy' => $tax_name, 'popular_cats' => $popular_ids, ) ); ?>
    cap->edit_terms ) ) : ?> <div id="-adder" class="wp-hidden-children"> <a id="-add-toggle" href="#-add" class="hide-if-no-js taxonomy-add-new"> labels->add_new_item ); ?> <p id="-add" class="category-add wp-hidden-child"> <label class="screen-reader-text" for="new">labels->add_new_item; ?> <input type="text" name="new" id="new" class="form-required form-input-tip" value="labels->new_item_name ); ?>" aria-required="true" /> <label class="screen-reader-text" for="new_parent"> labels->parent_item_colon; ?> $tax_name, 'hide_empty' => 0, 'name' => 'new' . $tax_name . '_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => '— ' . $taxonomy->labels->parent_item . ' —', ); /** * Filters the arguments for the taxonomy parent dropdown on the Post Edit page. * * @since 4.4.0 * * @param array $parent_dropdown_args { * Optional. Array of arguments to generate parent dropdown. * * @type string $taxonomy Name of the taxonomy to retrieve. * @type bool $hide_if_empty True to skip generating markup if no * categories are found. Default 0. * @type string $name Value for the 'name' attribute * of the select element. * Default "new{$tax_name}_parent". * @type string $orderby Which column to use for ordering * terms. Default 'name'. * @type bool|int $hierarchical Whether to traverse the taxonomy * hierarchy. Default 1. * @type string $show_option_none Text to display for the "none" option. * Default "— {$parent} —", * where `$parent` is 'parent_item' * taxonomy label. * } */ $parent_dropdown_args = apply_filters( 'post_edit_category_parent_dropdown_args', $parent_dropdown_args ); wp_dropdown_categories( $parent_dropdown_args ); ?> <input type="button" id="-add-submit" data-wp-lists="add:checklist:-add" class="button category-add-submit" value="labels->add_new_item ); ?>" /> <span id="-ajax-response">

    <?php } View all references View on Trac View on GitHub Hooks apply_filters( ‘post_edit_category_parent_dropdown_args’, array $parent_dropdown_args )Filters the arguments for the taxonomy parent dropdown on the Post Edit page. Related UsesDescriptionwp_popular_terms_checklist()wp-admin/includes/template.phpRetrieves a list of the most popular terms from the specified taxonomy. wp_terms_checklist()wp-admin/includes/template.phpOutputs an unordered list of checkbox input elements labelled with term names. wp_dropdown_categories()wp-includes/category-template.phpDisplays or retrieves the HTML dropdown list of categories. wp_nonce_field()wp-includes/functions.phpRetrieves or display nonce hidden field for forms. current_user_can()wp-includes/capabilities.phpReturns whether the current user has the specified capability. __()wp-includes/l10n.phpRetrieves the translation of $text. esc_attr()wp-includes/formatting.phpEscaping for HTML attributes. esc_html()wp-includes/formatting.phpEscaping for HTML blocks. wp_parse_args()wp-includes/functions.phpMerges user defined arguments into defaults array. get_taxonomy()wp-includes/taxonomy.phpRetrieves the taxonomy object of $taxonomy. apply_filters()wp-includes/plugin.phpCalls the callback functions that have been added to a filter hook. Show 7 moreShow less Changelog VersionDescription2.6.0Introduced.

    Исходный код

    wp-admin/includes/meta-boxes.php:635

    function post_categories_meta_box( $post, $box ) {
    	$defaults = array( 'taxonomy' => 'category' );
    	if ( ! isset( $box['args'] ) || ! is_array( $box['args'] ) ) {
    		$args = array();
    	} else {
    		$args = $box['args'];
    	}
    	$parsed_args = wp_parse_args( $args, $defaults );
    	$tax_name    = esc_attr( $parsed_args['taxonomy'] );
    	$taxonomy    = get_taxonomy( $parsed_args['taxonomy'] );
    	?>
    	<div id="taxonomy-<?php echo $tax_name; ?>" class="categorydiv">
    		<ul id="<?php echo $tax_name; ?>-tabs" class="category-tabs" role="tablist">
    			<li class="tabs"><a href="#<?php echo $tax_name; ?>-all" role="tab" aria-selected="true" aria-controls="<?php echo $tax_name; ?>-all"><?php echo $taxonomy->labels->all_items; ?></a></li>
    			<li class="hide-if-no-js"><a href="#<?php echo $tax_name; ?>-pop" role="tab" aria-controls="<?php echo $tax_name; ?>-pop"><?php echo esc_html( $taxonomy->labels->most_used ); ?></a></li>
    		</ul>
    
    		<div id="<?php echo $tax_name; ?>-pop" class="tabs-panel" style="display: none;" role="tabpanel">
    			<ul id="<?php echo $tax_name; ?>checklist-pop" class="categorychecklist form-no-clear" >
    				<?php $popular_ids = wp_popular_terms_checklist( $tax_name ); ?>
    			</ul>
    		</div>
    
    		<div id="<?php echo $tax_name; ?>-all" class="tabs-panel" role="tabpanel">
    			<?php
    			$name = ( 'category' === $tax_name ) ? 'post_category' : 'tax_input[' . $tax_name . ']';
    			// Allows for an empty term set to be sent. 0 is an invalid term ID and will be ignored by empty() checks.
    			echo "<input type='hidden' name='{$name}[]' value='0' />";
    			?>
    			<ul id="<?php echo $tax_name; ?>checklist" data-wp-lists="list:<?php echo $tax_name; ?>" class="categorychecklist form-no-clear">
    				<?php
    				wp_terms_checklist(
    					$post->ID,
    					array(
    						'taxonomy'     => $tax_name,
    						'popular_cats' => $popular_ids,
    					)
    				);
    				?>
    			</ul>
    		</div>
    	<?php if ( current_user_can( $taxonomy->cap->edit_terms ) ) : ?>
    			<div id="<?php echo $tax_name; ?>-adder" class="wp-hidden-children">
    				<a id="<?php echo $tax_name; ?>-add-toggle" href="#<?php echo $tax_name; ?>-add" class="hide-if-no-js taxonomy-add-new">
    					<?php
    						/* translators: %s: Add New taxonomy label. */
    						printf( __( '+ %s' ), $taxonomy->labels->add_new_item );
    					?>
    				</a>
    				<p id="<?php echo $tax_name; ?>-add" class="category-add wp-hidden-child">
    					<label class="screen-reader-text" for="new<?php echo $tax_name; ?>"><?php echo $taxonomy->labels->add_new_item; ?></label>
    					<input type="text" name="new<?php echo $tax_name; ?>" id="new<?php echo $tax_name; ?>" class="form-required form-input-tip" value="<?php echo esc_attr( $taxonomy->labels->new_item_name ); ?>" aria-required="true" />
    					<label class="screen-reader-text" for="new<?php echo $tax_name; ?>_parent">
    						<?php echo $taxonomy->labels->parent_item_colon; ?>
    					</label>
    					<?php
    					$parent_dropdown_args = array(
    						'taxonomy'         => $tax_name,
    						'hide_empty'       => 0,
    						'name'             => 'new' . $tax_name . '_parent',
    						'orderby'          => 'name',
    						'hierarchical'     => 1,
    						'show_option_none' => '— ' . $taxonomy->labels->parent_item . ' —',
    					);
    
    					/**
    					 * Filters the arguments for the taxonomy parent dropdown on the Post Edit page.
    					 *
    					 * @since 4.4.0
    					 *
    					 * @param array $parent_dropdown_args {
    					 *     Optional. Array of arguments to generate parent dropdown.
    					 *
    					 *     @type string   $taxonomy         Name of the taxonomy to retrieve.
    					 *     @type bool     $hide_if_empty    True to skip generating markup if no
    					 *                                      categories are found. Default 0.
    					 *     @type string   $name             Value for the 'name' attribute
    					 *                                      of the select element.
    					 *                                      Default "new{$tax_name}_parent".
    					 *     @type string   $orderby          Which column to use for ordering
    					 *                                      terms. Default 'name'.
    					 *     @type bool|int $hierarchical     Whether to traverse the taxonomy
    					 *                                      hierarchy. Default 1.
    					 *     @type string   $show_option_none Text to display for the "none" option.
    					 *                                      Default "&mdash; {$parent} &mdash;",
    					 *                                      where `$parent` is 'parent_item'
    					 *                                      taxonomy label.
    					 * }
    					 */
    					$parent_dropdown_args = apply_filters( 'post_edit_category_parent_dropdown_args', $parent_dropdown_args );
    
    					wp_dropdown_categories( $parent_dropdown_args );
    					?>
    					<input type="button" id="<?php echo $tax_name; ?>-add-submit" data-wp-lists="add:<?php echo $tax_name; ?>checklist:<?php echo $tax_name; ?>-add" class="button category-add-submit" value="<?php echo esc_attr( $taxonomy->labels->add_new_item ); ?>" />
    					<?php wp_nonce_field( 'add-' . $tax_name, '_ajax_nonce-add-' . $tax_name, false ); ?>
    					<span id="<?php echo $tax_name; ?>-ajax-response"></span>
    				</p>
    			</div>
    		<?php endif; ?>
    	</div>
    	<?php
    }

    История изменений

    ВерсияОписание
    2.6.0 Introduced.

    Что будем искать? Например,Продвижение

    Этот сайт использует куки-файлы. Оставаясь на сайте, Вы соглашаетесь на их использование. Для получения дополнительной информации, пожалуйста, ознакомьтесь с политикой в отношении персональных данных.