* Template WordPress Administration API.
* A Big Mess. Also some neat functions that are nicely written.
* @subpackage Administration
/** Walker_Category_Checklist class */
require_once ABSPATH . 'wp-admin/includes/class-walker-category-checklist.php';
/** WP_Internal_Pointers class */
require_once ABSPATH . 'wp-admin/includes/class-wp-internal-pointers.php';
* Output an unordered list of checkbox input elements labeled with category names.
* @see wp_terms_checklist()
* @param int $post_id Optional. Post to generate a categories checklist for. Default 0.
* $selected_cats must not be an array. Default 0.
* @param int $descendants_and_self Optional. ID of the category to output along with its descendants.
* @param int[]|false $selected_cats Optional. Array of category IDs to mark as checked. Default false.
* @param int[]|false $popular_cats Optional. Array of category IDs to receive the "popular-category" class.
* @param Walker $walker Optional. Walker object to use to build the output.
* Default is a Walker_Category_Checklist instance.
* @param bool $checked_ontop Optional. Whether to move checked items out of the hierarchy and to
* the top of the list. Default true.
function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false, $popular_cats = false, $walker = null, $checked_ontop = true ) {
'taxonomy' => 'category',
'descendants_and_self' => $descendants_and_self,
'selected_cats' => $selected_cats,
'popular_cats' => $popular_cats,
'checked_ontop' => $checked_ontop,
* Output an unordered list of checkbox input elements labelled with term names.
* Taxonomy-independent version of wp_category_checklist().
* @since 4.4.0 Introduced the `$echo` argument.
* @param int $post_id Optional. Post ID. Default 0.
* @param array|string $args {
* Optional. Array or string of arguments for generating a terms checklist. Default empty array.
* @type int $descendants_and_self ID of the category to output along with its descendants.
* @type int[] $selected_cats Array of category IDs to mark as checked. Default false.
* @type int[] $popular_cats Array of category IDs to receive the "popular-category" class.
* @type Walker $walker Walker object to use to build the output.
* Default is a Walker_Category_Checklist instance.
* @type string $taxonomy Taxonomy to generate the checklist for. Default 'category'.
* @type bool $checked_ontop Whether to move checked items out of the hierarchy and to
* the top of the list. Default true.
* @type bool $echo Whether to echo the generated markup. False to return the markup instead
* of echoing it. Default true.
* @return string HTML list of input elements.
function wp_terms_checklist( $post_id = 0, $args = array() ) {
'descendants_and_self' => 0,
'selected_cats' => false,
'taxonomy' => 'category',
* Filters the taxonomy terms checklist arguments.
* @see wp_terms_checklist()
* @param array $args An array of arguments.
* @param int $post_id The post ID.
$params = apply_filters( 'wp_terms_checklist_args', $args, $post_id );
$parsed_args = wp_parse_args( $params, $defaults );
if ( empty( $parsed_args['walker'] ) || ! ( $parsed_args['walker'] instanceof Walker ) ) {
$walker = new Walker_Category_Checklist;
$walker = $parsed_args['walker'];
$taxonomy = $parsed_args['taxonomy'];
$descendants_and_self = (int) $parsed_args['descendants_and_self'];
$args = array( 'taxonomy' => $taxonomy );
$tax = get_taxonomy( $taxonomy );
$args['disabled'] = ! current_user_can( $tax->cap->assign_terms );
$args['list_only'] = ! empty( $parsed_args['list_only'] );
if ( is_array( $parsed_args['selected_cats'] ) ) {
$args['selected_cats'] = array_map( 'intval', $parsed_args['selected_cats'] );
$args['selected_cats'] = wp_get_object_terms( $post_id, $taxonomy, array_merge( $args, array( 'fields' => 'ids' ) ) );
$args['selected_cats'] = array();
if ( is_array( $parsed_args['popular_cats'] ) ) {
$args['popular_cats'] = array_map( 'intval', $parsed_args['popular_cats'] );
$args['popular_cats'] = get_terms(
if ( $descendants_and_self ) {
$categories = (array) get_terms(
'child_of' => $descendants_and_self,
$self = get_term( $descendants_and_self, $taxonomy );
array_unshift( $categories, $self );
$categories = (array) get_terms(
if ( $parsed_args['checked_ontop'] ) {
// Post-process $categories rather than adding an exclude to the get_terms() query
// to keep the query the same across all posts (for any query cache).
$checked_categories = array();
$keys = array_keys( $categories );
foreach ( $keys as $k ) {
if ( in_array( $categories[ $k ]->term_id, $args['selected_cats'], true ) ) {
$checked_categories[] = $categories[ $k ];
unset( $categories[ $k ] );
// Put checked categories on top.
$output .= $walker->walk( $checked_categories, 0, $args );
// Then the rest of them.
$output .= $walker->walk( $categories, 0, $args );
if ( $parsed_args['echo'] ) {
* Retrieve a list of the most popular terms from the specified taxonomy.
* If the $echo argument is true then the elements for a list of checkbox
* `<input>` elements labelled with the names of the selected terms is output.
* If the $post_ID global isn't empty then the terms associated with that
* post will be marked as checked.
* @param string $taxonomy Taxonomy to retrieve terms from.
* @param int $default Not used.
* @param int $number Number of terms to retrieve. Defaults to 10.
* @param bool $echo Optionally output the list as well. Defaults to true.
* @return int[] Array of popular term IDs.
function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $echo = true ) {
if ( $post && $post->ID ) {
$checked_terms = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );
$checked_terms = array();
$tax = get_taxonomy( $taxonomy );
foreach ( (array) $terms as $term ) {
$popular_ids[] = $term->term_id;
if ( ! $echo ) { // Hack for Ajax use.
$id = "popular-$taxonomy-$term->term_id";
$checked = in_array( $term->term_id, $checked_terms, true ) ? 'checked="checked"' : '';
<li id="<?php echo $id; ?>" class="popular-category">
<input id="in-<?php echo $id; ?>" type="checkbox" <?php echo $checked; ?> value="<?php echo (int) $term->term_id; ?>" <?php disabled( ! current_user_can( $tax->cap->assign_terms ) ); ?> />
/** This filter is documented in wp-includes/category-template.php */
echo esc_html( apply_filters( 'the_category', $term->name, '', '' ) );
* Outputs a link category checklist element.
function wp_link_category_checklist( $link_id = 0 ) {
$checked_categories = array();
$checked_categories = wp_get_link_cats( $link_id );
// No selected categories, strange.
if ( ! count( $checked_categories ) ) {
$checked_categories[] = $default;
$checked_categories[] = $default;
'taxonomy' => 'link_category',
if ( empty( $categories ) ) {
foreach ( $categories as $category ) {
$cat_id = $category->term_id;
/** This filter is documented in wp-includes/category-template.php */
$name = esc_html( apply_filters( 'the_category', $category->name, '', '' ) );
$checked = in_array( $cat_id, $checked_categories, true ) ? ' checked="checked"' : '';
echo '<li id="link-category-', $cat_id, '"><label for="in-link-category-', $cat_id, '" class="selectit"><input value="', $cat_id, '" type="checkbox" name="link_category[]" id="in-link-category-', $cat_id, '"', $checked, '/> ', $name, '</label></li>';
* Adds hidden fields with the data for use in the inline editor for posts and pages.
* @param WP_Post $post Post object.
function get_inline_data( $post ) {
$post_type_object = get_post_type_object( $post->post_type );
if ( ! current_user_can( 'edit_post', $post->ID ) ) {
$title = esc_textarea( trim( $post->post_title ) );
<div class="hidden" id="inline_' . $post->ID . '">
<div class="post_title">' . $title . '</div>' .
/** This filter is documented in wp-admin/edit-tag-form.php */
'<div class="post_name">' . apply_filters( 'editable_slug', $post->post_name, $post ) . '</div>
<div class="post_author">' . $post->post_author . '</div>
<div class="comment_status">' . esc_html( $post->comment_status ) . '</div>
<div class="ping_status">' . esc_html( $post->ping_status ) . '</div>
<div class="_status">' . esc_html( $post->post_status ) . '</div>
<div class="jj">' . mysql2date( 'd', $post->post_date, false ) . '</div>
<div class="mm">' . mysql2date( 'm', $post->post_date, false ) . '</div>
<div class="aa">' . mysql2date( 'Y', $post->post_date, false ) . '</div>
<div class="hh">' . mysql2date( 'H', $post->post_date, false ) . '</div>
<div class="mn">' . mysql2date( 'i', $post->post_date, false ) . '</div>
<div class="ss">' . mysql2date( 's', $post->post_date, false ) . '</div>
<div class="post_password">' . esc_html( $post->post_password ) . '</div>';
if ( $post_type_object->hierarchical ) {
echo '<div class="post_parent">' . $post->post_parent . '</div>';
echo '<div class="page_template">' . ( $post->page_template ? esc_html( $post->page_template ) : 'default' ) . '</div>';
if ( post_type_supports( $post->post_type, 'page-attributes' ) ) {
echo '<div class="menu_order">' . $post->menu_order . '</div>';
$taxonomy_names = get_object_taxonomies( $post->post_type );
foreach ( $taxonomy_names as $taxonomy_name ) {
$taxonomy = get_taxonomy( $taxonomy_name );
if ( $taxonomy->hierarchical && $taxonomy->show_ui ) {
$terms = get_object_term_cache( $post->ID, $taxonomy_name );
if ( false === $terms ) {
$terms = wp_get_object_terms( $post->ID, $taxonomy_name );
wp_cache_add( $post->ID, wp_list_pluck( $terms, 'term_id' ), $taxonomy_name . '_relationships' );
$term_ids = empty( $terms ) ? array() : wp_list_pluck( $terms, 'term_id' );
echo '<div class="post_category" id="' . $taxonomy_name . '_' . $post->ID . '">' . implode( ',', $term_ids ) . '</div>';
} elseif ( $taxonomy->show_ui ) {
$terms_to_edit = get_terms_to_edit( $post->ID, $taxonomy_name );
if ( ! is_string( $terms_to_edit ) ) {
echo '<div class="tags_input" id="' . $taxonomy_name . '_' . $post->ID . '">'
. esc_html( str_replace( ',', ', ', $terms_to_edit ) ) . '</div>';
if ( ! $post_type_object->hierarchical ) {
echo '<div class="sticky">' . ( is_sticky( $post->ID ) ? 'sticky' : '' ) . '</div>';
if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
echo '<div class="post_format">' . esc_html( get_post_format( $post->ID ) ) . '</div>';
* Fires after outputting the fields for the inline editor for posts and pages.
* @param WP_Post $post The current post object.
* @param WP_Post_Type $post_type_object The current post's post type object.
do_action( 'add_inline_data', $post, $post_type_object );
* Outputs the in-line comment reply-to form in the Comments list table.
* @global WP_List_Table $wp_list_table
function wp_comment_reply( $position = 1, $checkbox = false, $mode = 'single', $table_row = true ) {
* Filters the in-line comment reply-to form output in the Comments
* Returning a non-empty value here will short-circuit display
* of the in-line comment-reply form in the Comments list table,
* echoing the returned value instead.
* @see wp_comment_reply()
* @param string $content The reply-to form content.
* @param array $args An array of default args.
$content = apply_filters(
if ( ! empty( $content ) ) {
if ( ! $wp_list_table ) {
if ( 'single' === $mode ) {
$wp_list_table = _get_list_table( 'WP_Post_Comments_List_Table' );
$wp_list_table = _get_list_table( 'WP_Comments_List_Table' );
<?php if ( $table_row ) : ?>
<table style="display:none;"><tbody id="com-reply"><tr id="replyrow" class="inline-edit-row" style="display:none;"><td colspan="<?php echo $wp_list_table->get_column_count(); ?>" class="colspanchange">
<div id="com-reply" style="display:none;"><div id="replyrow" style="display:none;">
<fieldset class="comment-reply">
<span class="hidden" id="editlegend"><?php _e( 'Edit Comment' ); ?></span>
<span class="hidden" id="replyhead"><?php _e( 'Reply to Comment' ); ?></span>
<span class="hidden" id="addhead"><?php _e( 'Add new Comment' ); ?></span>
<div id="replycontainer">
<label for="replycontent" class="screen-reader-text"><?php _e( 'Comment' ); ?></label>
$quicktags_settings = array( 'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,close' );
'media_buttons' => false,
'quicktags' => $quicktags_settings,
<div id="edithead" style="display:none;">
<label for="author-name"><?php _e( 'Name' ); ?></label>
<input type="text" name="newcomment_author" size="50" value="" id="author-name" />
<label for="author-email"><?php _e( 'Email' ); ?></label>
<input type="text" name="newcomment_author_email" size="50" value="" id="author-email" />
<label for="author-url"><?php _e( 'URL' ); ?></label>
<input type="text" id="author-url" name="newcomment_author_url" class="code" size="103" value="" />
<div id="replysubmit" class="submit">
<p class="reply-submit-buttons">
<button type="button" class="save button button-primary">
<span id="addbtn" style="display: none;"><?php _e( 'Add Comment' ); ?></span>
<span id="savebtn" style="display: none;"><?php _e( 'Update Comment' ); ?></span>
<span id="replybtn" style="display: none;"><?php _e( 'Submit Reply' ); ?></span>
<button type="button" class="cancel button"><?php _e( 'Cancel' ); ?></button>
<span class="waiting spinner"></span>