wp/wp-admin/includes/meta-boxes.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
--- a/wp/wp-admin/includes/meta-boxes.php	Wed Sep 21 18:19:35 2022 +0200
+++ b/wp/wp-admin/includes/meta-boxes.php	Tue Sep 27 16:37:53 2022 +0200
@@ -87,7 +87,8 @@
 		endif;
 
 		/**
-		 * Fires before the post time/date setting in the Publish meta box.
+		 * Fires after the Save Draft (or Save as Pending) and Preview (or Preview Changes) buttons
+		 * in the Publish meta box.
 		 *
 		 * @since 4.4.0
 		 *
@@ -286,7 +287,7 @@
 					<?php
 					printf(
 						/* translators: %s: URL to the Customizer. */
-						__( 'This draft comes from your <a href="%s">unpublished customization changes</a>. You can edit, but there&#8217;s no need to publish now. It will be published automatically with those changes.' ),
+						__( 'This draft comes from your <a href="%s">unpublished customization changes</a>. You can edit, but there is no need to publish now. It will be published automatically with those changes.' ),
 						esc_url(
 							add_query_arg(
 								'changeset_uuid',
@@ -381,11 +382,11 @@
 }
 
 /**
- * Display attachment submit form fields.
+ * Displays attachment submit form fields.
  *
  * @since 3.5.0
  *
- * @param WP_Post $post
+ * @param WP_Post $post Current post object.
  */
 function attachment_submit_meta_box( $post ) {
 	?>
@@ -461,11 +462,11 @@
 }
 
 /**
- * Display post format form elements.
+ * Displays post format form elements.
  *
  * @since 3.1.0
  *
- * @param WP_Post $post Post object.
+ * @param WP_Post $post Current post object.
  * @param array   $box {
  *     Post formats meta box arguments.
  *
@@ -484,7 +485,7 @@
 			if ( ! $post_format ) {
 				$post_format = '0';
 			}
-			// Add in the current one if it isn't there yet, in case the current theme doesn't support it.
+			// Add in the current one if it isn't there yet, in case the active theme doesn't support it.
 			if ( $post_format && ! in_array( $post_format, $post_formats[0], true ) ) {
 				$post_formats[0][] = $post_format;
 			}
@@ -504,13 +505,13 @@
 }
 
 /**
- * Display post tags form fields.
+ * Displays post tags form fields.
  *
  * @since 2.6.0
  *
  * @todo Create taxonomy-agnostic wrapper for this.
  *
- * @param WP_Post $post Post object.
+ * @param WP_Post $post Current post object.
  * @param array   $box {
  *     Tags meta box arguments.
  *
@@ -567,13 +568,13 @@
 }
 
 /**
- * Display post categories form fields.
+ * Displays post categories form fields.
  *
  * @since 2.6.0
  *
  * @todo Create taxonomy-agnostic wrapper for this.
  *
- * @param WP_Post $post Post object.
+ * @param WP_Post $post Current post object.
  * @param array   $box {
  *     Categories meta box arguments.
  *
@@ -691,11 +692,11 @@
 }
 
 /**
- * Display post excerpt form fields.
+ * Displays post excerpt form fields.
  *
  * @since 2.6.0
  *
- * @param WP_Post $post
+ * @param WP_Post $post Current post object.
  */
 function post_excerpt_meta_box( $post ) {
 	?>
@@ -713,11 +714,11 @@
 }
 
 /**
- * Display trackback links form fields.
+ * Displays trackback links form fields.
  *
  * @since 2.6.0
  *
- * @param WP_Post $post
+ * @param WP_Post $post Current post object.
  */
 function post_trackback_meta_box( $post ) {
 	$form_trackback = '<input type="text" name="trackback_url" id="trackback_url" class="code" value="' .
@@ -754,11 +755,11 @@
 }
 
 /**
- * Display custom fields form fields.
+ * Displays custom fields form fields.
  *
  * @since 2.6.0
  *
- * @param WP_Post $post
+ * @param WP_Post $post Current post object.
  */
 function post_custom_meta_box( $post ) {
 	?>
@@ -788,11 +789,11 @@
 }
 
 /**
- * Display comments status form fields.
+ * Displays comments status form fields.
  *
  * @since 2.6.0
  *
- * @param WP_Post $post
+ * @param WP_Post $post Current post object.
  */
 function post_comment_status_meta_box( $post ) {
 	?>
@@ -814,7 +815,7 @@
 	 *
 	 * @since 3.1.0
 	 *
-	 * @param WP_Post $post WP_Post object of the current post.
+	 * @param WP_Post $post WP_Post object for the current post.
 	 */
 	do_action( 'post_comment_status_meta_box-options', $post ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
 	?>
@@ -823,11 +824,11 @@
 }
 
 /**
- * Display comments for post table header
+ * Displays comments for post table header
  *
  * @since 3.0.0
  *
- * @param array $result table header rows
+ * @param array $result Table header rows.
  * @return array
  */
 function post_comment_meta_box_thead( $result ) {
@@ -836,11 +837,11 @@
 }
 
 /**
- * Display comments for post.
+ * Displays comments for post.
  *
  * @since 2.8.0
  *
- * @param WP_Post $post
+ * @param WP_Post $post Current post object.
  */
 function post_comment_meta_box( $post ) {
 	wp_nonce_field( 'get-comments', 'add_comment_nonce', false );
@@ -864,7 +865,7 @@
 		$hidden = get_hidden_meta_boxes( get_current_screen() );
 		if ( ! in_array( 'commentsdiv', $hidden, true ) ) {
 			?>
-			<script type="text/javascript">jQuery(document).ready(function(){commentsBox.get(<?php echo $total; ?>, 10);});</script>
+			<script type="text/javascript">jQuery(function(){commentsBox.get(<?php echo $total; ?>, 10);});</script>
 			<?php
 		}
 
@@ -877,11 +878,11 @@
 }
 
 /**
- * Display slug form fields.
+ * Displays slug form fields.
  *
  * @since 2.6.0
  *
- * @param WP_Post $post
+ * @param WP_Post $post Current post object.
  */
 function post_slug_meta_box( $post ) {
 	/** This filter is documented in wp-admin/edit-tag-form.php */
@@ -892,22 +893,24 @@
 }
 
 /**
- * Display form field with list of authors.
+ * Displays form field with list of authors.
  *
  * @since 2.6.0
  *
  * @global int $user_ID
  *
- * @param WP_Post $post
+ * @param WP_Post $post Current post object.
  */
 function post_author_meta_box( $post ) {
 	global $user_ID;
+
+	$post_type_object = get_post_type_object( $post->post_type );
 	?>
 <label class="screen-reader-text" for="post_author_override"><?php _e( 'Author' ); ?></label>
 	<?php
 	wp_dropdown_users(
 		array(
-			'who'              => 'authors',
+			'capability'       => array( $post_type_object->cap->edit_posts ),
 			'name'             => 'post_author_override',
 			'selected'         => empty( $post->ID ) ? $user_ID : $post->post_author,
 			'include_selected' => true,
@@ -917,11 +920,11 @@
 }
 
 /**
- * Display list of revisions.
+ * Displays list of revisions.
  *
  * @since 2.6.0
  *
- * @param WP_Post $post
+ * @param WP_Post $post Current post object.
  */
 function post_revisions_meta_box( $post ) {
 	wp_list_post_revisions( $post );
@@ -932,11 +935,11 @@
 //
 
 /**
- * Display page attributes form fields.
+ * Displays page attributes form fields.
  *
  * @since 2.7.0
  *
- * @param WP_Post $post
+ * @param WP_Post $post Current post object.
  */
 function page_attributes_meta_box( $post ) {
 	if ( is_post_type_hierarchical( $post->post_type ) ) :
@@ -981,8 +984,8 @@
 		 *
 		 * @since 4.4.0
 		 *
-		 * @param string  $template The template used for the current post.
-		 * @param WP_Post $post     The current post.
+		 * @param string|false $template The template used for the current post.
+		 * @param WP_Post      $post     The current post.
 		 */
 		do_action( 'page_attributes_meta_box_template', $template, $post );
 		?>
@@ -1029,11 +1032,11 @@
 //
 
 /**
- * Display link create form fields.
+ * Displays link create form fields.
  *
  * @since 2.7.0
  *
- * @param object $link
+ * @param object $link Current link object.
  */
 function link_submit_meta_box( $link ) {
 	?>
@@ -1105,11 +1108,11 @@
 }
 
 /**
- * Display link categories form fields.
+ * Displays link categories form fields.
  *
  * @since 2.6.0
  *
- * @param object $link
+ * @param object $link Current link object.
  */
 function link_categories_meta_box( $link ) {
 	?>
@@ -1152,11 +1155,11 @@
 }
 
 /**
- * Display form fields for changing link target.
+ * Displays form fields for changing link target.
  *
  * @since 2.6.0
  *
- * @param object $link
+ * @param object $link Current link object.
  */
 function link_target_meta_box( $link ) {
 
@@ -1177,52 +1180,70 @@
 }
 
 /**
- * Display checked checkboxes attribute for xfn microformat options.
+ * Displays 'checked' checkboxes attribute for XFN microformat options.
  *
  * @since 1.0.1
  *
- * @global object $link
+ * @global object $link Current link object.
  *
- * @param string $class
- * @param string $value
- * @param mixed  $deprecated Never used.
+ * @param string $xfn_relationship XFN relationship category. Possible values are:
+ *                                 'friendship', 'physical', 'professional',
+ *                                 'geographical', 'family', 'romantic', 'identity'.
+ * @param string $xfn_value        Optional. The XFN value to mark as checked
+ *                                 if it matches the current link's relationship.
+ *                                 Default empty string.
+ * @param mixed  $deprecated       Deprecated. Not used.
  */
-function xfn_check( $class, $value = '', $deprecated = '' ) {
+function xfn_check( $xfn_relationship, $xfn_value = '', $deprecated = '' ) {
 	global $link;
 
 	if ( ! empty( $deprecated ) ) {
 		_deprecated_argument( __FUNCTION__, '2.5.0' ); // Never implemented.
 	}
 
-	$link_rel = isset( $link->link_rel ) ? $link->link_rel : ''; // In PHP 5.3: $link_rel = $link->link_rel ?: '';
-	$rels     = preg_split( '/\s+/', $link_rel );
+	$link_rel  = isset( $link->link_rel ) ? $link->link_rel : ''; // In PHP 5.3: $link_rel = $link->link_rel ?: '';
+	$link_rels = preg_split( '/\s+/', $link_rel );
 
-	if ( '' !== $value && in_array( $value, $rels, true ) ) {
+	// Mark the specified value as checked if it matches the current link's relationship.
+	if ( '' !== $xfn_value && in_array( $xfn_value, $link_rels, true ) ) {
 		echo ' checked="checked"';
 	}
 
-	if ( '' === $value ) {
-		if ( 'family' === $class && strpos( $link_rel, 'child' ) === false && strpos( $link_rel, 'parent' ) === false && strpos( $link_rel, 'sibling' ) === false && strpos( $link_rel, 'spouse' ) === false && strpos( $link_rel, 'kin' ) === false ) {
+	if ( '' === $xfn_value ) {
+		// Mark the 'none' value as checked if the current link does not match the specified relationship.
+		if ( 'family' === $xfn_relationship
+			&& ! array_intersect( $link_rels, array( 'child', 'parent', 'sibling', 'spouse', 'kin' ) )
+		) {
 			echo ' checked="checked"';
 		}
-		if ( 'friendship' === $class && strpos( $link_rel, 'friend' ) === false && strpos( $link_rel, 'acquaintance' ) === false && strpos( $link_rel, 'contact' ) === false ) {
+
+		if ( 'friendship' === $xfn_relationship
+			&& ! array_intersect( $link_rels, array( 'friend', 'acquaintance', 'contact' ) )
+		) {
 			echo ' checked="checked"';
 		}
-		if ( 'geographical' === $class && strpos( $link_rel, 'co-resident' ) === false && strpos( $link_rel, 'neighbor' ) === false ) {
+
+		if ( 'geographical' === $xfn_relationship
+			&& ! array_intersect( $link_rels, array( 'co-resident', 'neighbor' ) )
+		) {
 			echo ' checked="checked"';
 		}
-		if ( 'identity' === $class && in_array( 'me', $rels, true ) ) {
+
+		// Mark the 'me' value as checked if it matches the current link's relationship.
+		if ( 'identity' === $xfn_relationship
+			&& in_array( 'me', $link_rels, true )
+		) {
 			echo ' checked="checked"';
 		}
 	}
 }
 
 /**
- * Display xfn form fields.
+ * Displays XFN form fields.
  *
  * @since 2.6.0
  *
- * @param object $link
+ * @param object $link Current link object.
  */
 function link_xfn_meta_box( $link ) {
 	?>
@@ -1336,11 +1357,11 @@
 }
 
 /**
- * Display advanced link options form fields.
+ * Displays advanced link options form fields.
  *
  * @since 2.6.0
  *
- * @param object $link
+ * @param object $link Current link object.
  */
 function link_advanced_meta_box( $link ) {
 	?>
@@ -1361,12 +1382,12 @@
 		<th scope="row"><label for="link_rating"><?php _e( 'Rating' ); ?></label></th>
 		<td><select name="link_rating" id="link_rating" size="1">
 		<?php
-		for ( $parsed_args = 0; $parsed_args <= 10; $parsed_args++ ) {
-			echo '<option value="' . $parsed_args . '"';
-			if ( isset( $link->link_rating ) && $link->link_rating == $parsed_args ) {
+		for ( $rating = 0; $rating <= 10; $rating++ ) {
+			echo '<option value="' . $rating . '"';
+			if ( isset( $link->link_rating ) && $link->link_rating == $rating ) {
 				echo ' selected="selected"';
 			}
-			echo( '>' . $parsed_args . '</option>' );
+			echo '>' . $rating . '</option>';
 		}
 		?>
 		</select>&nbsp;<?php _e( '(Leave at 0 for no rating.)' ); ?>
@@ -1377,11 +1398,11 @@
 }
 
 /**
- * Display post thumbnail meta box.
+ * Displays post thumbnail meta box.
  *
  * @since 2.9.0
  *
- * @param WP_Post $post A post object.
+ * @param WP_Post $post Current post object.
  */
 function post_thumbnail_meta_box( $post ) {
 	$thumbnail_id = get_post_meta( $post->ID, '_thumbnail_id', true );
@@ -1389,11 +1410,11 @@
 }
 
 /**
- * Display fields for ID3 data
+ * Displays fields for ID3 data.
  *
  * @since 3.9.0
  *
- * @param WP_Post $post A post object.
+ * @param WP_Post $post Current post object.
  */
 function attachment_id3_data_meta_box( $post ) {
 	$meta = array();
@@ -1580,7 +1601,13 @@
 	/**
 	 * Fires after all built-in meta boxes have been added, contextually for the given post type.
 	 *
-	 * The dynamic portion of the hook, `$post_type`, refers to the post type of the post.
+	 * The dynamic portion of the hook name, `$post_type`, refers to the post type of the post.
+	 *
+	 * Possible hook names include:
+	 *
+	 *  - `add_meta_boxes_post`
+	 *  - `add_meta_boxes_page`
+	 *  - `add_meta_boxes_attachment`
 	 *
 	 * @since 3.0.0
 	 *