wp/wp-admin/includes/post.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
    11  *
    11  *
    12  * Manipulates $_POST directly.
    12  * Manipulates $_POST directly.
    13  *
    13  *
    14  * @since 2.6.0
    14  * @since 2.6.0
    15  *
    15  *
    16  * @param bool $update Are we updating a pre-existing post?
    16  * @param bool  $update    Are we updating a pre-existing post?
    17  * @param array $post_data Array of post data. Defaults to the contents of $_POST.
    17  * @param array $post_data Array of post data. Defaults to the contents of $_POST.
    18  * @return object|bool WP_Error on failure, true on success.
    18  * @return array|WP_Error Array of post data on success, WP_Error on failure.
    19  */
    19  */
    20 function _wp_translate_postdata( $update = false, $post_data = null ) {
    20 function _wp_translate_postdata( $update = false, $post_data = null ) {
    21 
    21 
    22 	if ( empty( $post_data ) ) {
    22 	if ( empty( $post_data ) ) {
    23 		$post_data = &$_POST;
    23 		$post_data = &$_POST;
    28 	}
    28 	}
    29 
    29 
    30 	$ptype = get_post_type_object( $post_data['post_type'] );
    30 	$ptype = get_post_type_object( $post_data['post_type'] );
    31 
    31 
    32 	if ( $update && ! current_user_can( 'edit_post', $post_data['ID'] ) ) {
    32 	if ( $update && ! current_user_can( 'edit_post', $post_data['ID'] ) ) {
    33 		if ( 'page' == $post_data['post_type'] ) {
    33 		if ( 'page' === $post_data['post_type'] ) {
    34 			return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to edit pages as this user.' ) );
    34 			return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to edit pages as this user.' ) );
    35 		} else {
    35 		} else {
    36 			return new WP_Error( 'edit_others_posts', __( 'Sorry, you are not allowed to edit posts as this user.' ) );
    36 			return new WP_Error( 'edit_others_posts', __( 'Sorry, you are not allowed to edit posts as this user.' ) );
    37 		}
    37 		}
    38 	} elseif ( ! $update && ! current_user_can( $ptype->cap->create_posts ) ) {
    38 	} elseif ( ! $update && ! current_user_can( $ptype->cap->create_posts ) ) {
    39 		if ( 'page' == $post_data['post_type'] ) {
    39 		if ( 'page' === $post_data['post_type'] ) {
    40 			return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to create pages as this user.' ) );
    40 			return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to create pages as this user.' ) );
    41 		} else {
    41 		} else {
    42 			return new WP_Error( 'edit_others_posts', __( 'Sorry, you are not allowed to create posts as this user.' ) );
    42 			return new WP_Error( 'edit_others_posts', __( 'Sorry, you are not allowed to create posts as this user.' ) );
    43 		}
    43 		}
    44 	}
    44 	}
    73 
    73 
    74 	if ( isset( $post_data['user_ID'] ) && ( $post_data['post_author'] != $post_data['user_ID'] )
    74 	if ( isset( $post_data['user_ID'] ) && ( $post_data['post_author'] != $post_data['user_ID'] )
    75 		&& ! current_user_can( $ptype->cap->edit_others_posts ) ) {
    75 		&& ! current_user_can( $ptype->cap->edit_others_posts ) ) {
    76 
    76 
    77 		if ( $update ) {
    77 		if ( $update ) {
    78 			if ( 'page' == $post_data['post_type'] ) {
    78 			if ( 'page' === $post_data['post_type'] ) {
    79 				return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to edit pages as this user.' ) );
    79 				return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to edit pages as this user.' ) );
    80 			} else {
    80 			} else {
    81 				return new WP_Error( 'edit_others_posts', __( 'Sorry, you are not allowed to edit posts as this user.' ) );
    81 				return new WP_Error( 'edit_others_posts', __( 'Sorry, you are not allowed to edit posts as this user.' ) );
    82 			}
    82 			}
    83 		} else {
    83 		} else {
    84 			if ( 'page' == $post_data['post_type'] ) {
    84 			if ( 'page' === $post_data['post_type'] ) {
    85 				return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to create pages as this user.' ) );
    85 				return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to create pages as this user.' ) );
    86 			} else {
    86 			} else {
    87 				return new WP_Error( 'edit_others_posts', __( 'Sorry, you are not allowed to create posts as this user.' ) );
    87 				return new WP_Error( 'edit_others_posts', __( 'Sorry, you are not allowed to create posts as this user.' ) );
    88 			}
    88 			}
    89 		}
    89 		}
    90 	}
    90 	}
    91 
    91 
    92 	if ( ! empty( $post_data['post_status'] ) ) {
    92 	if ( ! empty( $post_data['post_status'] ) ) {
    93 		$post_data['post_status'] = sanitize_key( $post_data['post_status'] );
    93 		$post_data['post_status'] = sanitize_key( $post_data['post_status'] );
    94 
    94 
    95 		// No longer an auto-draft
    95 		// No longer an auto-draft.
    96 		if ( 'auto-draft' === $post_data['post_status'] ) {
    96 		if ( 'auto-draft' === $post_data['post_status'] ) {
    97 			$post_data['post_status'] = 'draft';
    97 			$post_data['post_status'] = 'draft';
    98 		}
    98 		}
    99 
    99 
   100 		if ( ! get_post_status_object( $post_data['post_status'] ) ) {
   100 		if ( ! get_post_status_object( $post_data['post_status'] ) ) {
   101 			unset( $post_data['post_status'] );
   101 			unset( $post_data['post_status'] );
   102 		}
   102 		}
   103 	}
   103 	}
   104 
   104 
   105 	// What to do based on which button they pressed
   105 	// What to do based on which button they pressed.
   106 	if ( isset( $post_data['saveasdraft'] ) && '' != $post_data['saveasdraft'] ) {
   106 	if ( isset( $post_data['saveasdraft'] ) && '' !== $post_data['saveasdraft'] ) {
   107 		$post_data['post_status'] = 'draft';
   107 		$post_data['post_status'] = 'draft';
   108 	}
   108 	}
   109 	if ( isset( $post_data['saveasprivate'] ) && '' != $post_data['saveasprivate'] ) {
   109 	if ( isset( $post_data['saveasprivate'] ) && '' !== $post_data['saveasprivate'] ) {
   110 		$post_data['post_status'] = 'private';
   110 		$post_data['post_status'] = 'private';
   111 	}
   111 	}
   112 	if ( isset( $post_data['publish'] ) && ( '' != $post_data['publish'] ) && ( ! isset( $post_data['post_status'] ) || $post_data['post_status'] != 'private' ) ) {
   112 	if ( isset( $post_data['publish'] ) && ( '' !== $post_data['publish'] )
       
   113 		&& ( ! isset( $post_data['post_status'] ) || 'private' !== $post_data['post_status'] )
       
   114 	) {
   113 		$post_data['post_status'] = 'publish';
   115 		$post_data['post_status'] = 'publish';
   114 	}
   116 	}
   115 	if ( isset( $post_data['advanced'] ) && '' != $post_data['advanced'] ) {
   117 	if ( isset( $post_data['advanced'] ) && '' !== $post_data['advanced'] ) {
   116 		$post_data['post_status'] = 'draft';
   118 		$post_data['post_status'] = 'draft';
   117 	}
   119 	}
   118 	if ( isset( $post_data['pending'] ) && '' != $post_data['pending'] ) {
   120 	if ( isset( $post_data['pending'] ) && '' !== $post_data['pending'] ) {
   119 		$post_data['post_status'] = 'pending';
   121 		$post_data['post_status'] = 'pending';
   120 	}
   122 	}
   121 
   123 
   122 	if ( isset( $post_data['ID'] ) ) {
   124 	if ( isset( $post_data['ID'] ) ) {
   123 		$post_id = $post_data['ID'];
   125 		$post_id = $post_data['ID'];
   124 	} else {
   126 	} else {
   125 		$post_id = false;
   127 		$post_id = false;
   126 	}
   128 	}
   127 	$previous_status = $post_id ? get_post_field( 'post_status', $post_id ) : false;
   129 	$previous_status = $post_id ? get_post_field( 'post_status', $post_id ) : false;
   128 
   130 
   129 	if ( isset( $post_data['post_status'] ) && 'private' == $post_data['post_status'] && ! current_user_can( $ptype->cap->publish_posts ) ) {
   131 	if ( isset( $post_data['post_status'] ) && 'private' === $post_data['post_status'] && ! current_user_can( $ptype->cap->publish_posts ) ) {
   130 		$post_data['post_status'] = $previous_status ? $previous_status : 'pending';
   132 		$post_data['post_status'] = $previous_status ? $previous_status : 'pending';
   131 	}
   133 	}
   132 
   134 
   133 	$published_statuses = array( 'publish', 'future' );
   135 	$published_statuses = array( 'publish', 'future' );
   134 
   136 
   135 	// Posts 'submitted for approval' present are submitted to $_POST the same as if they were being published.
   137 	// Posts 'submitted for approval' are submitted to $_POST the same as if they were being published.
   136 	// Change status from 'publish' to 'pending' if user lacks permissions to publish or to resave published posts.
   138 	// Change status from 'publish' to 'pending' if user lacks permissions to publish or to resave published posts.
   137 	if ( isset( $post_data['post_status'] ) && ( in_array( $post_data['post_status'], $published_statuses ) && ! current_user_can( $ptype->cap->publish_posts ) ) ) {
   139 	if ( isset( $post_data['post_status'] )
   138 		if ( ! in_array( $previous_status, $published_statuses ) || ! current_user_can( 'edit_post', $post_id ) ) {
   140 		&& ( in_array( $post_data['post_status'], $published_statuses, true )
       
   141 		&& ! current_user_can( $ptype->cap->publish_posts ) )
       
   142 	) {
       
   143 		if ( ! in_array( $previous_status, $published_statuses, true ) || ! current_user_can( 'edit_post', $post_id ) ) {
   139 			$post_data['post_status'] = 'pending';
   144 			$post_data['post_status'] = 'pending';
   140 		}
   145 		}
   141 	}
   146 	}
   142 
   147 
   143 	if ( ! isset( $post_data['post_status'] ) ) {
   148 	if ( ! isset( $post_data['post_status'] ) ) {
   168 		$mm                     = $post_data['mm'];
   173 		$mm                     = $post_data['mm'];
   169 		$jj                     = $post_data['jj'];
   174 		$jj                     = $post_data['jj'];
   170 		$hh                     = $post_data['hh'];
   175 		$hh                     = $post_data['hh'];
   171 		$mn                     = $post_data['mn'];
   176 		$mn                     = $post_data['mn'];
   172 		$ss                     = $post_data['ss'];
   177 		$ss                     = $post_data['ss'];
   173 		$aa                     = ( $aa <= 0 ) ? date( 'Y' ) : $aa;
   178 		$aa                     = ( $aa <= 0 ) ? gmdate( 'Y' ) : $aa;
   174 		$mm                     = ( $mm <= 0 ) ? date( 'n' ) : $mm;
   179 		$mm                     = ( $mm <= 0 ) ? gmdate( 'n' ) : $mm;
   175 		$jj                     = ( $jj > 31 ) ? 31 : $jj;
   180 		$jj                     = ( $jj > 31 ) ? 31 : $jj;
   176 		$jj                     = ( $jj <= 0 ) ? date( 'j' ) : $jj;
   181 		$jj                     = ( $jj <= 0 ) ? gmdate( 'j' ) : $jj;
   177 		$hh                     = ( $hh > 23 ) ? $hh - 24 : $hh;
   182 		$hh                     = ( $hh > 23 ) ? $hh - 24 : $hh;
   178 		$mn                     = ( $mn > 59 ) ? $mn - 60 : $mn;
   183 		$mn                     = ( $mn > 59 ) ? $mn - 60 : $mn;
   179 		$ss                     = ( $ss > 59 ) ? $ss - 60 : $ss;
   184 		$ss                     = ( $ss > 59 ) ? $ss - 60 : $ss;
   180 		$post_data['post_date'] = sprintf( '%04d-%02d-%02d %02d:%02d:%02d', $aa, $mm, $jj, $hh, $mn, $ss );
   185 		$post_data['post_date'] = sprintf( '%04d-%02d-%02d %02d:%02d:%02d', $aa, $mm, $jj, $hh, $mn, $ss );
   181 		$valid_date             = wp_checkdate( $mm, $jj, $aa, $post_data['post_date'] );
   186 		$valid_date             = wp_checkdate( $mm, $jj, $aa, $post_data['post_date'] );
   199  * Returns only allowed post data fields
   204  * Returns only allowed post data fields
   200  *
   205  *
   201  * @since 5.0.1
   206  * @since 5.0.1
   202  *
   207  *
   203  * @param array $post_data Array of post data. Defaults to the contents of $_POST.
   208  * @param array $post_data Array of post data. Defaults to the contents of $_POST.
   204  * @return object|bool WP_Error on failure, true on success.
   209  * @return array|WP_Error Array of post data on success, WP_Error on failure.
   205  */
   210  */
   206 function _wp_get_allowed_postdata( $post_data = null ) {
   211 function _wp_get_allowed_postdata( $post_data = null ) {
   207 	if ( empty( $post_data ) ) {
   212 	if ( empty( $post_data ) ) {
   208 		$post_data = $_POST;
   213 		$post_data = $_POST;
   209 	}
   214 	}
   210 
   215 
   211 	// Pass through errors
   216 	// Pass through errors.
   212 	if ( is_wp_error( $post_data ) ) {
   217 	if ( is_wp_error( $post_data ) ) {
   213 		return $post_data;
   218 		return $post_data;
   214 	}
   219 	}
   215 
   220 
   216 	return array_diff_key( $post_data, array_flip( array( 'meta_input', 'file', 'guid' ) ) );
   221 	return array_diff_key( $post_data, array_flip( array( 'meta_input', 'file', 'guid' ) ) );
   217 }
   222 }
   218 
   223 
   219 /**
   224 /**
   220  * Update an existing post with values provided in $_POST.
   225  * Update an existing post with values provided in $_POST.
   221  *
   226  *
       
   227  * If post data is passed as an argument, it is treated as an array of data
       
   228  * keyed appropriately for turning into a post object.
       
   229  *
       
   230  * If post data is not passed, the $_POST global variable is used instead.
       
   231  *
   222  * @since 1.5.0
   232  * @since 1.5.0
   223  *
   233  *
   224  * @global wpdb $wpdb WordPress database abstraction object.
   234  * @global wpdb $wpdb WordPress database abstraction object.
   225  *
   235  *
   226  * @param array $post_data Optional.
   236  * @param array $post_data Optional. Defaults to the $_POST global.
   227  * @return int Post ID.
   237  * @return int Post ID.
   228  */
   238  */
   229 function edit_post( $post_data = null ) {
   239 function edit_post( $post_data = null ) {
   230 	global $wpdb;
   240 	global $wpdb;
   231 
   241 
   242 	$post_data['post_mime_type'] = $post->post_mime_type;
   252 	$post_data['post_mime_type'] = $post->post_mime_type;
   243 
   253 
   244 	if ( ! empty( $post_data['post_status'] ) ) {
   254 	if ( ! empty( $post_data['post_status'] ) ) {
   245 		$post_data['post_status'] = sanitize_key( $post_data['post_status'] );
   255 		$post_data['post_status'] = sanitize_key( $post_data['post_status'] );
   246 
   256 
   247 		if ( 'inherit' == $post_data['post_status'] ) {
   257 		if ( 'inherit' === $post_data['post_status'] ) {
   248 			unset( $post_data['post_status'] );
   258 			unset( $post_data['post_status'] );
   249 		}
   259 		}
   250 	}
   260 	}
   251 
   261 
   252 	$ptype = get_post_type_object( $post_data['post_type'] );
   262 	$ptype = get_post_type_object( $post_data['post_type'] );
   253 	if ( ! current_user_can( 'edit_post', $post_ID ) ) {
   263 	if ( ! current_user_can( 'edit_post', $post_ID ) ) {
   254 		if ( 'page' == $post_data['post_type'] ) {
   264 		if ( 'page' === $post_data['post_type'] ) {
   255 			wp_die( __( 'Sorry, you are not allowed to edit this page.' ) );
   265 			wp_die( __( 'Sorry, you are not allowed to edit this page.' ) );
   256 		} else {
   266 		} else {
   257 			wp_die( __( 'Sorry, you are not allowed to edit this post.' ) );
   267 			wp_die( __( 'Sorry, you are not allowed to edit this post.' ) );
   258 		}
   268 		}
   259 	}
   269 	}
   266 				'posts_per_page' => 1,
   276 				'posts_per_page' => 1,
   267 			)
   277 			)
   268 		);
   278 		);
   269 		$revision  = current( $revisions );
   279 		$revision  = current( $revisions );
   270 
   280 
   271 		// Check if the revisions have been upgraded
   281 		// Check if the revisions have been upgraded.
   272 		if ( $revisions && _wp_get_post_revision_version( $revision ) < 1 ) {
   282 		if ( $revisions && _wp_get_post_revision_version( $revision ) < 1 ) {
   273 			_wp_upgrade_revisions_of_post( $post, wp_get_post_revisions( $post_ID ) );
   283 			_wp_upgrade_revisions_of_post( $post, wp_get_post_revisions( $post_ID ) );
   274 		}
   284 		}
   275 	}
   285 	}
   276 
   286 
   294 	if ( is_wp_error( $post_data ) ) {
   304 	if ( is_wp_error( $post_data ) ) {
   295 		wp_die( $post_data->get_error_message() );
   305 		wp_die( $post_data->get_error_message() );
   296 	}
   306 	}
   297 	$translated = _wp_get_allowed_postdata( $post_data );
   307 	$translated = _wp_get_allowed_postdata( $post_data );
   298 
   308 
   299 	// Post Formats
   309 	// Post formats.
   300 	if ( isset( $post_data['post_format'] ) ) {
   310 	if ( isset( $post_data['post_format'] ) ) {
   301 		set_post_format( $post_ID, $post_data['post_format'] );
   311 		set_post_format( $post_ID, $post_data['post_format'] );
   302 	}
   312 	}
   303 
   313 
   304 	$format_meta_urls = array( 'url', 'link_url', 'quote_source_url' );
   314 	$format_meta_urls = array( 'url', 'link_url', 'quote_source_url' );
   334 			}
   344 			}
   335 		}
   345 		}
   336 		wp_update_attachment_metadata( $post_ID, $id3data );
   346 		wp_update_attachment_metadata( $post_ID, $id3data );
   337 	}
   347 	}
   338 
   348 
   339 	// Meta Stuff
   349 	// Meta stuff.
   340 	if ( isset( $post_data['meta'] ) && $post_data['meta'] ) {
   350 	if ( isset( $post_data['meta'] ) && $post_data['meta'] ) {
   341 		foreach ( $post_data['meta'] as $key => $value ) {
   351 		foreach ( $post_data['meta'] as $key => $value ) {
   342 			if ( ! $meta = get_post_meta_by_id( $key ) ) {
   352 			$meta = get_post_meta_by_id( $key );
       
   353 			if ( ! $meta ) {
   343 				continue;
   354 				continue;
   344 			}
   355 			}
   345 			if ( $meta->post_id != $post_ID ) {
   356 			if ( $meta->post_id != $post_ID ) {
   346 				continue;
   357 				continue;
   347 			}
   358 			}
   355 		}
   366 		}
   356 	}
   367 	}
   357 
   368 
   358 	if ( isset( $post_data['deletemeta'] ) && $post_data['deletemeta'] ) {
   369 	if ( isset( $post_data['deletemeta'] ) && $post_data['deletemeta'] ) {
   359 		foreach ( $post_data['deletemeta'] as $key => $value ) {
   370 		foreach ( $post_data['deletemeta'] as $key => $value ) {
   360 			if ( ! $meta = get_post_meta_by_id( $key ) ) {
   371 			$meta = get_post_meta_by_id( $key );
       
   372 			if ( ! $meta ) {
   361 				continue;
   373 				continue;
   362 			}
   374 			}
   363 			if ( $meta->post_id != $post_ID ) {
   375 			if ( $meta->post_id != $post_ID ) {
   364 				continue;
   376 				continue;
   365 			}
   377 			}
   368 			}
   380 			}
   369 			delete_meta( $key );
   381 			delete_meta( $key );
   370 		}
   382 		}
   371 	}
   383 	}
   372 
   384 
   373 	// Attachment stuff
   385 	// Attachment stuff.
   374 	if ( 'attachment' == $post_data['post_type'] ) {
   386 	if ( 'attachment' === $post_data['post_type'] ) {
   375 		if ( isset( $post_data['_wp_attachment_image_alt'] ) ) {
   387 		if ( isset( $post_data['_wp_attachment_image_alt'] ) ) {
   376 			$image_alt = wp_unslash( $post_data['_wp_attachment_image_alt'] );
   388 			$image_alt = wp_unslash( $post_data['_wp_attachment_image_alt'] );
   377 			if ( $image_alt != get_post_meta( $post_ID, '_wp_attachment_image_alt', true ) ) {
   389 
       
   390 			if ( get_post_meta( $post_ID, '_wp_attachment_image_alt', true ) !== $image_alt ) {
   378 				$image_alt = wp_strip_all_tags( $image_alt, true );
   391 				$image_alt = wp_strip_all_tags( $image_alt, true );
   379 				// update_meta expects slashed.
   392 
       
   393 				// update_post_meta() expects slashed.
   380 				update_post_meta( $post_ID, '_wp_attachment_image_alt', wp_slash( $image_alt ) );
   394 				update_post_meta( $post_ID, '_wp_attachment_image_alt', wp_slash( $image_alt ) );
   381 			}
   395 			}
   382 		}
   396 		}
   383 
   397 
   384 		$attachment_data = isset( $post_data['attachments'][ $post_ID ] ) ? $post_data['attachments'][ $post_ID ] : array();
   398 		$attachment_data = isset( $post_data['attachments'][ $post_ID ] ) ? $post_data['attachments'][ $post_ID ] : array();
   401 	add_meta( $post_ID );
   415 	add_meta( $post_ID );
   402 
   416 
   403 	update_post_meta( $post_ID, '_edit_last', get_current_user_id() );
   417 	update_post_meta( $post_ID, '_edit_last', get_current_user_id() );
   404 
   418 
   405 	$success = wp_update_post( $translated );
   419 	$success = wp_update_post( $translated );
   406 	// If the save failed, see if we can sanity check the main fields and try again
   420 
       
   421 	// If the save failed, see if we can sanity check the main fields and try again.
   407 	if ( ! $success && is_callable( array( $wpdb, 'strip_invalid_text_for_column' ) ) ) {
   422 	if ( ! $success && is_callable( array( $wpdb, 'strip_invalid_text_for_column' ) ) ) {
   408 		$fields = array( 'post_title', 'post_content', 'post_excerpt' );
   423 		$fields = array( 'post_title', 'post_content', 'post_excerpt' );
   409 
   424 
   410 		foreach ( $fields as $field ) {
   425 		foreach ( $fields as $field ) {
   411 			if ( isset( $translated[ $field ] ) ) {
   426 			if ( isset( $translated[ $field ] ) ) {
   414 		}
   429 		}
   415 
   430 
   416 		wp_update_post( $translated );
   431 		wp_update_post( $translated );
   417 	}
   432 	}
   418 
   433 
   419 	// Now that we have an ID we can fix any attachment anchor hrefs
   434 	// Now that we have an ID we can fix any attachment anchor hrefs.
   420 	_fix_attachment_links( $post_ID );
   435 	_fix_attachment_links( $post_ID );
   421 
   436 
   422 	wp_set_post_lock( $post_ID );
   437 	wp_set_post_lock( $post_ID );
   423 
   438 
   424 	if ( current_user_can( $ptype->cap->edit_others_posts ) && current_user_can( $ptype->cap->publish_posts ) ) {
   439 	if ( current_user_can( $ptype->cap->edit_others_posts ) && current_user_can( $ptype->cap->publish_posts ) ) {
   457 	} else {
   472 	} else {
   458 		$ptype = get_post_type_object( 'post' );
   473 		$ptype = get_post_type_object( 'post' );
   459 	}
   474 	}
   460 
   475 
   461 	if ( ! current_user_can( $ptype->cap->edit_posts ) ) {
   476 	if ( ! current_user_can( $ptype->cap->edit_posts ) ) {
   462 		if ( 'page' == $ptype->name ) {
   477 		if ( 'page' === $ptype->name ) {
   463 			wp_die( __( 'Sorry, you are not allowed to edit pages.' ) );
   478 			wp_die( __( 'Sorry, you are not allowed to edit pages.' ) );
   464 		} else {
   479 		} else {
   465 			wp_die( __( 'Sorry, you are not allowed to edit posts.' ) );
   480 			wp_die( __( 'Sorry, you are not allowed to edit posts.' ) );
   466 		}
   481 		}
   467 	}
   482 	}
   475 	unset( $post_data['_status'] );
   490 	unset( $post_data['_status'] );
   476 
   491 
   477 	if ( ! empty( $post_data['post_status'] ) ) {
   492 	if ( ! empty( $post_data['post_status'] ) ) {
   478 		$post_data['post_status'] = sanitize_key( $post_data['post_status'] );
   493 		$post_data['post_status'] = sanitize_key( $post_data['post_status'] );
   479 
   494 
   480 		if ( 'inherit' == $post_data['post_status'] ) {
   495 		if ( 'inherit' === $post_data['post_status'] ) {
   481 			unset( $post_data['post_status'] );
   496 			unset( $post_data['post_status'] );
   482 		}
   497 		}
   483 	}
   498 	}
   484 
   499 
   485 	$post_IDs = array_map( 'intval', (array) $post_data['post'] );
   500 	$post_IDs = array_map( 'intval', (array) $post_data['post'] );
   498 		'sticky',
   513 		'sticky',
   499 		'post_format',
   514 		'post_format',
   500 	);
   515 	);
   501 
   516 
   502 	foreach ( $reset as $field ) {
   517 	foreach ( $reset as $field ) {
   503 		if ( isset( $post_data[ $field ] ) && ( '' == $post_data[ $field ] || -1 == $post_data[ $field ] ) ) {
   518 		if ( isset( $post_data[ $field ] ) && ( '' === $post_data[ $field ] || -1 == $post_data[ $field ] ) ) {
   504 			unset( $post_data[ $field ] );
   519 			unset( $post_data[ $field ] );
   505 		}
   520 		}
   506 	}
   521 	}
   507 
   522 
   508 	if ( isset( $post_data['post_category'] ) ) {
   523 	if ( isset( $post_data['post_category'] ) ) {
   529 				$tax_input[ $tax_name ] = explode( ',', trim( $terms, " \n\t\r\0\x0B," ) );
   544 				$tax_input[ $tax_name ] = explode( ',', trim( $terms, " \n\t\r\0\x0B," ) );
   530 			}
   545 			}
   531 		}
   546 		}
   532 	}
   547 	}
   533 
   548 
   534 	if ( isset( $post_data['post_parent'] ) && ( $parent = (int) $post_data['post_parent'] ) ) {
   549 	if ( isset( $post_data['post_parent'] ) && (int) $post_data['post_parent'] ) {
       
   550 		$parent   = (int) $post_data['post_parent'];
   535 		$pages    = $wpdb->get_results( "SELECT ID, post_parent FROM $wpdb->posts WHERE post_type = 'page'" );
   551 		$pages    = $wpdb->get_results( "SELECT ID, post_parent FROM $wpdb->posts WHERE post_type = 'page'" );
   536 		$children = array();
   552 		$children = array();
   537 
   553 
   538 		for ( $i = 0; $i < 50 && $parent > 0; $i++ ) {
   554 		for ( $i = 0; $i < 50 && $parent > 0; $i++ ) {
   539 			$children[] = $parent;
   555 			$children[] = $parent;
   540 
   556 
   541 			foreach ( $pages as $page ) {
   557 			foreach ( $pages as $page ) {
   542 				if ( $page->ID == $parent ) {
   558 				if ( (int) $page->ID === $parent ) {
   543 					$parent = $page->post_parent;
   559 					$parent = (int) $page->post_parent;
   544 					break;
   560 					break;
   545 				}
   561 				}
   546 			}
   562 			}
   547 		}
   563 		}
   548 	}
   564 	}
   549 
   565 
   550 	$updated          = $skipped = $locked = array();
   566 	$updated          = array();
       
   567 	$skipped          = array();
       
   568 	$locked           = array();
   551 	$shared_post_data = $post_data;
   569 	$shared_post_data = $post_data;
   552 
   570 
   553 	foreach ( $post_IDs as $post_ID ) {
   571 	foreach ( $post_IDs as $post_ID ) {
   554 		// Start with fresh post data with each iteration.
   572 		// Start with fresh post data with each iteration.
   555 		$post_data = $shared_post_data;
   573 		$post_data = $shared_post_data;
   556 
   574 
   557 		$post_type_object = get_post_type_object( get_post_type( $post_ID ) );
   575 		$post_type_object = get_post_type_object( get_post_type( $post_ID ) );
   558 
   576 
   559 		if ( ! isset( $post_type_object ) || ( isset( $children ) && in_array( $post_ID, $children ) ) || ! current_user_can( 'edit_post', $post_ID ) ) {
   577 		if ( ! isset( $post_type_object )
       
   578 			|| ( isset( $children ) && in_array( $post_ID, $children, true ) )
       
   579 			|| ! current_user_can( 'edit_post', $post_ID )
       
   580 		) {
   560 			$skipped[] = $post_ID;
   581 			$skipped[] = $post_ID;
   561 			continue;
   582 			continue;
   562 		}
   583 		}
   563 
   584 
   564 		if ( wp_check_post_lock( $post_ID ) ) {
   585 		if ( wp_check_post_lock( $post_ID ) ) {
   583 			}
   604 			}
   584 
   605 
   585 			$post_data['tax_input'][ $tax_name ] = array_merge( $current_terms, $new_terms );
   606 			$post_data['tax_input'][ $tax_name ] = array_merge( $current_terms, $new_terms );
   586 		}
   607 		}
   587 
   608 
   588 		if ( isset( $new_cats ) && in_array( 'category', $tax_names ) ) {
   609 		if ( isset( $new_cats ) && in_array( 'category', $tax_names, true ) ) {
   589 			$cats                       = (array) wp_get_post_categories( $post_ID );
   610 			$cats                       = (array) wp_get_post_categories( $post_ID );
   590 			$post_data['post_category'] = array_unique( array_merge( $cats, $new_cats ) );
   611 			$post_data['post_category'] = array_unique( array_merge( $cats, $new_cats ) );
   591 			unset( $post_data['tax_input']['category'] );
   612 			unset( $post_data['tax_input']['category'] );
   592 		}
   613 		}
   593 
   614 
   616 		unset( $post_data['tax_input']['post_format'] );
   637 		unset( $post_data['tax_input']['post_format'] );
   617 
   638 
   618 		$updated[] = wp_update_post( $post_data );
   639 		$updated[] = wp_update_post( $post_data );
   619 
   640 
   620 		if ( isset( $post_data['sticky'] ) && current_user_can( $ptype->cap->edit_others_posts ) ) {
   641 		if ( isset( $post_data['sticky'] ) && current_user_can( $ptype->cap->edit_others_posts ) ) {
   621 			if ( 'sticky' == $post_data['sticky'] ) {
   642 			if ( 'sticky' === $post_data['sticky'] ) {
   622 				stick_post( $post_ID );
   643 				stick_post( $post_ID );
   623 			} else {
   644 			} else {
   624 				unstick_post( $post_ID );
   645 				unstick_post( $post_ID );
   625 			}
   646 			}
   626 		}
   647 		}
   669 		$post    = get_post( $post_id );
   690 		$post    = get_post( $post_id );
   670 		if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post->post_type, 'post-formats' ) && get_option( 'default_post_format' ) ) {
   691 		if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post->post_type, 'post-formats' ) && get_option( 'default_post_format' ) ) {
   671 			set_post_format( $post, get_option( 'default_post_format' ) );
   692 			set_post_format( $post, get_option( 'default_post_format' ) );
   672 		}
   693 		}
   673 
   694 
   674 		// Schedule auto-draft cleanup
   695 		// Schedule auto-draft cleanup.
   675 		if ( ! wp_next_scheduled( 'wp_scheduled_auto_draft_delete' ) ) {
   696 		if ( ! wp_next_scheduled( 'wp_scheduled_auto_draft_delete' ) ) {
   676 			wp_schedule_event( time(), 'daily', 'wp_scheduled_auto_draft_delete' );
   697 			wp_schedule_event( time(), 'daily', 'wp_scheduled_auto_draft_delete' );
   677 		}
   698 		}
   678 	} else {
   699 	} else {
   679 		$post                 = new stdClass;
   700 		$post                 = new stdClass;
   797 	} else {
   818 	} else {
   798 		$ptype = get_post_type_object( 'post' );
   819 		$ptype = get_post_type_object( 'post' );
   799 	}
   820 	}
   800 
   821 
   801 	if ( ! current_user_can( $ptype->cap->edit_posts ) ) {
   822 	if ( ! current_user_can( $ptype->cap->edit_posts ) ) {
   802 		if ( 'page' == $ptype->name ) {
   823 		if ( 'page' === $ptype->name ) {
   803 			return new WP_Error( 'edit_pages', __( 'Sorry, you are not allowed to create pages on this site.' ) );
   824 			return new WP_Error( 'edit_pages', __( 'Sorry, you are not allowed to create pages on this site.' ) );
   804 		} else {
   825 		} else {
   805 			return new WP_Error( 'edit_posts', __( 'Sorry, you are not allowed to create posts or drafts on this site.' ) );
   826 			return new WP_Error( 'edit_posts', __( 'Sorry, you are not allowed to create posts or drafts on this site.' ) );
   806 		}
   827 		}
   807 	}
   828 	}
   809 	$_POST['post_mime_type'] = '';
   830 	$_POST['post_mime_type'] = '';
   810 
   831 
   811 	// Clear out any data in internal vars.
   832 	// Clear out any data in internal vars.
   812 	unset( $_POST['filter'] );
   833 	unset( $_POST['filter'] );
   813 
   834 
   814 	// Edit don't write if we have a post id.
   835 	// Edit, don't write, if we have a post ID.
   815 	if ( isset( $_POST['post_ID'] ) ) {
   836 	if ( isset( $_POST['post_ID'] ) ) {
   816 		return edit_post();
   837 		return edit_post();
   817 	}
   838 	}
   818 
   839 
   819 	if ( isset( $_POST['visibility'] ) ) {
   840 	if ( isset( $_POST['visibility'] ) ) {
   850 
   871 
   851 	add_meta( $post_ID );
   872 	add_meta( $post_ID );
   852 
   873 
   853 	add_post_meta( $post_ID, '_edit_last', $GLOBALS['current_user']->ID );
   874 	add_post_meta( $post_ID, '_edit_last', $GLOBALS['current_user']->ID );
   854 
   875 
   855 	// Now that we have an ID we can fix any attachment anchor hrefs
   876 	// Now that we have an ID we can fix any attachment anchor hrefs.
   856 	_fix_attachment_links( $post_ID );
   877 	_fix_attachment_links( $post_ID );
   857 
   878 
   858 	wp_set_post_lock( $post_ID );
   879 	wp_set_post_lock( $post_ID );
   859 
   880 
   860 	return $post_ID;
   881 	return $post_ID;
   875 		return $result;
   896 		return $result;
   876 	}
   897 	}
   877 }
   898 }
   878 
   899 
   879 //
   900 //
   880 // Post Meta
   901 // Post Meta.
   881 //
   902 //
   882 
   903 
   883 /**
   904 /**
   884  * Add post meta data defined in $_POST superglobal for post with given ID.
   905  * Add post meta data defined in $_POST superglobal for post with given ID.
   885  *
   906  *
   896 	$metavalue     = isset( $_POST['metavalue'] ) ? $_POST['metavalue'] : '';
   917 	$metavalue     = isset( $_POST['metavalue'] ) ? $_POST['metavalue'] : '';
   897 	if ( is_string( $metavalue ) ) {
   918 	if ( is_string( $metavalue ) ) {
   898 		$metavalue = trim( $metavalue );
   919 		$metavalue = trim( $metavalue );
   899 	}
   920 	}
   900 
   921 
   901 	if ( ( ( '#NONE#' != $metakeyselect ) && ! empty( $metakeyselect ) ) || ! empty( $metakeyinput ) ) {
   922 	if ( ( ( '#NONE#' !== $metakeyselect ) && ! empty( $metakeyselect ) ) || ! empty( $metakeyinput ) ) {
   902 		/*
   923 		/*
   903 		 * We have a key/value pair. If both the select and the input
   924 		 * We have a key/value pair. If both the select and the input
   904 		 * for the key have data, the input takes precedence.
   925 		 * for the key have data, the input takes precedence.
   905 		 */
   926 		 */
   906 		if ( '#NONE#' != $metakeyselect ) {
   927 		if ( '#NONE#' !== $metakeyselect ) {
   907 			$metakey = $metakeyselect;
   928 			$metakey = $metakeyselect;
   908 		}
   929 		}
   909 
   930 
   910 		if ( $metakeyinput ) {
   931 		if ( $metakeyinput ) {
   911 			$metakey = $metakeyinput; // default
   932 			$metakey = $metakeyinput; // Default.
   912 		}
   933 		}
   913 
   934 
   914 		if ( is_protected_meta( $metakey, 'post' ) || ! current_user_can( 'add_post_meta', $post_ID, $metakey ) ) {
   935 		if ( is_protected_meta( $metakey, 'post' ) || ! current_user_can( 'add_post_meta', $post_ID, $metakey ) ) {
   915 			return false;
   936 			return false;
   916 		}
   937 		}
   919 
   940 
   920 		return add_post_meta( $post_ID, $metakey, $metavalue );
   941 		return add_post_meta( $post_ID, $metakey, $metavalue );
   921 	}
   942 	}
   922 
   943 
   923 	return false;
   944 	return false;
   924 } // add_meta
   945 }
   925 
   946 
   926 /**
   947 /**
   927  * Delete post meta data by meta ID.
   948  * Delete post meta data by meta ID.
   928  *
   949  *
   929  * @since 1.2.0
   950  * @since 1.2.0
  1010 
  1031 
  1011 	return update_metadata_by_mid( 'post', $meta_id, $meta_value, $meta_key );
  1032 	return update_metadata_by_mid( 'post', $meta_id, $meta_value, $meta_key );
  1012 }
  1033 }
  1013 
  1034 
  1014 //
  1035 //
  1015 // Private
  1036 // Private.
  1016 //
  1037 //
  1017 
  1038 
  1018 /**
  1039 /**
  1019  * Replace hrefs of attachment anchors with up-to-date permalinks.
  1040  * Replace hrefs of attachment anchors with up-to-date permalinks.
  1020  *
  1041  *
  1027 function _fix_attachment_links( $post ) {
  1048 function _fix_attachment_links( $post ) {
  1028 	$post    = get_post( $post, ARRAY_A );
  1049 	$post    = get_post( $post, ARRAY_A );
  1029 	$content = $post['post_content'];
  1050 	$content = $post['post_content'];
  1030 
  1051 
  1031 	// Don't run if no pretty permalinks or post is not published, scheduled, or privately published.
  1052 	// Don't run if no pretty permalinks or post is not published, scheduled, or privately published.
  1032 	if ( ! get_option( 'permalink_structure' ) || ! in_array( $post['post_status'], array( 'publish', 'future', 'private' ) ) ) {
  1053 	if ( ! get_option( 'permalink_structure' ) || ! in_array( $post['post_status'], array( 'publish', 'future', 'private' ), true ) ) {
  1033 		return;
  1054 		return;
  1034 	}
  1055 	}
  1035 
  1056 
  1036 	// Short if there aren't any links or no '?attachment_id=' strings (strpos cannot be zero)
  1057 	// Short if there aren't any links or no '?attachment_id=' strings (strpos cannot be zero).
  1037 	if ( ! strpos( $content, '?attachment_id=' ) || ! preg_match_all( '/<a ([^>]+)>[\s\S]+?<\/a>/', $content, $link_matches ) ) {
  1058 	if ( ! strpos( $content, '?attachment_id=' ) || ! preg_match_all( '/<a ([^>]+)>[\s\S]+?<\/a>/', $content, $link_matches ) ) {
  1038 		return;
  1059 		return;
  1039 	}
  1060 	}
  1040 
  1061 
  1041 	$site_url = get_bloginfo( 'url' );
  1062 	$site_url = get_bloginfo( 'url' );
  1042 	$site_url = substr( $site_url, (int) strpos( $site_url, '://' ) ); // remove the http(s)
  1063 	$site_url = substr( $site_url, (int) strpos( $site_url, '://' ) ); // Remove the http(s).
  1043 	$replace  = '';
  1064 	$replace  = '';
  1044 
  1065 
  1045 	foreach ( $link_matches[1] as $key => $value ) {
  1066 	foreach ( $link_matches[1] as $key => $value ) {
  1046 		if ( ! strpos( $value, '?attachment_id=' ) || ! strpos( $value, 'wp-att-' )
  1067 		if ( ! strpos( $value, '?attachment_id=' ) || ! strpos( $value, 'wp-att-' )
  1047 			|| ! preg_match( '/href=(["\'])[^"\']*\?attachment_id=(\d+)[^"\']*\\1/', $value, $url_match )
  1068 			|| ! preg_match( '/href=(["\'])[^"\']*\?attachment_id=(\d+)[^"\']*\\1/', $value, $url_match )
  1048 			|| ! preg_match( '/rel=["\'][^"\']*wp-att-(\d+)/', $value, $rel_match ) ) {
  1069 			|| ! preg_match( '/rel=["\'][^"\']*wp-att-(\d+)/', $value, $rel_match ) ) {
  1049 				continue;
  1070 				continue;
  1050 		}
  1071 		}
  1051 
  1072 
  1052 		$quote  = $url_match[1]; // the quote (single or double)
  1073 		$quote  = $url_match[1]; // The quote (single or double).
  1053 		$url_id = (int) $url_match[2];
  1074 		$url_id = (int) $url_match[2];
  1054 		$rel_id = (int) $rel_match[1];
  1075 		$rel_id = (int) $rel_match[1];
  1055 
  1076 
  1056 		if ( ! $url_id || ! $rel_id || $url_id != $rel_id || strpos( $url_match[0], $site_url ) === false ) {
  1077 		if ( ! $url_id || ! $rel_id || $url_id != $rel_id || strpos( $url_match[0], $site_url ) === false ) {
  1057 			continue;
  1078 			continue;
  1075 /**
  1096 /**
  1076  * Get all the possible statuses for a post_type
  1097  * Get all the possible statuses for a post_type
  1077  *
  1098  *
  1078  * @since 2.5.0
  1099  * @since 2.5.0
  1079  *
  1100  *
  1080  * @param string $type The post_type you want the statuses for
  1101  * @param string $type The post_type you want the statuses for. Default 'post'.
  1081  * @return array As array of all the statuses for the supplied post type
  1102  * @return string[] An array of all the statuses for the supplied post type.
  1082  */
  1103  */
  1083 function get_available_post_statuses( $type = 'post' ) {
  1104 function get_available_post_statuses( $type = 'post' ) {
  1084 	$stati = wp_count_posts( $type );
  1105 	$stati = wp_count_posts( $type );
  1085 
  1106 
  1086 	return array_keys( get_object_vars( $stati ) );
  1107 	return array_keys( get_object_vars( $stati ) );
  1100 	}
  1121 	}
  1101 	$q['m']     = isset( $q['m'] ) ? (int) $q['m'] : 0;
  1122 	$q['m']     = isset( $q['m'] ) ? (int) $q['m'] : 0;
  1102 	$q['cat']   = isset( $q['cat'] ) ? (int) $q['cat'] : 0;
  1123 	$q['cat']   = isset( $q['cat'] ) ? (int) $q['cat'] : 0;
  1103 	$post_stati = get_post_stati();
  1124 	$post_stati = get_post_stati();
  1104 
  1125 
  1105 	if ( isset( $q['post_type'] ) && in_array( $q['post_type'], get_post_types() ) ) {
  1126 	if ( isset( $q['post_type'] ) && in_array( $q['post_type'], get_post_types(), true ) ) {
  1106 		$post_type = $q['post_type'];
  1127 		$post_type = $q['post_type'];
  1107 	} else {
  1128 	} else {
  1108 		$post_type = 'post';
  1129 		$post_type = 'post';
  1109 	}
  1130 	}
  1110 
  1131 
  1111 	$avail_post_stati = get_available_post_statuses( $post_type );
  1132 	$avail_post_stati = get_available_post_statuses( $post_type );
  1112 	$post_status      = '';
  1133 	$post_status      = '';
  1113 	$perm             = '';
  1134 	$perm             = '';
  1114 
  1135 
  1115 	if ( isset( $q['post_status'] ) && in_array( $q['post_status'], $post_stati ) ) {
  1136 	if ( isset( $q['post_status'] ) && in_array( $q['post_status'], $post_stati, true ) ) {
  1116 		$post_status = $q['post_status'];
  1137 		$post_status = $q['post_status'];
  1117 		$perm        = 'readable';
  1138 		$perm        = 'readable';
  1118 	}
  1139 	}
  1119 
  1140 
  1120 	$orderby = '';
  1141 	$orderby = '';
  1121 
  1142 
  1122 	if ( isset( $q['orderby'] ) ) {
  1143 	if ( isset( $q['orderby'] ) ) {
  1123 		$orderby = $q['orderby'];
  1144 		$orderby = $q['orderby'];
  1124 	} elseif ( isset( $q['post_status'] ) && in_array( $q['post_status'], array( 'pending', 'draft' ) ) ) {
  1145 	} elseif ( isset( $q['post_status'] ) && in_array( $q['post_status'], array( 'pending', 'draft' ), true ) ) {
  1125 		$orderby = 'modified';
  1146 		$orderby = 'modified';
  1126 	}
  1147 	}
  1127 
  1148 
  1128 	$order = '';
  1149 	$order = '';
  1129 
  1150 
  1130 	if ( isset( $q['order'] ) ) {
  1151 	if ( isset( $q['order'] ) ) {
  1131 		$order = $q['order'];
  1152 		$order = $q['order'];
  1132 	} elseif ( isset( $q['post_status'] ) && 'pending' == $q['post_status'] ) {
  1153 	} elseif ( isset( $q['post_status'] ) && 'pending' === $q['post_status'] ) {
  1133 		$order = 'ASC';
  1154 		$order = 'ASC';
  1134 	}
  1155 	}
  1135 
  1156 
  1136 	$per_page       = "edit_{$post_type}_per_page";
  1157 	$per_page       = "edit_{$post_type}_per_page";
  1137 	$posts_per_page = (int) get_user_option( $per_page );
  1158 	$posts_per_page = (int) get_user_option( $per_page );
  1204 	$states         = 'inherit';
  1225 	$states         = 'inherit';
  1205 	if ( current_user_can( $post_type->cap->read_private_posts ) ) {
  1226 	if ( current_user_can( $post_type->cap->read_private_posts ) ) {
  1206 		$states .= ',private';
  1227 		$states .= ',private';
  1207 	}
  1228 	}
  1208 
  1229 
  1209 	$q['post_status'] = isset( $q['status'] ) && 'trash' == $q['status'] ? 'trash' : $states;
  1230 	$q['post_status'] = isset( $q['status'] ) && 'trash' === $q['status'] ? 'trash' : $states;
  1210 	$q['post_status'] = isset( $q['attachment-filter'] ) && 'trash' == $q['attachment-filter'] ? 'trash' : $states;
  1231 	$q['post_status'] = isset( $q['attachment-filter'] ) && 'trash' === $q['attachment-filter'] ? 'trash' : $states;
  1211 
  1232 
  1212 	$media_per_page = (int) get_user_option( 'upload_per_page' );
  1233 	$media_per_page = (int) get_user_option( 'upload_per_page' );
  1213 	if ( empty( $media_per_page ) || $media_per_page < 1 ) {
  1234 	if ( empty( $media_per_page ) || $media_per_page < 1 ) {
  1214 		$media_per_page = 20;
  1235 		$media_per_page = 20;
  1215 	}
  1236 	}
  1227 	if ( isset( $q['post_mime_type'] ) && ! array_intersect( (array) $q['post_mime_type'], array_keys( $post_mime_types ) ) ) {
  1248 	if ( isset( $q['post_mime_type'] ) && ! array_intersect( (array) $q['post_mime_type'], array_keys( $post_mime_types ) ) ) {
  1228 		unset( $q['post_mime_type'] );
  1249 		unset( $q['post_mime_type'] );
  1229 	}
  1250 	}
  1230 
  1251 
  1231 	foreach ( array_keys( $post_mime_types ) as $type ) {
  1252 	foreach ( array_keys( $post_mime_types ) as $type ) {
  1232 		if ( isset( $q['attachment-filter'] ) && "post_mime_type:$type" == $q['attachment-filter'] ) {
  1253 		if ( isset( $q['attachment-filter'] ) && "post_mime_type:$type" === $q['attachment-filter'] ) {
  1233 			$q['post_mime_type'] = $type;
  1254 			$q['post_mime_type'] = $type;
  1234 			break;
  1255 			break;
  1235 		}
  1256 		}
  1236 	}
  1257 	}
  1237 
  1258 
  1238 	if ( isset( $q['detached'] ) || ( isset( $q['attachment-filter'] ) && 'detached' == $q['attachment-filter'] ) ) {
  1259 	if ( isset( $q['detached'] ) || ( isset( $q['attachment-filter'] ) && 'detached' === $q['attachment-filter'] ) ) {
  1239 		$q['post_parent'] = 0;
  1260 		$q['post_parent'] = 0;
  1240 	}
  1261 	}
  1241 
  1262 
  1242 	if ( isset( $q['mine'] ) || ( isset( $q['attachment-filter'] ) && 'mine' == $q['attachment-filter'] ) ) {
  1263 	if ( isset( $q['mine'] ) || ( isset( $q['attachment-filter'] ) && 'mine' === $q['attachment-filter'] ) ) {
  1243 		$q['author'] = get_current_user_id();
  1264 		$q['author'] = get_current_user_id();
  1244 	}
  1265 	}
  1245 
  1266 
  1246 	// Filter query clauses to include filenames.
  1267 	// Filter query clauses to include filenames.
  1247 	if ( isset( $q['s'] ) ) {
  1268 	if ( isset( $q['s'] ) ) {
  1279  * @return string Space-separated string of class names.
  1300  * @return string Space-separated string of class names.
  1280  */
  1301  */
  1281 function postbox_classes( $box_id, $screen_id ) {
  1302 function postbox_classes( $box_id, $screen_id ) {
  1282 	if ( isset( $_GET['edit'] ) && $_GET['edit'] == $box_id ) {
  1303 	if ( isset( $_GET['edit'] ) && $_GET['edit'] == $box_id ) {
  1283 		$classes = array( '' );
  1304 		$classes = array( '' );
  1284 	} elseif ( $closed = get_user_option( 'closedpostboxes_' . $screen_id ) ) {
  1305 	} elseif ( get_user_option( 'closedpostboxes_' . $screen_id ) ) {
       
  1306 		$closed = get_user_option( 'closedpostboxes_' . $screen_id );
  1285 		if ( ! is_array( $closed ) ) {
  1307 		if ( ! is_array( $closed ) ) {
  1286 			$classes = array( '' );
  1308 			$classes = array( '' );
  1287 		} else {
  1309 		} else {
  1288 			$classes = in_array( $box_id, $closed ) ? array( 'closed' ) : array( '' );
  1310 			$classes = in_array( $box_id, $closed, true ) ? array( 'closed' ) : array( '' );
  1289 		}
  1311 		}
  1290 	} else {
  1312 	} else {
  1291 		$classes = array( '' );
  1313 		$classes = array( '' );
  1292 	}
  1314 	}
  1293 
  1315 
  1311  * @since 2.5.0
  1333  * @since 2.5.0
  1312  *
  1334  *
  1313  * @param int    $id    Post ID or post object.
  1335  * @param int    $id    Post ID or post object.
  1314  * @param string $title Optional. Title to override the post's current title when generating the post name. Default null.
  1336  * @param string $title Optional. Title to override the post's current title when generating the post name. Default null.
  1315  * @param string $name  Optional. Name to override the post name. Default null.
  1337  * @param string $name  Optional. Name to override the post name. Default null.
  1316  * @return array Array containing the sample permalink with placeholder for the post name, and the post name.
  1338  * @return array {
       
  1339  *     Array containing the sample permalink with placeholder for the post name, and the post name.
       
  1340  *
       
  1341  *     @type string $0 The permalink with placeholder for the post name.
       
  1342  *     @type string $1 The post name.
       
  1343  * }
  1317  */
  1344  */
  1318 function get_sample_permalink( $id, $title = null, $name = null ) {
  1345 function get_sample_permalink( $id, $title = null, $name = null ) {
  1319 	$post = get_post( $id );
  1346 	$post = get_post( $id );
  1320 	if ( ! $post ) {
  1347 	if ( ! $post ) {
  1321 		return array( '', '' );
  1348 		return array( '', '' );
  1326 	$original_status = $post->post_status;
  1353 	$original_status = $post->post_status;
  1327 	$original_date   = $post->post_date;
  1354 	$original_date   = $post->post_date;
  1328 	$original_name   = $post->post_name;
  1355 	$original_name   = $post->post_name;
  1329 
  1356 
  1330 	// Hack: get_permalink() would return ugly permalink for drafts, so we will fake that our post is published.
  1357 	// Hack: get_permalink() would return ugly permalink for drafts, so we will fake that our post is published.
  1331 	if ( in_array( $post->post_status, array( 'draft', 'pending', 'future' ) ) ) {
  1358 	if ( in_array( $post->post_status, array( 'draft', 'pending', 'future' ), true ) ) {
  1332 		$post->post_status = 'publish';
  1359 		$post->post_status = 'publish';
  1333 		$post->post_name   = sanitize_title( $post->post_name ? $post->post_name : $post->post_title, $post->ID );
  1360 		$post->post_name   = sanitize_title( $post->post_name ? $post->post_name : $post->post_title, $post->ID );
  1334 	}
  1361 	}
  1335 
  1362 
  1336 	// If the user wants to set a new name -- override the current one
  1363 	// If the user wants to set a new name -- override the current one.
  1337 	// Note: if empty name is supplied -- use the title instead, see #6072
  1364 	// Note: if empty name is supplied -- use the title instead, see #6072.
  1338 	if ( ! is_null( $name ) ) {
  1365 	if ( ! is_null( $name ) ) {
  1339 		$post->post_name = sanitize_title( $name ? $name : $title, $post->ID );
  1366 		$post->post_name = sanitize_title( $name ? $name : $title, $post->ID );
  1340 	}
  1367 	}
  1341 
  1368 
  1342 	$post->post_name = wp_unique_post_slug( $post->post_name, $post->ID, $post->post_status, $post->post_type, $post->post_parent );
  1369 	$post->post_name = wp_unique_post_slug( $post->post_name, $post->ID, $post->post_status, $post->post_type, $post->post_parent );
  1343 
  1370 
  1344 	$post->filter = 'sample';
  1371 	$post->filter = 'sample';
  1345 
  1372 
  1346 	$permalink = get_permalink( $post, true );
  1373 	$permalink = get_permalink( $post, true );
  1347 
  1374 
  1348 	// Replace custom post_type Token with generic pagename token for ease of use.
  1375 	// Replace custom post_type token with generic pagename token for ease of use.
  1349 	$permalink = str_replace( "%$post->post_type%", '%pagename%', $permalink );
  1376 	$permalink = str_replace( "%$post->post_type%", '%pagename%', $permalink );
  1350 
  1377 
  1351 	// Handle page hierarchy
  1378 	// Handle page hierarchy.
  1352 	if ( $ptype->hierarchical ) {
  1379 	if ( $ptype->hierarchical ) {
  1353 		$uri = get_page_uri( $post );
  1380 		$uri = get_page_uri( $post );
  1354 		if ( $uri ) {
  1381 		if ( $uri ) {
  1355 			$uri = untrailingslashit( $uri );
  1382 			$uri = untrailingslashit( $uri );
  1356 			$uri = strrev( stristr( strrev( $uri ), '/' ) );
  1383 			$uri = strrev( stristr( strrev( $uri ), '/' ) );
  1375 	/**
  1402 	/**
  1376 	 * Filters the sample permalink.
  1403 	 * Filters the sample permalink.
  1377 	 *
  1404 	 *
  1378 	 * @since 4.4.0
  1405 	 * @since 4.4.0
  1379 	 *
  1406 	 *
  1380 	 * @param array   $permalink Array containing the sample permalink with placeholder for the post name, and the post name.
  1407 	 * @param array   $permalink {
       
  1408 	 *     Array containing the sample permalink with placeholder for the post name, and the post name.
       
  1409 	 *
       
  1410 	 *     @type string $0 The permalink with placeholder for the post name.
       
  1411 	 *     @type string $1 The post name.
       
  1412 	 * }
  1381 	 * @param int     $post_id   Post ID.
  1413 	 * @param int     $post_id   Post ID.
  1382 	 * @param string  $title     Post title.
  1414 	 * @param string  $title     Post title.
  1383 	 * @param string  $name      Post name (slug).
  1415 	 * @param string  $name      Post name (slug).
  1384 	 * @param WP_Post $post      Post object.
  1416 	 * @param WP_Post $post      Post object.
  1385 	 */
  1417 	 */
  1413 			$preview_target = " target='wp-preview-{$post->ID}'";
  1445 			$preview_target = " target='wp-preview-{$post->ID}'";
  1414 		} else {
  1446 		} else {
  1415 			if ( 'publish' === $post->post_status || 'attachment' === $post->post_type ) {
  1447 			if ( 'publish' === $post->post_status || 'attachment' === $post->post_type ) {
  1416 				$view_link = get_permalink( $post );
  1448 				$view_link = get_permalink( $post );
  1417 			} else {
  1449 			} else {
  1418 				// Allow non-published (private, future) to be viewed at a pretty permalink, in case $post->post_name is set
  1450 				// Allow non-published (private, future) to be viewed at a pretty permalink, in case $post->post_name is set.
  1419 				$view_link = str_replace( array( '%pagename%', '%postname%' ), $post->post_name, $permalink );
  1451 				$view_link = str_replace( array( '%pagename%', '%postname%' ), $post->post_name, $permalink );
  1420 			}
  1452 			}
  1421 		}
  1453 		}
  1422 	}
  1454 	}
  1423 
  1455 
  1424 	// Permalinks without a post/page name placeholder don't have anything to edit
  1456 	// Permalinks without a post/page name placeholder don't have anything to edit.
  1425 	if ( false === strpos( $permalink, '%postname%' ) && false === strpos( $permalink, '%pagename%' ) ) {
  1457 	if ( false === strpos( $permalink, '%postname%' ) && false === strpos( $permalink, '%pagename%' ) ) {
  1426 		$return = '<strong>' . __( 'Permalink:' ) . "</strong>\n";
  1458 		$return = '<strong>' . __( 'Permalink:' ) . "</strong>\n";
  1427 
  1459 
  1428 		if ( false !== $view_link ) {
  1460 		if ( false !== $view_link ) {
  1429 			$display_link = urldecode( $view_link );
  1461 			$display_link = urldecode( $view_link );
  1430 			$return      .= '<a id="sample-permalink" href="' . esc_url( $view_link ) . '"' . $preview_target . '>' . esc_html( $display_link ) . "</a>\n";
  1462 			$return      .= '<a id="sample-permalink" href="' . esc_url( $view_link ) . '"' . $preview_target . '>' . esc_html( $display_link ) . "</a>\n";
  1431 		} else {
  1463 		} else {
  1432 			$return .= '<span id="sample-permalink">' . $permalink . "</span>\n";
  1464 			$return .= '<span id="sample-permalink">' . $permalink . "</span>\n";
  1433 		}
  1465 		}
  1434 
  1466 
  1435 		// Encourage a pretty permalink setting
  1467 		// Encourage a pretty permalink setting.
  1436 		if ( '' == get_option( 'permalink_structure' ) && current_user_can( 'manage_options' ) && ! ( 'page' == get_option( 'show_on_front' ) && $id == get_option( 'page_on_front' ) ) ) {
  1468 		if ( ! get_option( 'permalink_structure' ) && current_user_can( 'manage_options' )
       
  1469 			&& ! ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $id )
       
  1470 		) {
  1437 			$return .= '<span id="change-permalinks"><a href="options-permalink.php" class="button button-small" target="_blank">' . __( 'Change Permalinks' ) . "</a></span>\n";
  1471 			$return .= '<span id="change-permalinks"><a href="options-permalink.php" class="button button-small" target="_blank">' . __( 'Change Permalinks' ) . "</a></span>\n";
  1438 		}
  1472 		}
  1439 	} else {
  1473 	} else {
  1440 		if ( mb_strlen( $post_name ) > 34 ) {
  1474 		if ( mb_strlen( $post_name ) > 34 ) {
  1441 			$post_name_abridged = mb_substr( $post_name, 0, 16 ) . '&hellip;' . mb_substr( $post_name, -16 );
  1475 			$post_name_abridged = mb_substr( $post_name, 0, 16 ) . '&hellip;' . mb_substr( $post_name, -16 );
  1469 
  1503 
  1470 	return $return;
  1504 	return $return;
  1471 }
  1505 }
  1472 
  1506 
  1473 /**
  1507 /**
  1474  * Output HTML for the post thumbnail meta-box.
  1508  * Returns HTML for the post thumbnail meta box.
  1475  *
  1509  *
  1476  * @since 2.9.0
  1510  * @since 2.9.0
  1477  *
  1511  *
  1478  * @param int $thumbnail_id ID of the attachment used for thumbnail
  1512  * @param int         $thumbnail_id ID of the attachment used for thumbnail
  1479  * @param mixed $post The post ID or object associated with the thumbnail, defaults to global $post.
  1513  * @param int|WP_Post $post         Optional. The post ID or object associated with the thumbnail, defaults to global $post.
  1480  * @return string html
  1514  * @return string The post thumbnail HTML.
  1481  */
  1515  */
  1482 function _wp_post_thumbnail_html( $thumbnail_id = null, $post = null ) {
  1516 function _wp_post_thumbnail_html( $thumbnail_id = null, $post = null ) {
  1483 	$_wp_additional_image_sizes = wp_get_additional_image_sizes();
  1517 	$_wp_additional_image_sizes = wp_get_additional_image_sizes();
  1484 
  1518 
  1485 	$post               = get_post( $post );
  1519 	$post               = get_post( $post );
  1496 
  1530 
  1497 	if ( $thumbnail_id && get_post( $thumbnail_id ) ) {
  1531 	if ( $thumbnail_id && get_post( $thumbnail_id ) ) {
  1498 		$size = isset( $_wp_additional_image_sizes['post-thumbnail'] ) ? 'post-thumbnail' : array( 266, 266 );
  1532 		$size = isset( $_wp_additional_image_sizes['post-thumbnail'] ) ? 'post-thumbnail' : array( 266, 266 );
  1499 
  1533 
  1500 		/**
  1534 		/**
  1501 		 * Filters the size used to display the post thumbnail image in the 'Featured Image' meta box.
  1535 		 * Filters the size used to display the post thumbnail image in the 'Featured image' meta box.
  1502 		 *
  1536 		 *
  1503 		 * Note: When a theme adds 'post-thumbnail' support, a special 'post-thumbnail'
  1537 		 * Note: When a theme adds 'post-thumbnail' support, a special 'post-thumbnail'
  1504 		 * image size is registered, which differs from the 'thumbnail' image size
  1538 		 * image size is registered, which differs from the 'thumbnail' image size
  1505 		 * managed via the Settings > Media screen. See the `$size` parameter description
  1539 		 * managed via the Settings > Media screen. See the `$size` parameter description
  1506 		 * for more information on default values.
  1540 		 * for more information on default values.
  1554  * @param int $post_id ID of the post to check for editing.
  1588  * @param int $post_id ID of the post to check for editing.
  1555  * @return int|false ID of the user with lock. False if the post does not exist, post is not locked,
  1589  * @return int|false ID of the user with lock. False if the post does not exist, post is not locked,
  1556  *                   the user with lock does not exist, or the post is locked by current user.
  1590  *                   the user with lock does not exist, or the post is locked by current user.
  1557  */
  1591  */
  1558 function wp_check_post_lock( $post_id ) {
  1592 function wp_check_post_lock( $post_id ) {
  1559 	if ( ! $post = get_post( $post_id ) ) {
  1593 	$post = get_post( $post_id );
       
  1594 	if ( ! $post ) {
  1560 		return false;
  1595 		return false;
  1561 	}
  1596 	}
  1562 
  1597 
  1563 	if ( ! $lock = get_post_meta( $post->ID, '_edit_lock', true ) ) {
  1598 	$lock = get_post_meta( $post->ID, '_edit_lock', true );
       
  1599 	if ( ! $lock ) {
  1564 		return false;
  1600 		return false;
  1565 	}
  1601 	}
  1566 
  1602 
  1567 	$lock = explode( ':', $lock );
  1603 	$lock = explode( ':', $lock );
  1568 	$time = $lock[0];
  1604 	$time = $lock[0];
  1573 	}
  1609 	}
  1574 
  1610 
  1575 	/** This filter is documented in wp-admin/includes/ajax-actions.php */
  1611 	/** This filter is documented in wp-admin/includes/ajax-actions.php */
  1576 	$time_window = apply_filters( 'wp_check_post_lock_window', 150 );
  1612 	$time_window = apply_filters( 'wp_check_post_lock_window', 150 );
  1577 
  1613 
  1578 	if ( $time && $time > time() - $time_window && $user != get_current_user_id() ) {
  1614 	if ( $time && $time > time() - $time_window && get_current_user_id() != $user ) {
  1579 		return $user;
  1615 		return $user;
  1580 	}
  1616 	}
  1581 
  1617 
  1582 	return false;
  1618 	return false;
  1583 }
  1619 }
  1590  * @param int $post_id ID of the post being edited.
  1626  * @param int $post_id ID of the post being edited.
  1591  * @return array|false Array of the lock time and user ID. False if the post does not exist, or
  1627  * @return array|false Array of the lock time and user ID. False if the post does not exist, or
  1592  *                     there is no current user.
  1628  *                     there is no current user.
  1593  */
  1629  */
  1594 function wp_set_post_lock( $post_id ) {
  1630 function wp_set_post_lock( $post_id ) {
  1595 	if ( ! $post = get_post( $post_id ) ) {
  1631 	$post = get_post( $post_id );
       
  1632 	if ( ! $post ) {
  1596 		return false;
  1633 		return false;
  1597 	}
  1634 	}
  1598 
  1635 
  1599 	if ( 0 == ( $user_id = get_current_user_id() ) ) {
  1636 	$user_id = get_current_user_id();
       
  1637 	if ( 0 == $user_id ) {
  1600 		return false;
  1638 		return false;
  1601 	}
  1639 	}
  1602 
  1640 
  1603 	$now  = time();
  1641 	$now  = time();
  1604 	$lock = "$now:$user_id";
  1642 	$lock = "$now:$user_id";
  1610 
  1648 
  1611 /**
  1649 /**
  1612  * Outputs the HTML for the notice to say that someone else is editing or has taken over editing of this post.
  1650  * Outputs the HTML for the notice to say that someone else is editing or has taken over editing of this post.
  1613  *
  1651  *
  1614  * @since 2.8.5
  1652  * @since 2.8.5
  1615  * @return none
       
  1616  */
  1653  */
  1617 function _admin_notice_post_locked() {
  1654 function _admin_notice_post_locked() {
  1618 	if ( ! $post = get_post() ) {
  1655 	$post = get_post();
       
  1656 	if ( ! $post ) {
  1619 		return;
  1657 		return;
  1620 	}
  1658 	}
  1621 
  1659 
  1622 	$user = null;
  1660 	$user    = null;
  1623 	if ( $user_id = wp_check_post_lock( $post->ID ) ) {
  1661 	$user_id = wp_check_post_lock( $post->ID );
       
  1662 	if ( $user_id ) {
  1624 		$user = get_userdata( $user_id );
  1663 		$user = get_userdata( $user_id );
  1625 	}
  1664 	}
  1626 
  1665 
  1627 	if ( $user ) {
  1666 	if ( $user ) {
  1628 
       
  1629 		/**
  1667 		/**
  1630 		 * Filters whether to show the post locked dialog.
  1668 		 * Filters whether to show the post locked dialog.
  1631 		 *
  1669 		 *
  1632 		 * Returning a falsey value to the filter will short-circuit displaying the dialog.
  1670 		 * Returning false from the filter will prevent the dialog from being displayed.
  1633 		 *
  1671 		 *
  1634 		 * @since 3.6.0
  1672 		 * @since 3.6.0
  1635 		 *
  1673 		 *
  1636 		 * @param bool         $display Whether to display the dialog. Default true.
  1674 		 * @param bool    $display Whether to display the dialog. Default true.
  1637 		 * @param WP_Post      $post    Post object.
  1675 		 * @param WP_Post $post    Post object.
  1638 		 * @param WP_User|bool $user    WP_User object on success, false otherwise.
  1676 		 * @param WP_User $user    The user with the lock for the post.
  1639 		 */
  1677 		 */
  1640 		if ( ! apply_filters( 'show_post_locked_dialog', true, $post, $user ) ) {
  1678 		if ( ! apply_filters( 'show_post_locked_dialog', true, $post, $user ) ) {
  1641 			return;
  1679 			return;
  1642 		}
  1680 		}
  1643 
  1681 
  1644 		$locked = true;
  1682 		$locked = true;
  1645 	} else {
  1683 	} else {
  1646 		$locked = false;
  1684 		$locked = false;
  1647 	}
  1685 	}
  1648 
  1686 
  1649 	if ( $locked && ( $sendback = wp_get_referer() ) &&
  1687 	$sendback = wp_get_referer();
  1650 		false === strpos( $sendback, 'post.php' ) && false === strpos( $sendback, 'post-new.php' ) ) {
  1688 	if ( $locked && $sendback && false === strpos( $sendback, 'post.php' ) && false === strpos( $sendback, 'post-new.php' ) ) {
  1651 
  1689 
  1652 		$sendback_text = __( 'Go back' );
  1690 		$sendback_text = __( 'Go back' );
  1653 	} else {
  1691 	} else {
  1654 		$sendback = admin_url( 'edit.php' );
  1692 		$sendback = admin_url( 'edit.php' );
  1655 
  1693 
  1656 		if ( 'post' != $post->post_type ) {
  1694 		if ( 'post' !== $post->post_type ) {
  1657 			$sendback = add_query_arg( 'post_type', $post->post_type, $sendback );
  1695 			$sendback = add_query_arg( 'post_type', $post->post_type, $sendback );
  1658 		}
  1696 		}
  1659 
  1697 
  1660 		$sendback_text = get_post_type_object( $post->post_type )->labels->all_items;
  1698 		$sendback_text = get_post_type_object( $post->post_type )->labels->all_items;
  1661 	}
  1699 	}
  1669 	<?php
  1707 	<?php
  1670 
  1708 
  1671 	if ( $locked ) {
  1709 	if ( $locked ) {
  1672 		$query_args = array();
  1710 		$query_args = array();
  1673 		if ( get_post_type_object( $post->post_type )->public ) {
  1711 		if ( get_post_type_object( $post->post_type )->public ) {
  1674 			if ( 'publish' == $post->post_status || $user->ID != $post->post_author ) {
  1712 			if ( 'publish' === $post->post_status || $user->ID != $post->post_author ) {
  1675 				// Latest content is in autosave
  1713 				// Latest content is in autosave.
  1676 				$nonce                       = wp_create_nonce( 'post_preview_' . $post->ID );
  1714 				$nonce                       = wp_create_nonce( 'post_preview_' . $post->ID );
  1677 				$query_args['preview_id']    = $post->ID;
  1715 				$query_args['preview_id']    = $post->ID;
  1678 				$query_args['preview_nonce'] = $nonce;
  1716 				$query_args['preview_nonce'] = $nonce;
  1679 			}
  1717 			}
  1680 		}
  1718 		}
  1682 		$preview_link = get_preview_post_link( $post->ID, $query_args );
  1720 		$preview_link = get_preview_post_link( $post->ID, $query_args );
  1683 
  1721 
  1684 		/**
  1722 		/**
  1685 		 * Filters whether to allow the post lock to be overridden.
  1723 		 * Filters whether to allow the post lock to be overridden.
  1686 		 *
  1724 		 *
  1687 		 * Returning a falsey value to the filter will disable the ability
  1725 		 * Returning false from the filter will disable the ability
  1688 		 * to override the post lock.
  1726 		 * to override the post lock.
  1689 		 *
  1727 		 *
  1690 		 * @since 3.6.0
  1728 		 * @since 3.6.0
  1691 		 *
  1729 		 *
  1692 		 * @param bool    $override Whether to allow overriding post locks. Default true.
  1730 		 * @param bool    $override Whether to allow the post lock to be overridden. Default true.
  1693 		 * @param WP_Post $post     Post object.
  1731 		 * @param WP_Post $post     Post object.
  1694 		 * @param WP_User $user     User object.
  1732 		 * @param WP_User $user     The user with the lock for the post.
  1695 		 */
  1733 		 */
  1696 		$override = apply_filters( 'override_post_lock', true, $post, $user );
  1734 		$override = apply_filters( 'override_post_lock', true, $post, $user );
  1697 		$tab_last = $override ? '' : ' wp-tab-last';
  1735 		$tab_last = $override ? '' : ' wp-tab-last';
  1698 
  1736 
  1699 		?>
  1737 		?>
  1700 		<div class="post-locked-message">
  1738 		<div class="post-locked-message">
  1701 		<div class="post-locked-avatar"><?php echo get_avatar( $user->ID, 64 ); ?></div>
  1739 		<div class="post-locked-avatar"><?php echo get_avatar( $user->ID, 64 ); ?></div>
  1702 		<p class="currently-editing wp-tab-first" tabindex="0">
  1740 		<p class="currently-editing wp-tab-first" tabindex="0">
  1703 		<?php
  1741 		<?php
  1704 		if ( $override ) {
  1742 		if ( $override ) {
  1705 			/* translators: %s: user's display name */
  1743 			/* translators: %s: User's display name. */
  1706 			printf( __( '%s is already editing this post. Do you want to take over?' ), esc_html( $user->display_name ) );
  1744 			printf( __( '%s is already editing this post. Do you want to take over?' ), esc_html( $user->display_name ) );
  1707 		} else {
  1745 		} else {
  1708 			/* translators: %s: user's display name */
  1746 			/* translators: %s: User's display name. */
  1709 			printf( __( '%s is already editing this post.' ), esc_html( $user->display_name ) );
  1747 			printf( __( '%s is already editing this post.' ), esc_html( $user->display_name ) );
  1710 		}
  1748 		}
  1711 		?>
  1749 		?>
  1712 		</p>
  1750 		</p>
  1713 		<?php
  1751 		<?php
  1714 		/**
  1752 		/**
  1715 		 * Fires inside the post locked dialog before the buttons are displayed.
  1753 		 * Fires inside the post locked dialog before the buttons are displayed.
  1716 		 *
  1754 		 *
  1717 		 * @since 3.6.0
  1755 		 * @since 3.6.0
       
  1756 		 * @since 5.4.0 The $user parameter was added.
  1718 		 *
  1757 		 *
  1719 		 * @param WP_Post $post Post object.
  1758 		 * @param WP_Post $post Post object.
       
  1759 		 * @param WP_User $user The user with the lock for the post.
  1720 		 */
  1760 		 */
  1721 		do_action( 'post_locked_dialog', $post );
  1761 		do_action( 'post_locked_dialog', $post, $user );
  1722 		?>
  1762 		?>
  1723 		<p>
  1763 		<p>
  1724 		<a class="button" href="<?php echo esc_url( $sendback ); ?>"><?php echo $sendback_text; ?></a>
  1764 		<a class="button" href="<?php echo esc_url( $sendback ); ?>"><?php echo $sendback_text; ?></a>
  1725 		<?php if ( $preview_link ) { ?>
  1765 		<?php if ( $preview_link ) { ?>
  1726 		<a class="button<?php echo $tab_last; ?>" href="<?php echo esc_url( $preview_link ); ?>"><?php _e( 'Preview' ); ?></a>
  1766 		<a class="button<?php echo $tab_last; ?>" href="<?php echo esc_url( $preview_link ); ?>"><?php _e( 'Preview' ); ?></a>
  1727 			<?php
  1767 			<?php
  1728 		}
  1768 		}
  1729 
  1769 
  1730 		// Allow plugins to prevent some users overriding the post lock
  1770 		// Allow plugins to prevent some users overriding the post lock.
  1731 		if ( $override ) {
  1771 		if ( $override ) {
  1732 			?>
  1772 			?>
  1733 	<a class="button button-primary wp-tab-last" href="<?php echo esc_url( add_query_arg( 'get-post-lock', '1', wp_nonce_url( get_edit_post_link( $post->ID, 'url' ), 'lock-post_' . $post->ID ) ) ); ?>"><?php _e( 'Take over' ); ?></a>
  1773 	<a class="button button-primary wp-tab-last" href="<?php echo esc_url( add_query_arg( 'get-post-lock', '1', wp_nonce_url( get_edit_post_link( $post->ID, 'url' ), 'lock-post_' . $post->ID ) ) ); ?>"><?php _e( 'Take over' ); ?></a>
  1734 			<?php
  1774 			<?php
  1735 		}
  1775 		}
  1771 /**
  1811 /**
  1772  * Creates autosave data for the specified post from $_POST data.
  1812  * Creates autosave data for the specified post from $_POST data.
  1773  *
  1813  *
  1774  * @since 2.6.0
  1814  * @since 2.6.0
  1775  *
  1815  *
  1776  * @param mixed $post_data Associative array containing the post data or int post ID.
  1816  * @param array|int $post_data Associative array containing the post data or int post ID.
  1777  * @return mixed The autosave revision ID. WP_Error or 0 on error.
  1817  * @return int|WP_Error The autosave revision ID. WP_Error or 0 on error.
  1778  */
  1818  */
  1779 function wp_create_post_autosave( $post_data ) {
  1819 function wp_create_post_autosave( $post_data ) {
  1780 	if ( is_numeric( $post_data ) ) {
  1820 	if ( is_numeric( $post_data ) ) {
  1781 		$post_id   = $post_data;
  1821 		$post_id   = $post_data;
  1782 		$post_data = $_POST;
  1822 		$post_data = $_POST;
  1791 	$post_data = _wp_get_allowed_postdata( $post_data );
  1831 	$post_data = _wp_get_allowed_postdata( $post_data );
  1792 
  1832 
  1793 	$post_author = get_current_user_id();
  1833 	$post_author = get_current_user_id();
  1794 
  1834 
  1795 	// Store one autosave per author. If there is already an autosave, overwrite it.
  1835 	// Store one autosave per author. If there is already an autosave, overwrite it.
  1796 	if ( $old_autosave = wp_get_post_autosave( $post_id, $post_author ) ) {
  1836 	$old_autosave = wp_get_post_autosave( $post_id, $post_author );
       
  1837 	if ( $old_autosave ) {
  1797 		$new_autosave                = _wp_post_revision_data( $post_data, true );
  1838 		$new_autosave                = _wp_post_revision_data( $post_data, true );
  1798 		$new_autosave['ID']          = $old_autosave->ID;
  1839 		$new_autosave['ID']          = $old_autosave->ID;
  1799 		$new_autosave['post_author'] = $post_author;
  1840 		$new_autosave['post_author'] = $post_author;
  1800 
  1841 
       
  1842 		$post = get_post( $post_id );
       
  1843 
  1801 		// If the new autosave has the same content as the post, delete the autosave.
  1844 		// If the new autosave has the same content as the post, delete the autosave.
  1802 		$post                  = get_post( $post_id );
       
  1803 		$autosave_is_different = false;
  1845 		$autosave_is_different = false;
  1804 		foreach ( array_intersect( array_keys( $new_autosave ), array_keys( _wp_post_revision_fields( $post ) ) ) as $field ) {
  1846 		foreach ( array_intersect( array_keys( $new_autosave ), array_keys( _wp_post_revision_fields( $post ) ) ) as $field ) {
  1805 			if ( normalize_whitespace( $new_autosave[ $field ] ) != normalize_whitespace( $post->$field ) ) {
  1847 			if ( normalize_whitespace( $new_autosave[ $field ] ) !== normalize_whitespace( $post->$field ) ) {
  1806 				$autosave_is_different = true;
  1848 				$autosave_is_different = true;
  1807 				break;
  1849 				break;
  1808 			}
  1850 			}
  1809 		}
  1851 		}
  1810 
  1852 
  1826 	}
  1868 	}
  1827 
  1869 
  1828 	// _wp_put_post_revision() expects unescaped.
  1870 	// _wp_put_post_revision() expects unescaped.
  1829 	$post_data = wp_unslash( $post_data );
  1871 	$post_data = wp_unslash( $post_data );
  1830 
  1872 
  1831 	// Otherwise create the new autosave as a special post revision
  1873 	// Otherwise create the new autosave as a special post revision.
  1832 	return _wp_put_post_revision( $post_data, true );
  1874 	return _wp_put_post_revision( $post_data, true );
  1833 }
  1875 }
  1834 
  1876 
  1835 /**
  1877 /**
  1836  * Saves a draft or manually autosaves for the purpose of showing a post preview.
  1878  * Saves a draft or manually autosaves for the purpose of showing a post preview.
  1842 function post_preview() {
  1884 function post_preview() {
  1843 
  1885 
  1844 	$post_ID     = (int) $_POST['post_ID'];
  1886 	$post_ID     = (int) $_POST['post_ID'];
  1845 	$_POST['ID'] = $post_ID;
  1887 	$_POST['ID'] = $post_ID;
  1846 
  1888 
  1847 	if ( ! $post = get_post( $post_ID ) ) {
  1889 	$post = get_post( $post_ID );
       
  1890 	if ( ! $post ) {
  1848 		wp_die( __( 'Sorry, you are not allowed to edit this post.' ) );
  1891 		wp_die( __( 'Sorry, you are not allowed to edit this post.' ) );
  1849 	}
  1892 	}
  1850 
  1893 
  1851 	if ( ! current_user_can( 'edit_post', $post->ID ) ) {
  1894 	if ( ! current_user_can( 'edit_post', $post->ID ) ) {
  1852 		wp_die( __( 'Sorry, you are not allowed to edit this post.' ) );
  1895 		wp_die( __( 'Sorry, you are not allowed to edit this post.' ) );
  1853 	}
  1896 	}
  1854 
  1897 
  1855 	$is_autosave = false;
  1898 	$is_autosave = false;
  1856 
  1899 
  1857 	if ( ! wp_check_post_lock( $post->ID ) && get_current_user_id() == $post->post_author && ( 'draft' == $post->post_status || 'auto-draft' == $post->post_status ) ) {
  1900 	if ( ! wp_check_post_lock( $post->ID ) && get_current_user_id() == $post->post_author
       
  1901 		&& ( 'draft' === $post->post_status || 'auto-draft' === $post->post_status )
       
  1902 	) {
  1858 		$saved_post_id = edit_post();
  1903 		$saved_post_id = edit_post();
  1859 	} else {
  1904 	} else {
  1860 		$is_autosave = true;
  1905 		$is_autosave = true;
  1861 
  1906 
  1862 		if ( isset( $_POST['post_status'] ) && 'auto-draft' == $_POST['post_status'] ) {
  1907 		if ( isset( $_POST['post_status'] ) && 'auto-draft' === $_POST['post_status'] ) {
  1863 			$_POST['post_status'] = 'draft';
  1908 			$_POST['post_status'] = 'draft';
  1864 		}
  1909 		}
  1865 
  1910 
  1866 		$saved_post_id = wp_create_post_autosave( $post->ID );
  1911 		$saved_post_id = wp_create_post_autosave( $post->ID );
  1867 	}
  1912 	}
  1898  * @param array $post_data Associative array of the submitted post data.
  1943  * @param array $post_data Associative array of the submitted post data.
  1899  * @return mixed The value 0 or WP_Error on failure. The saved post ID on success.
  1944  * @return mixed The value 0 or WP_Error on failure. The saved post ID on success.
  1900  *               The ID can be the draft post_id or the autosave revision post_id.
  1945  *               The ID can be the draft post_id or the autosave revision post_id.
  1901  */
  1946  */
  1902 function wp_autosave( $post_data ) {
  1947 function wp_autosave( $post_data ) {
  1903 	// Back-compat
  1948 	// Back-compat.
  1904 	if ( ! defined( 'DOING_AUTOSAVE' ) ) {
  1949 	if ( ! defined( 'DOING_AUTOSAVE' ) ) {
  1905 		define( 'DOING_AUTOSAVE', true );
  1950 		define( 'DOING_AUTOSAVE', true );
  1906 	}
  1951 	}
  1907 
  1952 
  1908 	$post_id         = (int) $post_data['post_id'];
  1953 	$post_id              = (int) $post_data['post_id'];
  1909 	$post_data['ID'] = $post_data['post_ID'] = $post_id;
  1954 	$post_data['ID']      = $post_id;
       
  1955 	$post_data['post_ID'] = $post_id;
  1910 
  1956 
  1911 	if ( false === wp_verify_nonce( $post_data['_wpnonce'], 'update-post_' . $post_id ) ) {
  1957 	if ( false === wp_verify_nonce( $post_data['_wpnonce'], 'update-post_' . $post_id ) ) {
  1912 		return new WP_Error( 'invalid_nonce', __( 'Error while saving.' ) );
  1958 		return new WP_Error( 'invalid_nonce', __( 'Error while saving.' ) );
  1913 	}
  1959 	}
  1914 
  1960 
  1916 
  1962 
  1917 	if ( ! current_user_can( 'edit_post', $post->ID ) ) {
  1963 	if ( ! current_user_can( 'edit_post', $post->ID ) ) {
  1918 		return new WP_Error( 'edit_posts', __( 'Sorry, you are not allowed to edit this item.' ) );
  1964 		return new WP_Error( 'edit_posts', __( 'Sorry, you are not allowed to edit this item.' ) );
  1919 	}
  1965 	}
  1920 
  1966 
  1921 	if ( 'auto-draft' == $post->post_status ) {
  1967 	if ( 'auto-draft' === $post->post_status ) {
  1922 		$post_data['post_status'] = 'draft';
  1968 		$post_data['post_status'] = 'draft';
  1923 	}
  1969 	}
  1924 
  1970 
  1925 	if ( $post_data['post_type'] != 'page' && ! empty( $post_data['catslist'] ) ) {
  1971 	if ( 'page' !== $post_data['post_type'] && ! empty( $post_data['catslist'] ) ) {
  1926 		$post_data['post_category'] = explode( ',', $post_data['catslist'] );
  1972 		$post_data['post_category'] = explode( ',', $post_data['catslist'] );
  1927 	}
  1973 	}
  1928 
  1974 
  1929 	if ( ! wp_check_post_lock( $post->ID ) && get_current_user_id() == $post->post_author && ( 'auto-draft' == $post->post_status || 'draft' == $post->post_status ) ) {
  1975 	if ( ! wp_check_post_lock( $post->ID ) && get_current_user_id() == $post->post_author
  1930 		// Drafts and auto-drafts are just overwritten by autosave for the same user if the post is not locked
  1976 		&& ( 'auto-draft' === $post->post_status || 'draft' === $post->post_status )
       
  1977 	) {
       
  1978 		// Drafts and auto-drafts are just overwritten by autosave for the same user if the post is not locked.
  1931 		return edit_post( wp_slash( $post_data ) );
  1979 		return edit_post( wp_slash( $post_data ) );
  1932 	} else {
  1980 	} else {
  1933 		// Non drafts or other users drafts are not overwritten. The autosave is stored in a special post revision for each user.
  1981 		// Non-drafts or other users' drafts are not overwritten.
       
  1982 		// The autosave is stored in a special post revision for each user.
  1934 		return wp_create_post_autosave( wp_slash( $post_data ) );
  1983 		return wp_create_post_autosave( wp_slash( $post_data ) );
  1935 	}
  1984 	}
  1936 }
  1985 }
  1937 
  1986 
  1938 /**
  1987 /**
  1939  * Redirect to previous page.
  1988  * Redirect to previous page.
       
  1989  *
       
  1990  * @since 2.7.0
  1940  *
  1991  *
  1941  * @param int $post_id Optional. Post ID.
  1992  * @param int $post_id Optional. Post ID.
  1942  */
  1993  */
  1943 function redirect_post( $post_id = '' ) {
  1994 function redirect_post( $post_id = '' ) {
  1944 	if ( isset( $_POST['save'] ) || isset( $_POST['publish'] ) ) {
  1995 	if ( isset( $_POST['save'] ) || isset( $_POST['publish'] ) ) {
  1954 					break;
  2005 					break;
  1955 				default:
  2006 				default:
  1956 					$message = 6;
  2007 					$message = 6;
  1957 			}
  2008 			}
  1958 		} else {
  2009 		} else {
  1959 			$message = 'draft' == $status ? 10 : 1;
  2010 			$message = 'draft' === $status ? 10 : 1;
  1960 		}
  2011 		}
  1961 
  2012 
  1962 		$location = add_query_arg( 'message', $message, get_edit_post_link( $post_id, 'url' ) );
  2013 		$location = add_query_arg( 'message', $message, get_edit_post_link( $post_id, 'url' ) );
  1963 	} elseif ( isset( $_POST['addmeta'] ) && $_POST['addmeta'] ) {
  2014 	} elseif ( isset( $_POST['addmeta'] ) && $_POST['addmeta'] ) {
  1964 		$location = add_query_arg( 'message', 2, wp_get_referer() );
  2015 		$location = add_query_arg( 'message', 2, wp_get_referer() );
  1987 /**
  2038 /**
  1988  * Sanitizes POST values from a checkbox taxonomy metabox.
  2039  * Sanitizes POST values from a checkbox taxonomy metabox.
  1989  *
  2040  *
  1990  * @since 5.1.0
  2041  * @since 5.1.0
  1991  *
  2042  *
  1992  * @param mixed $terms Raw term data from the 'tax_input' field.
  2043  * @param string $taxonomy The taxonomy name.
  1993  * @return array
  2044  * @param array  $terms    Raw term data from the 'tax_input' field.
       
  2045  * @return int[] Array of sanitized term IDs.
  1994  */
  2046  */
  1995 function taxonomy_meta_box_sanitize_cb_checkboxes( $taxonomy, $terms ) {
  2047 function taxonomy_meta_box_sanitize_cb_checkboxes( $taxonomy, $terms ) {
  1996 	return array_map( 'intval', $terms );
  2048 	return array_map( 'intval', $terms );
  1997 }
  2049 }
  1998 
  2050 
  1999 /**
  2051 /**
  2000  * Sanitizes POST values from an input taxonomy metabox.
  2052  * Sanitizes POST values from an input taxonomy metabox.
  2001  *
  2053  *
  2002  * @since 5.1.0
  2054  * @since 5.1.0
  2003  *
  2055  *
  2004  * @param mixed $terms Raw term data from the 'tax_input' field.
  2056  * @param string       $taxonomy The taxonomy name.
       
  2057  * @param array|string $terms    Raw term data from the 'tax_input' field.
  2005  * @return array
  2058  * @return array
  2006  */
  2059  */
  2007 function taxonomy_meta_box_sanitize_cb_input( $taxonomy, $terms ) {
  2060 function taxonomy_meta_box_sanitize_cb_input( $taxonomy, $terms ) {
  2008 	/*
  2061 	/*
  2009 	 * Assume that a 'tax_input' string is a comma-separated list of term names.
  2062 	 * Assume that a 'tax_input' string is a comma-separated list of term names.
  2024 		if ( empty( $term ) ) {
  2077 		if ( empty( $term ) ) {
  2025 			continue;
  2078 			continue;
  2026 		}
  2079 		}
  2027 
  2080 
  2028 		$_term = get_terms(
  2081 		$_term = get_terms(
  2029 			$taxonomy,
       
  2030 			array(
  2082 			array(
       
  2083 				'taxonomy'   => $taxonomy,
  2031 				'name'       => $term,
  2084 				'name'       => $term,
  2032 				'fields'     => 'ids',
  2085 				'fields'     => 'ids',
  2033 				'hide_empty' => false,
  2086 				'hide_empty' => false,
  2034 			)
  2087 			)
  2035 		);
  2088 		);
  2124  * Returns all the block categories that will be shown in the block editor.
  2177  * Returns all the block categories that will be shown in the block editor.
  2125  *
  2178  *
  2126  * @since 5.0.0
  2179  * @since 5.0.0
  2127  *
  2180  *
  2128  * @param WP_Post $post Post object.
  2181  * @param WP_Post $post Post object.
  2129  * @return array Array of block categories.
  2182  * @return array[] Array of block categories.
  2130  */
  2183  */
  2131 function get_block_categories( $post ) {
  2184 function get_block_categories( $post ) {
  2132 	$default_categories = array(
  2185 	$default_categories = array(
  2133 		array(
  2186 		array(
  2134 			'slug'  => 'common',
  2187 			'slug'  => 'text',
  2135 			'title' => __( 'Common Blocks' ),
  2188 			'title' => _x( 'Text', 'block category' ),
  2136 			'icon'  => null,
  2189 			'icon'  => null,
  2137 		),
  2190 		),
  2138 		array(
  2191 		array(
  2139 			'slug'  => 'formatting',
  2192 			'slug'  => 'media',
  2140 			'title' => __( 'Formatting' ),
  2193 			'title' => _x( 'Media', 'block category' ),
  2141 			'icon'  => null,
  2194 			'icon'  => null,
  2142 		),
  2195 		),
  2143 		array(
  2196 		array(
  2144 			'slug'  => 'layout',
  2197 			'slug'  => 'design',
  2145 			'title' => __( 'Layout Elements' ),
  2198 			'title' => _x( 'Design', 'block category' ),
  2146 			'icon'  => null,
  2199 			'icon'  => null,
  2147 		),
  2200 		),
  2148 		array(
  2201 		array(
  2149 			'slug'  => 'widgets',
  2202 			'slug'  => 'widgets',
  2150 			'title' => __( 'Widgets' ),
  2203 			'title' => _x( 'Widgets', 'block category' ),
  2151 			'icon'  => null,
  2204 			'icon'  => null,
  2152 		),
  2205 		),
  2153 		array(
  2206 		array(
  2154 			'slug'  => 'embed',
  2207 			'slug'  => 'embed',
  2155 			'title' => __( 'Embeds' ),
  2208 			'title' => _x( 'Embeds', 'block category' ),
  2156 			'icon'  => null,
  2209 			'icon'  => null,
  2157 		),
  2210 		),
  2158 		array(
  2211 		array(
  2159 			'slug'  => 'reusable',
  2212 			'slug'  => 'reusable',
  2160 			'title' => __( 'Reusable Blocks' ),
  2213 			'title' => _x( 'Reusable Blocks', 'block category' ),
  2161 			'icon'  => null,
  2214 			'icon'  => null,
  2162 		),
  2215 		),
  2163 	);
  2216 	);
  2164 
  2217 
  2165 	/**
  2218 	/**
  2166 	 * Filter the default array of block categories.
  2219 	 * Filter the default array of block categories.
  2167 	 *
  2220 	 *
  2168 	 * @since 5.0.0
  2221 	 * @since 5.0.0
  2169 	 *
  2222 	 *
  2170 	 * @param array   $default_categories Array of block categories.
  2223 	 * @param array[] $default_categories Array of block categories.
  2171 	 * @param WP_Post $post               Post being loaded.
  2224 	 * @param WP_Post $post               Post being loaded.
  2172 	 */
  2225 	 */
  2173 	return apply_filters( 'block_categories', $default_categories, $post );
  2226 	return apply_filters( 'block_categories', $default_categories, $post );
  2174 }
  2227 }
  2175 
  2228 
  2184  * @return array An associative array of registered block data.
  2237  * @return array An associative array of registered block data.
  2185  */
  2238  */
  2186 function get_block_editor_server_block_settings() {
  2239 function get_block_editor_server_block_settings() {
  2187 	$block_registry = WP_Block_Type_Registry::get_instance();
  2240 	$block_registry = WP_Block_Type_Registry::get_instance();
  2188 	$blocks         = array();
  2241 	$blocks         = array();
  2189 	$keys_to_pick   = array( 'title', 'description', 'icon', 'category', 'keywords', 'supports', 'attributes' );
  2242 	$fields_to_pick = array(
       
  2243 		'title'            => 'title',
       
  2244 		'description'      => 'description',
       
  2245 		'icon'             => 'icon',
       
  2246 		'category'         => 'category',
       
  2247 		'keywords'         => 'keywords',
       
  2248 		'parent'           => 'parent',
       
  2249 		'supports'         => 'supports',
       
  2250 		'attributes'       => 'attributes',
       
  2251 		'provides_context' => 'providesContext',
       
  2252 		'uses_context'     => 'usesContext',
       
  2253 		'styles'           => 'styles',
       
  2254 		'textdomain'       => 'textdomain',
       
  2255 		'example'          => 'example',
       
  2256 	);
  2190 
  2257 
  2191 	foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) {
  2258 	foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) {
  2192 		foreach ( $keys_to_pick as $key ) {
  2259 		foreach ( $fields_to_pick as $field => $key ) {
  2193 			if ( ! isset( $block_type->{ $key } ) ) {
  2260 			if ( ! isset( $block_type->{ $field } ) ) {
  2194 				continue;
  2261 				continue;
  2195 			}
  2262 			}
  2196 
  2263 
  2197 			if ( ! isset( $blocks[ $block_name ] ) ) {
  2264 			if ( ! isset( $blocks[ $block_name ] ) ) {
  2198 				$blocks[ $block_name ] = array();
  2265 				$blocks[ $block_name ] = array();
  2199 			}
  2266 			}
  2200 
  2267 
  2201 			$blocks[ $block_name ][ $key ] = $block_type->{ $key };
  2268 			$blocks[ $block_name ][ $key ] = $block_type->{ $field };
  2202 		}
  2269 		}
  2203 	}
  2270 	}
  2204 
  2271 
  2205 	return $blocks;
  2272 	return $blocks;
  2206 }
  2273 }
  2402 	 * Hook into this action to print `<input type="hidden" ... />` fields, which will be POSTed back to
  2469 	 * Hook into this action to print `<input type="hidden" ... />` fields, which will be POSTed back to
  2403 	 * the server when meta boxes are saved.
  2470 	 * the server when meta boxes are saved.
  2404 	 *
  2471 	 *
  2405 	 * @since 5.0.0
  2472 	 * @since 5.0.0
  2406 	 *
  2473 	 *
  2407 	 * @params WP_Post $post The post that is being edited.
  2474 	 * @param WP_Post $post The post that is being edited.
  2408 	 */
  2475 	 */
  2409 	do_action( 'block_editor_meta_box_hidden_fields', $post );
  2476 	do_action( 'block_editor_meta_box_hidden_fields', $post );
  2410 }
  2477 }