wp/wp-includes/post.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
--- a/wp/wp-includes/post.php	Mon Oct 14 18:06:33 2019 +0200
+++ b/wp/wp-includes/post.php	Mon Oct 14 18:28:13 2019 +0200
@@ -18,296 +18,417 @@
  * @since 2.9.0
  */
 function create_initial_post_types() {
-	register_post_type( 'post', array(
-		'labels' => array(
-			'name_admin_bar' => _x( 'Post', 'add new from admin bar' ),
-		),
-		'public'  => true,
-		'_builtin' => true, /* internal use only. don't use this when registering your own post type. */
-		'_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */
-		'capability_type' => 'post',
-		'map_meta_cap' => true,
-		'menu_position' => 5,
-		'hierarchical' => false,
-		'rewrite' => false,
-		'query_var' => false,
-		'delete_with_user' => true,
-		'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'post-formats' ),
-		'show_in_rest' => true,
-		'rest_base' => 'posts',
-		'rest_controller_class' => 'WP_REST_Posts_Controller',
-	) );
-
-	register_post_type( 'page', array(
-		'labels' => array(
-			'name_admin_bar' => _x( 'Page', 'add new from admin bar' ),
-		),
-		'public' => true,
-		'publicly_queryable' => false,
-		'_builtin' => true, /* internal use only. don't use this when registering your own post type. */
-		'_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */
-		'capability_type' => 'page',
-		'map_meta_cap' => true,
-		'menu_position' => 20,
-		'hierarchical' => true,
-		'rewrite' => false,
-		'query_var' => false,
-		'delete_with_user' => true,
-		'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes', 'custom-fields', 'comments', 'revisions' ),
-		'show_in_rest' => true,
-		'rest_base' => 'pages',
-		'rest_controller_class' => 'WP_REST_Posts_Controller',
-	) );
-
-	register_post_type( 'attachment', array(
-		'labels' => array(
-			'name' => _x('Media', 'post type general name'),
-			'name_admin_bar' => _x( 'Media', 'add new from admin bar' ),
-			'add_new' => _x( 'Add New', 'add new media' ),
- 			'edit_item' => __( 'Edit Media' ),
- 			'view_item' => __( 'View Attachment Page' ),
-			'attributes' => __( 'Attachment Attributes' ),
-		),
-		'public' => true,
-		'show_ui' => true,
-		'_builtin' => true, /* internal use only. don't use this when registering your own post type. */
-		'_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */
-		'capability_type' => 'post',
-		'capabilities' => array(
-			'create_posts' => 'upload_files',
-		),
-		'map_meta_cap' => true,
-		'hierarchical' => false,
-		'rewrite' => false,
-		'query_var' => false,
-		'show_in_nav_menus' => false,
-		'delete_with_user' => true,
-		'supports' => array( 'title', 'author', 'comments' ),
-		'show_in_rest' => true,
-		'rest_base' => 'media',
-		'rest_controller_class' => 'WP_REST_Attachments_Controller',
-	) );
+	register_post_type(
+		'post',
+		array(
+			'labels'                => array(
+				'name_admin_bar' => _x( 'Post', 'add new from admin bar' ),
+			),
+			'public'                => true,
+			'_builtin'              => true, /* internal use only. don't use this when registering your own post type. */
+			'_edit_link'            => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */
+			'capability_type'       => 'post',
+			'map_meta_cap'          => true,
+			'menu_position'         => 5,
+			'hierarchical'          => false,
+			'rewrite'               => false,
+			'query_var'             => false,
+			'delete_with_user'      => true,
+			'supports'              => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'post-formats' ),
+			'show_in_rest'          => true,
+			'rest_base'             => 'posts',
+			'rest_controller_class' => 'WP_REST_Posts_Controller',
+		)
+	);
+
+	register_post_type(
+		'page',
+		array(
+			'labels'                => array(
+				'name_admin_bar' => _x( 'Page', 'add new from admin bar' ),
+			),
+			'public'                => true,
+			'publicly_queryable'    => false,
+			'_builtin'              => true, /* internal use only. don't use this when registering your own post type. */
+			'_edit_link'            => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */
+			'capability_type'       => 'page',
+			'map_meta_cap'          => true,
+			'menu_position'         => 20,
+			'hierarchical'          => true,
+			'rewrite'               => false,
+			'query_var'             => false,
+			'delete_with_user'      => true,
+			'supports'              => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes', 'custom-fields', 'comments', 'revisions' ),
+			'show_in_rest'          => true,
+			'rest_base'             => 'pages',
+			'rest_controller_class' => 'WP_REST_Posts_Controller',
+		)
+	);
+
+	register_post_type(
+		'attachment',
+		array(
+			'labels'                => array(
+				'name'           => _x( 'Media', 'post type general name' ),
+				'name_admin_bar' => _x( 'Media', 'add new from admin bar' ),
+				'add_new'        => _x( 'Add New', 'add new media' ),
+				'edit_item'      => __( 'Edit Media' ),
+				'view_item'      => __( 'View Attachment Page' ),
+				'attributes'     => __( 'Attachment Attributes' ),
+			),
+			'public'                => true,
+			'show_ui'               => true,
+			'_builtin'              => true, /* internal use only. don't use this when registering your own post type. */
+			'_edit_link'            => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */
+			'capability_type'       => 'post',
+			'capabilities'          => array(
+				'create_posts' => 'upload_files',
+			),
+			'map_meta_cap'          => true,
+			'hierarchical'          => false,
+			'rewrite'               => false,
+			'query_var'             => false,
+			'show_in_nav_menus'     => false,
+			'delete_with_user'      => true,
+			'supports'              => array( 'title', 'author', 'comments' ),
+			'show_in_rest'          => true,
+			'rest_base'             => 'media',
+			'rest_controller_class' => 'WP_REST_Attachments_Controller',
+		)
+	);
 	add_post_type_support( 'attachment:audio', 'thumbnail' );
 	add_post_type_support( 'attachment:video', 'thumbnail' );
 
-	register_post_type( 'revision', array(
-		'labels' => array(
-			'name' => __( 'Revisions' ),
-			'singular_name' => __( 'Revision' ),
-		),
-		'public' => false,
-		'_builtin' => true, /* internal use only. don't use this when registering your own post type. */
-		'_edit_link' => 'revision.php?revision=%d', /* internal use only. don't use this when registering your own post type. */
-		'capability_type' => 'post',
-		'map_meta_cap' => true,
-		'hierarchical' => false,
-		'rewrite' => false,
-		'query_var' => false,
-		'can_export' => false,
-		'delete_with_user' => true,
-		'supports' => array( 'author' ),
-	) );
-
-	register_post_type( 'nav_menu_item', array(
-		'labels' => array(
-			'name' => __( 'Navigation Menu Items' ),
-			'singular_name' => __( 'Navigation Menu Item' ),
-		),
-		'public' => false,
-		'_builtin' => true, /* internal use only. don't use this when registering your own post type. */
-		'hierarchical' => false,
-		'rewrite' => false,
-		'delete_with_user' => false,
-		'query_var' => false,
-	) );
-
-	register_post_type( 'custom_css', array(
-		'labels' => array(
-			'name'          => __( 'Custom CSS' ),
-			'singular_name' => __( 'Custom CSS' ),
-		),
-		'public'           => false,
-		'hierarchical'     => false,
-		'rewrite'          => false,
-		'query_var'        => false,
-		'delete_with_user' => false,
-		'can_export'       => true,
-		'_builtin'         => true, /* internal use only. don't use this when registering your own post type. */
-		'supports'         => array( 'title', 'revisions' ),
-		'capabilities'     => array(
-			'delete_posts'           => 'edit_theme_options',
-			'delete_post'            => 'edit_theme_options',
-			'delete_published_posts' => 'edit_theme_options',
-			'delete_private_posts'   => 'edit_theme_options',
-			'delete_others_posts'    => 'edit_theme_options',
-			'edit_post'              => 'edit_css',
-			'edit_posts'             => 'edit_css',
-			'edit_others_posts'      => 'edit_css',
-			'edit_published_posts'   => 'edit_css',
-			'read_post'              => 'read',
-			'read_private_posts'     => 'read',
-			'publish_posts'          => 'edit_theme_options',
-		),
-	) );
-
-	register_post_type( 'customize_changeset', array(
-		'labels' => array(
-			'name'               => _x( 'Changesets', 'post type general name' ),
-			'singular_name'      => _x( 'Changeset', 'post type singular name' ),
-			'menu_name'          => _x( 'Changesets', 'admin menu' ),
-			'name_admin_bar'     => _x( 'Changeset', 'add new on admin bar' ),
-			'add_new'            => _x( 'Add New', 'Customize Changeset' ),
-			'add_new_item'       => __( 'Add New Changeset' ),
-			'new_item'           => __( 'New Changeset' ),
-			'edit_item'          => __( 'Edit Changeset' ),
-			'view_item'          => __( 'View Changeset' ),
-			'all_items'          => __( 'All Changesets' ),
-			'search_items'       => __( 'Search Changesets' ),
-			'not_found'          => __( 'No changesets found.' ),
-			'not_found_in_trash' => __( 'No changesets found in Trash.' ),
-		),
-		'public' => false,
-		'_builtin' => true, /* internal use only. don't use this when registering your own post type. */
-		'map_meta_cap' => true,
-		'hierarchical' => false,
-		'rewrite' => false,
-		'query_var' => false,
-		'can_export' => false,
-		'delete_with_user' => false,
-		'supports' => array( 'title', 'author' ),
-		'capability_type' => 'customize_changeset',
-		'capabilities' => array(
-			'create_posts' => 'customize',
-			'delete_others_posts' => 'customize',
-			'delete_post' => 'customize',
-			'delete_posts' => 'customize',
-			'delete_private_posts' => 'customize',
-			'delete_published_posts' => 'customize',
-			'edit_others_posts' => 'customize',
-			'edit_post' => 'customize',
-			'edit_posts' => 'customize',
-			'edit_private_posts' => 'customize',
-			'edit_published_posts' => 'do_not_allow',
-			'publish_posts' => 'customize',
-			'read' => 'read',
-			'read_post' => 'customize',
-			'read_private_posts' => 'customize',
-		),
-	) );
-
-	register_post_type( 'oembed_cache', array(
-		'labels' => array(
-			'name'          => __( 'oEmbed Responses' ),
-			'singular_name' => __( 'oEmbed Response' ),
-		),
-		'public'           => false,
-		'hierarchical'     => false,
-		'rewrite'          => false,
-		'query_var'        => false,
-		'delete_with_user' => false,
-		'can_export'       => false,
-		'_builtin'         => true, /* internal use only. don't use this when registering your own post type. */
-		'supports'         => array(),
-	) );
-
-	register_post_type( 'user_request', array(
-		'labels'           => array(
-			'name'          => __( 'User Requests' ),
-			'singular_name' => __( 'User Request' ),
-		),
-		'public'           => false,
-		'_builtin'         => true, /* internal use only. don't use this when registering your own post type. */
-		'hierarchical'     => false,
-		'rewrite'          => false,
-		'query_var'        => false,
-		'can_export'       => false,
-		'delete_with_user' => false,
-		'supports'         => array(),
-	) );
-
-	register_post_status( 'publish', array(
-		'label'       => _x( 'Published', 'post status' ),
-		'public'      => true,
-		'_builtin'    => true, /* internal use only. */
-		'label_count' => _n_noop( 'Published <span class="count">(%s)</span>', 'Published <span class="count">(%s)</span>' ),
-	) );
-
-	register_post_status( 'future', array(
-		'label'       => _x( 'Scheduled', 'post status' ),
-		'protected'   => true,
-		'_builtin'    => true, /* internal use only. */
-		'label_count' => _n_noop('Scheduled <span class="count">(%s)</span>', 'Scheduled <span class="count">(%s)</span>' ),
-	) );
-
-	register_post_status( 'draft', array(
-		'label'       => _x( 'Draft', 'post status' ),
-		'protected'   => true,
-		'_builtin'    => true, /* internal use only. */
-		'label_count' => _n_noop( 'Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>' ),
-	) );
-
-	register_post_status( 'pending', array(
-		'label'       => _x( 'Pending', 'post status' ),
-		'protected'   => true,
-		'_builtin'    => true, /* internal use only. */
-		'label_count' => _n_noop( 'Pending <span class="count">(%s)</span>', 'Pending <span class="count">(%s)</span>' ),
-	) );
-
-	register_post_status( 'private', array(
-		'label'       => _x( 'Private', 'post status' ),
-		'private'     => true,
-		'_builtin'    => true, /* internal use only. */
-		'label_count' => _n_noop( 'Private <span class="count">(%s)</span>', 'Private <span class="count">(%s)</span>' ),
-	) );
-
-	register_post_status( 'trash', array(
-		'label'       => _x( 'Trash', 'post status' ),
-		'internal'    => true,
-		'_builtin'    => true, /* internal use only. */
-		'label_count' => _n_noop( 'Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>' ),
-		'show_in_admin_status_list' => true,
-	) );
-
-	register_post_status( 'auto-draft', array(
-		'label'    => 'auto-draft',
-		'internal' => true,
-		'_builtin' => true, /* internal use only. */
-	) );
-
-	register_post_status( 'inherit', array(
-		'label'    => 'inherit',
-		'internal' => true,
-		'_builtin' => true, /* internal use only. */
-		'exclude_from_search' => false,
-	) );
-
-	register_post_status( 'request-pending', array(
-		'label'               => _x( 'Pending', 'request status' ),
-		'internal'            => true,
-		'_builtin'            => true, /* internal use only. */
-		'exclude_from_search' => false,
-	) );
-
-	register_post_status( 'request-confirmed', array(
-		'label'               => _x( 'Confirmed', 'request status' ),
-		'internal'            => true,
-		'_builtin'            => true, /* internal use only. */
-		'exclude_from_search' => false,
-	) );
-
-	register_post_status( 'request-failed', array(
-		'label'               => _x( 'Failed', 'request status' ),
-		'internal'            => true,
-		'_builtin'            => true, /* internal use only. */
-		'exclude_from_search' => false,
-	) );
-
-	register_post_status( 'request-completed', array(
-		'label'               => _x( 'Completed', 'request status' ),
-		'internal'            => true,
-		'_builtin'            => true, /* internal use only. */
-		'exclude_from_search' => false,
-	) );
+	register_post_type(
+		'revision',
+		array(
+			'labels'           => array(
+				'name'          => __( 'Revisions' ),
+				'singular_name' => __( 'Revision' ),
+			),
+			'public'           => false,
+			'_builtin'         => true, /* internal use only. don't use this when registering your own post type. */
+			'_edit_link'       => 'revision.php?revision=%d', /* internal use only. don't use this when registering your own post type. */
+			'capability_type'  => 'post',
+			'map_meta_cap'     => true,
+			'hierarchical'     => false,
+			'rewrite'          => false,
+			'query_var'        => false,
+			'can_export'       => false,
+			'delete_with_user' => true,
+			'supports'         => array( 'author' ),
+		)
+	);
+
+	register_post_type(
+		'nav_menu_item',
+		array(
+			'labels'           => array(
+				'name'          => __( 'Navigation Menu Items' ),
+				'singular_name' => __( 'Navigation Menu Item' ),
+			),
+			'public'           => false,
+			'_builtin'         => true, /* internal use only. don't use this when registering your own post type. */
+			'hierarchical'     => false,
+			'rewrite'          => false,
+			'delete_with_user' => false,
+			'query_var'        => false,
+		)
+	);
+
+	register_post_type(
+		'custom_css',
+		array(
+			'labels'           => array(
+				'name'          => __( 'Custom CSS' ),
+				'singular_name' => __( 'Custom CSS' ),
+			),
+			'public'           => false,
+			'hierarchical'     => false,
+			'rewrite'          => false,
+			'query_var'        => false,
+			'delete_with_user' => false,
+			'can_export'       => true,
+			'_builtin'         => true, /* internal use only. don't use this when registering your own post type. */
+			'supports'         => array( 'title', 'revisions' ),
+			'capabilities'     => array(
+				'delete_posts'           => 'edit_theme_options',
+				'delete_post'            => 'edit_theme_options',
+				'delete_published_posts' => 'edit_theme_options',
+				'delete_private_posts'   => 'edit_theme_options',
+				'delete_others_posts'    => 'edit_theme_options',
+				'edit_post'              => 'edit_css',
+				'edit_posts'             => 'edit_css',
+				'edit_others_posts'      => 'edit_css',
+				'edit_published_posts'   => 'edit_css',
+				'read_post'              => 'read',
+				'read_private_posts'     => 'read',
+				'publish_posts'          => 'edit_theme_options',
+			),
+		)
+	);
+
+	register_post_type(
+		'customize_changeset',
+		array(
+			'labels'           => array(
+				'name'               => _x( 'Changesets', 'post type general name' ),
+				'singular_name'      => _x( 'Changeset', 'post type singular name' ),
+				'menu_name'          => _x( 'Changesets', 'admin menu' ),
+				'name_admin_bar'     => _x( 'Changeset', 'add new on admin bar' ),
+				'add_new'            => _x( 'Add New', 'Customize Changeset' ),
+				'add_new_item'       => __( 'Add New Changeset' ),
+				'new_item'           => __( 'New Changeset' ),
+				'edit_item'          => __( 'Edit Changeset' ),
+				'view_item'          => __( 'View Changeset' ),
+				'all_items'          => __( 'All Changesets' ),
+				'search_items'       => __( 'Search Changesets' ),
+				'not_found'          => __( 'No changesets found.' ),
+				'not_found_in_trash' => __( 'No changesets found in Trash.' ),
+			),
+			'public'           => false,
+			'_builtin'         => true, /* internal use only. don't use this when registering your own post type. */
+			'map_meta_cap'     => true,
+			'hierarchical'     => false,
+			'rewrite'          => false,
+			'query_var'        => false,
+			'can_export'       => false,
+			'delete_with_user' => false,
+			'supports'         => array( 'title', 'author' ),
+			'capability_type'  => 'customize_changeset',
+			'capabilities'     => array(
+				'create_posts'           => 'customize',
+				'delete_others_posts'    => 'customize',
+				'delete_post'            => 'customize',
+				'delete_posts'           => 'customize',
+				'delete_private_posts'   => 'customize',
+				'delete_published_posts' => 'customize',
+				'edit_others_posts'      => 'customize',
+				'edit_post'              => 'customize',
+				'edit_posts'             => 'customize',
+				'edit_private_posts'     => 'customize',
+				'edit_published_posts'   => 'do_not_allow',
+				'publish_posts'          => 'customize',
+				'read'                   => 'read',
+				'read_post'              => 'customize',
+				'read_private_posts'     => 'customize',
+			),
+		)
+	);
+
+	register_post_type(
+		'oembed_cache',
+		array(
+			'labels'           => array(
+				'name'          => __( 'oEmbed Responses' ),
+				'singular_name' => __( 'oEmbed Response' ),
+			),
+			'public'           => false,
+			'hierarchical'     => false,
+			'rewrite'          => false,
+			'query_var'        => false,
+			'delete_with_user' => false,
+			'can_export'       => false,
+			'_builtin'         => true, /* internal use only. don't use this when registering your own post type. */
+			'supports'         => array(),
+		)
+	);
+
+	register_post_type(
+		'user_request',
+		array(
+			'labels'           => array(
+				'name'          => __( 'User Requests' ),
+				'singular_name' => __( 'User Request' ),
+			),
+			'public'           => false,
+			'_builtin'         => true, /* internal use only. don't use this when registering your own post type. */
+			'hierarchical'     => false,
+			'rewrite'          => false,
+			'query_var'        => false,
+			'can_export'       => false,
+			'delete_with_user' => false,
+			'supports'         => array(),
+		)
+	);
+
+	register_post_type(
+		'wp_block',
+		array(
+			'labels'                => array(
+				'name'                     => _x( 'Blocks', 'post type general name' ),
+				'singular_name'            => _x( 'Block', 'post type singular name' ),
+				'menu_name'                => _x( 'Blocks', 'admin menu' ),
+				'name_admin_bar'           => _x( 'Block', 'add new on admin bar' ),
+				'add_new'                  => _x( 'Add New', 'Block' ),
+				'add_new_item'             => __( 'Add New Block' ),
+				'new_item'                 => __( 'New Block' ),
+				'edit_item'                => __( 'Edit Block' ),
+				'view_item'                => __( 'View Block' ),
+				'all_items'                => __( 'All Blocks' ),
+				'search_items'             => __( 'Search Blocks' ),
+				'not_found'                => __( 'No blocks found.' ),
+				'not_found_in_trash'       => __( 'No blocks found in Trash.' ),
+				'filter_items_list'        => __( 'Filter blocks list' ),
+				'items_list_navigation'    => __( 'Blocks list navigation' ),
+				'items_list'               => __( 'Blocks list' ),
+				'item_published'           => __( 'Block published.' ),
+				'item_published_privately' => __( 'Block published privately.' ),
+				'item_reverted_to_draft'   => __( 'Block reverted to draft.' ),
+				'item_scheduled'           => __( 'Block scheduled.' ),
+				'item_updated'             => __( 'Block updated.' ),
+			),
+			'public'                => false,
+			'_builtin'              => true, /* internal use only. don't use this when registering your own post type. */
+			'show_ui'               => true,
+			'show_in_menu'          => false,
+			'rewrite'               => false,
+			'show_in_rest'          => true,
+			'rest_base'             => 'blocks',
+			'rest_controller_class' => 'WP_REST_Blocks_Controller',
+			'capability_type'       => 'block',
+			'capabilities'          => array(
+				// You need to be able to edit posts, in order to read blocks in their raw form.
+				'read'                   => 'edit_posts',
+				// You need to be able to publish posts, in order to create blocks.
+				'create_posts'           => 'publish_posts',
+				'edit_posts'             => 'edit_posts',
+				'edit_published_posts'   => 'edit_published_posts',
+				'delete_published_posts' => 'delete_published_posts',
+				'edit_others_posts'      => 'edit_others_posts',
+				'delete_others_posts'    => 'delete_others_posts',
+			),
+			'map_meta_cap'          => true,
+			'supports'              => array(
+				'title',
+				'editor',
+			),
+		)
+	);
+
+	register_post_status(
+		'publish',
+		array(
+			'label'       => _x( 'Published', 'post status' ),
+			'public'      => true,
+			'_builtin'    => true, /* internal use only. */
+			'label_count' => _n_noop( 'Published <span class="count">(%s)</span>', 'Published <span class="count">(%s)</span>' ),
+		)
+	);
+
+	register_post_status(
+		'future',
+		array(
+			'label'       => _x( 'Scheduled', 'post status' ),
+			'protected'   => true,
+			'_builtin'    => true, /* internal use only. */
+			'label_count' => _n_noop( 'Scheduled <span class="count">(%s)</span>', 'Scheduled <span class="count">(%s)</span>' ),
+		)
+	);
+
+	register_post_status(
+		'draft',
+		array(
+			'label'       => _x( 'Draft', 'post status' ),
+			'protected'   => true,
+			'_builtin'    => true, /* internal use only. */
+			'label_count' => _n_noop( 'Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>' ),
+		)
+	);
+
+	register_post_status(
+		'pending',
+		array(
+			'label'       => _x( 'Pending', 'post status' ),
+			'protected'   => true,
+			'_builtin'    => true, /* internal use only. */
+			'label_count' => _n_noop( 'Pending <span class="count">(%s)</span>', 'Pending <span class="count">(%s)</span>' ),
+		)
+	);
+
+	register_post_status(
+		'private',
+		array(
+			'label'       => _x( 'Private', 'post status' ),
+			'private'     => true,
+			'_builtin'    => true, /* internal use only. */
+			'label_count' => _n_noop( 'Private <span class="count">(%s)</span>', 'Private <span class="count">(%s)</span>' ),
+		)
+	);
+
+	register_post_status(
+		'trash',
+		array(
+			'label'                     => _x( 'Trash', 'post status' ),
+			'internal'                  => true,
+			'_builtin'                  => true, /* internal use only. */
+			'label_count'               => _n_noop( 'Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>' ),
+			'show_in_admin_status_list' => true,
+		)
+	);
+
+	register_post_status(
+		'auto-draft',
+		array(
+			'label'    => 'auto-draft',
+			'internal' => true,
+			'_builtin' => true, /* internal use only. */
+		)
+	);
+
+	register_post_status(
+		'inherit',
+		array(
+			'label'               => 'inherit',
+			'internal'            => true,
+			'_builtin'            => true, /* internal use only. */
+			'exclude_from_search' => false,
+		)
+	);
+
+	register_post_status(
+		'request-pending',
+		array(
+			'label'               => _x( 'Pending', 'request status' ),
+			'internal'            => true,
+			'_builtin'            => true, /* internal use only. */
+			'label_count'         => _n_noop( 'Pending <span class="count">(%s)</span>', 'Pending <span class="count">(%s)</span>' ),
+			'exclude_from_search' => false,
+		)
+	);
+
+	register_post_status(
+		'request-confirmed',
+		array(
+			'label'               => _x( 'Confirmed', 'request status' ),
+			'internal'            => true,
+			'_builtin'            => true, /* internal use only. */
+			'label_count'         => _n_noop( 'Confirmed <span class="count">(%s)</span>', 'Confirmed <span class="count">(%s)</span>' ),
+			'exclude_from_search' => false,
+		)
+	);
+
+	register_post_status(
+		'request-failed',
+		array(
+			'label'               => _x( 'Failed', 'request status' ),
+			'internal'            => true,
+			'_builtin'            => true, /* internal use only. */
+			'label_count'         => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>' ),
+			'exclude_from_search' => false,
+		)
+	);
+
+	register_post_status(
+		'request-completed',
+		array(
+			'label'               => _x( 'Completed', 'request status' ),
+			'internal'            => true,
+			'_builtin'            => true, /* internal use only. */
+			'label_count'         => _n_noop( 'Completed <span class="count">(%s)</span>', 'Completed <span class="count">(%s)</span>' ),
+			'exclude_from_search' => false,
+		)
+	);
 }
 
 /**
@@ -364,8 +485,9 @@
  * @return bool True on success, false on failure.
  */
 function update_attached_file( $attachment_id, $file ) {
-	if ( !get_post( $attachment_id ) )
+	if ( ! get_post( $attachment_id ) ) {
 		return false;
+	}
 
 	/**
 	 * Filters the path to the attached file to update.
@@ -377,10 +499,11 @@
 	 */
 	$file = apply_filters( 'update_attached_file', $file, $attachment_id );
 
-	if ( $file = _wp_relative_upload_path( $file ) )
+	if ( $file = _wp_relative_upload_path( $file ) ) {
 		return update_post_meta( $attachment_id, '_wp_attached_file', $file );
-	else
+	} else {
 		return delete_post_meta( $attachment_id, '_wp_attached_file' );
+	}
 }
 
 /**
@@ -389,6 +512,7 @@
  * The path is relative to the current upload dir.
  *
  * @since 2.9.0
+ * @access private
  *
  * @param string $path Full path to the file.
  * @return string Relative path on success, unchanged path on failure.
@@ -468,48 +592,53 @@
 	$kids = array();
 	if ( empty( $args ) ) {
 		if ( isset( $GLOBALS['post'] ) ) {
-			$args = array('post_parent' => (int) $GLOBALS['post']->post_parent );
+			$args = array( 'post_parent' => (int) $GLOBALS['post']->post_parent );
 		} else {
 			return $kids;
 		}
 	} elseif ( is_object( $args ) ) {
-		$args = array('post_parent' => (int) $args->post_parent );
+		$args = array( 'post_parent' => (int) $args->post_parent );
 	} elseif ( is_numeric( $args ) ) {
-		$args = array('post_parent' => (int) $args);
+		$args = array( 'post_parent' => (int) $args );
 	}
 
 	$defaults = array(
-		'numberposts' => -1, 'post_type' => 'any',
-		'post_status' => 'any', 'post_parent' => 0,
+		'numberposts' => -1,
+		'post_type'   => 'any',
+		'post_status' => 'any',
+		'post_parent' => 0,
 	);
 
 	$r = wp_parse_args( $args, $defaults );
 
 	$children = get_posts( $r );
 
-	if ( ! $children )
+	if ( ! $children ) {
 		return $kids;
-
-	if ( ! empty( $r['fields'] ) )
+	}
+
+	if ( ! empty( $r['fields'] ) ) {
 		return $children;
-
-	update_post_cache($children);
-
-	foreach ( $children as $key => $child )
-		$kids[$child->ID] = $children[$key];
+	}
+
+	update_post_cache( $children );
+
+	foreach ( $children as $key => $child ) {
+		$kids[ $child->ID ] = $children[ $key ];
+	}
 
 	if ( $output == OBJECT ) {
 		return $kids;
 	} elseif ( $output == ARRAY_A ) {
 		$weeuns = array();
 		foreach ( (array) $kids as $kid ) {
-			$weeuns[$kid->ID] = get_object_vars($kids[$kid->ID]);
+			$weeuns[ $kid->ID ] = get_object_vars( $kids[ $kid->ID ] );
 		}
 		return $weeuns;
 	} elseif ( $output == ARRAY_N ) {
 		$babes = array();
 		foreach ( (array) $kids as $kid ) {
-			$babes[$kid->ID] = array_values(get_object_vars($kids[$kid->ID]));
+			$babes[ $kid->ID ] = array_values( get_object_vars( $kids[ $kid->ID ] ) );
 		}
 		return $babes;
 	} else {
@@ -535,21 +664,25 @@
  */
 function get_extended( $post ) {
 	//Match the new style more links.
-	if ( preg_match('/<!--more(.*?)?-->/', $post, $matches) ) {
-		list($main, $extended) = explode($matches[0], $post, 2);
-		$more_text = $matches[1];
+	if ( preg_match( '/<!--more(.*?)?-->/', $post, $matches ) ) {
+		list($main, $extended) = explode( $matches[0], $post, 2 );
+		$more_text             = $matches[1];
 	} else {
-		$main = $post;
-		$extended = '';
+		$main      = $post;
+		$extended  = '';
 		$more_text = '';
 	}
 
 	//  leading and trailing whitespace.
-	$main = preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $main);
-	$extended = preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $extended);
-	$more_text = preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $more_text);
-
-	return array( 'main' => $main, 'extended' => $extended, 'more_text' => $more_text );
+	$main      = preg_replace( '/^[\s]*(.*)[\s]*$/', '\\1', $main );
+	$extended  = preg_replace( '/^[\s]*(.*)[\s]*$/', '\\1', $extended );
+	$more_text = preg_replace( '/^[\s]*(.*)[\s]*$/', '\\1', $more_text );
+
+	return array(
+		'main'      => $main,
+		'extended'  => $extended,
+		'more_text' => $more_text,
+	);
 }
 
 /**
@@ -571,8 +704,9 @@
  *                            When $output is OBJECT, a `WP_Post` instance is returned.
  */
 function get_post( $post = null, $output = OBJECT, $filter = 'raw' ) {
-	if ( empty( $post ) && isset( $GLOBALS['post'] ) )
+	if ( empty( $post ) && isset( $GLOBALS['post'] ) ) {
 		$post = $GLOBALS['post'];
+	}
 
 	if ( $post instanceof WP_Post ) {
 		$_post = $post;
@@ -589,15 +723,17 @@
 		$_post = WP_Post::get_instance( $post );
 	}
 
-	if ( ! $_post )
+	if ( ! $_post ) {
 		return null;
+	}
 
 	$_post = $_post->filter( $filter );
 
-	if ( $output == ARRAY_A )
+	if ( $output == ARRAY_A ) {
 		return $_post->to_array();
-	elseif ( $output == ARRAY_N )
+	} elseif ( $output == ARRAY_N ) {
 		return array_values( $_post->to_array() );
+	}
 
 	return $_post;
 }
@@ -613,8 +749,9 @@
 function get_post_ancestors( $post ) {
 	$post = get_post( $post );
 
-	if ( ! $post || empty( $post->post_parent ) || $post->post_parent == $post->ID )
+	if ( ! $post || empty( $post->post_parent ) || $post->post_parent == $post->ID ) {
 		return array();
+	}
 
 	$ancestors = array();
 
@@ -622,8 +759,9 @@
 
 	while ( $ancestor = get_post( $id ) ) {
 		// Loop detection: If the ancestor has been seen before, break.
-		if ( empty( $ancestor->post_parent ) || ( $ancestor->post_parent == $post->ID ) || in_array( $ancestor->post_parent, $ancestors ) )
+		if ( empty( $ancestor->post_parent ) || ( $ancestor->post_parent == $post->ID ) || in_array( $ancestor->post_parent, $ancestors ) ) {
 			break;
+		}
 
 		$id = $ancestors[] = $ancestor->post_parent;
 	}
@@ -646,7 +784,7 @@
  * @see sanitize_post_field()
  *
  * @param string      $field   Post field name.
- * @param int|WP_Post $post    Optional. Post ID or post object. Defaults to current post.
+ * @param int|WP_Post $post    Optional. Post ID or post object. Defaults to global $post.
  * @param string      $context Optional. How to filter the field. Accepts 'raw', 'edit', 'db',
  *                             or 'display'. Default 'display'.
  * @return string The value of the post field on success, empty string on failure.
@@ -654,13 +792,15 @@
 function get_post_field( $field, $post = null, $context = 'display' ) {
 	$post = get_post( $post );
 
-	if ( !$post )
+	if ( ! $post ) {
 		return '';
-
-	if ( !isset($post->$field) )
+	}
+
+	if ( ! isset( $post->$field ) ) {
 		return '';
-
-	return sanitize_post_field($field, $post->$field, $post->ID, $context);
+	}
+
+	return sanitize_post_field( $field, $post->$field, $post->ID, $context );
 }
 
 /**
@@ -671,42 +811,46 @@
  *
  * @since 2.0.0
  *
- * @param int|WP_Post $ID Optional. Post ID or post object. Default empty.
+ * @param int|WP_Post $post Optional. Post ID or post object. Defaults to global $post.
  * @return string|false The mime type on success, false on failure.
  */
-function get_post_mime_type( $ID = '' ) {
-	$post = get_post($ID);
-
-	if ( is_object($post) )
+function get_post_mime_type( $post = null ) {
+	$post = get_post( $post );
+
+	if ( is_object( $post ) ) {
 		return $post->post_mime_type;
+	}
 
 	return false;
 }
 
 /**
- * Retrieve the post status based on the Post ID.
+ * Retrieve the post status based on the post ID.
  *
  * If the post ID is of an attachment, then the parent post status will be given
  * instead.
  *
  * @since 2.0.0
  *
- * @param int|WP_Post $ID Optional. Post ID or post object. Default empty.
+ * @param int|WP_Post $post Optional. Post ID or post object. Defaults to global $post..
  * @return string|false Post status on success, false on failure.
  */
-function get_post_status( $ID = '' ) {
-	$post = get_post($ID);
-
-	if ( !is_object($post) )
+function get_post_status( $post = null ) {
+	$post = get_post( $post );
+
+	if ( ! is_object( $post ) ) {
 		return false;
+	}
 
 	if ( 'attachment' == $post->post_type ) {
-		if ( 'private' == $post->post_status )
+		if ( 'private' == $post->post_status ) {
 			return 'private';
+		}
 
 		// Unattached attachments are assumed to be published.
-		if ( ( 'inherit' == $post->post_status ) && ( 0 == $post->post_parent) )
+		if ( ( 'inherit' == $post->post_status ) && ( 0 == $post->post_parent ) ) {
 			return 'publish';
+		}
 
 		// Inherit status from the parent.
 		if ( $post->post_parent && ( $post->ID != $post->post_parent ) ) {
@@ -717,7 +861,6 @@
 				return $parent_post_status;
 			}
 		}
-
 	}
 
 	/**
@@ -746,7 +889,7 @@
 		'draft'   => __( 'Draft' ),
 		'pending' => __( 'Pending Review' ),
 		'private' => __( 'Private' ),
-		'publish' => __( 'Published' )
+		'publish' => __( 'Published' ),
 	);
 
 	return $status;
@@ -766,7 +909,7 @@
 	$status = array(
 		'draft'   => __( 'Draft' ),
 		'private' => __( 'Private' ),
-		'publish' => __( 'Published' )
+		'publish' => __( 'Published' ),
 	);
 
 	return $status;
@@ -775,7 +918,8 @@
 /**
  * Return statuses for privacy requests.
  *
- * @since 5.0.0
+ * @since 4.9.6
+ * @access private
  *
  * @return array
  */
@@ -834,64 +978,77 @@
 function register_post_status( $post_status, $args = array() ) {
 	global $wp_post_statuses;
 
-	if (!is_array($wp_post_statuses))
+	if ( ! is_array( $wp_post_statuses ) ) {
 		$wp_post_statuses = array();
+	}
 
 	// Args prefixed with an underscore are reserved for internal use.
 	$defaults = array(
-		'label' => false,
-		'label_count' => false,
-		'exclude_from_search' => null,
-		'_builtin' => false,
-		'public' => null,
-		'internal' => null,
-		'protected' => null,
-		'private' => null,
-		'publicly_queryable' => null,
+		'label'                     => false,
+		'label_count'               => false,
+		'exclude_from_search'       => null,
+		'_builtin'                  => false,
+		'public'                    => null,
+		'internal'                  => null,
+		'protected'                 => null,
+		'private'                   => null,
+		'publicly_queryable'        => null,
 		'show_in_admin_status_list' => null,
-		'show_in_admin_all_list' => null,
+		'show_in_admin_all_list'    => null,
 	);
-	$args = wp_parse_args($args, $defaults);
-	$args = (object) $args;
-
-	$post_status = sanitize_key($post_status);
-	$args->name = $post_status;
+	$args     = wp_parse_args( $args, $defaults );
+	$args     = (object) $args;
+
+	$post_status = sanitize_key( $post_status );
+	$args->name  = $post_status;
 
 	// Set various defaults.
-	if ( null === $args->public && null === $args->internal && null === $args->protected && null === $args->private )
+	if ( null === $args->public && null === $args->internal && null === $args->protected && null === $args->private ) {
 		$args->internal = true;
-
-	if ( null === $args->public  )
+	}
+
+	if ( null === $args->public ) {
 		$args->public = false;
-
-	if ( null === $args->private  )
+	}
+
+	if ( null === $args->private ) {
 		$args->private = false;
-
-	if ( null === $args->protected  )
+	}
+
+	if ( null === $args->protected ) {
 		$args->protected = false;
-
-	if ( null === $args->internal  )
+	}
+
+	if ( null === $args->internal ) {
 		$args->internal = false;
-
-	if ( null === $args->publicly_queryable )
+	}
+
+	if ( null === $args->publicly_queryable ) {
 		$args->publicly_queryable = $args->public;
-
-	if ( null === $args->exclude_from_search )
+	}
+
+	if ( null === $args->exclude_from_search ) {
 		$args->exclude_from_search = $args->internal;
-
-	if ( null === $args->show_in_admin_all_list )
-		$args->show_in_admin_all_list = !$args->internal;
-
-	if ( null === $args->show_in_admin_status_list )
-		$args->show_in_admin_status_list = !$args->internal;
-
-	if ( false === $args->label )
+	}
+
+	if ( null === $args->show_in_admin_all_list ) {
+		$args->show_in_admin_all_list = ! $args->internal;
+	}
+
+	if ( null === $args->show_in_admin_status_list ) {
+		$args->show_in_admin_status_list = ! $args->internal;
+	}
+
+	if ( false === $args->label ) {
 		$args->label = $post_status;
-
-	if ( false === $args->label_count )
+	}
+
+	if ( false === $args->label_count ) {
+		// phpcs:ignore WordPress.WP.I18n.NonSingularStringLiteralSingle,WordPress.WP.I18n.NonSingularStringLiteralPlural
 		$args->label_count = _n_noop( $args->label, $args->label );
-
-	$wp_post_statuses[$post_status] = $args;
+	}
+
+	$wp_post_statuses[ $post_status ] = $args;
 
 	return $args;
 }
@@ -911,10 +1068,11 @@
 function get_post_status_object( $post_status ) {
 	global $wp_post_statuses;
 
-	if ( empty($wp_post_statuses[$post_status]) )
+	if ( empty( $wp_post_statuses[ $post_status ] ) ) {
 		return null;
-
-	return $wp_post_statuses[$post_status];
+	}
+
+	return $wp_post_statuses[ $post_status ];
 }
 
 /**
@@ -937,9 +1095,9 @@
 function get_post_stati( $args = array(), $output = 'names', $operator = 'and' ) {
 	global $wp_post_statuses;
 
-	$field = ('names' == $output) ? 'name' : false;
-
-	return wp_filter_object_list($wp_post_statuses, $args, $operator, $field);
+	$field = ( 'names' == $output ) ? 'name' : false;
+
+	return wp_filter_object_list( $wp_post_statuses, $args, $operator, $field );
 }
 
 /**
@@ -955,15 +1113,20 @@
  * @return bool Whether post type is hierarchical.
  */
 function is_post_type_hierarchical( $post_type ) {
-	if ( ! post_type_exists( $post_type ) )
+	if ( ! post_type_exists( $post_type ) ) {
 		return false;
+	}
 
 	$post_type = get_post_type_object( $post_type );
 	return $post_type->hierarchical;
 }
 
 /**
- * Check if a post type is registered.
+ * Determines whether a post type is registered.
+ *
+ * For more information on this and similar theme functions, check out
+ * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
+ * Conditional Tags} article in the Theme Developer Handbook.
  *
  * @since 3.0.0
  *
@@ -985,8 +1148,9 @@
  * @return string|false          Post type on success, false on failure.
  */
 function get_post_type( $post = null ) {
-	if ( $post = get_post( $post ) )
+	if ( $post = get_post( $post ) ) {
 		return $post->post_type;
+	}
 
 	return false;
 }
@@ -995,7 +1159,7 @@
  * Retrieves a post type object by name.
  *
  * @since 3.0.0
- * @since 4.6.0 Object returned is now an instance of WP_Post_Type.
+ * @since 4.6.0 Object returned is now an instance of `WP_Post_Type`.
  *
  * @global array $wp_post_types List of post types.
  *
@@ -1030,14 +1194,14 @@
  * @param string       $operator Optional. The logical operation to perform. 'or' means only one
  *                               element from the array needs to match; 'and' means all elements
  *                               must match; 'not' means no elements may match. Default 'and'.
- * @return array A list of post type names or objects.
+ * @return string[]|WP_Post_Type[] An array of post type names or objects.
  */
 function get_post_types( $args = array(), $output = 'names', $operator = 'and' ) {
 	global $wp_post_types;
 
-	$field = ('names' == $output) ? 'name' : false;
-
-	return wp_filter_object_list($wp_post_types, $args, $operator, $field);
+	$field = ( 'names' == $output ) ? 'name' : false;
+
+	return wp_filter_object_list( $wp_post_types, $args, $operator, $field );
 }
 
 /**
@@ -1058,8 +1222,8 @@
  * @since 3.0.0 The `show_ui` argument is now enforced on the new post screen.
  * @since 4.4.0 The `show_ui` argument is now enforced on the post type listing
  *              screen and post editing screen.
- * @since 4.6.0 Post type object returned is now an instance of WP_Post_Type.
- * @since 4.7.0 Introduced `show_in_rest`, 'rest_base' and 'rest_controller_class'
+ * @since 4.6.0 Post type object returned is now an instance of `WP_Post_Type`.
+ * @since 4.7.0 Introduced `show_in_rest`, `rest_base` and `rest_controller_class`
  *              arguments to register the post type in REST API.
  *
  * @global array $wp_post_types List of post types.
@@ -1205,7 +1369,7 @@
 	 * Fires after a post type is registered.
 	 *
 	 * @since 3.3.0
-	 * @since 4.6.0 Converted the `$post_type` parameter to accept a WP_Post_Type object.
+	 * @since 4.6.0 Converted the `$post_type` parameter to accept a `WP_Post_Type` object.
 	 *
 	 * @param string       $post_type        Post type.
 	 * @param WP_Post_Type $post_type_object Arguments used to register the post type.
@@ -1317,21 +1481,22 @@
  * @return object Object with all the capabilities as member variables.
  */
 function get_post_type_capabilities( $args ) {
-	if ( ! is_array( $args->capability_type ) )
+	if ( ! is_array( $args->capability_type ) ) {
 		$args->capability_type = array( $args->capability_type, $args->capability_type . 's' );
+	}
 
 	// Singular base for meta capabilities, plural base for primitive capabilities.
 	list( $singular_base, $plural_base ) = $args->capability_type;
 
 	$default_capabilities = array(
 		// Meta capabilities
-		'edit_post'          => 'edit_'         . $singular_base,
-		'read_post'          => 'read_'         . $singular_base,
-		'delete_post'        => 'delete_'       . $singular_base,
+		'edit_post'          => 'edit_' . $singular_base,
+		'read_post'          => 'read_' . $singular_base,
+		'delete_post'        => 'delete_' . $singular_base,
 		// Primitive capabilities used outside of map_meta_cap():
-		'edit_posts'         => 'edit_'         . $plural_base,
-		'edit_others_posts'  => 'edit_others_'  . $plural_base,
-		'publish_posts'      => 'publish_'      . $plural_base,
+		'edit_posts'         => 'edit_' . $plural_base,
+		'edit_others_posts'  => 'edit_others_' . $plural_base,
+		'publish_posts'      => 'publish_' . $plural_base,
 		'read_private_posts' => 'read_private_' . $plural_base,
 	);
 
@@ -1339,25 +1504,27 @@
 	if ( $args->map_meta_cap ) {
 		$default_capabilities_for_mapping = array(
 			'read'                   => 'read',
-			'delete_posts'           => 'delete_'           . $plural_base,
-			'delete_private_posts'   => 'delete_private_'   . $plural_base,
+			'delete_posts'           => 'delete_' . $plural_base,
+			'delete_private_posts'   => 'delete_private_' . $plural_base,
 			'delete_published_posts' => 'delete_published_' . $plural_base,
-			'delete_others_posts'    => 'delete_others_'    . $plural_base,
-			'edit_private_posts'     => 'edit_private_'     . $plural_base,
-			'edit_published_posts'   => 'edit_published_'   . $plural_base,
+			'delete_others_posts'    => 'delete_others_' . $plural_base,
+			'edit_private_posts'     => 'edit_private_' . $plural_base,
+			'edit_published_posts'   => 'edit_published_' . $plural_base,
 		);
-		$default_capabilities = array_merge( $default_capabilities, $default_capabilities_for_mapping );
+		$default_capabilities             = array_merge( $default_capabilities, $default_capabilities_for_mapping );
 	}
 
 	$capabilities = array_merge( $default_capabilities, $args->capabilities );
 
 	// Post creation capability simply maps to edit_posts by default:
-	if ( ! isset( $capabilities['create_posts'] ) )
+	if ( ! isset( $capabilities['create_posts'] ) ) {
 		$capabilities['create_posts'] = $capabilities['edit_posts'];
+	}
 
 	// Remember meta capabilities for future reference.
-	if ( $args->map_meta_cap )
+	if ( $args->map_meta_cap ) {
 		_post_type_meta_capabilities( $capabilities );
+	}
 
 	return (object) $capabilities;
 }
@@ -1420,6 +1587,14 @@
  * - `items_list_navigation` - Label for the table pagination hidden heading. Default is 'Posts list navigation' /
  *                           'Pages list navigation'.
  * - `items_list` - Label for the table hidden heading. Default is 'Posts list' / 'Pages list'.
+ * - `item_published` - Label used when an item is published. Default is 'Post published.' / 'Page published.'
+ * - `item_published_privately` - Label used when an item is published with private visibility.
+ *                              Default is 'Post published privately.' / 'Page published privately.'
+ * - `item_reverted_to_draft` - Label used when an item is switched to a draft.
+ *                            Default is 'Post reverted to draft.' / 'Page reverted to draft.'
+ * - `item_scheduled` - Label used when an item is scheduled for publishing. Default is 'Post scheduled.' /
+ *                    'Page scheduled.'
+ * - `item_updated` - Label used when an item is updated. Default is 'Post updated.' / 'Page updated.'
  *
  * Above, the first default value is for non-hierarchical post types (like posts)
  * and the second one is for hierarchical post types (like pages).
@@ -1431,8 +1606,10 @@
  *              and `use_featured_image` labels.
  * @since 4.4.0 Added the `archives`, `insert_into_item`, `uploaded_to_this_item`, `filter_items_list`,
  *              `items_list_navigation`, and `items_list` labels.
- * @since 4.6.0 Converted the `$post_type` parameter to accept a WP_Post_Type object.
+ * @since 4.6.0 Converted the `$post_type` parameter to accept a `WP_Post_Type` object.
  * @since 4.7.0 Added the `view_items` and `attributes` labels.
+ * @since 5.0.0 Added the `item_published`, `item_published_privately`, `item_reverted_to_draft`,
+ *              `item_scheduled`, and `item_updated` labels.
  *
  * @access private
  *
@@ -1440,31 +1617,36 @@
  * @return object Object with all the labels as member variables.
  */
 function get_post_type_labels( $post_type_object ) {
-	$nohier_vs_hier_defaults = array(
-		'name' => array( _x('Posts', 'post type general name'), _x('Pages', 'post type general name') ),
-		'singular_name' => array( _x('Post', 'post type singular name'), _x('Page', 'post type singular name') ),
-		'add_new' => array( _x('Add New', 'post'), _x('Add New', 'page') ),
-		'add_new_item' => array( __('Add New Post'), __('Add New Page') ),
-		'edit_item' => array( __('Edit Post'), __('Edit Page') ),
-		'new_item' => array( __('New Post'), __('New Page') ),
-		'view_item' => array( __('View Post'), __('View Page') ),
-		'view_items' => array( __('View Posts'), __('View Pages') ),
-		'search_items' => array( __('Search Posts'), __('Search Pages') ),
-		'not_found' => array( __('No posts found.'), __('No pages found.') ),
-		'not_found_in_trash' => array( __('No posts found in Trash.'), __('No pages found in Trash.') ),
-		'parent_item_colon' => array( null, __('Parent Page:') ),
-		'all_items' => array( __( 'All Posts' ), __( 'All Pages' ) ),
-		'archives' => array( __( 'Post Archives' ), __( 'Page Archives' ) ),
-		'attributes' => array( __( 'Post Attributes' ), __( 'Page Attributes' ) ),
-		'insert_into_item' => array( __( 'Insert into post' ), __( 'Insert into page' ) ),
-		'uploaded_to_this_item' => array( __( 'Uploaded to this post' ), __( 'Uploaded to this page' ) ),
-		'featured_image' => array( _x( 'Featured Image', 'post' ), _x( 'Featured Image', 'page' ) ),
-		'set_featured_image' => array( _x( 'Set featured image', 'post' ), _x( 'Set featured image', 'page' ) ),
-		'remove_featured_image' => array( _x( 'Remove featured image', 'post' ), _x( 'Remove featured image', 'page' ) ),
-		'use_featured_image' => array( _x( 'Use as featured image', 'post' ), _x( 'Use as featured image', 'page' ) ),
-		'filter_items_list' => array( __( 'Filter posts list' ), __( 'Filter pages list' ) ),
-		'items_list_navigation' => array( __( 'Posts list navigation' ), __( 'Pages list navigation' ) ),
-		'items_list' => array( __( 'Posts list' ), __( 'Pages list' ) ),
+	$nohier_vs_hier_defaults              = array(
+		'name'                     => array( _x( 'Posts', 'post type general name' ), _x( 'Pages', 'post type general name' ) ),
+		'singular_name'            => array( _x( 'Post', 'post type singular name' ), _x( 'Page', 'post type singular name' ) ),
+		'add_new'                  => array( _x( 'Add New', 'post' ), _x( 'Add New', 'page' ) ),
+		'add_new_item'             => array( __( 'Add New Post' ), __( 'Add New Page' ) ),
+		'edit_item'                => array( __( 'Edit Post' ), __( 'Edit Page' ) ),
+		'new_item'                 => array( __( 'New Post' ), __( 'New Page' ) ),
+		'view_item'                => array( __( 'View Post' ), __( 'View Page' ) ),
+		'view_items'               => array( __( 'View Posts' ), __( 'View Pages' ) ),
+		'search_items'             => array( __( 'Search Posts' ), __( 'Search Pages' ) ),
+		'not_found'                => array( __( 'No posts found.' ), __( 'No pages found.' ) ),
+		'not_found_in_trash'       => array( __( 'No posts found in Trash.' ), __( 'No pages found in Trash.' ) ),
+		'parent_item_colon'        => array( null, __( 'Parent Page:' ) ),
+		'all_items'                => array( __( 'All Posts' ), __( 'All Pages' ) ),
+		'archives'                 => array( __( 'Post Archives' ), __( 'Page Archives' ) ),
+		'attributes'               => array( __( 'Post Attributes' ), __( 'Page Attributes' ) ),
+		'insert_into_item'         => array( __( 'Insert into post' ), __( 'Insert into page' ) ),
+		'uploaded_to_this_item'    => array( __( 'Uploaded to this post' ), __( 'Uploaded to this page' ) ),
+		'featured_image'           => array( _x( 'Featured Image', 'post' ), _x( 'Featured Image', 'page' ) ),
+		'set_featured_image'       => array( _x( 'Set featured image', 'post' ), _x( 'Set featured image', 'page' ) ),
+		'remove_featured_image'    => array( _x( 'Remove featured image', 'post' ), _x( 'Remove featured image', 'page' ) ),
+		'use_featured_image'       => array( _x( 'Use as featured image', 'post' ), _x( 'Use as featured image', 'page' ) ),
+		'filter_items_list'        => array( __( 'Filter posts list' ), __( 'Filter pages list' ) ),
+		'items_list_navigation'    => array( __( 'Posts list navigation' ), __( 'Pages list navigation' ) ),
+		'items_list'               => array( __( 'Posts list' ), __( 'Pages list' ) ),
+		'item_published'           => array( __( 'Post published.' ), __( 'Page published.' ) ),
+		'item_published_privately' => array( __( 'Post published privately.' ), __( 'Page published privately.' ) ),
+		'item_reverted_to_draft'   => array( __( 'Post reverted to draft.' ), __( 'Page reverted to draft.' ) ),
+		'item_scheduled'           => array( __( 'Post scheduled.' ), __( 'Page scheduled.' ) ),
+		'item_updated'             => array( __( 'Post updated.' ), __( 'Page updated.' ) ),
 	);
 	$nohier_vs_hier_defaults['menu_name'] = $nohier_vs_hier_defaults['name'];
 
@@ -1508,30 +1690,35 @@
 function _get_custom_object_labels( $object, $nohier_vs_hier_defaults ) {
 	$object->labels = (array) $object->labels;
 
-	if ( isset( $object->label ) && empty( $object->labels['name'] ) )
+	if ( isset( $object->label ) && empty( $object->labels['name'] ) ) {
 		$object->labels['name'] = $object->label;
-
-	if ( !isset( $object->labels['singular_name'] ) && isset( $object->labels['name'] ) )
+	}
+
+	if ( ! isset( $object->labels['singular_name'] ) && isset( $object->labels['name'] ) ) {
 		$object->labels['singular_name'] = $object->labels['name'];
-
-	if ( ! isset( $object->labels['name_admin_bar'] ) )
+	}
+
+	if ( ! isset( $object->labels['name_admin_bar'] ) ) {
 		$object->labels['name_admin_bar'] = isset( $object->labels['singular_name'] ) ? $object->labels['singular_name'] : $object->name;
-
-	if ( !isset( $object->labels['menu_name'] ) && isset( $object->labels['name'] ) )
+	}
+
+	if ( ! isset( $object->labels['menu_name'] ) && isset( $object->labels['name'] ) ) {
 		$object->labels['menu_name'] = $object->labels['name'];
-
-	if ( !isset( $object->labels['all_items'] ) && isset( $object->labels['menu_name'] ) )
+	}
+
+	if ( ! isset( $object->labels['all_items'] ) && isset( $object->labels['menu_name'] ) ) {
 		$object->labels['all_items'] = $object->labels['menu_name'];
-
-	if ( !isset( $object->labels['archives'] ) && isset( $object->labels['all_items'] ) ) {
+	}
+
+	if ( ! isset( $object->labels['archives'] ) && isset( $object->labels['all_items'] ) ) {
 		$object->labels['archives'] = $object->labels['all_items'];
 	}
 
 	$defaults = array();
 	foreach ( $nohier_vs_hier_defaults as $key => $value ) {
-		$defaults[$key] = $object->hierarchical ? $value[1] : $value[0];
-	}
-	$labels = array_merge( $defaults, $object->labels );
+		$defaults[ $key ] = $object->hierarchical ? $value[1] : $value[0];
+	}
+	$labels         = array_merge( $defaults, $object->labels );
 	$object->labels = (object) $object->labels;
 
 	return (object) $labels;
@@ -1547,8 +1734,9 @@
 	foreach ( get_post_types( array( 'show_ui' => true ) ) as $ptype ) {
 		$ptype_obj = get_post_type_object( $ptype );
 		// Sub-menus only.
-		if ( ! $ptype_obj->show_in_menu || $ptype_obj->show_in_menu === true )
+		if ( ! $ptype_obj->show_in_menu || $ptype_obj->show_in_menu === true ) {
 			continue;
+		}
 		add_submenu_page( $ptype_obj->show_in_menu, $ptype_obj->labels->name, $ptype_obj->labels->all_items, $ptype_obj->cap->edit_posts, "edit.php?post_type=$ptype" );
 	}
 }
@@ -1577,11 +1765,12 @@
 	global $_wp_post_type_features;
 
 	$features = (array) $feature;
-	foreach ($features as $feature) {
-		if ( func_num_args() == 2 )
-			$_wp_post_type_features[$post_type][$feature] = true;
-		else
-			$_wp_post_type_features[$post_type][$feature] = array_slice( func_get_args(), 2 );
+	foreach ( $features as $feature ) {
+		if ( func_num_args() == 2 ) {
+			$_wp_post_type_features[ $post_type ][ $feature ] = true;
+		} else {
+			$_wp_post_type_features[ $post_type ][ $feature ] = array_slice( func_get_args(), 2 );
+		}
 	}
 }
 
@@ -1614,8 +1803,9 @@
 function get_all_post_type_supports( $post_type ) {
 	global $_wp_post_type_features;
 
-	if ( isset( $_wp_post_type_features[$post_type] ) )
-		return $_wp_post_type_features[$post_type];
+	if ( isset( $_wp_post_type_features[ $post_type ] ) ) {
+		return $_wp_post_type_features[ $post_type ];
+	}
 
 	return array();
 }
@@ -1634,7 +1824,7 @@
 function post_type_supports( $post_type, $feature ) {
 	global $_wp_post_type_features;
 
-	return ( isset( $_wp_post_type_features[$post_type][$feature] ) );
+	return ( isset( $_wp_post_type_features[ $post_type ][ $feature ] ) );
 }
 
 /**
@@ -1676,8 +1866,8 @@
 function set_post_type( $post_id = 0, $post_type = 'post' ) {
 	global $wpdb;
 
-	$post_type = sanitize_post_field('post_type', $post_type, $post_id, 'db');
-	$return = $wpdb->update( $wpdb->posts, array('post_type' => $post_type), array('ID' => $post_id) );
+	$post_type = sanitize_post_field( 'post_type', $post_type, $post_id, 'db' );
+	$return    = $wpdb->update( $wpdb->posts, array( 'post_type' => $post_type ), array( 'ID' => $post_id ) );
 
 	clean_post_cache( $post_id );
 
@@ -1692,7 +1882,7 @@
  *
  * @since 4.4.0
  * @since 4.5.0 Added the ability to pass a post type name in addition to object.
- * @since 4.6.0 Converted the `$post_type` parameter to accept a WP_Post_Type object.
+ * @since 4.6.0 Converted the `$post_type` parameter to accept a `WP_Post_Type` object.
  *
  * @param string|WP_Post_Type $post_type Post type name or object.
  * @return bool Whether the post type should be considered viewable.
@@ -1709,7 +1899,7 @@
 }
 
 /**
- * Retrieve list of latest posts or posts matching criteria.
+ * Retrieves an array of the latest posts, or posts matching the given criteria.
  *
  * The defaults are as follows:
  *
@@ -1730,37 +1920,45 @@
  *     @type array      $exclude          An array of post IDs not to retrieve. Default empty array.
  *     @type bool       $suppress_filters Whether to suppress filters. Default true.
  * }
- * @return array List of posts.
+ * @return WP_Post[]|int[] Array of post objects or post IDs.
  */
 function get_posts( $args = null ) {
 	$defaults = array(
-		'numberposts' => 5,
-		'category' => 0, 'orderby' => 'date',
-		'order' => 'DESC', 'include' => array(),
-		'exclude' => array(), 'meta_key' => '',
-		'meta_value' =>'', 'post_type' => 'post',
-		'suppress_filters' => true
+		'numberposts'      => 5,
+		'category'         => 0,
+		'orderby'          => 'date',
+		'order'            => 'DESC',
+		'include'          => array(),
+		'exclude'          => array(),
+		'meta_key'         => '',
+		'meta_value'       => '',
+		'post_type'        => 'post',
+		'suppress_filters' => true,
 	);
 
 	$r = wp_parse_args( $args, $defaults );
-	if ( empty( $r['post_status'] ) )
+	if ( empty( $r['post_status'] ) ) {
 		$r['post_status'] = ( 'attachment' == $r['post_type'] ) ? 'inherit' : 'publish';
-	if ( ! empty($r['numberposts']) && empty($r['posts_per_page']) )
+	}
+	if ( ! empty( $r['numberposts'] ) && empty( $r['posts_per_page'] ) ) {
 		$r['posts_per_page'] = $r['numberposts'];
-	if ( ! empty($r['category']) )
+	}
+	if ( ! empty( $r['category'] ) ) {
 		$r['cat'] = $r['category'];
-	if ( ! empty($r['include']) ) {
-		$incposts = wp_parse_id_list( $r['include'] );
-		$r['posts_per_page'] = count($incposts);  // only the number of posts included
-		$r['post__in'] = $incposts;
-	} elseif ( ! empty($r['exclude']) )
+	}
+	if ( ! empty( $r['include'] ) ) {
+		$incposts            = wp_parse_id_list( $r['include'] );
+		$r['posts_per_page'] = count( $incposts );  // only the number of posts included
+		$r['post__in']       = $incposts;
+	} elseif ( ! empty( $r['exclude'] ) ) {
 		$r['post__not_in'] = wp_parse_id_list( $r['exclude'] );
+	}
 
 	$r['ignore_sticky_posts'] = true;
-	$r['no_found_rows'] = true;
+	$r['no_found_rows']       = true;
 
 	$get_posts = new WP_Query;
-	return $get_posts->query($r);
+	return $get_posts->query( $r );
 
 }
 
@@ -1769,7 +1967,7 @@
 //
 
 /**
- * Add meta data field to a post.
+ * Adds a meta field to the given post.
  *
  * Post meta data is called "Custom Fields" on the Administration Screen.
  *
@@ -1784,22 +1982,20 @@
  */
 function add_post_meta( $post_id, $meta_key, $meta_value, $unique = false ) {
 	// Make sure meta is added to the post, not a revision.
-	if ( $the_post = wp_is_post_revision($post_id) )
+	$the_post = wp_is_post_revision( $post_id );
+	if ( $the_post ) {
 		$post_id = $the_post;
-
-	$added = add_metadata( 'post', $post_id, $meta_key, $meta_value, $unique );
-	if ( $added ) {
-		wp_cache_set( 'last_changed', microtime(), 'posts' );
-	}
-	return $added;
+	}
+
+	return add_metadata( 'post', $post_id, $meta_key, $meta_value, $unique );
 }
 
 /**
- * Remove metadata matching criteria from a post.
+ * Deletes a post meta field for the given post ID.
  *
  * You can match based on the key, or key and value. Removing based on key and
  * value, will keep from removing duplicate metadata with the same key. It also
- * allows removing all metadata matching key, if needed.
+ * allows removing all metadata matching the key, if needed.
  *
  * @since 1.5.0
  *
@@ -1811,64 +2007,62 @@
  */
 function delete_post_meta( $post_id, $meta_key, $meta_value = '' ) {
 	// Make sure meta is added to the post, not a revision.
-	if ( $the_post = wp_is_post_revision($post_id) )
+	$the_post = wp_is_post_revision( $post_id );
+	if ( $the_post ) {
 		$post_id = $the_post;
-
-	$deleted = delete_metadata( 'post', $post_id, $meta_key, $meta_value );
-	if ( $deleted ) {
-		wp_cache_set( 'last_changed', microtime(), 'posts' );
-	}
-	return $deleted;
+	}
+
+	return delete_metadata( 'post', $post_id, $meta_key, $meta_value );
 }
 
 /**
- * Retrieve post meta field for a post.
+ * Retrieves a post meta field for the given post ID.
  *
  * @since 1.5.0
  *
  * @param int    $post_id Post ID.
  * @param string $key     Optional. The meta key to retrieve. By default, returns
  *                        data for all keys. Default empty.
- * @param bool   $single  Optional. Whether to return a single value. Default false.
- * @return mixed Will be an array if $single is false. Will be value of meta data
+ * @param bool   $single  Optional. If true, returns only the first value for the specified meta key.
+ *                        This parameter has no effect if $key is not specified. Default false.
+ * @return mixed Will be an array if $single is false. Will be value of the meta
  *               field if $single is true.
  */
 function get_post_meta( $post_id, $key = '', $single = false ) {
-	return get_metadata('post', $post_id, $key, $single);
+	return get_metadata( 'post', $post_id, $key, $single );
 }
 
 /**
- * Update post meta field based on post ID.
- *
- * Use the $prev_value parameter to differentiate between meta fields with the
+ * Updates a post meta field based on the given post ID.
+ *
+ * Use the `$prev_value` parameter to differentiate between meta fields with the
  * same key and post ID.
  *
- * If the meta field for the post does not exist, it will be added.
+ * If the meta field for the post does not exist, it will be added and its ID returned.
+ *
+ * Can be used in place of add_post_meta().
  *
  * @since 1.5.0
  *
  * @param int    $post_id    Post ID.
  * @param string $meta_key   Metadata key.
  * @param mixed  $meta_value Metadata value. Must be serializable if non-scalar.
- * @param mixed  $prev_value Optional. Previous value to check before removing.
- *                           Default empty.
- * @return int|bool Meta ID if the key didn't exist, true on successful update,
- *                  false on failure.
+ * @param mixed  $prev_value Optional. Previous value to check before updating.
+ * @return int|bool The new meta field ID if a field with the given key didn't exist and was
+ *                  therefore added, true on successful update, false on failure.
  */
 function update_post_meta( $post_id, $meta_key, $meta_value, $prev_value = '' ) {
 	// Make sure meta is added to the post, not a revision.
-	if ( $the_post = wp_is_post_revision($post_id) )
+	$the_post = wp_is_post_revision( $post_id );
+	if ( $the_post ) {
 		$post_id = $the_post;
-
-	$updated = update_metadata( 'post', $post_id, $meta_key, $meta_value, $prev_value );
-	if ( $updated ) {
-		wp_cache_set( 'last_changed', microtime(), 'posts' );
-	}
-	return $updated;
+	}
+
+	return update_metadata( 'post', $post_id, $meta_key, $meta_value, $prev_value );
 }
 
 /**
- * Delete everything from post meta matching meta key.
+ * Deletes everything from post meta matching the given meta key.
  *
  * @since 2.3.0
  *
@@ -1876,11 +2070,7 @@
  * @return bool Whether the post meta key was deleted from the database.
  */
 function delete_post_meta_by_key( $post_meta_key ) {
-	$deleted = delete_metadata( 'post', null, $post_meta_key, '', true );
-	if ( $deleted ) {
-		wp_cache_set( 'last_changed', microtime(), 'posts' );
-	}
-	return $deleted;
+	return delete_metadata( 'post', null, $post_meta_key, '', true );
 }
 
 /**
@@ -1929,8 +2119,9 @@
  */
 function get_post_custom( $post_id = 0 ) {
 	$post_id = absint( $post_id );
-	if ( ! $post_id )
+	if ( ! $post_id ) {
 		$post_id = get_the_ID();
+	}
 
 	return get_post_meta( $post_id );
 }
@@ -1948,11 +2139,13 @@
 function get_post_custom_keys( $post_id = 0 ) {
 	$custom = get_post_custom( $post_id );
 
-	if ( !is_array($custom) )
+	if ( ! is_array( $custom ) ) {
 		return;
-
-	if ( $keys = array_keys($custom) )
+	}
+
+	if ( $keys = array_keys( $custom ) ) {
 		return $keys;
+	}
 }
 
 /**
@@ -1968,20 +2161,25 @@
  * @return array|null Meta field values.
  */
 function get_post_custom_values( $key = '', $post_id = 0 ) {
-	if ( !$key )
+	if ( ! $key ) {
 		return null;
-
-	$custom = get_post_custom($post_id);
-
-	return isset($custom[$key]) ? $custom[$key] : null;
+	}
+
+	$custom = get_post_custom( $post_id );
+
+	return isset( $custom[ $key ] ) ? $custom[ $key ] : null;
 }
 
 /**
- * Check if post is sticky.
+ * Determines whether a post is sticky.
  *
  * Sticky posts should remain at the top of The Loop. If the post ID is not
  * given, then The Loop ID for the current post will be used.
  *
+ * For more information on this and similar theme functions, check out
+ * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
+ * Conditional Tags} article in the Theme Developer Handbook.
+ *
  * @since 2.7.0
  *
  * @param int $post_id Optional. Post ID. Default is ID of the global $post.
@@ -1990,16 +2188,19 @@
 function is_sticky( $post_id = 0 ) {
 	$post_id = absint( $post_id );
 
-	if ( ! $post_id )
+	if ( ! $post_id ) {
 		$post_id = get_the_ID();
+	}
 
 	$stickies = get_option( 'sticky_posts' );
 
-	if ( ! is_array( $stickies ) )
+	if ( ! is_array( $stickies ) ) {
 		return false;
-
-	if ( in_array( $post_id, $stickies ) )
+	}
+
+	if ( in_array( $post_id, $stickies ) ) {
 		return true;
+	}
 
 	return false;
 }
@@ -2022,23 +2223,29 @@
  *                              same type as $post).
  */
 function sanitize_post( $post, $context = 'display' ) {
-	if ( is_object($post) ) {
+	if ( is_object( $post ) ) {
 		// Check if post already filtered for this context.
-		if ( isset($post->filter) && $context == $post->filter )
+		if ( isset( $post->filter ) && $context == $post->filter ) {
 			return $post;
-		if ( !isset($post->ID) )
+		}
+		if ( ! isset( $post->ID ) ) {
 			$post->ID = 0;
-		foreach ( array_keys(get_object_vars($post)) as $field )
-			$post->$field = sanitize_post_field($field, $post->$field, $post->ID, $context);
+		}
+		foreach ( array_keys( get_object_vars( $post ) ) as $field ) {
+			$post->$field = sanitize_post_field( $field, $post->$field, $post->ID, $context );
+		}
 		$post->filter = $context;
 	} elseif ( is_array( $post ) ) {
 		// Check if post already filtered for this context.
-		if ( isset($post['filter']) && $context == $post['filter'] )
+		if ( isset( $post['filter'] ) && $context == $post['filter'] ) {
 			return $post;
-		if ( !isset($post['ID']) )
+		}
+		if ( ! isset( $post['ID'] ) ) {
 			$post['ID'] = 0;
-		foreach ( array_keys($post) as $field )
-			$post[$field] = sanitize_post_field($field, $post[$field], $post['ID'], $context);
+		}
+		foreach ( array_keys( $post ) as $field ) {
+			$post[ $field ] = sanitize_post_field( $field, $post[ $field ], $post['ID'], $context );
+		}
 		$post['filter'] = $context;
 	}
 	return $post;
@@ -2062,28 +2269,30 @@
  * @return mixed Sanitized value.
  */
 function sanitize_post_field( $field, $value, $post_id, $context = 'display' ) {
-	$int_fields = array('ID', 'post_parent', 'menu_order');
-	if ( in_array($field, $int_fields) )
+	$int_fields = array( 'ID', 'post_parent', 'menu_order' );
+	if ( in_array( $field, $int_fields ) ) {
 		$value = (int) $value;
+	}
 
 	// Fields which contain arrays of integers.
 	$array_int_fields = array( 'ancestors' );
-	if ( in_array($field, $array_int_fields) ) {
-		$value = array_map( 'absint', $value);
+	if ( in_array( $field, $array_int_fields ) ) {
+		$value = array_map( 'absint', $value );
 		return $value;
 	}
 
-	if ( 'raw' == $context )
+	if ( 'raw' == $context ) {
 		return $value;
+	}
 
 	$prefixed = false;
-	if ( false !== strpos($field, 'post_') ) {
-		$prefixed = true;
-		$field_no_prefix = str_replace('post_', '', $field);
+	if ( false !== strpos( $field, 'post_' ) ) {
+		$prefixed        = true;
+		$field_no_prefix = str_replace( 'post_', '', $field );
 	}
 
 	if ( 'edit' == $context ) {
-		$format_to_edit = array('post_content', 'post_excerpt', 'post_title', 'post_password');
+		$format_to_edit = array( 'post_content', 'post_excerpt', 'post_title', 'post_password' );
 
 		if ( $prefixed ) {
 
@@ -2116,13 +2325,14 @@
 			$value = apply_filters( "edit_post_{$field}", $value, $post_id );
 		}
 
-		if ( in_array($field, $format_to_edit) ) {
-			if ( 'post_content' == $field )
-				$value = format_to_edit($value, user_can_richedit());
-			else
-				$value = format_to_edit($value);
+		if ( in_array( $field, $format_to_edit ) ) {
+			if ( 'post_content' == $field ) {
+				$value = format_to_edit( $value, user_can_richedit() );
+			} else {
+				$value = format_to_edit( $value );
+			}
 		} else {
-			$value = esc_attr($value);
+			$value = esc_attr( $value );
 		}
 	} elseif ( 'db' == $context ) {
 		if ( $prefixed ) {
@@ -2209,13 +2419,15 @@
  * @param int $post_id Post ID.
  */
 function stick_post( $post_id ) {
-	$stickies = get_option('sticky_posts');
-
-	if ( !is_array($stickies) )
-		$stickies = array($post_id);
-
-	if ( ! in_array($post_id, $stickies) )
+	$stickies = get_option( 'sticky_posts' );
+
+	if ( ! is_array( $stickies ) ) {
+		$stickies = array( $post_id );
+	}
+
+	if ( ! in_array( $post_id, $stickies ) ) {
 		$stickies[] = $post_id;
+	}
 
 	$updated = update_option( 'sticky_posts', $stickies );
 
@@ -2241,19 +2453,22 @@
  * @param int $post_id Post ID.
  */
 function unstick_post( $post_id ) {
-	$stickies = get_option('sticky_posts');
-
-	if ( !is_array($stickies) )
+	$stickies = get_option( 'sticky_posts' );
+
+	if ( ! is_array( $stickies ) ) {
 		return;
-
-	if ( ! in_array($post_id, $stickies) )
+	}
+
+	if ( ! in_array( $post_id, $stickies ) ) {
 		return;
-
-	$offset = array_search($post_id, $stickies);
-	if ( false === $offset )
+	}
+
+	$offset = array_search( $post_id, $stickies );
+	if ( false === $offset ) {
 		return;
-
-	array_splice($stickies, $offset, 1);
+	}
+
+	array_splice( $stickies, $offset, 1 );
 
 	$updated = update_option( 'sticky_posts', $stickies );
 
@@ -2273,6 +2488,7 @@
  * Return the cache key for wp_count_posts() based on the passed arguments.
  *
  * @since 3.9.0
+ * @access private
  *
  * @param string $type Optional. Post type to retrieve count Default 'post'.
  * @param string $perm Optional. 'readable' or empty. Default empty.
@@ -2311,8 +2527,9 @@
 function wp_count_posts( $type = 'post', $perm = '' ) {
 	global $wpdb;
 
-	if ( ! post_type_exists( $type ) )
+	if ( ! post_type_exists( $type ) ) {
 		return new stdClass;
+	}
 
 	$cache_key = _count_posts_cache_key( $type, $perm );
 
@@ -2324,9 +2541,10 @@
 
 	$query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s";
 	if ( 'readable' == $perm && is_user_logged_in() ) {
-		$post_type_object = get_post_type_object($type);
+		$post_type_object = get_post_type_object( $type );
 		if ( ! current_user_can( $post_type_object->cap->read_private_posts ) ) {
-			$query .= $wpdb->prepare( " AND (post_status != 'private' OR ( post_author = %d AND post_status = 'private' ))",
+			$query .= $wpdb->prepare(
+				" AND (post_status != 'private' OR ( post_author = %d AND post_status = 'private' ))",
 				get_current_user_id()
 			);
 		}
@@ -2334,7 +2552,7 @@
 	$query .= ' GROUP BY post_status';
 
 	$results = (array) $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A );
-	$counts = array_fill_keys( get_post_stati(), 0 );
+	$counts  = array_fill_keys( get_post_stati(), 0 );
 
 	foreach ( $results as $row ) {
 		$counts[ $row['post_status'] ] = $row['num_posts'];
@@ -2376,14 +2594,14 @@
 function wp_count_attachments( $mime_type = '' ) {
 	global $wpdb;
 
-	$and = wp_post_mime_type_where( $mime_type );
+	$and   = wp_post_mime_type_where( $mime_type );
 	$count = $wpdb->get_results( "SELECT post_mime_type, COUNT( * ) AS num_posts FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' $and GROUP BY post_mime_type", ARRAY_A );
 
 	$counts = array();
 	foreach ( (array) $count as $row ) {
 		$counts[ $row['post_mime_type'] ] = $row['num_posts'];
 	}
-	$counts['trash'] = $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status = 'trash' $and");
+	$counts['trash'] = $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status = 'trash' $and" );
 
 	/**
 	 * Modify returned attachment counts by mime type.
@@ -2406,10 +2624,10 @@
  * @return array List of post mime types.
  */
 function get_post_mime_types() {
-	$post_mime_types = array(	//	array( adj, noun )
-		'image' => array(__('Images'), __('Manage Images'), _n_noop('Image <span class="count">(%s)</span>', 'Images <span class="count">(%s)</span>')),
-		'audio' => array(__('Audio'), __('Manage Audio'), _n_noop('Audio <span class="count">(%s)</span>', 'Audio <span class="count">(%s)</span>')),
-		'video' => array(__('Video'), __('Manage Video'), _n_noop('Video <span class="count">(%s)</span>', 'Video <span class="count">(%s)</span>')),
+	$post_mime_types = array(   //	array( adj, noun )
+		'image' => array( __( 'Images' ), __( 'Manage Images' ), _n_noop( 'Image <span class="count">(%s)</span>', 'Images <span class="count">(%s)</span>' ) ),
+		'audio' => array( __( 'Audio' ), __( 'Manage Audio' ), _n_noop( 'Audio <span class="count">(%s)</span>', 'Audio <span class="count">(%s)</span>' ) ),
+		'video' => array( __( 'Video' ), __( 'Manage Video' ), _n_noop( 'Video <span class="count">(%s)</span>', 'Video <span class="count">(%s)</span>' ) ),
 	);
 
 	/**
@@ -2446,16 +2664,16 @@
 	}
 
 	$patternses = array();
-	$wild = '[-._a-z0-9]*';
+	$wild       = '[-._a-z0-9]*';
 
 	foreach ( (array) $wildcard_mime_types as $type ) {
 		$mimes = array_map( 'trim', explode( ',', $type ) );
 		foreach ( $mimes as $mime ) {
-			$regex = str_replace( '__wildcard__', $wild, preg_quote( str_replace( '*', '__wildcard__', $mime ) ) );
-			$patternses[][$type] = "^$regex$";
+			$regex                 = str_replace( '__wildcard__', $wild, preg_quote( str_replace( '*', '__wildcard__', $mime ) ) );
+			$patternses[][ $type ] = "^$regex$";
 			if ( false === strpos( $mime, '/' ) ) {
-				$patternses[][$type] = "^$regex/";
-				$patternses[][$type] = $regex;
+				$patternses[][ $type ] = "^$regex/";
+				$patternses[][ $type ] = $regex;
 			}
 		}
 	}
@@ -2464,8 +2682,8 @@
 	foreach ( $patternses as $patterns ) {
 		foreach ( $patterns as $type => $pattern ) {
 			foreach ( (array) $real_mime_types as $real ) {
-				if ( preg_match( "#$pattern#", $real ) && ( empty( $matches[$type] ) || false === array_search( $real, $matches[$type] ) ) ) {
-					$matches[$type][] = $real;
+				if ( preg_match( "#$pattern#", $real ) && ( empty( $matches[ $type ] ) || false === array_search( $real, $matches[ $type ] ) ) ) {
+					$matches[ $type ][] = $real;
 				}
 			}
 		}
@@ -2485,42 +2703,48 @@
  * @return string The SQL AND clause for mime searching.
  */
 function wp_post_mime_type_where( $post_mime_types, $table_alias = '' ) {
-	$where = '';
-	$wildcards = array('', '%', '%/%');
-	if ( is_string($post_mime_types) )
-		$post_mime_types = array_map('trim', explode(',', $post_mime_types));
+	$where     = '';
+	$wildcards = array( '', '%', '%/%' );
+	if ( is_string( $post_mime_types ) ) {
+		$post_mime_types = array_map( 'trim', explode( ',', $post_mime_types ) );
+	}
 
 	$wheres = array();
 
 	foreach ( (array) $post_mime_types as $mime_type ) {
-		$mime_type = preg_replace('/\s/', '', $mime_type);
-		$slashpos = strpos($mime_type, '/');
+		$mime_type = preg_replace( '/\s/', '', $mime_type );
+		$slashpos  = strpos( $mime_type, '/' );
 		if ( false !== $slashpos ) {
-			$mime_group = preg_replace('/[^-*.a-zA-Z0-9]/', '', substr($mime_type, 0, $slashpos));
-			$mime_subgroup = preg_replace('/[^-*.+a-zA-Z0-9]/', '', substr($mime_type, $slashpos + 1));
-			if ( empty($mime_subgroup) )
+			$mime_group    = preg_replace( '/[^-*.a-zA-Z0-9]/', '', substr( $mime_type, 0, $slashpos ) );
+			$mime_subgroup = preg_replace( '/[^-*.+a-zA-Z0-9]/', '', substr( $mime_type, $slashpos + 1 ) );
+			if ( empty( $mime_subgroup ) ) {
 				$mime_subgroup = '*';
-			else
-				$mime_subgroup = str_replace('/', '', $mime_subgroup);
+			} else {
+				$mime_subgroup = str_replace( '/', '', $mime_subgroup );
+			}
 			$mime_pattern = "$mime_group/$mime_subgroup";
 		} else {
-			$mime_pattern = preg_replace('/[^-*.a-zA-Z0-9]/', '', $mime_type);
-			if ( false === strpos($mime_pattern, '*') )
+			$mime_pattern = preg_replace( '/[^-*.a-zA-Z0-9]/', '', $mime_type );
+			if ( false === strpos( $mime_pattern, '*' ) ) {
 				$mime_pattern .= '/*';
+			}
 		}
 
-		$mime_pattern = preg_replace('/\*+/', '%', $mime_pattern);
-
-		if ( in_array( $mime_type, $wildcards ) )
+		$mime_pattern = preg_replace( '/\*+/', '%', $mime_pattern );
+
+		if ( in_array( $mime_type, $wildcards ) ) {
 			return '';
-
-		if ( false !== strpos($mime_pattern, '%') )
-			$wheres[] = empty($table_alias) ? "post_mime_type LIKE '$mime_pattern'" : "$table_alias.post_mime_type LIKE '$mime_pattern'";
-		else
-			$wheres[] = empty($table_alias) ? "post_mime_type = '$mime_pattern'" : "$table_alias.post_mime_type = '$mime_pattern'";
-	}
-	if ( !empty($wheres) )
-		$where = ' AND (' . join(' OR ', $wheres) . ') ';
+		}
+
+		if ( false !== strpos( $mime_pattern, '%' ) ) {
+			$wheres[] = empty( $table_alias ) ? "post_mime_type LIKE '$mime_pattern'" : "$table_alias.post_mime_type LIKE '$mime_pattern'";
+		} else {
+			$wheres[] = empty( $table_alias ) ? "post_mime_type = '$mime_pattern'" : "$table_alias.post_mime_type = '$mime_pattern'";
+		}
+	}
+	if ( ! empty( $wheres ) ) {
+		$where = ' AND (' . join( ' OR ', $wheres ) . ') ';
+	}
 	return $where;
 }
 
@@ -2589,18 +2813,18 @@
 	 */
 	do_action( 'before_delete_post', $postid );
 
-	delete_post_meta($postid,'_wp_trash_meta_status');
-	delete_post_meta($postid,'_wp_trash_meta_time');
-
-	wp_delete_object_term_relationships($postid, get_object_taxonomies($post->post_type));
-
-	$parent_data = array( 'post_parent' => $post->post_parent );
+	delete_post_meta( $postid, '_wp_trash_meta_status' );
+	delete_post_meta( $postid, '_wp_trash_meta_time' );
+
+	wp_delete_object_term_relationships( $postid, get_object_taxonomies( $post->post_type ) );
+
+	$parent_data  = array( 'post_parent' => $post->post_parent );
 	$parent_where = array( 'post_parent' => $postid );
 
 	if ( is_post_type_hierarchical( $post->post_type ) ) {
 		// Point children of this page to its parent, also clean the cache of affected children.
 		$children_query = $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_parent = %d AND post_type = %s", $postid, $post->post_type );
-		$children = $wpdb->get_results( $children_query );
+		$children       = $wpdb->get_results( $children_query );
 		if ( $children ) {
 			$wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => $post->post_type ) );
 		}
@@ -2609,24 +2833,26 @@
 	// Do raw query. wp_get_post_revisions() is filtered.
 	$revision_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'revision'", $postid ) );
 	// Use wp_delete_post (via wp_delete_post_revision) again. Ensures any meta/misplaced data gets cleaned up.
-	foreach ( $revision_ids as $revision_id )
+	foreach ( $revision_ids as $revision_id ) {
 		wp_delete_post_revision( $revision_id );
+	}
 
 	// Point all attachments to this post up one level.
 	$wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => 'attachment' ) );
 
 	wp_defer_comment_counting( true );
 
-	$comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $postid ));
+	$comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $postid ) );
 	foreach ( $comment_ids as $comment_id ) {
 		wp_delete_comment( $comment_id, true );
 	}
 
 	wp_defer_comment_counting( false );
 
-	$post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $postid ));
-	foreach ( $post_meta_ids as $mid )
+	$post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $postid ) );
+	foreach ( $post_meta_ids as $mid ) {
 		delete_metadata_by_mid( 'post', $mid );
+	}
 
 	/**
 	 * Fires immediately before a post is deleted from the database.
@@ -2653,11 +2879,12 @@
 	clean_post_cache( $post );
 
 	if ( is_post_type_hierarchical( $post->post_type ) && $children ) {
-		foreach ( $children as $child )
+		foreach ( $children as $child ) {
 			clean_post_cache( $child );
-	}
-
-	wp_clear_scheduled_hook('publish_future_post', array( $postid ) );
+		}
+	}
+
+	wp_clear_scheduled_hook( 'publish_future_post', array( $postid ) );
 
 	/**
 	 * Fires after a post is deleted, at the conclusion of wp_delete_post().
@@ -2687,10 +2914,10 @@
 function _reset_front_page_settings_for_post( $post_id ) {
 	$post = get_post( $post_id );
 	if ( 'page' == $post->post_type ) {
-	 	/*
-	 	 * If the page is defined in option page_on_front or post_for_posts,
-	 	 * adjust the corresponding options.
-	 	 */
+		/*
+		  * If the page is defined in option page_on_front or post_for_posts,
+		  * adjust the corresponding options.
+		  */
 		if ( get_option( 'page_on_front' ) == $post->ID ) {
 			update_option( 'show_on_front', 'posts' );
 			update_option( 'page_on_front', 0 );
@@ -2755,7 +2982,12 @@
 	add_post_meta( $post_id, '_wp_trash_meta_status', $post->post_status );
 	add_post_meta( $post_id, '_wp_trash_meta_time', time() );
 
-	wp_update_post( array( 'ID' => $post_id, 'post_status' => 'trash' ) );
+	wp_update_post(
+		array(
+			'ID'          => $post_id,
+			'post_status' => 'trash',
+		)
+	);
 
 	wp_trash_post_comments( $post_id );
 
@@ -2817,7 +3049,12 @@
 	delete_post_meta( $post_id, '_wp_trash_meta_status' );
 	delete_post_meta( $post_id, '_wp_trash_meta_time' );
 
-	wp_update_post( array( 'ID' => $post_id, 'post_status' => $post_status ) );
+	wp_update_post(
+		array(
+			'ID'          => $post_id,
+			'post_status' => $post_status,
+		)
+	);
 
 	wp_untrash_post_comments( $post_id );
 
@@ -2846,9 +3083,10 @@
 function wp_trash_post_comments( $post = null ) {
 	global $wpdb;
 
-	$post = get_post($post);
-	if ( empty($post) )
+	$post = get_post( $post );
+	if ( empty( $post ) ) {
 		return;
+	}
 
 	$post_id = $post->ID;
 
@@ -2861,20 +3099,22 @@
 	 */
 	do_action( 'trash_post_comments', $post_id );
 
-	$comments = $wpdb->get_results( $wpdb->prepare("SELECT comment_ID, comment_approved FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id) );
-	if ( empty($comments) )
+	$comments = $wpdb->get_results( $wpdb->prepare( "SELECT comment_ID, comment_approved FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id ) );
+	if ( empty( $comments ) ) {
 		return;
+	}
 
 	// Cache current status for each comment.
 	$statuses = array();
-	foreach ( $comments as $comment )
-		$statuses[$comment->comment_ID] = $comment->comment_approved;
-	add_post_meta($post_id, '_wp_trash_meta_comments_status', $statuses);
+	foreach ( $comments as $comment ) {
+		$statuses[ $comment->comment_ID ] = $comment->comment_approved;
+	}
+	add_post_meta( $post_id, '_wp_trash_meta_comments_status', $statuses );
 
 	// Set status for all comments to post-trashed.
-	$result = $wpdb->update($wpdb->comments, array('comment_approved' => 'post-trashed'), array('comment_post_ID' => $post_id));
-
-	clean_comment_cache( array_keys($statuses) );
+	$result = $wpdb->update( $wpdb->comments, array( 'comment_approved' => 'post-trashed' ), array( 'comment_post_ID' => $post_id ) );
+
+	clean_comment_cache( array_keys( $statuses ) );
 
 	/**
 	 * Fires after comments are sent to the trash.
@@ -2902,16 +3142,18 @@
 function wp_untrash_post_comments( $post = null ) {
 	global $wpdb;
 
-	$post = get_post($post);
-	if ( empty($post) )
+	$post = get_post( $post );
+	if ( empty( $post ) ) {
 		return;
+	}
 
 	$post_id = $post->ID;
 
-	$statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
-
-	if ( empty($statuses) )
+	$statuses = get_post_meta( $post_id, '_wp_trash_meta_comments_status', true );
+
+	if ( empty( $statuses ) ) {
 		return true;
+	}
 
 	/**
 	 * Fires before comments are restored for a post from the trash.
@@ -2924,8 +3166,9 @@
 
 	// Restore each comment to its original status.
 	$group_by_status = array();
-	foreach ( $statuses as $comment_id => $comment_status )
-		$group_by_status[$comment_status][] = $comment_id;
+	foreach ( $statuses as $comment_id => $comment_status ) {
+		$group_by_status[ $comment_status ][] = $comment_id;
+	}
 
 	foreach ( $group_by_status as $status => $comments ) {
 		// Sanity check. This shouldn't happen.
@@ -2936,9 +3179,9 @@
 		$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->comments SET comment_approved = %s WHERE comment_ID IN ($comments_in)", $status ) );
 	}
 
-	clean_comment_cache( array_keys($statuses) );
-
-	delete_post_meta($post_id, '_wp_trash_meta_comments_status');
+	clean_comment_cache( array_keys( $statuses ) );
+
+	delete_post_meta( $post_id, '_wp_trash_meta_comments_status' );
 
 	/**
 	 * Fires after comments are restored for a post from the trash.
@@ -2972,10 +3215,10 @@
 function wp_get_post_categories( $post_id = 0, $args = array() ) {
 	$post_id = (int) $post_id;
 
-	$defaults = array('fields' => 'ids');
-	$args = wp_parse_args( $args, $defaults );
-
-	$cats = wp_get_object_terms($post_id, 'category', $args);
+	$defaults = array( 'fields' => 'ids' );
+	$args     = wp_parse_args( $args, $defaults );
+
+	$cats = wp_get_object_terms( $post_id, 'category', $args );
 	return $cats;
 }
 
@@ -2996,7 +3239,7 @@
  *                        WP_Error object if 'post_tag' taxonomy doesn't exist.
  */
 function wp_get_post_tags( $post_id = 0, $args = array() ) {
-	return wp_get_post_terms( $post_id, 'post_tag', $args);
+	return wp_get_post_terms( $post_id, 'post_tag', $args );
 }
 
 /**
@@ -3019,10 +3262,10 @@
 function wp_get_post_terms( $post_id = 0, $taxonomy = 'post_tag', $args = array() ) {
 	$post_id = (int) $post_id;
 
-	$defaults = array('fields' => 'all');
-	$args = wp_parse_args( $args, $defaults );
-
-	$tags = wp_get_object_terms($post_id, $taxonomy, $args);
+	$defaults = array( 'fields' => 'all' );
+	$args     = wp_parse_args( $args, $defaults );
+
+	$tags = wp_get_object_terms( $post_id, $taxonomy, $args );
 
 	return $tags;
 }
@@ -3049,12 +3292,18 @@
 
 	// Set default arguments.
 	$defaults = array(
-		'numberposts' => 10, 'offset' => 0,
-		'category' => 0, 'orderby' => 'post_date',
-		'order' => 'DESC', 'include' => '',
-		'exclude' => '', 'meta_key' => '',
-		'meta_value' =>'', 'post_type' => 'post', 'post_status' => 'draft, publish, future, pending, private',
-		'suppress_filters' => true
+		'numberposts'      => 10,
+		'offset'           => 0,
+		'category'         => 0,
+		'orderby'          => 'post_date',
+		'order'            => 'DESC',
+		'include'          => '',
+		'exclude'          => '',
+		'meta_key'         => '',
+		'meta_value'       => '',
+		'post_type'        => 'post',
+		'post_status'      => 'draft, publish, future, pending, private',
+		'suppress_filters' => true,
 	);
 
 	$r = wp_parse_args( $args, $defaults );
@@ -3062,9 +3311,9 @@
 	$results = get_posts( $r );
 
 	// Backward compatibility. Prior to 3.1 expected posts to be returned in array.
-	if ( ARRAY_A == $output ){
+	if ( ARRAY_A == $output ) {
 		foreach ( $results as $key => $result ) {
-			$results[$key] = get_object_vars( $result );
+			$results[ $key ] = get_object_vars( $result );
 		}
 		return $results ? $results : array();
 	}
@@ -3124,7 +3373,7 @@
  *     @type int    $menu_order            The order the post should be displayed in. Default 0.
  *     @type string $post_mime_type        The mime type of the post. Default empty.
  *     @type string $guid                  Global Unique ID for referencing the post. Default empty.
- *     @type array  $post_category         Array of category names, slugs, or IDs.
+ *     @type array  $post_category         Array of category IDs.
  *                                         Defaults to value of the 'default_category' option.
  *     @type array  $tags_input            Array of tag names, slugs, or IDs. Default empty.
  *     @type array  $tax_input             Array of taxonomy terms keyed by their taxonomy name. Default empty.
@@ -3139,41 +3388,41 @@
 	$user_id = get_current_user_id();
 
 	$defaults = array(
-		'post_author' => $user_id,
-		'post_content' => '',
+		'post_author'           => $user_id,
+		'post_content'          => '',
 		'post_content_filtered' => '',
-		'post_title' => '',
-		'post_excerpt' => '',
-		'post_status' => 'draft',
-		'post_type' => 'post',
-		'comment_status' => '',
-		'ping_status' => '',
-		'post_password' => '',
-		'to_ping' =>  '',
-		'pinged' => '',
-		'post_parent' => 0,
-		'menu_order' => 0,
-		'guid' => '',
-		'import_id' => 0,
-		'context' => '',
+		'post_title'            => '',
+		'post_excerpt'          => '',
+		'post_status'           => 'draft',
+		'post_type'             => 'post',
+		'comment_status'        => '',
+		'ping_status'           => '',
+		'post_password'         => '',
+		'to_ping'               => '',
+		'pinged'                => '',
+		'post_parent'           => 0,
+		'menu_order'            => 0,
+		'guid'                  => '',
+		'import_id'             => 0,
+		'context'               => '',
 	);
 
-	$postarr = wp_parse_args($postarr, $defaults);
-
-	unset( $postarr[ 'filter' ] );
-
-	$postarr = sanitize_post($postarr, 'db');
+	$postarr = wp_parse_args( $postarr, $defaults );
+
+	unset( $postarr['filter'] );
+
+	$postarr = sanitize_post( $postarr, 'db' );
 
 	// Are we updating or creating?
 	$post_ID = 0;
-	$update = false;
-	$guid = $postarr['guid'];
+	$update  = false;
+	$guid    = $postarr['guid'];
 
 	if ( ! empty( $postarr['ID'] ) ) {
 		$update = true;
 
 		// Get the post ID and GUID.
-		$post_ID = $postarr['ID'];
+		$post_ID     = $postarr['ID'];
 		$post_before = get_post( $post_ID );
 		if ( is_null( $post_before ) ) {
 			if ( $wp_error ) {
@@ -3182,15 +3431,15 @@
 			return 0;
 		}
 
-		$guid = get_post_field( 'guid', $post_ID );
-		$previous_status = get_post_field('post_status', $post_ID );
+		$guid            = get_post_field( 'guid', $post_ID );
+		$previous_status = get_post_field( 'post_status', $post_ID );
 	} else {
 		$previous_status = 'new';
 	}
 
 	$post_type = empty( $postarr['post_type'] ) ? 'post' : $postarr['post_type'];
 
-	$post_title = $postarr['post_title'];
+	$post_title   = $postarr['post_title'];
 	$post_content = $postarr['post_content'];
 	$post_excerpt = $postarr['post_excerpt'];
 	if ( isset( $postarr['post_name'] ) ) {
@@ -3244,14 +3493,22 @@
 	if ( empty( $post_category ) || 0 == count( $post_category ) || ! is_array( $post_category ) ) {
 		// 'post' requires at least one category.
 		if ( 'post' == $post_type && 'auto-draft' != $post_status ) {
-			$post_category = array( get_option('default_category') );
+			$post_category = array( get_option( 'default_category' ) );
 		} else {
 			$post_category = array();
 		}
 	}
 
-	// Don't allow contributors to set the post slug for pending review posts.
-	if ( 'pending' == $post_status && !current_user_can( 'publish_posts' ) ) {
+	/*
+	 * Don't allow contributors to set the post slug for pending review posts.
+	 *
+	 * For new posts check the primitive capability, for updates check the meta capability.
+	 */
+	$post_type_object = get_post_type_object( $post_type );
+
+	if ( ! $update && 'pending' === $post_status && ! current_user_can( $post_type_object->cap->publish_posts ) ) {
+		$post_name = '';
+	} elseif ( $update && 'pending' === $post_status && ! current_user_can( 'publish_post', $post_ID ) ) {
 		$post_name = '';
 	}
 
@@ -3259,9 +3516,9 @@
 	 * Create a valid post name. Drafts and pending posts are allowed to have
 	 * an empty post name.
 	 */
-	if ( empty($post_name) ) {
-		if ( !in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) {
-			$post_name = sanitize_title($post_title);
+	if ( empty( $post_name ) ) {
+		if ( ! in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) {
+			$post_name = sanitize_title( $post_title );
 		} else {
 			$post_name = '';
 		}
@@ -3271,7 +3528,7 @@
 		if ( $update && strtolower( urlencode( $post_name ) ) == $check_name && get_post_field( 'post_name', $post_ID ) == $check_name ) {
 			$post_name = $check_name;
 		} else { // new post, or slug has changed.
-			$post_name = sanitize_title($post_name);
+			$post_name = sanitize_title( $post_name );
 		}
 	}
 
@@ -3290,9 +3547,9 @@
 	}
 
 	// Validate the date.
-	$mm = substr( $post_date, 5, 2 );
-	$jj = substr( $post_date, 8, 2 );
-	$aa = substr( $post_date, 0, 4 );
+	$mm         = substr( $post_date, 5, 2 );
+	$jj         = substr( $post_date, 8, 2 );
+	$aa         = substr( $post_date, 0, 4 );
 	$valid_date = wp_checkdate( $mm, $jj, $aa, $post_date );
 	if ( ! $valid_date ) {
 		if ( $wp_error ) {
@@ -3322,13 +3579,13 @@
 
 	if ( 'attachment' !== $post_type ) {
 		if ( 'publish' == $post_status ) {
-			$now = gmdate('Y-m-d H:i:59');
-			if ( mysql2date('U', $post_date_gmt, false) > mysql2date('U', $now, false) ) {
+			$now = gmdate( 'Y-m-d H:i:59' );
+			if ( mysql2date( 'U', $post_date_gmt, false ) > mysql2date( 'U', $now, false ) ) {
 				$post_status = 'future';
 			}
 		} elseif ( 'future' == $post_status ) {
-			$now = gmdate('Y-m-d H:i:59');
-			if ( mysql2date('U', $post_date_gmt, false) <= mysql2date('U', $now, false) ) {
+			$now = gmdate( 'Y-m-d H:i:59' );
+			if ( mysql2date( 'U', $post_date_gmt, false ) <= mysql2date( 'U', $now, false ) ) {
 				$post_status = 'publish';
 			}
 		}
@@ -3347,11 +3604,11 @@
 
 	// These variables are needed by compact() later.
 	$post_content_filtered = $postarr['post_content_filtered'];
-	$post_author = isset( $postarr['post_author'] ) ? $postarr['post_author'] : $user_id;
-	$ping_status = empty( $postarr['ping_status'] ) ? get_default_comment_status( $post_type, 'pingback' ) : $postarr['ping_status'];
-	$to_ping = isset( $postarr['to_ping'] ) ? sanitize_trackback_urls( $postarr['to_ping'] ) : '';
-	$pinged = isset( $postarr['pinged'] ) ? $postarr['pinged'] : '';
-	$import_id = isset( $postarr['import_id'] ) ? $postarr['import_id'] : 0;
+	$post_author           = isset( $postarr['post_author'] ) ? $postarr['post_author'] : $user_id;
+	$ping_status           = empty( $postarr['ping_status'] ) ? get_default_comment_status( $post_type, 'pingback' ) : $postarr['ping_status'];
+	$to_ping               = isset( $postarr['to_ping'] ) ? sanitize_trackback_urls( $postarr['to_ping'] ) : '';
+	$pinged                = isset( $postarr['pinged'] ) ? $postarr['pinged'] : '';
+	$import_id             = isset( $postarr['import_id'] ) ? $postarr['import_id'] : 0;
 
 	/*
 	 * The 'wp_insert_post_parent' filter expects all variables to be present.
@@ -3374,6 +3631,13 @@
 		$post_parent = 0;
 	}
 
+	$new_postarr = array_merge(
+		array(
+			'ID' => $post_ID,
+		),
+		compact( array_diff( array_keys( $defaults ), array( 'context', 'filter' ) ) )
+	);
+
 	/**
 	 * Filters the post parent -- used to check for and prevent hierarchy loops.
 	 *
@@ -3384,7 +3648,7 @@
 	 * @param array $new_postarr Array of parsed post data.
 	 * @param array $postarr     Array of sanitized, but otherwise unmodified post data.
 	 */
-	$post_parent = apply_filters( 'wp_insert_post_parent', $post_parent, $post_ID, compact( array_keys( $postarr ) ), $postarr );
+	$post_parent = apply_filters( 'wp_insert_post_parent', $post_parent, $post_ID, $new_postarr, $postarr );
 
 	/*
 	 * If the post is being untrashed and it has a desired slug stored in post meta,
@@ -3448,7 +3712,7 @@
 		 */
 		$data = apply_filters( 'wp_insert_post_data', $data, $postarr );
 	}
-	$data = wp_unslash( $data );
+	$data  = wp_unslash( $data );
 	$where = array( 'ID' => $post_ID );
 
 	if ( $update ) {
@@ -3463,7 +3727,7 @@
 		do_action( 'pre_post_update', $post_ID, $data );
 		if ( false === $wpdb->update( $wpdb->posts, $data, $where ) ) {
 			if ( $wp_error ) {
-				return new WP_Error('db_update_error', __('Could not update post in the database'), $wpdb->last_error);
+				return new WP_Error( 'db_update_error', __( 'Could not update post in the database' ), $wpdb->last_error );
 			} else {
 				return 0;
 			}
@@ -3472,13 +3736,13 @@
 		// If there is a suggested ID, use it if not already present.
 		if ( ! empty( $import_id ) ) {
 			$import_id = (int) $import_id;
-			if ( ! $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE ID = %d", $import_id) ) ) {
+			if ( ! $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE ID = %d", $import_id ) ) ) {
 				$data['ID'] = $import_id;
 			}
 		}
 		if ( false === $wpdb->insert( $wpdb->posts, $data ) ) {
 			if ( $wp_error ) {
-				return new WP_Error('db_insert_error', __('Could not insert post into the database'), $wpdb->last_error);
+				return new WP_Error( 'db_insert_error', __( 'Could not insert post into the database' ), $wpdb->last_error );
 			} else {
 				return 0;
 			}
@@ -3506,7 +3770,7 @@
 	// New-style support for all custom taxonomies.
 	if ( ! empty( $postarr['tax_input'] ) ) {
 		foreach ( $postarr['tax_input'] as $taxonomy => $tags ) {
-			$taxonomy_obj = get_taxonomy($taxonomy);
+			$taxonomy_obj = get_taxonomy( $taxonomy );
 			if ( ! $taxonomy_obj ) {
 				/* translators: %s: taxonomy name */
 				_doing_it_wrong( __FUNCTION__, sprintf( __( 'Invalid taxonomy: %s.' ), $taxonomy ), '4.4.0' );
@@ -3515,7 +3779,7 @@
 
 			// array = hierarchical, string = non-hierarchical.
 			if ( is_array( $tags ) ) {
-				$tags = array_filter($tags);
+				$tags = array_filter( $tags );
 			}
 			if ( current_user_can( $taxonomy_obj->cap->assign_terms ) ) {
 				wp_set_post_terms( $post_ID, $tags, $taxonomy );
@@ -3573,7 +3837,7 @@
 
 	if ( ! empty( $postarr['page_template'] ) ) {
 		$post->page_template = $postarr['page_template'];
-		$page_templates = wp_get_theme()->get_page_templates( $post );
+		$page_templates      = wp_get_theme()->get_page_templates( $post );
 		if ( 'default' != $postarr['page_template'] && ! isset( $page_templates[ $postarr['page_template'] ] ) ) {
 			if ( $wp_error ) {
 				return new WP_Error( 'invalid_page_template', __( 'Invalid page template.' ) );
@@ -3627,13 +3891,27 @@
 		/**
 		 * Fires once an existing post has been updated.
 		 *
+		 * The dynamic portion of the hook name, `$post->post_type`, refers to
+		 * the post type slug.
+		 *
+		 * @since 5.1.0
+		 *
+		 * @param int     $post_ID Post ID.
+		 * @param WP_Post $post    Post object.
+		 */
+		do_action( "edit_post_{$post->post_type}", $post_ID, $post );
+
+		/**
+		 * Fires once an existing post has been updated.
+		 *
 		 * @since 1.2.0
 		 *
 		 * @param int     $post_ID Post ID.
 		 * @param WP_Post $post    Post object.
 		 */
 		do_action( 'edit_post', $post_ID, $post );
-		$post_after = get_post($post_ID);
+
+		$post_after = get_post( $post_ID );
 
 		/**
 		 * Fires once an existing post has been updated.
@@ -3644,7 +3922,7 @@
 		 * @param WP_Post $post_after   Post object following the update.
 		 * @param WP_Post $post_before  Post object before the update.
 		 */
-		do_action( 'post_updated', $post_ID, $post_after, $post_before);
+		do_action( 'post_updated', $post_ID, $post_after, $post_before );
 	}
 
 	/**
@@ -3700,48 +3978,52 @@
  * @return int|WP_Error The value 0 or WP_Error on failure. The post ID on success.
  */
 function wp_update_post( $postarr = array(), $wp_error = false ) {
-	if ( is_object($postarr) ) {
+	if ( is_object( $postarr ) ) {
 		// Non-escaped post was passed.
-		$postarr = get_object_vars($postarr);
-		$postarr = wp_slash($postarr);
+		$postarr = get_object_vars( $postarr );
+		$postarr = wp_slash( $postarr );
 	}
 
 	// First, get all of the original fields.
-	$post = get_post($postarr['ID'], ARRAY_A);
+	$post = get_post( $postarr['ID'], ARRAY_A );
 
 	if ( is_null( $post ) ) {
-		if ( $wp_error )
+		if ( $wp_error ) {
 			return new WP_Error( 'invalid_post', __( 'Invalid post ID.' ) );
+		}
 		return 0;
 	}
 
 	// Escape data pulled from DB.
-	$post = wp_slash($post);
+	$post = wp_slash( $post );
 
 	// Passed post category list overwrites existing category list if not empty.
-	if ( isset($postarr['post_category']) && is_array($postarr['post_category'])
-			 && 0 != count($postarr['post_category']) )
+	if ( isset( $postarr['post_category'] ) && is_array( $postarr['post_category'] )
+			&& 0 != count( $postarr['post_category'] ) ) {
 		$post_cats = $postarr['post_category'];
-	else
+	} else {
 		$post_cats = $post['post_category'];
+	}
 
 	// Drafts shouldn't be assigned a date unless explicitly done so by the user.
-	if ( isset( $post['post_status'] ) && in_array($post['post_status'], array('draft', 'pending', 'auto-draft')) && empty($postarr['edit_date']) &&
-			 ('0000-00-00 00:00:00' == $post['post_date_gmt']) )
+	if ( isset( $post['post_status'] ) && in_array( $post['post_status'], array( 'draft', 'pending', 'auto-draft' ) ) && empty( $postarr['edit_date'] ) &&
+			( '0000-00-00 00:00:00' == $post['post_date_gmt'] ) ) {
 		$clear_date = true;
-	else
+	} else {
 		$clear_date = false;
+	}
 
 	// Merge old and new fields with new fields overwriting old ones.
-	$postarr = array_merge($post, $postarr);
+	$postarr                  = array_merge( $post, $postarr );
 	$postarr['post_category'] = $post_cats;
 	if ( $clear_date ) {
-		$postarr['post_date'] = current_time('mysql');
+		$postarr['post_date']     = current_time( 'mysql' );
 		$postarr['post_date_gmt'] = '';
 	}
 
-	if ($postarr['post_type'] == 'attachment')
-		return wp_insert_attachment($postarr);
+	if ( $postarr['post_type'] == 'attachment' ) {
+		return wp_insert_attachment( $postarr, false, 0, $wp_error );
+	}
 
 	return wp_insert_post( $postarr, $wp_error );
 }
@@ -3758,21 +4040,26 @@
 function wp_publish_post( $post ) {
 	global $wpdb;
 
-	if ( ! $post = get_post( $post ) )
+	if ( ! $post = get_post( $post ) ) {
 		return;
-
-	if ( 'publish' == $post->post_status )
+	}
+
+	if ( 'publish' == $post->post_status ) {
 		return;
+	}
 
 	$wpdb->update( $wpdb->posts, array( 'post_status' => 'publish' ), array( 'ID' => $post->ID ) );
 
 	clean_post_cache( $post->ID );
 
-	$old_status = $post->post_status;
+	$old_status        = $post->post_status;
 	$post->post_status = 'publish';
 	wp_transition_post_status( 'publish', $old_status, $post );
 
 	/** This action is documented in wp-includes/post.php */
+	do_action( "edit_post_{$post->post_type}", $post->ID, $post );
+
+	/** This action is documented in wp-includes/post.php */
 	do_action( 'edit_post', $post->ID, $post );
 
 	/** This action is documented in wp-includes/post.php */
@@ -3796,13 +4083,15 @@
  * @param int|WP_Post $post_id Post ID or post object.
  */
 function check_and_publish_future_post( $post_id ) {
-	$post = get_post($post_id);
-
-	if ( empty($post) )
+	$post = get_post( $post_id );
+
+	if ( empty( $post ) ) {
 		return;
-
-	if ( 'future' != $post->post_status )
+	}
+
+	if ( 'future' != $post->post_status ) {
 		return;
+	}
 
 	$time = strtotime( $post->post_date_gmt . ' GMT' );
 
@@ -3833,20 +4122,42 @@
  * @return string Unique slug for the post, based on $post_name (with a -1, -2, etc. suffix)
  */
 function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_parent ) {
-	if ( in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) || ( 'inherit' == $post_status && 'revision' == $post_type ) || 'user_request' === $post_type )
+	if ( in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) || ( 'inherit' == $post_status && 'revision' == $post_type ) || 'user_request' === $post_type ) {
 		return $slug;
+	}
+
+	/**
+	 * Filters the post slug before it is generated to be unique.
+	 *
+	 * Returning a non-null value will short-circuit the
+	 * unique slug generation, returning the passed value instead.
+	 *
+	 * @since 5.1.0
+	 *
+	 * @param string $override_slug Short-circuit return value.
+	 * @param string $slug          The desired slug (post_name).
+	 * @param int    $post_ID       Post ID.
+	 * @param string $post_status   The post status.
+	 * @param string $post_type     Post type.
+	 * @param int    $post_parent   Post parent ID.
+	 */
+	$override_slug = apply_filters( 'pre_wp_unique_post_slug', null, $slug, $post_ID, $post_status, $post_type, $post_parent );
+	if ( null !== $override_slug ) {
+		return $override_slug;
+	}
 
 	global $wpdb, $wp_rewrite;
 
 	$original_slug = $slug;
 
 	$feeds = $wp_rewrite->feeds;
-	if ( ! is_array( $feeds ) )
+	if ( ! is_array( $feeds ) ) {
 		$feeds = array();
+	}
 
 	if ( 'attachment' == $post_type ) {
 		// Attachment slugs must be unique across all types.
-		$check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND ID != %d LIMIT 1";
+		$check_sql       = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND ID != %d LIMIT 1";
 		$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_ID ) );
 
 		/**
@@ -3860,21 +4171,22 @@
 		if ( $post_name_check || in_array( $slug, $feeds ) || 'embed' === $slug || apply_filters( 'wp_unique_post_slug_is_bad_attachment_slug', false, $slug ) ) {
 			$suffix = 2;
 			do {
-				$alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
+				$alt_post_name   = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
 				$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_ID ) );
 				$suffix++;
 			} while ( $post_name_check );
 			$slug = $alt_post_name;
 		}
 	} elseif ( is_post_type_hierarchical( $post_type ) ) {
-		if ( 'nav_menu_item' == $post_type )
+		if ( 'nav_menu_item' == $post_type ) {
 			return $slug;
+		}
 
 		/*
 		 * Page slugs must be unique within their own trees. Pages are in a separate
 		 * namespace than posts so page slugs are allowed to overlap post slugs.
 		 */
-		$check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ( %s, 'attachment' ) AND ID != %d AND post_parent = %d LIMIT 1";
+		$check_sql       = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ( %s, 'attachment' ) AND ID != %d AND post_parent = %d LIMIT 1";
 		$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_ID, $post_parent ) );
 
 		/**
@@ -3887,10 +4199,10 @@
 		 * @param string $post_type   Post type.
 		 * @param int    $post_parent Post parent ID.
 		 */
-		if ( $post_name_check || in_array( $slug, $feeds ) || 'embed' === $slug || preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $slug )  || apply_filters( 'wp_unique_post_slug_is_bad_hierarchical_slug', false, $slug, $post_type, $post_parent ) ) {
+		if ( $post_name_check || in_array( $slug, $feeds ) || 'embed' === $slug || preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $slug ) || apply_filters( 'wp_unique_post_slug_is_bad_hierarchical_slug', false, $slug, $post_type, $post_parent ) ) {
 			$suffix = 2;
 			do {
-				$alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
+				$alt_post_name   = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
 				$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_type, $post_ID, $post_parent ) );
 				$suffix++;
 			} while ( $post_name_check );
@@ -3898,11 +4210,11 @@
 		}
 	} else {
 		// Post slugs must be unique across all posts.
-		$check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1";
+		$check_sql       = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1";
 		$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_ID ) );
 
 		// Prevent new post slugs that could result in URLs that conflict with date archives.
-		$post = get_post( $post_ID );
+		$post                        = get_post( $post_ID );
 		$conflicts_with_date_archive = false;
 		if ( 'post' === $post_type && ( ! $post || $post->post_name !== $slug ) && preg_match( '/^[0-9]+$/', $slug ) && $slug_num = intval( $slug ) ) {
 			$permastructs   = array_values( array_filter( explode( '/', get_option( 'permalink_structure' ) ) ) );
@@ -3935,7 +4247,7 @@
 		if ( $post_name_check || in_array( $slug, $feeds ) || 'embed' === $slug || $conflicts_with_date_archive || apply_filters( 'wp_unique_post_slug_is_bad_flat_slug', false, $slug, $post_type ) ) {
 			$suffix = 2;
 			do {
-				$alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
+				$alt_post_name   = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
 				$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_type, $post_ID ) );
 				$suffix++;
 			} while ( $post_name_check );
@@ -3973,10 +4285,11 @@
 function _truncate_post_slug( $slug, $length = 200 ) {
 	if ( strlen( $slug ) > $length ) {
 		$decoded_slug = urldecode( $slug );
-		if ( $decoded_slug === $slug )
+		if ( $decoded_slug === $slug ) {
 			$slug = substr( $slug, 0, $length );
-		else
+		} else {
 			$slug = utf8_uri_encode( $decoded_slug, $length );
+		}
 	}
 
 	return rtrim( $slug, '-' );
@@ -3995,7 +4308,7 @@
  * @return array|false|WP_Error Array of affected term IDs. WP_Error or false on failure.
  */
 function wp_add_post_tags( $post_id = 0, $tags = '' ) {
-	return wp_set_post_tags($post_id, $tags, true);
+	return wp_set_post_tags( $post_id, $tags, true );
 }
 
 /**
@@ -4013,7 +4326,7 @@
  * @return array|false|WP_Error Array of term taxonomy IDs of affected terms. WP_Error or false on failure.
  */
 function wp_set_post_tags( $post_id = 0, $tags = '', $append = false ) {
-	return wp_set_post_terms( $post_id, $tags, 'post_tag', $append);
+	return wp_set_post_terms( $post_id, $tags, 'post_tag', $append );
 }
 
 /**
@@ -4025,7 +4338,9 @@
  *
  * @param int          $post_id  Optional. The Post ID. Does not default to the ID of the global $post.
  * @param string|array $tags     Optional. An array of terms to set for the post, or a string of terms
- *                               separated by commas. Default empty.
+ *                               separated by commas. Hierarchical taxonomies must always pass IDs rather
+ *                               than names so that children with the same names but different parents
+ *                               aren't confused. Default empty.
  * @param string       $taxonomy Optional. Taxonomy name. Default 'post_tag'.
  * @param bool         $append   Optional. If true, don't delete existing terms, just add on. If false,
  *                               replace the terms with the new terms. Default false.
@@ -4034,16 +4349,19 @@
 function wp_set_post_terms( $post_id = 0, $tags = '', $taxonomy = 'post_tag', $append = false ) {
 	$post_id = (int) $post_id;
 
-	if ( !$post_id )
+	if ( ! $post_id ) {
 		return false;
-
-	if ( empty($tags) )
+	}
+
+	if ( empty( $tags ) ) {
 		$tags = array();
+	}
 
 	if ( ! is_array( $tags ) ) {
 		$comma = _x( ',', 'tag delimiter' );
-		if ( ',' !== $comma )
+		if ( ',' !== $comma ) {
 			$tags = str_replace( $comma, ',', $tags );
+		}
 		$tags = explode( ',', trim( $tags, " \n\t\r\0\x0B," ) );
 	}
 
@@ -4068,22 +4386,22 @@
  *
  * @param int       $post_ID         Optional. The Post ID. Does not default to the ID
  *                                   of the global $post. Default 0.
- * @param array|int $post_categories Optional. List of categories or ID of category.
+ * @param array|int $post_categories Optional. List of category IDs, or the ID of a single category.
  *                                   Default empty array.
- * @param bool      $append         If true, don't delete existing categories, just add on.
- *                                  If false, replace the categories with the new categories.
+ * @param bool      $append          If true, don't delete existing categories, just add on.
+ *                                   If false, replace the categories with the new categories.
  * @return array|false|WP_Error Array of term taxonomy IDs of affected categories. WP_Error or false on failure.
  */
 function wp_set_post_categories( $post_ID = 0, $post_categories = array(), $append = false ) {
-	$post_ID = (int) $post_ID;
-	$post_type = get_post_type( $post_ID );
+	$post_ID     = (int) $post_ID;
+	$post_type   = get_post_type( $post_ID );
 	$post_status = get_post_status( $post_ID );
 	// If $post_categories isn't already an array, make it one:
 	$post_categories = (array) $post_categories;
 	if ( empty( $post_categories ) ) {
 		if ( 'post' == $post_type && 'auto-draft' != $post_status ) {
-			$post_categories = array( get_option('default_category') );
-			$append = false;
+			$post_categories = array( get_option( 'default_category' ) );
+			$append          = false;
 		} else {
 			$post_categories = array();
 		}
@@ -4169,8 +4487,8 @@
  * Add a URL to those already pinged.
  *
  * @since 1.5.0
- * @since 4.7.0 $post_id can be a WP_Post object.
- * @since 4.7.0 $uri can be an array of URIs.
+ * @since 4.7.0 `$post_id` can be a WP_Post object.
+ * @since 4.7.0 `$uri` can be an array of URIs.
  *
  * @global wpdb $wpdb WordPress database abstraction object.
  *
@@ -4191,11 +4509,10 @@
 
 	if ( is_array( $uri ) ) {
 		$pung = array_merge( $pung, $uri );
-	}
-	else {
+	} else {
 		$pung[] = $uri;
 	}
-	$new = implode("\n", $pung);
+	$new = implode( "\n", $pung );
 
 	/**
 	 * Filters the new ping URL to add for the given post.
@@ -4221,16 +4538,18 @@
  */
 function get_enclosed( $post_id ) {
 	$custom_fields = get_post_custom( $post_id );
-	$pung = array();
-	if ( !is_array( $custom_fields ) )
+	$pung          = array();
+	if ( ! is_array( $custom_fields ) ) {
 		return $pung;
+	}
 
 	foreach ( $custom_fields as $key => $val ) {
-		if ( 'enclosure' != $key || !is_array( $val ) )
+		if ( 'enclosure' != $key || ! is_array( $val ) ) {
 			continue;
+		}
 		foreach ( $val as $enc ) {
 			$enclosure = explode( "\n", $enc );
-			$pung[] = trim( $enclosure[ 0 ] );
+			$pung[]    = trim( $enclosure[0] );
 		}
 	}
 
@@ -4250,10 +4569,10 @@
  *
  * @since 1.5.0
  *
- * @since 4.7.0 $post_id can be a WP_Post object.
+ * @since 4.7.0 `$post_id` can be a WP_Post object.
  *
  * @param int|WP_Post $post_id Post ID or object.
- * @return array
+ * @return bool|string[] Array of URLs already pinged for the given post, false if the post is not found.
  */
 function get_pung( $post_id ) {
 	$post = get_post( $post_id );
@@ -4269,7 +4588,7 @@
 	 *
 	 * @since 2.0.0
 	 *
-	 * @param array $pung Array of URLs already pinged for the given post.
+	 * @param string[] $pung Array of URLs already pinged for the given post.
 	 */
 	return apply_filters( 'get_pung', $pung );
 }
@@ -4278,7 +4597,7 @@
  * Retrieve URLs that need to be pinged.
  *
  * @since 1.5.0
- * @since 4.7.0 $post_id can be a WP_Post object.
+ * @since 4.7.0 `$post_id` can be a WP_Post object.
  *
  * @param int|WP_Post $post_id Post Object or ID
  * @return array
@@ -4291,7 +4610,7 @@
 	}
 
 	$to_ping = sanitize_trackback_urls( $post->to_ping );
-	$to_ping = preg_split('/\s/', $to_ping, -1, PREG_SPLIT_NO_EMPTY);
+	$to_ping = preg_split( '/\s/', $to_ping, -1, PREG_SPLIT_NO_EMPTY );
 
 	/**
 	 * Filters the list of URLs yet to ping for the given post.
@@ -4347,10 +4666,10 @@
 function get_all_page_ids() {
 	global $wpdb;
 
-	$page_ids = wp_cache_get('all_page_ids', 'posts');
+	$page_ids = wp_cache_get( 'all_page_ids', 'posts' );
 	if ( ! is_array( $page_ids ) ) {
-		$page_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_type = 'page'");
-		wp_cache_add('all_page_ids', $page_ids, 'posts');
+		$page_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type = 'page'" );
+		wp_cache_add( 'all_page_ids', $page_ids, 'posts' );
 	}
 
 	return $page_ids;
@@ -4371,7 +4690,7 @@
  *                       'edit', 'db', 'display'. Default 'raw'.
  * @return WP_Post|array|null WP_Post (or array) on success, or null on failure.
  */
-function get_page( $page, $output = OBJECT, $filter = 'raw') {
+function get_page( $page, $output = OBJECT, $filter = 'raw' ) {
 	return get_post( $page, $output, $filter );
 }
 
@@ -4393,9 +4712,9 @@
 
 	$last_changed = wp_cache_get_last_changed( 'posts' );
 
-	$hash = md5( $page_path . serialize( $post_type ) );
+	$hash      = md5( $page_path . serialize( $post_type ) );
 	$cache_key = "get_page_by_path:$hash:$last_changed";
-	$cached = wp_cache_get( $cache_key, 'posts' );
+	$cached    = wp_cache_get( $cache_key, 'posts' );
 	if ( false !== $cached ) {
 		// Special case: '0' is a bad `$page_path`.
 		if ( '0' === $cached || 0 === $cached ) {
@@ -4405,11 +4724,11 @@
 		}
 	}
 
-	$page_path = rawurlencode(urldecode($page_path));
-	$page_path = str_replace('%2F', '/', $page_path);
-	$page_path = str_replace('%20', ' ', $page_path);
-	$parts = explode( '/', trim( $page_path, '/' ) );
-	$parts = array_map( 'sanitize_title_for_query', $parts );
+	$page_path     = rawurlencode( urldecode( $page_path ) );
+	$page_path     = str_replace( '%2F', '/', $page_path );
+	$page_path     = str_replace( '%20', ' ', $page_path );
+	$parts         = explode( '/', trim( $page_path, '/' ) );
+	$parts         = array_map( 'sanitize_title_for_query', $parts );
 	$escaped_parts = esc_sql( $parts );
 
 	$in_string = "'" . implode( "','", $escaped_parts ) . "'";
@@ -4420,9 +4739,9 @@
 		$post_types = array( $post_type, 'attachment' );
 	}
 
-	$post_types = esc_sql( $post_types );
+	$post_types          = esc_sql( $post_types );
 	$post_type_in_string = "'" . implode( "','", $post_types ) . "'";
-	$sql = "
+	$sql                 = "
 		SELECT ID, post_name, post_parent, post_type
 		FROM $wpdb->posts
 		WHERE post_name IN ($in_string)
@@ -4437,7 +4756,7 @@
 	foreach ( (array) $pages as $page ) {
 		if ( $page->post_name == $revparts[0] ) {
 			$count = 0;
-			$p = $page;
+			$p     = $page;
 
 			/*
 			 * Loop through the given path parts from right to left,
@@ -4446,15 +4765,17 @@
 			while ( $p->post_parent != 0 && isset( $pages[ $p->post_parent ] ) ) {
 				$count++;
 				$parent = $pages[ $p->post_parent ];
-				if ( ! isset( $revparts[ $count ] ) || $parent->post_name != $revparts[ $count ] )
+				if ( ! isset( $revparts[ $count ] ) || $parent->post_name != $revparts[ $count ] ) {
 					break;
+				}
 				$p = $parent;
 			}
 
-			if ( $p->post_parent == 0 && $count+1 == count( $revparts ) && $p->post_name == $revparts[ $count ] ) {
+			if ( $p->post_parent == 0 && $count + 1 == count( $revparts ) && $p->post_name == $revparts[ $count ] ) {
 				$foundid = $page->ID;
-				if ( $page->post_type == $post_type )
+				if ( $page->post_type == $post_type ) {
 					break;
+				}
 			}
 		}
 	}
@@ -4484,21 +4805,28 @@
 	global $wpdb;
 
 	if ( is_array( $post_type ) ) {
-		$post_type = esc_sql( $post_type );
+		$post_type           = esc_sql( $post_type );
 		$post_type_in_string = "'" . implode( "','", $post_type ) . "'";
-		$sql = $wpdb->prepare( "
+		$sql                 = $wpdb->prepare(
+			"
 			SELECT ID
 			FROM $wpdb->posts
 			WHERE post_title = %s
 			AND post_type IN ($post_type_in_string)
-		", $page_title );
+		",
+			$page_title
+		);
 	} else {
-		$sql = $wpdb->prepare( "
+		$sql = $wpdb->prepare(
+			"
 			SELECT ID
 			FROM $wpdb->posts
 			WHERE post_title = %s
 			AND post_type = %s
-		", $page_title, $post_type );
+		",
+			$page_title,
+			$post_type
+		);
 	}
 
 	$page = $wpdb->get_var( $sql );
@@ -4534,7 +4862,7 @@
 		$to_look = array_reverse( $children[ $page_id ] );
 
 		while ( $to_look ) {
-			$p = array_pop( $to_look );
+			$p           = array_pop( $to_look );
 			$page_list[] = $p;
 			if ( isset( $children[ $p->ID ] ) ) {
 				foreach ( array_reverse( $children[ $p->ID ] ) as $child ) {
@@ -4567,7 +4895,7 @@
 
 	$children = array();
 	foreach ( (array) $pages as $p ) {
-		$parent_id = intval( $p->post_parent );
+		$parent_id                = intval( $p->post_parent );
 		$children[ $parent_id ][] = $p;
 	}
 
@@ -4583,6 +4911,7 @@
  * $children contains parent-children relations
  *
  * @since 2.9.0
+ * @access private
  *
  * @see _page_traverse_name()
  *
@@ -4590,9 +4919,9 @@
  * @param array $children  Parent-children relations (passed by reference).
  * @param array $result    Result (passed by reference).
  */
-function _page_traverse_name( $page_id, &$children, &$result ){
-	if ( isset( $children[ $page_id ] ) ){
-		foreach ( (array)$children[ $page_id ] as $child ) {
+function _page_traverse_name( $page_id, &$children, &$result ) {
+	if ( isset( $children[ $page_id ] ) ) {
+		foreach ( (array) $children[ $page_id ] as $child ) {
 			$result[ $child->ID ] = $child->post_name;
 			_page_traverse_name( $child->ID, $children, $result );
 		}
@@ -4615,8 +4944,9 @@
 		$page = get_post( $page );
 	}
 
-	if ( ! $page )
+	if ( ! $page ) {
 		return false;
+	}
 
 	$uri = $page->post_name;
 
@@ -4703,15 +5033,15 @@
 
 	$r = wp_parse_args( $args, $defaults );
 
-	$number = (int) $r['number'];
-	$offset = (int) $r['offset'];
-	$child_of = (int) $r['child_of'];
+	$number       = (int) $r['number'];
+	$offset       = (int) $r['offset'];
+	$child_of     = (int) $r['child_of'];
 	$hierarchical = $r['hierarchical'];
-	$exclude = $r['exclude'];
-	$meta_key = $r['meta_key'];
-	$meta_value = $r['meta_value'];
-	$parent = $r['parent'];
-	$post_status = $r['post_status'];
+	$exclude      = $r['exclude'];
+	$meta_key     = $r['meta_key'];
+	$meta_value   = $r['meta_value'];
+	$parent       = $r['parent'];
+	$post_status  = $r['post_status'];
 
 	// Make sure the post type is hierarchical.
 	$hierarchical_post_types = get_post_types( array( 'hierarchical' => true ) );
@@ -4732,11 +5062,12 @@
 	}
 
 	// $args can be whatever, only use the args defined in defaults to compute the key.
-	$key = md5( serialize( wp_array_slice_assoc( $r, array_keys( $defaults ) ) ) );
+	$key          = md5( serialize( wp_array_slice_assoc( $r, array_keys( $defaults ) ) ) );
 	$last_changed = wp_cache_get_last_changed( 'posts' );
 
 	$cache_key = "get_pages:$key:$last_changed";
-	if ( $cache = wp_cache_get( $cache_key, 'posts' ) ) {
+	$cache     = wp_cache_get( $cache_key, 'posts' );
+	if ( false !== $cache ) {
 		// Convert to WP_Post instances.
 		$pages = array_map( 'get_post', $cache );
 		/** This filter is documented in wp-includes/post.php */
@@ -4746,15 +5077,15 @@
 
 	$inclusions = '';
 	if ( ! empty( $r['include'] ) ) {
-		$child_of = 0; //ignore child_of, parent, exclude, meta_key, and meta_value params if using include
-		$parent = -1;
-		$exclude = '';
-		$meta_key = '';
-		$meta_value = '';
+		$child_of     = 0; //ignore child_of, parent, exclude, meta_key, and meta_value params if using include
+		$parent       = -1;
+		$exclude      = '';
+		$meta_key     = '';
+		$meta_value   = '';
 		$hierarchical = false;
-		$incpages = wp_parse_id_list( $r['include'] );
+		$incpages     = wp_parse_id_list( $r['include'] );
 		if ( ! empty( $incpages ) ) {
-			$inclusions = ' AND ID IN (' . implode( ',', $incpages ) .  ')';
+			$inclusions = ' AND ID IN (' . implode( ',', $incpages ) . ')';
 		}
 	}
 
@@ -4762,19 +5093,19 @@
 	if ( ! empty( $exclude ) ) {
 		$expages = wp_parse_id_list( $exclude );
 		if ( ! empty( $expages ) ) {
-			$exclusions = ' AND ID NOT IN (' . implode( ',', $expages ) .  ')';
+			$exclusions = ' AND ID NOT IN (' . implode( ',', $expages ) . ')';
 		}
 	}
 
 	$author_query = '';
 	if ( ! empty( $r['authors'] ) ) {
-		$post_authors = preg_split( '/[\s,]+/', $r['authors'] );
+		$post_authors = wp_parse_list( $r['authors'] );
 
 		if ( ! empty( $post_authors ) ) {
 			foreach ( $post_authors as $post_author ) {
 				//Do we have an author id or an author login?
-				if ( 0 == intval($post_author) ) {
-					$post_author = get_user_by('login', $post_author);
+				if ( 0 == intval( $post_author ) ) {
+					$post_author = get_user_by( 'login', $post_author );
 					if ( empty( $post_author ) ) {
 						continue;
 					}
@@ -4785,9 +5116,9 @@
 				}
 
 				if ( '' == $author_query ) {
-					$author_query = $wpdb->prepare(' post_author = %d ', $post_author);
+					$author_query = $wpdb->prepare( ' post_author = %d ', $post_author );
 				} else {
-					$author_query .= $wpdb->prepare(' OR post_author = %d ', $post_author);
+					$author_query .= $wpdb->prepare( ' OR post_author = %d ', $post_author );
 				}
 			}
 			if ( '' != $author_query ) {
@@ -4796,21 +5127,20 @@
 		}
 	}
 
-	$join = '';
+	$join  = '';
 	$where = "$exclusions $inclusions ";
 	if ( '' !== $meta_key || '' !== $meta_value ) {
 		$join = " LEFT JOIN $wpdb->postmeta ON ( $wpdb->posts.ID = $wpdb->postmeta.post_id )";
 
 		// meta_key and meta_value might be slashed
-		$meta_key = wp_unslash($meta_key);
-		$meta_value = wp_unslash($meta_value);
+		$meta_key   = wp_unslash( $meta_key );
+		$meta_value = wp_unslash( $meta_value );
 		if ( '' !== $meta_key ) {
-			$where .= $wpdb->prepare(" AND $wpdb->postmeta.meta_key = %s", $meta_key);
+			$where .= $wpdb->prepare( " AND $wpdb->postmeta.meta_key = %s", $meta_key );
 		}
 		if ( '' !== $meta_value ) {
-			$where .= $wpdb->prepare(" AND $wpdb->postmeta.meta_value = %s", $meta_value);
+			$where .= $wpdb->prepare( " AND $wpdb->postmeta.meta_value = %s", $meta_value );
 		}
-
 	}
 
 	if ( is_array( $parent ) ) {
@@ -4819,20 +5149,37 @@
 			$where .= " AND post_parent IN ($post_parent__in)";
 		}
 	} elseif ( $parent >= 0 ) {
-		$where .= $wpdb->prepare(' AND post_parent = %d ', $parent);
+		$where .= $wpdb->prepare( ' AND post_parent = %d ', $parent );
 	}
 
 	if ( 1 == count( $post_status ) ) {
-		$where_post_type = $wpdb->prepare( "post_type = %s AND post_status = %s", $r['post_type'], reset( $post_status ) );
+		$where_post_type = $wpdb->prepare( 'post_type = %s AND post_status = %s', $r['post_type'], reset( $post_status ) );
 	} else {
-		$post_status = implode( "', '", $post_status );
+		$post_status     = implode( "', '", $post_status );
 		$where_post_type = $wpdb->prepare( "post_type = %s AND post_status IN ('$post_status')", $r['post_type'] );
 	}
 
 	$orderby_array = array();
-	$allowed_keys = array( 'author', 'post_author', 'date', 'post_date', 'title', 'post_title', 'name', 'post_name', 'modified',
-		'post_modified', 'modified_gmt', 'post_modified_gmt', 'menu_order', 'parent', 'post_parent',
-		'ID', 'rand', 'comment_count' );
+	$allowed_keys  = array(
+		'author',
+		'post_author',
+		'date',
+		'post_date',
+		'title',
+		'post_title',
+		'name',
+		'post_name',
+		'modified',
+		'post_modified',
+		'modified_gmt',
+		'post_modified_gmt',
+		'menu_order',
+		'parent',
+		'post_parent',
+		'ID',
+		'rand',
+		'comment_count',
+	);
 
 	foreach ( explode( ',', $r['sort_column'] ) as $orderby ) {
 		$orderby = trim( $orderby );
@@ -4870,33 +5217,35 @@
 		$sort_order = 'ASC';
 	}
 
-	$query = "SELECT * FROM $wpdb->posts $join WHERE ($where_post_type) $where ";
+	$query  = "SELECT * FROM $wpdb->posts $join WHERE ($where_post_type) $where ";
 	$query .= $author_query;
-	$query .= " ORDER BY " . $sort_column . " " . $sort_order ;
+	$query .= ' ORDER BY ' . $sort_column . ' ' . $sort_order;
 
 	if ( ! empty( $number ) ) {
 		$query .= ' LIMIT ' . $offset . ',' . $number;
 	}
 
-	$pages = $wpdb->get_results($query);
-
-	if ( empty($pages) ) {
+	$pages = $wpdb->get_results( $query );
+
+	if ( empty( $pages ) ) {
+		wp_cache_set( $cache_key, array(), 'posts' );
+
 		/** This filter is documented in wp-includes/post.php */
 		$pages = apply_filters( 'get_pages', array(), $r );
 		return $pages;
 	}
 
 	// Sanitize before caching so it'll only get done once.
-	$num_pages = count($pages);
-	for ($i = 0; $i < $num_pages; $i++) {
-		$pages[$i] = sanitize_post($pages[$i], 'raw');
+	$num_pages = count( $pages );
+	for ( $i = 0; $i < $num_pages; $i++ ) {
+		$pages[ $i ] = sanitize_post( $pages[ $i ], 'raw' );
 	}
 
 	// Update cache.
 	update_post_cache( $pages );
 
 	if ( $child_of || $hierarchical ) {
-		$pages = get_page_children($child_of, $pages);
+		$pages = get_page_children( $child_of, $pages );
 	}
 
 	if ( ! empty( $r['exclude_tree'] ) ) {
@@ -4910,8 +5259,8 @@
 
 		$num_pages = count( $pages );
 		for ( $i = 0; $i < $num_pages; $i++ ) {
-			if ( in_array( $pages[$i]->ID, $exclude ) ) {
-				unset( $pages[$i] );
+			if ( in_array( $pages[ $i ]->ID, $exclude ) ) {
+				unset( $pages[ $i ] );
 			}
 		}
 	}
@@ -4942,22 +5291,29 @@
 //
 
 /**
- * Check if the attachment URI is local one and is really an attachment.
+ * Determines whether an attachment URI is local and really an attachment.
+ *
+ * For more information on this and similar theme functions, check out
+ * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
+ * Conditional Tags} article in the Theme Developer Handbook.
  *
  * @since 2.0.0
  *
  * @param string $url URL to check
  * @return bool True on success, false on failure.
  */
-function is_local_attachment($url) {
-	if (strpos($url, home_url()) === false)
+function is_local_attachment( $url ) {
+	if ( strpos( $url, home_url() ) === false ) {
 		return false;
-	if (strpos($url, home_url('/?attachment_id=')) !== false)
+	}
+	if ( strpos( $url, home_url( '/?attachment_id=' ) ) !== false ) {
 		return true;
-	if ( $id = url_to_postid($url) ) {
-		$post = get_post($id);
-		if ( 'attachment' == $post->post_type )
+	}
+	if ( $id = url_to_postid( $url ) ) {
+		$post = get_post( $id );
+		if ( 'attachment' == $post->post_type ) {
 			return true;
+		}
 	}
 	return false;
 }
@@ -4990,7 +5346,7 @@
 function wp_insert_attachment( $args, $file = false, $parent = 0, $wp_error = false ) {
 	$defaults = array(
 		'file'        => $file,
-		'post_parent' => 0
+		'post_parent' => 0,
 	);
 
 	$data = wp_parse_args( $args, $defaults );
@@ -5042,15 +5398,16 @@
 		return wp_trash_post( $post_id );
 	}
 
-	delete_post_meta($post_id, '_wp_trash_meta_status');
-	delete_post_meta($post_id, '_wp_trash_meta_time');
-
-	$meta = wp_get_attachment_metadata( $post_id );
+	delete_post_meta( $post_id, '_wp_trash_meta_status' );
+	delete_post_meta( $post_id, '_wp_trash_meta_time' );
+
+	$meta         = wp_get_attachment_metadata( $post_id );
 	$backup_sizes = get_post_meta( $post->ID, '_wp_attachment_backup_sizes', true );
-	$file = get_attached_file( $post_id );
-
-	if ( is_multisite() )
+	$file         = get_attached_file( $post_id );
+
+	if ( is_multisite() ) {
 		delete_transient( 'dirsize_cache' );
+	}
 
 	/**
 	 * Fires before an attachment is deleted, at the start of wp_delete_attachment().
@@ -5061,24 +5418,25 @@
 	 */
 	do_action( 'delete_attachment', $post_id );
 
-	wp_delete_object_term_relationships($post_id, array('category', 'post_tag'));
-	wp_delete_object_term_relationships($post_id, get_object_taxonomies($post->post_type));
+	wp_delete_object_term_relationships( $post_id, array( 'category', 'post_tag' ) );
+	wp_delete_object_term_relationships( $post_id, get_object_taxonomies( $post->post_type ) );
 
 	// Delete all for any posts.
 	delete_metadata( 'post', null, '_thumbnail_id', $post_id, true );
 
 	wp_defer_comment_counting( true );
 
-	$comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id ));
+	$comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id ) );
 	foreach ( $comment_ids as $comment_id ) {
 		wp_delete_comment( $comment_id, true );
 	}
 
 	wp_defer_comment_counting( false );
 
-	$post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $post_id ));
-	foreach ( $post_meta_ids as $mid )
+	$post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $post_id ) );
+	foreach ( $post_meta_ids as $mid ) {
 		delete_metadata_by_mid( 'post', $mid );
+	}
 
 	/** This action is documented in wp-includes/post.php */
 	do_action( 'delete_post', $post_id );
@@ -5116,7 +5474,7 @@
 	if ( ! empty( $meta['thumb'] ) ) {
 		// Don't delete the thumb if another attachment uses it.
 		if ( ! $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attachment_metadata' AND meta_value LIKE %s AND post_id <> %d", '%' . $wpdb->esc_like( $meta['thumb'] ) . '%', $post_id ) ) ) {
-			$thumbfile = str_replace( basename( $file ), $meta['thumb'], $file );
+			$thumbfile = str_replace( wp_basename( $file ), $meta['thumb'], $file );
 			if ( ! empty( $thumbfile ) ) {
 				$thumbfile = path_join( $uploadpath['basedir'], $thumbfile );
 				$thumbdir  = path_join( $uploadpath['basedir'], dirname( $file ) );
@@ -5132,7 +5490,7 @@
 	if ( isset( $meta['sizes'] ) && is_array( $meta['sizes'] ) ) {
 		$intermediate_dir = path_join( $uploadpath['basedir'], dirname( $file ) );
 		foreach ( $meta['sizes'] as $size => $sizeinfo ) {
-			$intermediate_file = str_replace( basename( $file ), $sizeinfo['file'], $file );
+			$intermediate_file = str_replace( wp_basename( $file ), $sizeinfo['file'], $file );
 			if ( ! empty( $intermediate_file ) ) {
 				$intermediate_file = path_join( $uploadpath['basedir'], $intermediate_file );
 
@@ -5181,8 +5539,9 @@
 
 	$data = get_post_meta( $post->ID, '_wp_attachment_metadata', true );
 
-	if ( $unfiltered )
+	if ( $unfiltered ) {
 		return $data;
+	}
 
 	/**
 	 * Filters the attachment meta data.
@@ -5219,10 +5578,11 @@
 	 * @param array $data          Array of updated attachment meta data.
 	 * @param int   $attachment_id Attachment post ID.
 	 */
-	if ( $data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID ) )
+	if ( $data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID ) ) {
 		return update_post_meta( $post->ID, '_wp_attachment_metadata', $data );
-	else
+	} else {
 		return delete_post_meta( $post->ID, '_wp_attachment_metadata' );
+	}
 }
 
 /**
@@ -5241,8 +5601,9 @@
 		return false;
 	}
 
-	if ( 'attachment' != $post->post_type )
+	if ( 'attachment' != $post->post_type ) {
 		return false;
+	}
 
 	$url = '';
 	// Get attached file.
@@ -5252,10 +5613,10 @@
 			// Check that the upload base exists in the file location.
 			if ( 0 === strpos( $file, $uploads['basedir'] ) ) {
 				// Replace file location with url location.
-				$url = str_replace($uploads['basedir'], $uploads['baseurl'], $file);
-			} elseif ( false !== strpos($file, 'wp-content/uploads') ) {
+				$url = str_replace( $uploads['basedir'], $uploads['baseurl'], $file );
+			} elseif ( false !== strpos( $file, 'wp-content/uploads' ) ) {
 				// Get the directory name relative to the basedir (back compat for pre-2.7 uploads)
-				$url = trailingslashit( $uploads['baseurl'] . '/' . _wp_get_attachment_relative_path( $file ) ) . basename( $file );
+				$url = trailingslashit( $uploads['baseurl'] . '/' . _wp_get_attachment_relative_path( $file ) ) . wp_basename( $file );
 			} else {
 				// It's a newly-uploaded file, therefore $file is relative to the basedir.
 				$url = $uploads['baseurl'] . "/$file";
@@ -5267,7 +5628,7 @@
 	 * If any of the above options failed, Fallback on the GUID as used pre-2.7,
 	 * not recommended to rely upon this.
 	 */
-	if ( empty($url) ) {
+	if ( empty( $url ) ) {
 		$url = get_the_guid( $post->ID );
 	}
 
@@ -5286,8 +5647,9 @@
 	 */
 	$url = apply_filters( 'wp_get_attachment_url', $url, $post->ID );
 
-	if ( empty( $url ) )
+	if ( empty( $url ) ) {
 		return false;
+	}
 
 	return $url;
 }
@@ -5333,14 +5695,16 @@
  */
 function wp_get_attachment_thumb_file( $post_id = 0 ) {
 	$post_id = (int) $post_id;
-	if ( !$post = get_post( $post_id ) )
+	if ( ! $post = get_post( $post_id ) ) {
 		return false;
-	if ( !is_array( $imagedata = wp_get_attachment_metadata( $post->ID ) ) )
+	}
+	if ( ! is_array( $imagedata = wp_get_attachment_metadata( $post->ID ) ) ) {
 		return false;
+	}
 
 	$file = get_attached_file( $post->ID );
 
-	if ( !empty($imagedata['thumb']) && ($thumbfile = str_replace(basename($file), $imagedata['thumb'], $file)) && file_exists($thumbfile) ) {
+	if ( ! empty( $imagedata['thumb'] ) && ( $thumbfile = str_replace( wp_basename( $file ), $imagedata['thumb'], $file ) ) && file_exists( $thumbfile ) ) {
 		/**
 		 * Filters the attachment thumbnail file path.
 		 *
@@ -5364,19 +5728,23 @@
  */
 function wp_get_attachment_thumb_url( $post_id = 0 ) {
 	$post_id = (int) $post_id;
-	if ( !$post = get_post( $post_id ) )
+	if ( ! $post = get_post( $post_id ) ) {
 		return false;
-	if ( !$url = wp_get_attachment_url( $post->ID ) )
+	}
+	if ( ! $url = wp_get_attachment_url( $post->ID ) ) {
 		return false;
+	}
 
 	$sized = image_downsize( $post_id, 'thumbnail' );
-	if ( $sized )
+	if ( $sized ) {
 		return $sized[0];
-
-	if ( !$thumb = wp_get_attachment_thumb_file( $post->ID ) )
+	}
+
+	if ( ! $thumb = wp_get_attachment_thumb_file( $post->ID ) ) {
 		return false;
-
-	$url = str_replace(basename($url), basename($thumb), $url);
+	}
+
+	$url = str_replace( wp_basename( $url ), wp_basename( $thumb ), $url );
 
 	/**
 	 * Filters the attachment thumbnail URL.
@@ -5423,23 +5791,27 @@
 	}
 
 	switch ( $type ) {
-	case 'image':
-		$image_exts = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png' );
-		return in_array( $ext, $image_exts );
-
-	case 'audio':
-		return in_array( $ext, wp_get_audio_extensions() );
-
-	case 'video':
-		return in_array( $ext, wp_get_video_extensions() );
-
-	default:
-		return $type === $ext;
+		case 'image':
+			$image_exts = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png' );
+			return in_array( $ext, $image_exts );
+
+		case 'audio':
+			return in_array( $ext, wp_get_audio_extensions() );
+
+		case 'video':
+			return in_array( $ext, wp_get_video_extensions() );
+
+		default:
+			return $type === $ext;
 	}
 }
 
 /**
- * Checks if the attachment is an image.
+ * Determines whether an attachment is an image.
+ *
+ * For more information on this and similar theme functions, check out
+ * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
+ * Conditional Tags} article in the Theme Developer Handbook.
  *
  * @since 2.1.0
  * @since 4.2.0 Modified into wrapper for wp_attachment_is() and
@@ -5461,22 +5833,24 @@
  * @return string|false Icon, false otherwise.
  */
 function wp_mime_type_icon( $mime = 0 ) {
-	if ( !is_numeric($mime) )
-		$icon = wp_cache_get("mime_type_icon_$mime");
+	if ( ! is_numeric( $mime ) ) {
+		$icon = wp_cache_get( "mime_type_icon_$mime" );
+	}
 
 	$post_id = 0;
-	if ( empty($icon) ) {
+	if ( empty( $icon ) ) {
 		$post_mimes = array();
-		if ( is_numeric($mime) ) {
+		if ( is_numeric( $mime ) ) {
 			$mime = (int) $mime;
 			if ( $post = get_post( $mime ) ) {
 				$post_id = (int) $post->ID;
-				$file = get_attached_file( $post_id );
-				$ext = preg_replace('/^.+?\.([^.]+)$/', '$1', $file);
-				if ( !empty($ext) ) {
+				$file    = get_attached_file( $post_id );
+				$ext     = preg_replace( '/^.+?\.([^.]+)$/', '$1', $file );
+				if ( ! empty( $ext ) ) {
 					$post_mimes[] = $ext;
-					if ( $ext_type = wp_ext2type( $ext ) )
+					if ( $ext_type = wp_ext2type( $ext ) ) {
 						$post_mimes[] = $ext_type;
+					}
 				}
 				$mime = $post->post_mime_type;
 			} else {
@@ -5486,9 +5860,9 @@
 			$post_mimes[] = $mime;
 		}
 
-		$icon_files = wp_cache_get('icon_files');
-
-		if ( !is_array($icon_files) ) {
+		$icon_files = wp_cache_get( 'icon_files' );
+
+		if ( ! is_array( $icon_files ) ) {
 			/**
 			 * Filters the icon directory path.
 			 *
@@ -5514,43 +5888,46 @@
 			 *
 			 * @param array $uris List of icon directory URIs.
 			 */
-			$dirs = apply_filters( 'icon_dirs', array( $icon_dir => $icon_dir_uri ) );
+			$dirs       = apply_filters( 'icon_dirs', array( $icon_dir => $icon_dir_uri ) );
 			$icon_files = array();
 			while ( $dirs ) {
 				$keys = array_keys( $dirs );
-				$dir = array_shift( $keys );
-				$uri = array_shift($dirs);
-				if ( $dh = opendir($dir) ) {
-					while ( false !== $file = readdir($dh) ) {
-						$file = basename($file);
-						if ( substr($file, 0, 1) == '.' )
-							continue;
-						if ( !in_array(strtolower(substr($file, -4)), array('.png', '.gif', '.jpg') ) ) {
-							if ( is_dir("$dir/$file") )
-								$dirs["$dir/$file"] = "$uri/$file";
+				$dir  = array_shift( $keys );
+				$uri  = array_shift( $dirs );
+				if ( $dh = opendir( $dir ) ) {
+					while ( false !== $file = readdir( $dh ) ) {
+						$file = wp_basename( $file );
+						if ( substr( $file, 0, 1 ) == '.' ) {
 							continue;
 						}
-						$icon_files["$dir/$file"] = "$uri/$file";
+						if ( ! in_array( strtolower( substr( $file, -4 ) ), array( '.png', '.gif', '.jpg' ) ) ) {
+							if ( is_dir( "$dir/$file" ) ) {
+								$dirs[ "$dir/$file" ] = "$uri/$file";
+							}
+							continue;
+						}
+						$icon_files[ "$dir/$file" ] = "$uri/$file";
 					}
-					closedir($dh);
+					closedir( $dh );
 				}
 			}
 			wp_cache_add( 'icon_files', $icon_files, 'default', 600 );
 		}
 
 		$types = array();
-		// Icon basename - extension = MIME wildcard.
-		foreach ( $icon_files as $file => $uri )
-			$types[ preg_replace('/^([^.]*).*$/', '$1', basename($file)) ] =& $icon_files[$file];
-
-		if ( ! empty($mime) ) {
-			$post_mimes[] = substr($mime, 0, strpos($mime, '/'));
-			$post_mimes[] = substr($mime, strpos($mime, '/') + 1);
-			$post_mimes[] = str_replace('/', '_', $mime);
+		// Icon wp_basename - extension = MIME wildcard.
+		foreach ( $icon_files as $file => $uri ) {
+			$types[ preg_replace( '/^([^.]*).*$/', '$1', wp_basename( $file ) ) ] =& $icon_files[ $file ];
 		}
 
-		$matches = wp_match_mime_types(array_keys($types), $post_mimes);
-		$matches['default'] = array('default');
+		if ( ! empty( $mime ) ) {
+			$post_mimes[] = substr( $mime, 0, strpos( $mime, '/' ) );
+			$post_mimes[] = substr( $mime, strpos( $mime, '/' ) + 1 );
+			$post_mimes[] = str_replace( '/', '_', $mime );
+		}
+
+		$matches            = wp_match_mime_types( array_keys( $types ), $post_mimes );
+		$matches['default'] = array( 'default' );
 
 		foreach ( $matches as $match => $wilds ) {
 			foreach ( $wilds as $wild ) {
@@ -5644,7 +6021,7 @@
  */
 function wp_check_for_changed_dates( $post_id, $post, $post_before ) {
 	$previous_date = date( 'Y-m-d', strtotime( $post_before->post_date ) );
-	$new_date = date( 'Y-m-d', strtotime( $post->post_date ) );
+	$new_date      = date( 'Y-m-d', strtotime( $post->post_date ) );
 	// Don't bother if it hasn't changed.
 	if ( $new_date == $previous_date ) {
 		return;
@@ -5752,7 +6129,7 @@
 		return $full ? 'WHERE 1 = 0' : '1 = 0';
 	}
 
-	$sql = '( '. implode( ' OR ', $post_type_clauses ) . ' )';
+	$sql = '( ' . implode( ' OR ', $post_type_clauses ) . ' )';
 
 	if ( null !== $post_author ) {
 		$sql .= $wpdb->prepare( ' AND post_author = %d', $post_author );
@@ -5831,7 +6208,7 @@
 
 	$lastpostmodified = _get_last_post_time( $timezone, 'modified', $post_type );
 
-	$lastpostdate = get_lastpostdate($timezone);
+	$lastpostdate = get_lastpostdate( $timezone );
 	if ( $lastpostdate > $lastpostmodified ) {
 		$lastpostmodified = $lastpostdate;
 	}
@@ -5892,14 +6269,14 @@
 
 	switch ( $timezone ) {
 		case 'gmt':
-			$date = $wpdb->get_var("SELECT post_{$field}_gmt FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1");
+			$date = $wpdb->get_var( "SELECT post_{$field}_gmt FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1" );
 			break;
 		case 'blog':
-			$date = $wpdb->get_var("SELECT post_{$field} FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1");
+			$date = $wpdb->get_var( "SELECT post_{$field} FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1" );
 			break;
 		case 'server':
 			$add_seconds_server = date( 'Z' );
-			$date = $wpdb->get_var("SELECT DATE_ADD(post_{$field}_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1");
+			$date               = $wpdb->get_var( "SELECT DATE_ADD(post_{$field}_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type IN ({$post_types}) ORDER BY post_{$field}_gmt DESC LIMIT 1" );
 			break;
 	}
 
@@ -5920,11 +6297,13 @@
  * @param array $posts Array of post objects (passed by reference).
  */
 function update_post_cache( &$posts ) {
-	if ( ! $posts )
+	if ( ! $posts ) {
 		return;
-
-	foreach ( $posts as $post )
+	}
+
+	foreach ( $posts as $post ) {
 		wp_cache_add( $post->ID, $post, 'posts' );
+	}
 }
 
 /**
@@ -5945,12 +6324,14 @@
 function clean_post_cache( $post ) {
 	global $_wp_suspend_cache_invalidation;
 
-	if ( ! empty( $_wp_suspend_cache_invalidation ) )
+	if ( ! empty( $_wp_suspend_cache_invalidation ) ) {
 		return;
+	}
 
 	$post = get_post( $post );
-	if ( empty( $post ) )
+	if ( empty( $post ) ) {
 		return;
+	}
 
 	wp_cache_delete( $post->ID, 'posts' );
 	wp_cache_delete( $post->ID, 'post_meta' );
@@ -5997,20 +6378,23 @@
  */
 function update_post_caches( &$posts, $post_type = 'post', $update_term_cache = true, $update_meta_cache = true ) {
 	// No point in doing all this work if we didn't match any posts.
-	if ( !$posts )
+	if ( ! $posts ) {
 		return;
-
-	update_post_cache($posts);
+	}
+
+	update_post_cache( $posts );
 
 	$post_ids = array();
-	foreach ( $posts as $post )
+	foreach ( $posts as $post ) {
 		$post_ids[] = $post->ID;
-
-	if ( ! $post_type )
+	}
+
+	if ( ! $post_type ) {
 		$post_type = 'any';
+	}
 
 	if ( $update_term_cache ) {
-		if ( is_array($post_type) ) {
+		if ( is_array( $post_type ) ) {
 			$ptypes = $post_type;
 		} elseif ( 'any' == $post_type ) {
 			$ptypes = array();
@@ -6018,17 +6402,19 @@
 			foreach ( $posts as $post ) {
 				$ptypes[] = $post->post_type;
 			}
-			$ptypes = array_unique($ptypes);
+			$ptypes = array_unique( $ptypes );
 		} else {
-			$ptypes = array($post_type);
+			$ptypes = array( $post_type );
 		}
 
-		if ( ! empty($ptypes) )
-			update_object_term_cache($post_ids, $ptypes);
-	}
-
-	if ( $update_meta_cache )
-		update_postmeta_cache($post_ids);
+		if ( ! empty( $ptypes ) ) {
+			update_object_term_cache( $post_ids, $ptypes );
+		}
+	}
+
+	if ( $update_meta_cache ) {
+		update_postmeta_cache( $post_ids );
+	}
 }
 
 /**
@@ -6045,7 +6431,7 @@
  *                     of metadata.
  */
 function update_postmeta_cache( $post_ids ) {
-	return update_meta_cache('post', $post_ids);
+	return update_meta_cache( 'post', $post_ids );
 }
 
 /**
@@ -6066,16 +6452,18 @@
 function clean_attachment_cache( $id, $clean_terms = false ) {
 	global $_wp_suspend_cache_invalidation;
 
-	if ( !empty($_wp_suspend_cache_invalidation) )
+	if ( ! empty( $_wp_suspend_cache_invalidation ) ) {
 		return;
+	}
 
 	$id = (int) $id;
 
-	wp_cache_delete($id, 'posts');
-	wp_cache_delete($id, 'post_meta');
-
-	if ( $clean_terms )
-		clean_object_term_cache($id, 'attachment');
+	wp_cache_delete( $id, 'posts' );
+	wp_cache_delete( $id, 'post_meta' );
+
+	if ( $clean_terms ) {
+		clean_object_term_cache( $id, 'attachment' );
+	}
 
 	/**
 	 * Fires after the given attachment's cache is cleaned.
@@ -6109,8 +6497,9 @@
 
 	if ( $old_status != 'publish' && $new_status == 'publish' ) {
 		// Reset GUID if transitioning to publish and it is empty.
-		if ( '' == get_the_guid($post->ID) )
+		if ( '' == get_the_guid( $post->ID ) ) {
 			$wpdb->update( $wpdb->posts, array( 'guid' => get_permalink( $post->ID ) ), array( 'ID' => $post->ID ) );
+		}
 
 		/**
 		 * Fires when a post's status is transitioned from private to published.
@@ -6120,11 +6509,11 @@
 		 *
 		 * @param int $post_id Post ID.
 		 */
-		do_action('private_to_published', $post->ID);
+		do_action( 'private_to_published', $post->ID );
 	}
 
 	// If published posts changed clear the lastpostmodified cache.
-	if ( 'publish' == $new_status || 'publish' == $old_status) {
+	if ( 'publish' == $new_status || 'publish' == $old_status ) {
 		foreach ( array( 'server', 'gmt', 'blog' ) as $timezone ) {
 			wp_cache_delete( "lastpostmodified:$timezone", 'timeinfo' );
 			wp_cache_delete( "lastpostdate:$timezone", 'timeinfo' );
@@ -6138,7 +6527,7 @@
 	}
 
 	// Always clears the hook in case the post status bounced from future to draft.
-	wp_clear_scheduled_hook('publish_future_post', array( $post->ID ) );
+	wp_clear_scheduled_hook( 'publish_future_post', array( $post->ID ) );
 }
 
 /**
@@ -6156,7 +6545,7 @@
  */
 function _future_post_hook( $deprecated, $post ) {
 	wp_clear_scheduled_hook( 'publish_future_post', array( $post->ID ) );
-	wp_schedule_single_event( strtotime( get_gmt_from_date( $post->post_date ) . ' GMT') , 'publish_future_post', array( $post->ID ) );
+	wp_schedule_single_event( strtotime( get_gmt_from_date( $post->post_date ) . ' GMT' ), 'publish_future_post', array( $post->ID ) );
 }
 
 /**
@@ -6181,11 +6570,13 @@
 		do_action( 'xmlrpc_publish_post', $post_id );
 	}
 
-	if ( defined('WP_IMPORTING') )
+	if ( defined( 'WP_IMPORTING' ) ) {
 		return;
-
-	if ( get_option('default_pingback_flag') )
+	}
+
+	if ( get_option( 'default_pingback_flag' ) ) {
 		add_post_meta( $post_id, '_pingme', '1' );
+	}
 	add_post_meta( $post_id, '_encloseme', '1' );
 
 	if ( ! wp_next_scheduled( 'do_pings' ) ) {
@@ -6194,18 +6585,18 @@
 }
 
 /**
- * Return the post's parent's post_ID
+ * Returns the ID of the post's parent.
  *
  * @since 3.1.0
  *
- * @param int $post_ID
- *
- * @return int|false Post parent ID, otherwise false.
+ * @param int|WP_Post $post Post ID or post object. Defaults to global $post.
+ * @return int|false Post parent ID (which can be 0 if there is no parent), or false if the post does not exist.
  */
-function wp_get_post_parent_id( $post_ID ) {
-	$post = get_post( $post_ID );
-	if ( !$post || is_wp_error( $post ) )
+function wp_get_post_parent_id( $post ) {
+	$post = get_post( $post );
+	if ( ! $post || is_wp_error( $post ) ) {
 		return false;
+	}
 	return (int) $post->post_parent;
 }
 
@@ -6225,34 +6616,45 @@
  */
 function wp_check_post_hierarchy_for_loops( $post_parent, $post_ID ) {
 	// Nothing fancy here - bail.
-	if ( !$post_parent )
+	if ( ! $post_parent ) {
 		return 0;
+	}
 
 	// New post can't cause a loop.
-	if ( empty( $post_ID ) )
+	if ( empty( $post_ID ) ) {
 		return $post_parent;
+	}
 
 	// Can't be its own parent.
-	if ( $post_parent == $post_ID )
+	if ( $post_parent == $post_ID ) {
 		return 0;
+	}
 
 	// Now look for larger loops.
-	if ( !$loop = wp_find_hierarchy_loop( 'wp_get_post_parent_id', $post_ID, $post_parent ) )
+	if ( ! $loop = wp_find_hierarchy_loop( 'wp_get_post_parent_id', $post_ID, $post_parent ) ) {
 		return $post_parent; // No loop
+	}
 
 	// Setting $post_parent to the given value causes a loop.
-	if ( isset( $loop[$post_ID] ) )
+	if ( isset( $loop[ $post_ID ] ) ) {
 		return 0;
+	}
 
 	// There's a loop, but it doesn't contain $post_ID. Break the loop.
-	foreach ( array_keys( $loop ) as $loop_member )
-		wp_update_post( array( 'ID' => $loop_member, 'post_parent' => 0 ) );
+	foreach ( array_keys( $loop ) as $loop_member ) {
+		wp_update_post(
+			array(
+				'ID'          => $loop_member,
+				'post_parent' => 0,
+			)
+		);
+	}
 
 	return $post_parent;
 }
 
 /**
- * Set a post thumbnail.
+ * Sets the post thumbnail (featured image) for the given post.
  *
  * @since 3.1.0
  *
@@ -6261,29 +6663,31 @@
  * @return int|bool True on success, false on failure.
  */
 function set_post_thumbnail( $post, $thumbnail_id ) {
-	$post = get_post( $post );
+	$post         = get_post( $post );
 	$thumbnail_id = absint( $thumbnail_id );
 	if ( $post && $thumbnail_id && get_post( $thumbnail_id ) ) {
-		if ( wp_get_attachment_image( $thumbnail_id, 'thumbnail' ) )
+		if ( wp_get_attachment_image( $thumbnail_id, 'thumbnail' ) ) {
 			return update_post_meta( $post->ID, '_thumbnail_id', $thumbnail_id );
-		else
+		} else {
 			return delete_post_meta( $post->ID, '_thumbnail_id' );
+		}
 	}
 	return false;
 }
 
 /**
- * Remove a post thumbnail.
+ * Removes the thumbnail (featured image) from the given post.
  *
  * @since 3.3.0
  *
- * @param int|WP_Post $post Post ID or post object where thumbnail should be removed from.
+ * @param int|WP_Post $post Post ID or post object from which the thumbnail should be removed.
  * @return bool True on success, false on failure.
  */
 function delete_post_thumbnail( $post ) {
 	$post = get_post( $post );
-	if ( $post )
+	if ( $post ) {
 		return delete_post_meta( $post->ID, '_thumbnail_id' );
+	}
 	return false;
 }
 
@@ -6381,8 +6785,8 @@
 	global $wpdb;
 
 	$non_cached_ids = _get_non_cached_ids( $ids, 'posts' );
-	if ( !empty( $non_cached_ids ) ) {
-		$fresh_posts = $wpdb->get_results( sprintf( "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE ID IN (%s)", join( ",", $non_cached_ids ) ) );
+	if ( ! empty( $non_cached_ids ) ) {
+		$fresh_posts = $wpdb->get_results( sprintf( "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE ID IN (%s)", join( ',', $non_cached_ids ) ) );
 
 		update_post_caches( $fresh_posts, 'any', $update_term_cache, $update_meta_cache );
 	}
@@ -6403,13 +6807,15 @@
  * @param string $post_ID   Optional. Post ID that should be ignored. Default 0.
  */
 function wp_add_trashed_suffix_to_post_name_for_trashed_posts( $post_name, $post_ID = 0 ) {
-	$trashed_posts_with_desired_slug = get_posts( array(
-		'name' => $post_name,
-		'post_status' => 'trash',
-		'post_type' => 'any',
-		'nopaging' => true,
-		'post__not_in' => array( $post_ID )
-	) );
+	$trashed_posts_with_desired_slug = get_posts(
+		array(
+			'name'         => $post_name,
+			'post_status'  => 'trash',
+			'post_type'    => 'any',
+			'nopaging'     => true,
+			'post__not_in' => array( $post_ID ),
+		)
+	);
 
 	if ( ! empty( $trashed_posts_with_desired_slug ) ) {
 		foreach ( $trashed_posts_with_desired_slug as $_post ) {
@@ -6470,8 +6876,35 @@
 
 	$clauses['where'] = preg_replace(
 		"/\({$wpdb->posts}.post_content (NOT LIKE|LIKE) (\'[^']+\')\)/",
-		"$0 OR ( sq1.meta_value $1 $2 )",
-		$clauses['where'] );
+		'$0 OR ( sq1.meta_value $1 $2 )',
+		$clauses['where']
+	);
 
 	return $clauses;
 }
+
+/**
+ * Sets the last changed time for the 'posts' cache group.
+ *
+ * @since 5.0.0
+ */
+function wp_cache_set_posts_last_changed() {
+	wp_cache_set( 'last_changed', microtime(), 'posts' );
+}
+
+/**
+ * Get all available post MIME types for a given post type.
+ *
+ * @since 2.5.0
+ *
+ * @global wpdb $wpdb WordPress database abstraction object.
+ *
+ * @param string $type
+ * @return mixed
+ */
+function get_available_post_mime_types( $type = 'attachment' ) {
+	global $wpdb;
+
+	$types = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT post_mime_type FROM $wpdb->posts WHERE post_type = %s", $type ) );
+	return $types;
+}