wp/wp-admin/includes/template.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
--- a/wp/wp-admin/includes/template.php	Wed Sep 21 18:19:35 2022 +0200
+++ b/wp/wp-admin/includes/template.php	Tue Sep 27 16:37:53 2022 +0200
@@ -19,7 +19,7 @@
 //
 
 /**
- * Output an unordered list of checkbox input elements labeled with category names.
+ * Outputs an unordered list of checkbox input elements labeled with category names.
  *
  * @since 2.5.1
  *
@@ -52,7 +52,7 @@
 }
 
 /**
- * Output an unordered list of checkbox input elements labelled with term names.
+ * Outputs an unordered list of checkbox input elements labelled with term names.
  *
  * Taxonomy-independent version of wp_category_checklist().
  *
@@ -68,8 +68,8 @@
  *     @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 Walker $walker               Walker object to use to build the output.
- *                                        Default is a Walker_Category_Checklist instance.
+ *     @type Walker $walker               Walker object to use to build the output. Default empty which
+ *                                        results in a Walker_Category_Checklist instance being used.
  *     @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.
@@ -96,8 +96,8 @@
 	 *
 	 * @see wp_terms_checklist()
 	 *
-	 * @param array $args    An array of arguments.
-	 * @param int   $post_id The post ID.
+	 * @param array|string $args    An array or string of arguments.
+	 * @param int          $post_id The post ID.
 	 */
 	$params = apply_filters( 'wp_terms_checklist_args', $args, $post_id );
 
@@ -191,22 +191,22 @@
 }
 
 /**
- * Retrieve a list of the most popular terms from the specified taxonomy.
+ * Retrieves 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
+ * If the `$display` 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
+ * If the `$post_ID` global is not empty then the terms associated with that
  * post will be marked as checked.
  *
  * @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.
+ * @param string $taxonomy     Taxonomy to retrieve terms from.
+ * @param int    $default_term Optional. Not used.
+ * @param int    $number       Optional. Number of terms to retrieve. Default 10.
+ * @param bool   $display      Optional. Whether to display the list as well. Default true.
  * @return int[] Array of popular term IDs.
  */
-function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $echo = true ) {
+function wp_popular_terms_checklist( $taxonomy, $default_term = 0, $number = 10, $display = true ) {
 	$post = get_post();
 
 	if ( $post && $post->ID ) {
@@ -231,9 +231,11 @@
 
 	foreach ( (array) $terms as $term ) {
 		$popular_ids[] = $term->term_id;
-		if ( ! $echo ) { // Hack for Ajax use.
+
+		if ( ! $display ) { // Hack for Ajax use.
 			continue;
 		}
+
 		$id      = "popular-$taxonomy-$term->term_id";
 		$checked = in_array( $term->term_id, $checked_terms, true ) ? 'checked="checked"' : '';
 		?>
@@ -344,7 +346,11 @@
 	foreach ( $taxonomy_names as $taxonomy_name ) {
 		$taxonomy = get_taxonomy( $taxonomy_name );
 
-		if ( $taxonomy->hierarchical && $taxonomy->show_ui ) {
+		if ( ! $taxonomy->show_in_quick_edit ) {
+			continue;
+		}
+
+		if ( $taxonomy->hierarchical ) {
 
 			$terms = get_object_term_cache( $post->ID, $taxonomy_name );
 			if ( false === $terms ) {
@@ -355,7 +361,7 @@
 
 			echo '<div class="post_category" id="' . $taxonomy_name . '_' . $post->ID . '">' . implode( ',', $term_ids ) . '</div>';
 
-		} elseif ( $taxonomy->show_ui ) {
+		} else {
 
 			$terms_to_edit = get_terms_to_edit( $post->ID, $taxonomy_name );
 			if ( ! is_string( $terms_to_edit ) ) {
@@ -527,7 +533,7 @@
 }
 
 /**
- * Output 'undo move to Trash' text for comments
+ * Outputs 'undo move to Trash' text for comments.
  *
  * @since 2.9.0
  */
@@ -770,7 +776,7 @@
 }
 
 /**
- * Print out HTML form date elements for editing post or comment publish date.
+ * Prints out HTML form date elements for editing post or comment publish date.
  *
  * @since 0.71
  * @since 4.4.0 Converted to use get_comment() instead of the global `$comment`.
@@ -865,40 +871,40 @@
 }
 
 /**
- * Print out option HTML elements for the page templates drop-down.
+ * Prints out option HTML elements for the page templates drop-down.
  *
  * @since 1.5.0
  * @since 4.7.0 Added the `$post_type` parameter.
  *
- * @param string $default   Optional. The template file name. Default empty.
- * @param string $post_type Optional. Post type to get templates for. Default 'post'.
+ * @param string $default_template Optional. The template file name. Default empty.
+ * @param string $post_type        Optional. Post type to get templates for. Default 'post'.
  */
-function page_template_dropdown( $default = '', $post_type = 'page' ) {
+function page_template_dropdown( $default_template = '', $post_type = 'page' ) {
 	$templates = get_page_templates( null, $post_type );
 
 	ksort( $templates );
 
 	foreach ( array_keys( $templates ) as $template ) {
-		$selected = selected( $default, $templates[ $template ], false );
+		$selected = selected( $default_template, $templates[ $template ], false );
 		echo "\n\t<option value='" . esc_attr( $templates[ $template ] ) . "' $selected>" . esc_html( $template ) . '</option>';
 	}
 }
 
 /**
- * Print out option HTML elements for the page parents drop-down.
+ * Prints out option HTML elements for the page parents drop-down.
  *
  * @since 1.5.0
  * @since 4.4.0 `$post` argument was added.
  *
  * @global wpdb $wpdb WordPress database abstraction object.
  *
- * @param int         $default Optional. The default page ID to be pre-selected. Default 0.
- * @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.
+ * @param int         $default_page Optional. The default page ID to be pre-selected. Default 0.
+ * @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 void|false Void on success, false if the page has no children.
  */
-function parent_dropdown( $default = 0, $parent = 0, $level = 0, $post = null ) {
+function parent_dropdown( $default_page = 0, $parent = 0, $level = 0, $post = null ) {
 	global $wpdb;
 
 	$post  = get_post( $post );
@@ -912,10 +918,10 @@
 			}
 
 			$pad      = str_repeat( '&nbsp;', $level * 3 );
-			$selected = selected( $default, $item->ID, false );
+			$selected = selected( $default_page, $item->ID, false );
 
 			echo "\n\t<option class='level-$level' value='$item->ID' $selected>$pad " . esc_html( $item->post_title ) . '</option>';
-			parent_dropdown( $default, $item->ID, $level + 1 );
+			parent_dropdown( $default_page, $item->ID, $level + 1 );
 		}
 	} else {
 		return false;
@@ -923,7 +929,7 @@
 }
 
 /**
- * Print out option HTML elements for role selectors.
+ * Prints out option HTML elements for role selectors.
  *
  * @since 2.1.0
  *
@@ -1119,13 +1125,13 @@
 
 
 /**
- * Function that renders a "fake" meta box with an information message,
+ * Renders a "fake" meta box with an information message,
  * shown on the block editor, when an incompatible meta box is found.
  *
  * @since 5.0.0
  *
- * @param mixed $object The data object being rendered on this screen.
- * @param array $box    {
+ * @param mixed $data_object The data object being rendered on this screen.
+ * @param array $box         {
  *     Custom formats meta box arguments.
  *
  *     @type string   $id           Meta box 'id' attribute.
@@ -1134,15 +1140,15 @@
  *     @type array    $args         Extra meta box arguments.
  * }
  */
-function do_block_editor_incompatible_meta_box( $object, $box ) {
+function do_block_editor_incompatible_meta_box( $data_object, $box ) {
 	$plugin  = _get_plugin_from_callback( $box['old_callback'] );
 	$plugins = get_plugins();
 	echo '<p>';
 	if ( $plugin ) {
 		/* 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>" );
+		printf( __( 'This meta box, from the %s plugin, is not compatible with the block editor.' ), "<strong>{$plugin['Name']}</strong>" );
 	} else {
-		_e( "This meta box isn't compatible with the block editor." );
+		_e( 'This meta box is not compatible with the block editor.' );
 	}
 	echo '</p>';
 
@@ -1170,13 +1176,13 @@
 			printf( __( 'Please activate the <a href="%s">Classic Editor plugin</a> to use this meta box.' ), esc_url( $activate_url ) );
 			echo '</p>';
 		}
-	} elseif ( $object instanceof WP_Post ) {
+	} elseif ( $data_object instanceof WP_Post ) {
 		$edit_url = add_query_arg(
 			array(
 				'classic-editor'         => '',
 				'classic-editor__forget' => '',
 			),
-			get_edit_post_link( $object )
+			get_edit_post_link( $data_object )
 		);
 		echo '<p>';
 		/* translators: %s: A link to use the Classic Editor plugin. */
@@ -1240,17 +1246,17 @@
  *
  * @global array $wp_meta_boxes
  *
- * @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 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.
+ * @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            $data_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.
  */
-function do_meta_boxes( $screen, $context, $object ) {
+function do_meta_boxes( $screen, $context, $data_object ) {
 	global $wp_meta_boxes;
 	static $already_sorted = false;
 
@@ -1384,7 +1390,7 @@
 								<p>
 									<?php
 										/* 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>" );
+										printf( __( 'This meta box, from the %s plugin, is not compatible with the block editor.' ), "<strong>{$plugin['Name']}</strong>" );
 									?>
 								</p>
 							</div>
@@ -1392,7 +1398,7 @@
 						}
 					}
 
-					call_user_func( $box['callback'], $object, $box );
+					call_user_func( $box['callback'], $data_object, $box );
 					echo "</div>\n";
 					echo "</div>\n";
 				}
@@ -1469,12 +1475,12 @@
  *
  * @uses global $wp_meta_boxes Used to retrieve registered meta boxes.
  *
- * @param string|object $screen  The screen identifier.
- * @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.
+ * @param string|object $screen      The screen identifier.
+ * @param string        $context     The screen context for which to display accordion sections.
+ * @param mixed         $data_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 ) {
+function do_accordion_sections( $screen, $context, $data_object ) {
 	global $wp_meta_boxes;
 
 	wp_enqueue_script( 'accordion' );
@@ -1519,7 +1525,7 @@
 						</h3>
 						<div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>">
 							<div class="inside">
-								<?php call_user_func( $box['callback'], $object, $box ); ?>
+								<?php call_user_func( $box['callback'], $data_object, $box ); ?>
 							</div><!-- .inside -->
 						</div><!-- .accordion-section-content -->
 					</li><!-- .accordion-section -->
@@ -1536,7 +1542,7 @@
 }
 
 /**
- * Add a new section to a settings page.
+ * Adds a new section to a settings page.
  *
  * Part of the Settings API. Use this to define new settings sections for an admin page.
  * Show settings sections in your admin page callback function with do_settings_sections().
@@ -1594,7 +1600,7 @@
 }
 
 /**
- * Add a new field to a section of a settings page.
+ * Adds a new field to a section of a settings page.
  *
  * Part of the Settings API. Use this to define a settings field that will show
  * as part of a settings section inside a settings page. The fields are shown using
@@ -1704,7 +1710,7 @@
 }
 
 /**
- * Print out the settings fields for a particular settings section.
+ * Prints out the settings fields for a particular settings section.
  *
  * Part of the Settings API. Use this in a settings page to output
  * a specific section. Should normally be called by do_settings_sections()
@@ -1747,7 +1753,7 @@
 }
 
 /**
- * Register a settings error to be displayed to the user.
+ * Registers a settings error to be displayed to the user.
  *
  * Part of the Settings API. Use this to show messages to users about settings validation
  * problems, missing settings or anything else.
@@ -1783,7 +1789,7 @@
 }
 
 /**
- * Fetch settings errors registered by add_settings_error().
+ * Fetches settings errors registered by add_settings_error().
  *
  * Checks the $wp_settings_errors array for any errors declared during the current
  * pageload and returns them.
@@ -1854,7 +1860,7 @@
 }
 
 /**
- * Display settings errors registered by add_settings_error().
+ * Displays settings errors registered by add_settings_error().
  *
  * Part of the Settings API. Outputs a div for each error retrieved by
  * get_settings_errors().
@@ -1974,7 +1980,7 @@
 }
 
 /**
- * Get the post title.
+ * Gets the post title.
  *
  * The post title is fetched and if it is blank then a default string is
  * returned.
@@ -2005,7 +2011,7 @@
 }
 
 /**
- * Generic Iframe header for use with Thickbox
+ * Generic Iframe header for use with Thickbox.
  *
  * @since 2.7.0
  *
@@ -2031,7 +2037,7 @@
 	wp_enqueue_style( 'colors' );
 	?>
 <script type="text/javascript">
-addLoadEvent = function(func){if(typeof jQuery!=='undefined')jQuery(document).ready(func);else if(typeof wpOnload!=='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}};
+addLoadEvent = function(func){if(typeof jQuery!=='undefined')jQuery(function(){func();});else if(typeof wpOnload!=='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}};
 function tb_close(){var win=window.dialogArguments||opener||parent||top;win.tb_remove();}
 var ajaxurl = '<?php echo esc_js( admin_url( 'admin-ajax.php', 'relative' ) ); ?>',
 	pagenow = '<?php echo esc_js( $current_screen->id ); ?>',
@@ -2093,7 +2099,7 @@
 }
 
 /**
- * Generic Iframe footer for use with Thickbox
+ * Generic Iframe footer for use with Thickbox.
  *
  * @since 2.7.0
  */
@@ -2128,35 +2134,39 @@
 }
 
 /**
- * Function to echo or return the post states as HTML.
+ * Echoes or returns the post states as HTML.
  *
  * @since 2.7.0
- * @since 5.3.0 Added the `$echo` parameter and a return value.
+ * @since 5.3.0 Added the `$display` 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.
+ * @param WP_Post $post    The post to retrieve states for.
+ * @param bool    $display Optional. Whether to display the post states as an HTML string.
+ *                         Default true.
  * @return string Post states string.
  */
-function _post_states( $post, $echo = true ) {
+function _post_states( $post, $display = true ) {
 	$post_states        = get_post_states( $post );
 	$post_states_string = '';
 
 	if ( ! empty( $post_states ) ) {
 		$state_count = count( $post_states );
-		$i           = 0;
+
+		$i = 0;
 
 		$post_states_string .= ' &mdash; ';
 
 		foreach ( $post_states as $state ) {
-			$sep = ( ++$i === $state_count ) ? '' : ', ';
+			++$i;
+
+			$sep = ( $i < $state_count ) ? ', ' : '';
 
 			$post_states_string .= "<span class='post-state'>$state$sep</span>";
 		}
 	}
 
-	if ( $echo ) {
+	if ( $display ) {
 		echo $post_states_string;
 	}
 
@@ -2243,30 +2253,34 @@
  * Outputs the attachment media states as HTML.
  *
  * @since 3.2.0
- * @since 5.6.0 Added the `$echo` parameter and a return value.
+ * @since 5.6.0 Added the `$display` parameter and a return value.
  *
- * @param WP_Post $post The attachment post to retrieve states for.
- * @param bool    $echo Optional. Whether to echo the post states as an HTML string. Default true.
+ * @param WP_Post $post    The attachment post to retrieve states for.
+ * @param bool    $display Optional. Whether to display the post states as an HTML string.
+ *                         Default true.
  * @return string Media states string.
  */
-function _media_states( $post, $echo = true ) {
+function _media_states( $post, $display = true ) {
 	$media_states        = get_media_states( $post );
 	$media_states_string = '';
 
 	if ( ! empty( $media_states ) ) {
 		$state_count = count( $media_states );
-		$i           = 0;
+
+		$i = 0;
 
 		$media_states_string .= ' &mdash; ';
 
 		foreach ( $media_states as $state ) {
-			$sep = ( ++$i === $state_count ) ? '' : ', ';
+			++$i;
+
+			$sep = ( $i < $state_count ) ? ', ' : '';
 
 			$media_states_string .= "<span class='post-state'>$state$sep</span>";
 		}
 	}
 
-	if ( $echo ) {
+	if ( $display ) {
 		echo $media_states_string;
 	}
 
@@ -2355,7 +2369,7 @@
 }
 
 /**
- * Test support for compressing JavaScript from PHP
+ * Tests support for compressing JavaScript from PHP.
  *
  * Outputs JavaScript that tests if compression from PHP works as expected
  * and sets an option with the result. Has no effect when the current user
@@ -2445,7 +2459,7 @@
 }
 
 /**
- * Returns a submit button, with provided text and appropriate class
+ * Returns a submit button, with provided text and appropriate class.
  *
  * @since 3.1.0
  *
@@ -2548,7 +2562,7 @@
 }
 
 /**
- * Convert a screen string to a screen object
+ * Converts a screen string to a screen object.
  *
  * @since 3.0.0
  *
@@ -2598,7 +2612,7 @@
 }
 
 /**
- * Output a HTML element with a star rating for a given rating.
+ * Outputs a HTML element with a star rating for a given rating.
  *
  * Outputs a HTML element with the star rating exposed on a 0..5 scale in
  * half star increments (ie. 1, 1.5, 2 stars). Optionally, if specified, the