--- a/wp/wp-admin/includes/template.php Tue Oct 22 16:11:46 2019 +0200
+++ b/wp/wp-admin/includes/template.php Tue Dec 15 13:49:49 2020 +0100
@@ -9,13 +9,13 @@
*/
/** Walker_Category_Checklist class */
-require_once( ABSPATH . 'wp-admin/includes/class-walker-category-checklist.php' );
+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' );
+require_once ABSPATH . 'wp-admin/includes/class-wp-internal-pointers.php';
//
-// Category Checklists
+// Category Checklists.
//
/**
@@ -32,7 +32,7 @@
* @param int[] $selected_cats Optional. Array of category IDs to mark as checked. Default false.
* @param int[] $popular_cats Optional. Array of category IDs to receive the "popular-category" class.
* Default false.
- * @param object $walker Optional. Walker object to use to build the output.
+ * @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.
@@ -68,7 +68,7 @@
* @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.
* Default false.
- * @type object $walker Walker object to use to build the output.
+ * @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
@@ -76,6 +76,7 @@
* @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() ) {
$defaults = array(
@@ -100,37 +101,38 @@
*/
$params = apply_filters( 'wp_terms_checklist_args', $args, $post_id );
- $r = wp_parse_args( $params, $defaults );
+ $parsed_args = wp_parse_args( $params, $defaults );
- if ( empty( $r['walker'] ) || ! ( $r['walker'] instanceof Walker ) ) {
+ if ( empty( $parsed_args['walker'] ) || ! ( $parsed_args['walker'] instanceof Walker ) ) {
$walker = new Walker_Category_Checklist;
} else {
- $walker = $r['walker'];
+ $walker = $parsed_args['walker'];
}
- $taxonomy = $r['taxonomy'];
- $descendants_and_self = (int) $r['descendants_and_self'];
+ $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( $r['list_only'] );
+ $args['list_only'] = ! empty( $parsed_args['list_only'] );
- if ( is_array( $r['selected_cats'] ) ) {
- $args['selected_cats'] = $r['selected_cats'];
+ if ( is_array( $parsed_args['selected_cats'] ) ) {
+ $args['selected_cats'] = array_map( 'intval', $parsed_args['selected_cats'] );
} elseif ( $post_id ) {
$args['selected_cats'] = wp_get_object_terms( $post_id, $taxonomy, array_merge( $args, array( 'fields' => 'ids' ) ) );
} else {
$args['selected_cats'] = array();
}
- if ( is_array( $r['popular_cats'] ) ) {
- $args['popular_cats'] = $r['popular_cats'];
+
+ if ( is_array( $parsed_args['popular_cats'] ) ) {
+ $args['popular_cats'] = array_map( 'intval', $parsed_args['popular_cats'] );
} else {
$args['popular_cats'] = get_terms(
- $taxonomy,
array(
+ 'taxonomy' => $taxonomy,
'fields' => 'ids',
'orderby' => 'count',
'order' => 'DESC',
@@ -139,10 +141,11 @@
)
);
}
+
if ( $descendants_and_self ) {
$categories = (array) get_terms(
- $taxonomy,
array(
+ 'taxonomy' => $taxonomy,
'child_of' => $descendants_and_self,
'hierarchical' => 0,
'hide_empty' => 0,
@@ -151,30 +154,36 @@
$self = get_term( $descendants_and_self, $taxonomy );
array_unshift( $categories, $self );
} else {
- $categories = (array) get_terms( $taxonomy, array( 'get' => 'all' ) );
+ $categories = (array) get_terms(
+ array(
+ 'taxonomy' => $taxonomy,
+ 'get' => 'all',
+ )
+ );
}
$output = '';
- if ( $r['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)
+ 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'] ) ) {
+ if ( in_array( $categories[ $k ]->term_id, $args['selected_cats'], true ) ) {
$checked_categories[] = $categories[ $k ];
unset( $categories[ $k ] );
}
}
- // Put checked cats on top
- $output .= call_user_func_array( array( $walker, 'walk' ), array( $checked_categories, 0, $args ) );
+ // Put checked categories on top.
+ $output .= $walker->walk( $checked_categories, 0, $args );
}
- // Then the rest of them
- $output .= call_user_func_array( array( $walker, 'walk' ), array( $categories, 0, $args ) );
+ // Then the rest of them.
+ $output .= $walker->walk( $categories, 0, $args );
- if ( $r['echo'] ) {
+ if ( $parsed_args['echo'] ) {
echo $output;
}
@@ -192,10 +201,10 @@
* @since 2.5.0
*
* @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 array List of popular term IDs.
+ * @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 ) {
$post = get_post();
@@ -207,8 +216,8 @@
}
$terms = get_terms(
- $taxonomy,
array(
+ 'taxonomy' => $taxonomy,
'orderby' => 'count',
'order' => 'DESC',
'number' => $number,
@@ -219,13 +228,14 @@
$tax = get_taxonomy( $taxonomy );
$popular_ids = array();
+
foreach ( (array) $terms as $term ) {
$popular_ids[] = $term->term_id;
if ( ! $echo ) { // Hack for Ajax use.
continue;
}
$id = "popular-$taxonomy-$term->term_id";
- $checked = in_array( $term->term_id, $checked_terms ) ? 'checked="checked"' : '';
+ $checked = in_array( $term->term_id, $checked_terms, true ) ? 'checked="checked"' : '';
?>
<li id="<?php echo $id; ?>" class="popular-category">
@@ -257,7 +267,7 @@
if ( $link_id ) {
$checked_categories = wp_get_link_cats( $link_id );
- // No selected categories, strange
+ // No selected categories, strange.
if ( ! count( $checked_categories ) ) {
$checked_categories[] = $default;
}
@@ -266,8 +276,8 @@
}
$categories = get_terms(
- 'link_category',
array(
+ 'taxonomy' => 'link_category',
'orderby' => 'name',
'hide_empty' => 0,
)
@@ -282,7 +292,7 @@
/** 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 ) ? ' checked="checked"' : '';
+ $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>';
}
}
@@ -302,7 +312,6 @@
$title = esc_textarea( trim( $post->post_title ) );
- /** This filter is documented in wp-admin/edit-tag-form.php */
echo '
<div class="hidden" id="inline_' . $post->ID . '">
<div class="post_title">' . $title . '</div>' .
@@ -331,6 +340,7 @@
}
$taxonomy_names = get_object_taxonomies( $post->post_type );
+
foreach ( $taxonomy_names as $taxonomy_name ) {
$taxonomy = get_taxonomy( $taxonomy_name );
@@ -424,7 +434,7 @@
}
if ( ! $wp_list_table ) {
- if ( $mode == 'single' ) {
+ if ( 'single' === $mode ) {
$wp_list_table = _get_list_table( 'WP_Post_Comments_List_Table' );
} else {
$wp_list_table = _get_list_table( 'WP_Comments_List_Table' );
@@ -517,17 +527,29 @@
}
/**
- * Output 'undo move to trash' text for comments
+ * Output 'undo move to Trash' text for comments
*
* @since 2.9.0
*/
function wp_comment_trashnotice() {
?>
<div class="hidden" id="trash-undo-holder">
- <div class="trash-undo-inside"><?php printf( __( 'Comment by %s moved to the trash.' ), '<strong></strong>' ); ?> <span class="undo untrash"><a href="#"><?php _e( 'Undo' ); ?></a></span></div>
+ <div class="trash-undo-inside">
+ <?php
+ /* translators: %s: Comment author, filled by Ajax. */
+ printf( __( 'Comment by %s moved to the Trash.' ), '<strong></strong>' );
+ ?>
+ <span class="undo untrash"><a href="#"><?php _e( 'Undo' ); ?></a></span>
+ </div>
</div>
<div class="hidden" id="spam-undo-holder">
- <div class="spam-undo-inside"><?php printf( __( 'Comment by %s marked as spam.' ), '<strong></strong>' ); ?> <span class="undo unspam"><a href="#"><?php _e( 'Undo' ); ?></a></span></div>
+ <div class="spam-undo-inside">
+ <?php
+ /* translators: %s: Comment author, filled by Ajax. */
+ printf( __( 'Comment by %s marked as spam.' ), '<strong></strong>' );
+ ?>
+ <span class="undo unspam"><a href="#"><?php _e( 'Undo' ); ?></a></span>
+ </div>
</div>
<?php
}
@@ -540,7 +562,7 @@
* @param array $meta
*/
function list_meta( $meta ) {
- // Exit if no meta
+ // Exit if no meta.
if ( ! $meta ) {
echo '
<table id="list-table" style="display: none;">
@@ -553,7 +575,7 @@
<tbody id="the-list" data-wp-lists="list:meta">
<tr><td></td></tr>
</tbody>
-</table>'; //TBODY needed for list-manipulation JS
+</table>'; // TBODY needed for list-manipulation JS.
return;
}
$count = 0;
@@ -581,8 +603,6 @@
*
* @since 2.5.0
*
- * @staticvar string $update_nonce
- *
* @param array $entry
* @param int $count
* @return string
@@ -613,7 +633,7 @@
}
$entry['meta_key'] = esc_attr( $entry['meta_key'] );
- $entry['meta_value'] = esc_textarea( $entry['meta_value'] ); // using a <textarea />
+ $entry['meta_value'] = esc_textarea( $entry['meta_value'] ); // Using a <textarea />.
$entry['meta_id'] = (int) $entry['meta_id'];
$delete_nonce = wp_create_nonce( 'delete-meta_' . $entry['meta_id'] );
@@ -669,13 +689,19 @@
* @param int $limit Number of custom fields to retrieve. Default 30.
*/
$limit = apply_filters( 'postmeta_form_limit', 30 );
- $sql = "SELECT DISTINCT meta_key
- FROM $wpdb->postmeta
- WHERE meta_key NOT BETWEEN '_' AND '_z'
- HAVING meta_key NOT LIKE %s
- ORDER BY meta_key
- LIMIT %d";
- $keys = $wpdb->get_col( $wpdb->prepare( $sql, $wpdb->esc_like( '_' ) . '%', $limit ) );
+
+ $keys = $wpdb->get_col(
+ $wpdb->prepare(
+ "SELECT DISTINCT meta_key
+ FROM $wpdb->postmeta
+ WHERE meta_key NOT BETWEEN '_' AND '_z'
+ HAVING meta_key NOT LIKE %s
+ ORDER BY meta_key
+ LIMIT %d",
+ $wpdb->esc_like( '_' ) . '%',
+ $limit
+ )
+ );
}
if ( $keys ) {
@@ -701,7 +727,6 @@
<select id="metakeyselect" name="metakeyselect">
<option value="#NONE#"><?php _e( '— Select —' ); ?></option>
<?php
-
foreach ( $keys as $key ) {
if ( is_protected_meta( $key, 'post' ) || ! current_user_can( 'add_post_meta', $post->ID, $key ) ) {
continue;
@@ -750,7 +775,7 @@
* @since 0.71
* @since 4.4.0 Converted to use get_comment() instead of the global `$comment`.
*
- * @global WP_Locale $wp_locale
+ * @global WP_Locale $wp_locale WordPress date and time locale object.
*
* @param int|bool $edit Accepts 1|true for editing the date, 0|false for adding the date.
* @param int|bool $for_post Accepts 1|true for applying the date to a post, 0|false for a comment.
@@ -763,7 +788,7 @@
$post = get_post();
if ( $for_post ) {
- $edit = ! ( in_array( $post->post_status, array( 'draft', 'pending' ) ) && ( ! $post->post_date_gmt || '0000-00-00 00:00:00' == $post->post_date_gmt ) );
+ $edit = ! ( in_array( $post->post_status, array( 'draft', 'pending' ), true ) && ( ! $post->post_date_gmt || '0000-00-00 00:00:00' === $post->post_date_gmt ) );
}
$tab_index_attribute = '';
@@ -771,7 +796,7 @@
$tab_index_attribute = " tabindex=\"$tab_index\"";
}
- // todo: Remove this?
+ // @todo Remove this?
// echo '<label for="timestamp" style="display: block;"><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp"'.$tab_index_attribute.' /> '.__( 'Edit timestamp' ).'</label><br />';
$post_date = ( $for_post ) ? $post->post_date : get_comment()->comment_date;
@@ -793,7 +818,7 @@
$monthnum = zeroise( $i, 2 );
$monthtext = $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) );
$month .= "\t\t\t" . '<option value="' . $monthnum . '" data-text="' . $monthtext . '" ' . selected( $monthnum, $mm, false ) . '>';
- /* translators: 1: month number (01, 02, etc.), 2: month abbreviation */
+ /* translators: 1: Month number (01, 02, etc.), 2: Month abbreviation. */
$month .= sprintf( __( '%1$s-%2$s' ), $monthnum, $monthtext ) . "</option>\n";
}
$month .= '</select></label>';
@@ -804,8 +829,8 @@
$minute = '<label><span class="screen-reader-text">' . __( 'Minute' ) . '</span><input type="text" ' . ( $multi ? '' : 'id="mn" ' ) . 'name="mn" value="' . $mn . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" /></label>';
echo '<div class="timestamp-wrap">';
- /* translators: 1: month, 2: day, 3: year, 4: hour, 5: minute */
- printf( __( '%1$s %2$s, %3$s @ %4$s:%5$s' ), $month, $day, $year, $hour, $minute );
+ /* translators: 1: Month, 2: Day, 3: Year, 4: Hour, 5: Minute. */
+ printf( __( '%1$s %2$s, %3$s at %4$s:%5$s' ), $month, $day, $year, $hour, $minute );
echo '</div><input type="hidden" id="ss" name="ss" value="' . $ss . '" />';
@@ -814,6 +839,7 @@
}
echo "\n\n";
+
$map = array(
'mm' => array( $mm, $cur_mm ),
'jj' => array( $jj, $cur_jj ),
@@ -821,6 +847,7 @@
'hh' => array( $hh, $cur_hh ),
'mn' => array( $mn, $cur_mn ),
);
+
foreach ( $map as $timeunit => $value ) {
list( $unit, $curr ) = $value;
@@ -848,7 +875,9 @@
*/
function page_template_dropdown( $default = '', $post_type = 'page' ) {
$templates = get_page_templates( null, $post_type );
+
ksort( $templates );
+
foreach ( array_keys( $templates ) as $template ) {
$selected = selected( $default, $templates[ $template ], false );
echo "\n\t<option value='" . esc_attr( $templates[ $template ] ) . "' $selected>" . esc_html( $template ) . '</option>';
@@ -867,18 +896,18 @@
* @param int $parent Optional. The parent page ID. Default 0.
* @param int $level Optional. Page depth level. Default 0.
* @param int|WP_Post $post Post ID or WP_Post object.
- *
- * @return null|false Boolean False if page has no children, otherwise print out html elements.
+ * @return void|false Void on success, false if the page has no children.
*/
function parent_dropdown( $default = 0, $parent = 0, $level = 0, $post = null ) {
global $wpdb;
+
$post = get_post( $post );
$items = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' ORDER BY menu_order", $parent ) );
if ( $items ) {
foreach ( $items as $item ) {
// A page cannot be its own parent.
- if ( $post && $post->ID && $item->ID == $post->ID ) {
+ if ( $post && $post->ID && (int) $item->ID === $post->ID ) {
continue;
}
@@ -894,7 +923,7 @@
}
/**
- * Print out option html elements for role selectors.
+ * Print out option HTML elements for role selectors.
*
* @since 2.1.0
*
@@ -907,8 +936,8 @@
foreach ( $editable_roles as $role => $details ) {
$name = translate_user_role( $details['name'] );
- // preselect specified role
- if ( $selected == $role ) {
+ // Preselect specified role.
+ if ( $selected === $role ) {
$r .= "\n\t<option selected='selected' value='" . esc_attr( $role ) . "'>$name</option>";
} else {
$r .= "\n\t<option value='" . esc_attr( $role ) . "'>$name</option>";
@@ -948,7 +977,14 @@
?>
<form enctype="multipart/form-data" id="import-upload-form" method="post" class="wp-upload-form" action="<?php echo esc_url( wp_nonce_url( $action, 'import-upload' ) ); ?>">
<p>
-<label for="upload"><?php _e( 'Choose a file from your computer:' ); ?></label> (<?php printf( __( 'Maximum size: %s' ), $size ); ?>)
+ <?php
+ printf(
+ '<label for="upload">%s</label> (%s)',
+ __( 'Choose a file from your computer:' ),
+ /* translators: %s: Maximum allowed file size. */
+ sprintf( __( 'Maximum size: %s' ), $size )
+ );
+ ?>
<input type="file" id="upload" name="import" size="25" />
<input type="hidden" name="action" value="save" />
<input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" />
@@ -1025,37 +1061,41 @@
continue;
}
- // If a core box was previously added or removed by a plugin, don't add.
- if ( 'core' == $priority ) {
- // If core box previously deleted, don't add
- if ( false === $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ] ) {
- return;
- }
+ // If a core box was previously removed, don't add.
+ if ( ( 'core' === $priority || 'sorted' === $priority )
+ && false === $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ]
+ ) {
+ return;
+ }
+ // If a core box was previously added by a plugin, don't add.
+ if ( 'core' === $priority ) {
/*
- * If box was added with default priority, give it core priority to
- * maintain sort order.
+ * If the box was added with default priority, give it core priority
+ * to maintain sort order.
*/
- if ( 'default' == $a_priority ) {
+ if ( 'default' === $a_priority ) {
$wp_meta_boxes[ $page ][ $a_context ]['core'][ $id ] = $wp_meta_boxes[ $page ][ $a_context ]['default'][ $id ];
unset( $wp_meta_boxes[ $page ][ $a_context ]['default'][ $id ] );
}
return;
}
- // If no priority given and id already present, use existing priority.
+
+ // If no priority given and ID already present, use existing priority.
if ( empty( $priority ) ) {
$priority = $a_priority;
/*
- * Else, if we're adding to the sorted priority, we don't know the title
- * or callback. Grab them from the previously added context/priority.
- */
- } elseif ( 'sorted' == $priority ) {
+ * Else, if we're adding to the sorted priority, we don't know the title
+ * or callback. Grab them from the previously added context/priority.
+ */
+ } elseif ( 'sorted' === $priority ) {
$title = $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ]['title'];
$callback = $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ]['callback'];
$callback_args = $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ]['args'];
}
- // An id can be in only one priority and one context.
- if ( $priority != $a_priority || $context != $a_context ) {
+
+ // An ID can be in only one priority and one context.
+ if ( $priority !== $a_priority || $context !== $a_context ) {
unset( $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ] );
}
}
@@ -1099,7 +1139,7 @@
$plugins = get_plugins();
echo '<p>';
if ( $plugin ) {
- /* translators: %s: the name of the plugin that generated this meta box. */
+ /* translators: %s: The name of the plugin that generated this meta box. */
printf( __( "This meta box, from the %s plugin, isn't compatible with the block editor." ), "<strong>{$plugin['Name']}</strong>" );
} else {
_e( "This meta box isn't compatible with the block editor." );
@@ -1109,8 +1149,11 @@
if ( empty( $plugins['classic-editor/classic-editor.php'] ) ) {
if ( current_user_can( 'install_plugins' ) ) {
echo '<p>';
- /* translators: %s: A link to install the Classic Editor plugin. */
- printf( __( 'Please install the <a href="%s">Classic Editor plugin</a> to use this meta box.' ), esc_url( self_admin_url( 'plugin-install.php?tab=featured' ) ) );
+ printf(
+ /* translators: %s: A link to install the Classic Editor plugin. */
+ __( 'Please install the <a href="%s">Classic Editor plugin</a> to use this meta box.' ),
+ esc_url( wp_nonce_url( self_admin_url( 'plugin-install.php?tab=favorites&user=wordpressdotorg&save=0' ), 'save_wporg_username_' . get_current_user_id() ) )
+ );
echo '</p>';
}
} elseif ( is_plugin_inactive( 'classic-editor/classic-editor.php' ) ) {
@@ -1166,11 +1209,13 @@
// Only show errors if the meta box was registered by a plugin.
$filename = wp_normalize_path( $reflection->getFileName() );
$plugin_dir = wp_normalize_path( WP_PLUGIN_DIR );
+
if ( strpos( $filename, $plugin_dir ) === 0 ) {
$filename = str_replace( $plugin_dir, '', $filename );
$filename = preg_replace( '|^/([^/]*/).*$|', '\\1', $filename );
$plugins = get_plugins();
+
foreach ( $plugins as $name => $plugin ) {
if ( strpos( $name, $filename ) === 0 ) {
return $plugin;
@@ -1189,17 +1234,15 @@
*
* @global array $wp_meta_boxes
*
- * @staticvar bool $already_sorted
- *
- * @param string|WP_Screen $screen Screen identifier. If you have used add_menu_page() or
+ * @param string|WP_Screen $screen The screen identifier. If you have used add_menu_page() or
* add_submenu_page() to create a new screen (and hence screen_id)
* make sure your menu slug conforms to the limits of sanitize_key()
* otherwise the 'screen' menu may not correctly render on your page.
* @param string $context The screen context for which to display meta boxes.
- * @param mixed $object Gets passed to the first parameter of the meta box callback function.
+ * @param mixed $object Gets passed to the meta box callback function as the first parameter.
* Often this is the object that's the focus of the current screen, for
* example a `WP_Post` or `WP_Comment` object.
- * @return int number of meta_boxes
+ * @return int Number of meta_boxes.
*/
function do_meta_boxes( $screen, $context, $object ) {
global $wp_meta_boxes;
@@ -1217,8 +1260,11 @@
printf( '<div id="%s-sortables" class="meta-box-sortables">', esc_attr( $context ) );
- // Grab the ones the user has manually sorted. Pull them out of their previous context/priority and into the one the user chose
- if ( ! $already_sorted && $sorted = get_user_option( "meta-box-order_$page" ) ) {
+ // Grab the ones the user has manually sorted.
+ // Pull them out of their previous context/priority and into the one the user chose.
+ $sorted = get_user_option( "meta-box-order_$page" );
+
+ if ( ! $already_sorted && $sorted ) {
foreach ( $sorted as $box_context => $ids ) {
foreach ( explode( ',', $ids ) as $id ) {
if ( $id && 'dashboard_browser_nag' !== $id ) {
@@ -1236,7 +1282,7 @@
foreach ( array( 'high', 'sorted', 'core', 'default', 'low' ) as $priority ) {
if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) {
foreach ( (array) $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) {
- if ( false == $box || ! $box['title'] ) {
+ if ( false === $box || ! $box['title'] ) {
continue;
}
@@ -1266,9 +1312,19 @@
$i++;
// get_hidden_meta_boxes() doesn't apply in the block editor.
- $hidden_class = ( ! $screen->is_block_editor() && in_array( $box['id'], $hidden ) ) ? ' hide-if-js' : '';
+ $hidden_class = ( ! $screen->is_block_editor() && in_array( $box['id'], $hidden, true ) ) ? ' hide-if-js' : '';
echo '<div id="' . $box['id'] . '" class="postbox ' . postbox_classes( $box['id'], $page ) . $hidden_class . '" ' . '>' . "\n";
- if ( 'dashboard_browser_nag' != $box['id'] ) {
+
+ echo '<div class="postbox-header">';
+ echo '<h2 class="hndle">';
+ if ( 'dashboard_php_nag' === $box['id'] ) {
+ echo '<span aria-hidden="true" class="dashicons dashicons-warning"></span>';
+ echo '<span class="screen-reader-text">' . __( 'Warning:' ) . ' </span>';
+ }
+ echo "{$box['title']}";
+ echo "</h2>\n";
+
+ if ( 'dashboard_browser_nag' !== $box['id'] ) {
$widget_title = $box['title'];
if ( is_array( $box['args'] ) && isset( $box['args']['__widget_basename'] ) ) {
@@ -1277,18 +1333,41 @@
unset( $box['args']['__widget_basename'] );
}
+ echo '<div class="handle-actions hide-if-no-js">';
+
+ echo '<button type="button" class="handle-order-higher" aria-disabled="false" aria-describedby="' . $box['id'] . '-handle-order-higher-description">';
+ echo '<span class="screen-reader-text">' . __( 'Move up' ) . '</span>';
+ echo '<span class="order-higher-indicator" aria-hidden="true"></span>';
+ echo '</button>';
+ echo '<span class="hidden" id="' . $box['id'] . '-handle-order-higher-description">' . sprintf(
+ /* translators: %s: Meta box title. */
+ __( 'Move %s box up' ),
+ $widget_title
+ ) . '</span>';
+
+ echo '<button type="button" class="handle-order-lower" aria-disabled="false" aria-describedby="' . $box['id'] . '-handle-order-lower-description">';
+ echo '<span class="screen-reader-text">' . __( 'Move down' ) . '</span>';
+ echo '<span class="order-lower-indicator" aria-hidden="true"></span>';
+ echo '</button>';
+ echo '<span class="hidden" id="' . $box['id'] . '-handle-order-lower-description">' . sprintf(
+ /* translators: %s: Meta box title. */
+ __( 'Move %s box down' ),
+ $widget_title
+ ) . '</span>';
+
echo '<button type="button" class="handlediv" aria-expanded="true">';
- echo '<span class="screen-reader-text">' . sprintf( __( 'Toggle panel: %s' ), $widget_title ) . '</span>';
+ echo '<span class="screen-reader-text">' . sprintf(
+ /* translators: %s: Meta box title. */
+ __( 'Toggle panel: %s' ),
+ $widget_title
+ ) . '</span>';
echo '<span class="toggle-indicator" aria-hidden="true"></span>';
echo '</button>';
+
+ echo '</div>';
}
- echo '<h2 class="hndle">';
- if ( 'dashboard_php_nag' === $box['id'] ) {
- echo '<span aria-hidden="true" class="dashicons dashicons-warning"></span>';
- echo '<span class="screen-reader-text">' . __( 'Warning:' ) . ' </span>';
- }
- echo "<span>{$box['title']}</span>";
- echo "</h2>\n";
+ echo '</div>';
+
echo '<div class="inside">' . "\n";
if ( WP_DEBUG && ! $block_compatible && 'edit' === $screen->parent_base && ! $screen->is_block_editor() && ! isset( $_GET['meta-box-loader'] ) ) {
@@ -1298,7 +1377,7 @@
<div class="error inline">
<p>
<?php
- /* translators: %s: the name of the plugin that generated this meta box. */
+ /* translators: %s: The name of the plugin that generated this meta box. */
printf( __( "This meta box, from the %s plugin, isn't compatible with the block editor." ), "<strong>{$plugin['Name']}</strong>" );
?>
</p>
@@ -1385,9 +1464,9 @@
* @uses global $wp_meta_boxes Used to retrieve registered meta boxes.
*
* @param string|object $screen The screen identifier.
- * @param string $context The meta box context.
- * @param mixed $object gets passed to the section callback function as first parameter.
- * @return int number of meta boxes as accordion sections.
+ * @param string $context The screen context for which to display accordion sections.
+ * @param mixed $object Gets passed to the section callback function as the first parameter.
+ * @return int Number of meta boxes as accordion sections.
*/
function do_accordion_sections( $screen, $context, $object ) {
global $wp_meta_boxes;
@@ -1414,11 +1493,12 @@
foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) {
if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) {
foreach ( $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) {
- if ( false == $box || ! $box['title'] ) {
+ if ( false === $box || ! $box['title'] ) {
continue;
}
+
$i++;
- $hidden_class = in_array( $box['id'], $hidden ) ? 'hide-if-js' : '';
+ $hidden_class = in_array( $box['id'], $hidden, true ) ? 'hide-if-js' : '';
$open_class = '';
if ( ! $first_open && empty( $hidden_class ) ) {
@@ -1462,7 +1542,7 @@
*
* @since 2.7.0
*
- * @global $wp_settings_sections Storage array of all settings sections added to admin pages.
+ * @global array $wp_settings_sections Storage array of all settings sections added to admin pages.
*
* @param string $id Slug-name to identify the section. Used in the 'id' attribute of tags.
* @param string $title Formatted title of the section. Shown as the heading for the section.
@@ -1474,12 +1554,12 @@
function add_settings_section( $id, $title, $callback, $page ) {
global $wp_settings_sections;
- if ( 'misc' == $page ) {
+ if ( 'misc' === $page ) {
_deprecated_argument(
__FUNCTION__,
'3.0.0',
- /* translators: %s: misc */
sprintf(
+ /* translators: %s: misc */
__( 'The "%s" options group has been removed. Use another settings group.' ),
'misc'
)
@@ -1487,12 +1567,12 @@
$page = 'general';
}
- if ( 'privacy' == $page ) {
+ if ( 'privacy' === $page ) {
_deprecated_argument(
__FUNCTION__,
'3.5.0',
- /* translators: %s: privacy */
sprintf(
+ /* translators: %s: privacy */
__( 'The "%s" options group has been removed. Use another settings group.' ),
'privacy'
)
@@ -1515,13 +1595,13 @@
* do_settings_fields() in do_settings-sections()
*
* The $callback argument should be the name of a function that echoes out the
- * html input tags for this setting field. Use get_option() to retrieve existing
+ * HTML input tags for this setting field. Use get_option() to retrieve existing
* values to show.
*
* @since 2.7.0
* @since 4.2.0 The `$class` argument was added.
*
- * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections.
+ * @global array $wp_settings_fields Storage array of settings fields and info about their pages/sections.
*
* @param string $id Slug-name to identify the field. Used in the 'id' attribute of tags.
* @param string $title Formatted title of the field. Shown as the label for the field
@@ -1545,12 +1625,12 @@
function add_settings_field( $id, $title, $callback, $page, $section = 'default', $args = array() ) {
global $wp_settings_fields;
- if ( 'misc' == $page ) {
+ if ( 'misc' === $page ) {
_deprecated_argument(
__FUNCTION__,
'3.0.0',
- /* translators: %s: misc */
sprintf(
+ /* translators: %s: misc */
__( 'The "%s" options group has been removed. Use another settings group.' ),
'misc'
)
@@ -1558,12 +1638,12 @@
$page = 'general';
}
- if ( 'privacy' == $page ) {
+ if ( 'privacy' === $page ) {
_deprecated_argument(
__FUNCTION__,
'3.5.0',
- /* translators: %s: privacy */
sprintf(
+ /* translators: %s: privacy */
__( 'The "%s" options group has been removed. Use another settings group.' ),
'privacy'
)
@@ -1586,8 +1666,8 @@
* to output all the sections and fields that were added to that $page with
* add_settings_section() and add_settings_field()
*
- * @global $wp_settings_sections Storage array of all settings sections added to admin pages.
- * @global $wp_settings_fields Storage array of settings fields and info about their pages/sections.
+ * @global array $wp_settings_sections Storage array of all settings sections added to admin pages.
+ * @global array $wp_settings_fields Storage array of settings fields and info about their pages/sections.
* @since 2.7.0
*
* @param string $page The slug name of the page whose settings sections you want to output.
@@ -1624,7 +1704,7 @@
* a specific section. Should normally be called by do_settings_sections()
* rather than directly.
*
- * @global $wp_settings_fields Storage array of settings fields and their pages/sections.
+ * @global array $wp_settings_fields Storage array of settings fields and their pages/sections.
*
* @since 2.7.0
*
@@ -1674,6 +1754,7 @@
* page is first accessed.
*
* @since 3.0.0
+ * @since 5.3.0 Added `warning` and `info` as possible values for `$type`.
*
* @global array $wp_settings_errors Storage array of errors registered during this pageload
*
@@ -1681,8 +1762,8 @@
* @param string $code Slug-name to identify the error. Used as part of 'id' attribute in HTML output.
* @param string $message The formatted message text to display to the user (will be shown inside styled
* `<div>` and `<p>` tags).
- * @param string $type Optional. Message type, controls HTML class. Accepts 'error' or 'updated'.
- * Default 'error'.
+ * @param string $type Optional. Message type, controls HTML class. Possible values include 'error',
+ * 'success', 'warning', 'info'. Default 'error'.
*/
function add_settings_error( $setting, $code, $message, $type = 'error' ) {
global $wp_settings_errors;
@@ -1714,8 +1795,8 @@
*
* @global array $wp_settings_errors Storage array of errors registered during this pageload
*
- * @param string $setting Optional slug title of a specific setting whose errors you want.
- * @param boolean $sanitize Whether to re-sanitize the setting value before returning errors.
+ * @param string $setting Optional. Slug title of a specific setting whose errors you want.
+ * @param bool $sanitize Optional. Whether to re-sanitize the setting value before returning errors.
* @return array Array of settings errors.
*/
function get_settings_errors( $setting = '', $sanitize = false ) {
@@ -1744,11 +1825,13 @@
// Filter the results to those of a specific setting if one was set.
if ( $setting ) {
$setting_errors = array();
+
foreach ( (array) $wp_settings_errors as $key => $details ) {
- if ( $setting == $details['setting'] ) {
+ if ( $setting === $details['setting'] ) {
$setting_errors[] = $wp_settings_errors[ $key ];
}
}
+
return $setting_errors;
}
@@ -1776,6 +1859,8 @@
* missing settings when the user arrives at the settings page.
*
* @since 3.0.0
+ * @since 5.3.0 Legacy `error` and `updated` CSS classes are mapped to
+ * `notice-error` and `notice-success`.
*
* @param string $setting Optional slug title of a specific setting whose errors you want.
* @param bool $sanitize Whether to re-sanitize the setting value before returning errors.
@@ -1795,13 +1880,30 @@
}
$output = '';
+
foreach ( $settings_errors as $key => $details ) {
- $css_id = 'setting-error-' . $details['code'];
- $css_class = $details['type'] . ' settings-error notice is-dismissible';
- $output .= "<div id='$css_id' class='$css_class'> \n";
- $output .= "<p><strong>{$details['message']}</strong></p>";
- $output .= "</div> \n";
+ if ( 'updated' === $details['type'] ) {
+ $details['type'] = 'success';
+ }
+
+ if ( in_array( $details['type'], array( 'error', 'success', 'warning', 'info' ), true ) ) {
+ $details['type'] = 'notice-' . $details['type'];
+ }
+
+ $css_id = sprintf(
+ 'setting-error-%s',
+ esc_attr( $details['code'] )
+ );
+ $css_class = sprintf(
+ 'notice %s settings-error is-dismissible',
+ esc_attr( $details['type'] )
+ );
+
+ $output .= "<div id='$css_id' class='$css_class'> \n";
+ $output .= "<p><strong>{$details['message']}</strong></p>";
+ $output .= "</div> \n";
}
+
echo $output;
}
@@ -1845,7 +1947,7 @@
/**
* Displays the post password.
*
- * The password is passed through esc_attr() to ensure that it is safe for placing in an html attribute.
+ * The password is passed through esc_attr() to ensure that it is safe for placing in an HTML attribute.
*
* @since 2.7.0
*/
@@ -1894,7 +1996,7 @@
*
* @global string $hook_suffix
* @global string $admin_body_class
- * @global WP_Locale $wp_locale
+ * @global WP_Locale $wp_locale WordPress date and time locale object.
*
* @param string $title Optional. Title of the Iframe page. Default empty.
* @param bool $deprecated Not used.
@@ -1906,7 +2008,7 @@
$current_screen = get_current_screen();
- @header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) );
+ header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) );
_wp_admin_html_begin();
?>
<title><?php bloginfo( 'name' ); ?> › <?php echo $title; ?> — <?php _e( 'WordPress' ); ?></title>
@@ -1929,19 +2031,19 @@
do_action( 'admin_enqueue_scripts', $hook_suffix );
/** This action is documented in wp-admin/admin-header.php */
- do_action( "admin_print_styles-$hook_suffix" );
+ do_action( "admin_print_styles-{$hook_suffix}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
/** This action is documented in wp-admin/admin-header.php */
do_action( 'admin_print_styles' );
/** This action is documented in wp-admin/admin-header.php */
- do_action( "admin_print_scripts-$hook_suffix" );
+ do_action( "admin_print_scripts-{$hook_suffix}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
/** This action is documented in wp-admin/admin-header.php */
do_action( 'admin_print_scripts' );
/** This action is documented in wp-admin/admin-header.php */
- do_action( "admin_head-$hook_suffix" );
+ do_action( "admin_head-{$hook_suffix}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
/** This action is documented in wp-admin/admin-header.php */
do_action( 'admin_head' );
@@ -1955,20 +2057,16 @@
?>
</head>
<?php
+ /**
+ * @global string $body_id
+ */
+ $admin_body_id = isset( $GLOBALS['body_id'] ) ? 'id="' . $GLOBALS['body_id'] . '" ' : '';
+
/** This filter is documented in wp-admin/admin-header.php */
$admin_body_classes = apply_filters( 'admin_body_class', '' );
$admin_body_classes = ltrim( $admin_body_classes . ' ' . $admin_body_class );
?>
-<body
- <?php
- /**
- * @global string $body_id
- */
- if ( isset( $GLOBALS['body_id'] ) ) {
- echo ' id="' . $GLOBALS['body_id'] . '"';
- }
- ?>
- class="wp-admin wp-core-ui no-js iframe <?php echo $admin_body_classes; ?>">
+<body <?php echo $admin_body_id; ?>class="wp-admin wp-core-ui no-js iframe <?php echo $admin_body_classes; ?>">
<script type="text/javascript">
(function(){
var c = document.body.className;
@@ -2002,7 +2100,7 @@
do_action( 'admin_footer', $hook_suffix );
/** This action is documented in wp-admin/admin-footer.php */
- do_action( "admin_print_footer_scripts-$hook_suffix" );
+ do_action( "admin_print_footer_scripts-{$hook_suffix}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
/** This action is documented in wp-admin/admin-footer.php */
do_action( 'admin_print_footer_scripts' );
@@ -2015,10 +2113,52 @@
}
/**
- * @param WP_Post $post
+ * Function to echo or return the post states as HTML.
+ *
+ * @since 2.7.0
+ * @since 5.3.0 Added the `$echo` parameter and a return value.
+ *
+ * @see get_post_states()
+ *
+ * @param WP_Post $post The post to retrieve states for.
+ * @param bool $echo Optional. Whether to echo the post states as an HTML string. Default true.
+ * @return string Post states string.
*/
-function _post_states( $post ) {
+function _post_states( $post, $echo = true ) {
+ $post_states = get_post_states( $post );
+ $post_states_string = '';
+
+ if ( ! empty( $post_states ) ) {
+ $state_count = count( $post_states );
+ $i = 0;
+
+ $post_states_string .= ' — ';
+
+ foreach ( $post_states as $state ) {
+ $sep = ( ++$i === $state_count ) ? '' : ', ';
+
+ $post_states_string .= "<span class='post-state'>$state$sep</span>";
+ }
+ }
+
+ if ( $echo ) {
+ echo $post_states_string;
+ }
+
+ return $post_states_string;
+}
+
+/**
+ * Retrieves an array of post states from a post.
+ *
+ * @since 5.3.0
+ *
+ * @param WP_Post $post The post to retrieve states for.
+ * @return string[] Array of post state labels keyed by their state.
+ */
+function get_post_states( $post ) {
$post_states = array();
+
if ( isset( $_REQUEST['post_status'] ) ) {
$post_status = $_REQUEST['post_status'];
} else {
@@ -2026,43 +2166,47 @@
}
if ( ! empty( $post->post_password ) ) {
- $post_states['protected'] = __( 'Password protected' );
+ $post_states['protected'] = _x( 'Password protected', 'post status' );
}
- if ( 'private' == $post->post_status && 'private' != $post_status ) {
- $post_states['private'] = __( 'Private' );
+
+ if ( 'private' === $post->post_status && 'private' !== $post_status ) {
+ $post_states['private'] = _x( 'Private', 'post status' );
}
+
if ( 'draft' === $post->post_status ) {
if ( get_post_meta( $post->ID, '_customize_changeset_uuid', true ) ) {
$post_states[] = __( 'Customization Draft' );
} elseif ( 'draft' !== $post_status ) {
- $post_states['draft'] = __( 'Draft' );
+ $post_states['draft'] = _x( 'Draft', 'post status' );
}
} elseif ( 'trash' === $post->post_status && get_post_meta( $post->ID, '_customize_changeset_uuid', true ) ) {
- $post_states[] = __( 'Customization Draft' );
+ $post_states[] = _x( 'Customization Draft', 'post status' );
}
- if ( 'pending' == $post->post_status && 'pending' != $post_status ) {
+
+ if ( 'pending' === $post->post_status && 'pending' !== $post_status ) {
$post_states['pending'] = _x( 'Pending', 'post status' );
}
+
if ( is_sticky( $post->ID ) ) {
- $post_states['sticky'] = __( 'Sticky' );
+ $post_states['sticky'] = _x( 'Sticky', 'post status' );
}
if ( 'future' === $post->post_status ) {
- $post_states['scheduled'] = __( 'Scheduled' );
+ $post_states['scheduled'] = _x( 'Scheduled', 'post status' );
}
if ( 'page' === get_option( 'show_on_front' ) ) {
if ( intval( get_option( 'page_on_front' ) ) === $post->ID ) {
- $post_states['page_on_front'] = __( 'Front Page' );
+ $post_states['page_on_front'] = _x( 'Front Page', 'page label' );
}
if ( intval( get_option( 'page_for_posts' ) ) === $post->ID ) {
- $post_states['page_for_posts'] = __( 'Posts Page' );
+ $post_states['page_for_posts'] = _x( 'Posts Page', 'page label' );
}
}
if ( intval( get_option( 'wp_page_for_privacy_policy' ) ) === $post->ID ) {
- $post_states['page_for_privacy_policy'] = __( 'Privacy Policy Page' );
+ $post_states['page_for_privacy_policy'] = _x( 'Privacy Policy Page', 'page label' );
}
/**
@@ -2070,29 +2214,26 @@
*
* @since 2.8.0
* @since 3.6.0 Added the `$post` parameter.
+ * @since 5.5.0 Also applied in the Customizer context. If any admin functions
+ * are used within the filter, their existence should be checked
+ * with `function_exists()` before being used.
*
* @param string[] $post_states An array of post display states.
* @param WP_Post $post The current post object.
*/
- $post_states = apply_filters( 'display_post_states', $post_states, $post );
-
- if ( ! empty( $post_states ) ) {
- $state_count = count( $post_states );
- $i = 0;
- echo ' — ';
- foreach ( $post_states as $state ) {
- ++$i;
- ( $i == $state_count ) ? $sep = '' : $sep = ', ';
- echo "<span class='post-state'>$state$sep</span>";
- }
- }
-
+ return apply_filters( 'display_post_states', $post_states, $post );
}
/**
- * @param WP_Post $post
+ * Outputs the attachment media states as HTML.
+ *
+ * @since 3.2.0
+ *
+ * @param WP_Post $post The attachment post to retrieve states for.
*/
function _media_states( $post ) {
+ static $header_images;
+
$media_states = array();
$stylesheet = get_option( 'stylesheet' );
@@ -2100,21 +2241,23 @@
$meta_header = get_post_meta( $post->ID, '_wp_attachment_is_custom_header', true );
if ( is_random_header_image() ) {
- $header_images = wp_list_pluck( get_uploaded_header_images(), 'attachment_id' );
+ if ( ! isset( $header_images ) ) {
+ $header_images = wp_list_pluck( get_uploaded_header_images(), 'attachment_id' );
+ }
- if ( $meta_header == $stylesheet && in_array( $post->ID, $header_images ) ) {
+ if ( $meta_header === $stylesheet && in_array( $post->ID, $header_images, true ) ) {
$media_states[] = __( 'Header Image' );
}
} else {
$header_image = get_header_image();
- // Display "Header Image" if the image was ever used as a header image
- if ( ! empty( $meta_header ) && $meta_header == $stylesheet && $header_image !== wp_get_attachment_url( $post->ID ) ) {
+ // Display "Header Image" if the image was ever used as a header image.
+ if ( ! empty( $meta_header ) && $meta_header === $stylesheet && wp_get_attachment_url( $post->ID ) !== $header_image ) {
$media_states[] = __( 'Header Image' );
}
- // Display "Current Header Image" if the image is currently the header image
- if ( $header_image && $header_image == wp_get_attachment_url( $post->ID ) ) {
+ // Display "Current Header Image" if the image is currently the header image.
+ if ( $header_image && wp_get_attachment_url( $post->ID ) === $header_image ) {
$media_states[] = __( 'Current Header Image' );
}
}
@@ -2123,21 +2266,21 @@
if ( current_theme_supports( 'custom-background' ) ) {
$meta_background = get_post_meta( $post->ID, '_wp_attachment_is_custom_background', true );
- if ( ! empty( $meta_background ) && $meta_background == $stylesheet ) {
+ if ( ! empty( $meta_background ) && $meta_background === $stylesheet ) {
$media_states[] = __( 'Background Image' );
$background_image = get_background_image();
- if ( $background_image && $background_image == wp_get_attachment_url( $post->ID ) ) {
+ if ( $background_image && wp_get_attachment_url( $post->ID ) === $background_image ) {
$media_states[] = __( 'Current Background Image' );
}
}
}
- if ( $post->ID == get_option( 'site_icon' ) ) {
+ if ( (int) get_option( 'site_icon' ) === $post->ID ) {
$media_states[] = __( 'Site Icon' );
}
- if ( $post->ID == get_theme_mod( 'custom_logo' ) ) {
+ if ( (int) get_theme_mod( 'custom_logo' ) === $post->ID ) {
$media_states[] = __( 'Logo' );
}
@@ -2156,10 +2299,12 @@
if ( ! empty( $media_states ) ) {
$state_count = count( $media_states );
$i = 0;
+
echo ' — ';
+
foreach ( $media_states as $state ) {
- ++$i;
- ( $i == $state_count ) ? $sep = '' : $sep = ', ';
+ $sep = ( ++$i === $state_count ) ? '' : ', ';
+
echo "<span class='post-state'>$state$sep</span>";
}
}
@@ -2217,7 +2362,7 @@
}
if ( 2 == test ) {
- if ( '"wpCompressionTest' == r )
+ if ( '"wpCompressionTest' === r )
this.get('yes');
else
this.get('no');
@@ -2283,18 +2428,21 @@
$button_shorthand = array( 'primary', 'small', 'large' );
$classes = array( 'button' );
+
foreach ( $type as $t ) {
if ( 'secondary' === $t || 'button-secondary' === $t ) {
continue;
}
- $classes[] = in_array( $t, $button_shorthand ) ? 'button-' . $t : $t;
+
+ $classes[] = in_array( $t, $button_shorthand, true ) ? 'button-' . $t : $t;
}
+
// Remove empty items, remove duplicate items, and finally build a string.
$class = implode( ' ', array_unique( array_filter( $classes ) ) );
$text = $text ? $text : __( 'Save Changes' );
- // Default the id attribute to $name unless an id was specifically provided in $other_attributes
+ // Default the id attribute to $name unless an id was specifically provided in $other_attributes.
$id = $name;
if ( is_array( $other_attributes ) && isset( $other_attributes['id'] ) ) {
$id = $other_attributes['id'];
@@ -2304,9 +2452,9 @@
$attributes = '';
if ( is_array( $other_attributes ) ) {
foreach ( $other_attributes as $attribute => $value ) {
- $attributes .= $attribute . '="' . esc_attr( $value ) . '" '; // Trailing space is important
+ $attributes .= $attribute . '="' . esc_attr( $value ) . '" '; // Trailing space is important.
}
- } elseif ( ! empty( $other_attributes ) ) { // Attributes provided as a string
+ } elseif ( ! empty( $other_attributes ) ) { // Attributes provided as a string.
$attributes = $other_attributes;
}
@@ -2333,13 +2481,12 @@
$admin_html_class = ( is_admin_bar_showing() ) ? 'wp-toolbar' : '';
if ( $is_IE ) {
- @header( 'X-UA-Compatible: IE=edge' );
+ header( 'X-UA-Compatible: IE=edge' );
}
?>
<!DOCTYPE html>
-<!--[if IE 8]>
-<html xmlns="http://www.w3.org/1999/xhtml" class="ie8 <?php echo $admin_html_class; ?>"
+<html class="<?php echo $admin_html_class; ?>"
<?php
/**
* Fires inside the HTML tag in the admin header.
@@ -2350,18 +2497,7 @@
language_attributes();
?>
- >
-<![endif]-->
-<!--[if !(IE 8) ]><!-->
-<html xmlns="http://www.w3.org/1999/xhtml" class="<?php echo $admin_html_class; ?>"
- <?php
- /** This action is documented in wp-admin/includes/template.php */
- do_action( 'admin_xml_ns' );
-
- language_attributes();
- ?>
- >
-<!--<![endif]-->
+>
<head>
<meta http-equiv="Content-Type" content="<?php bloginfo( 'html_type' ); ?>; charset=<?php echo get_option( 'blog_charset' ); ?>" />
<?php
@@ -2441,33 +2577,33 @@
* @return string Star rating HTML.
*/
function wp_star_rating( $args = array() ) {
- $defaults = array(
+ $defaults = array(
'rating' => 0,
'type' => 'rating',
'number' => 0,
'echo' => true,
);
- $r = wp_parse_args( $args, $defaults );
+ $parsed_args = wp_parse_args( $args, $defaults );
- // Non-English decimal places when the $rating is coming from a string
- $rating = (float) str_replace( ',', '.', $r['rating'] );
+ // Non-English decimal places when the $rating is coming from a string.
+ $rating = (float) str_replace( ',', '.', $parsed_args['rating'] );
- // Convert Percentage to star rating, 0..5 in .5 increments
- if ( 'percent' === $r['type'] ) {
+ // Convert percentage to star rating, 0..5 in .5 increments.
+ if ( 'percent' === $parsed_args['type'] ) {
$rating = round( $rating / 10, 0 ) / 2;
}
- // Calculate the number of each type of star needed
+ // Calculate the number of each type of star needed.
$full_stars = floor( $rating );
$half_stars = ceil( $rating - $full_stars );
$empty_stars = 5 - $full_stars - $half_stars;
- if ( $r['number'] ) {
- /* translators: 1: the rating, 2: the number of ratings */
- $format = _n( '%1$s rating based on %2$s rating', '%1$s rating based on %2$s ratings', $r['number'] );
- $title = sprintf( $format, number_format_i18n( $rating, 1 ), number_format_i18n( $r['number'] ) );
+ if ( $parsed_args['number'] ) {
+ /* translators: 1: The rating, 2: The number of ratings. */
+ $format = _n( '%1$s rating based on %2$s rating', '%1$s rating based on %2$s ratings', $parsed_args['number'] );
+ $title = sprintf( $format, number_format_i18n( $rating, 1 ), number_format_i18n( $parsed_args['number'] ) );
} else {
- /* translators: %s: the rating */
+ /* translators: %s: The rating. */
$title = sprintf( __( '%s rating' ), number_format_i18n( $rating, 1 ) );
}
@@ -2478,7 +2614,7 @@
$output .= str_repeat( '<div class="star star-empty" aria-hidden="true"></div>', $empty_stars );
$output .= '</div>';
- if ( $r['echo'] ) {
+ if ( $parsed_args['echo'] ) {
echo $output;
}