--- a/wp/wp-admin/includes/post.php Wed Sep 21 18:19:35 2022 +0200
+++ b/wp/wp-admin/includes/post.php Tue Sep 27 16:37:53 2022 +0200
@@ -7,14 +7,15 @@
*/
/**
- * Rename $_POST data from form names to DB post columns.
+ * Renames `$_POST` data from form names to DB post columns.
*
- * Manipulates $_POST directly.
+ * Manipulates `$_POST` directly.
*
* @since 2.6.0
*
- * @param bool $update Are we updating a pre-existing post?
- * @param array $post_data Array of post data. Defaults to the contents of $_POST.
+ * @param bool $update Whether the post already exists.
+ * @param array|null $post_data Optional. The array of post data to process.
+ * Defaults to the `$_POST` superglobal.
* @return array|WP_Error Array of post data on success, WP_Error on failure.
*/
function _wp_translate_postdata( $update = false, $post_data = null ) {
@@ -204,11 +205,12 @@
}
/**
- * Returns only allowed post data fields
+ * Returns only allowed post data fields.
*
* @since 5.0.1
*
- * @param array $post_data Array of post data. Defaults to the contents of $_POST.
+ * @param array|WP_Error|null $post_data The array of post data to process, or an error object.
+ * Defaults to the `$_POST` superglobal.
* @return array|WP_Error Array of post data on success, WP_Error on failure.
*/
function _wp_get_allowed_postdata( $post_data = null ) {
@@ -225,18 +227,19 @@
}
/**
- * Update an existing post with values provided in $_POST.
+ * Updates an existing post with values provided in `$_POST`.
*
* If post data is passed as an argument, it is treated as an array of data
* keyed appropriately for turning into a post object.
*
- * If post data is not passed, the $_POST global variable is used instead.
+ * If post data is not passed, the `$_POST` global variable is used instead.
*
* @since 1.5.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
- * @param array $post_data Optional. Defaults to the $_POST global.
+ * @param array|null $post_data Optional. The array of post data to process.
+ * Defaults to the `$_POST` superglobal.
* @return int Post ID.
*/
function edit_post( $post_data = null ) {
@@ -452,7 +455,7 @@
}
/**
- * Process the post data for the bulk editing of posts.
+ * Processes the post data for the bulk editing of posts.
*
* Updates all bulk edited posts/pages, adding (but not removing) tags and
* categories. Skips pages when they would be their own parent or child.
@@ -461,7 +464,8 @@
*
* @global wpdb $wpdb WordPress database abstraction object.
*
- * @param array $post_data Optional, the array of post data to process if not provided will use $_POST superglobal.
+ * @param array|null $post_data Optional. The array of post data to process.
+ * Defaults to the `$_POST` superglobal.
* @return array
*/
function bulk_edit_posts( $post_data = null ) {
@@ -640,7 +644,9 @@
// Prevent wp_insert_post() from overwriting post format with the old data.
unset( $post_data['tax_input']['post_format'] );
- $updated[] = wp_update_post( $post_data );
+ $post_id = wp_update_post( $post_data );
+ update_post_meta( $post_id, '_edit_last', get_current_user_id() );
+ $updated[] = $post_id;
if ( isset( $post_data['sticky'] ) && current_user_can( $ptype->cap->edit_others_posts ) ) {
if ( 'sticky' === $post_data['sticky'] ) {
@@ -659,7 +665,7 @@
}
/**
- * Default post information to use when populating the "Write Post" form.
+ * Returns default post information to use when populating the "Write Post" form.
*
* @since 2.0.0
*
@@ -768,10 +774,10 @@
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param string $title Post title.
- * @param string $content Optional post content.
- * @param string $date Optional post date.
- * @param string $type Optional post type.
- * @param string $status Optional post status.
+ * @param string $content Optional. Post content.
+ * @param string $date Optional. Post date.
+ * @param string $type Optional. Post type.
+ * @param string $status Optional. Post status.
* @return int Post ID if post exists, 0 otherwise.
*/
function post_exists( $title, $content = '', $date = '', $type = '', $status = '' ) {
@@ -819,7 +825,7 @@
}
/**
- * Creates a new post from the "Write Post" form using $_POST information.
+ * Creates a new post from the "Write Post" form using `$_POST` information.
*
* @since 2.1.0
*
@@ -917,7 +923,7 @@
//
/**
- * Add post meta data defined in $_POST superglobal for post with given ID.
+ * Adds post meta data defined in the `$_POST` superglobal for a post with given ID.
*
* @since 1.2.0
*
@@ -960,7 +966,7 @@
}
/**
- * Delete post meta data by meta ID.
+ * Deletes post meta data by meta ID.
*
* @since 1.2.0
*
@@ -972,13 +978,13 @@
}
/**
- * Get a list of previously defined keys.
+ * Returns a list of previously defined keys.
*
* @since 1.2.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
- * @return mixed
+ * @return string[] Array of meta key names.
*/
function get_meta_keys() {
global $wpdb;
@@ -995,7 +1001,7 @@
}
/**
- * Get post meta data by meta ID.
+ * Returns post meta data by meta ID.
*
* @since 2.1.0
*
@@ -1007,14 +1013,25 @@
}
/**
- * Get meta data for the given post ID.
+ * Returns meta data for the given post ID.
*
* @since 1.2.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
- * @param int $postid
- * @return mixed
+ * @param int $postid A post ID.
+ * @return array[] {
+ * Array of meta data arrays for the given post ID.
+ *
+ * @type array ...$0 {
+ * Associative array of meta data.
+ *
+ * @type string $meta_key Meta key.
+ * @type mixed $meta_value Meta value.
+ * @type string $meta_id Meta ID as a numeric string.
+ * @type string $post_id Post ID as a numeric string.
+ * }
+ * }
*/
function has_meta( $postid ) {
global $wpdb;
@@ -1031,13 +1048,13 @@
}
/**
- * Update post meta data by meta ID.
+ * Updates post meta data by meta ID.
*
* @since 1.2.0
*
- * @param int $meta_id
- * @param string $meta_key Expect Slashed
- * @param string $meta_value Expect Slashed
+ * @param int $meta_id Meta ID.
+ * @param string $meta_key Meta key. Expect slashed.
+ * @param string $meta_value Meta value. Expect slashed.
* @return bool
*/
function update_meta( $meta_id, $meta_key, $meta_value ) {
@@ -1052,7 +1069,7 @@
//
/**
- * Replace hrefs of attachment anchors with up-to-date permalinks.
+ * Replaces hrefs of attachment anchors with up-to-date permalinks.
*
* @since 2.3.0
* @access private
@@ -1109,7 +1126,7 @@
}
/**
- * Get all the possible statuses for a post_type
+ * Returns all the possible statuses for a post type.
*
* @since 2.5.0
*
@@ -1123,11 +1140,12 @@
}
/**
- * Run the wp query to fetch the posts for listing on the edit posts page
+ * Runs the query to fetch the posts for listing on the edit posts page.
*
* @since 2.5.0
*
- * @param array|false $q Array of query variables to use to build the query or false to use $_GET superglobal.
+ * @param array|false $q Optional. Array of query variables to use to build the query.
+ * Defaults to the `$_GET` superglobal.
* @return array
*/
function wp_edit_posts_query( $q = false ) {
@@ -1224,12 +1242,12 @@
}
/**
- * Get the query variables for the current attachments request.
+ * Returns the query variables for the current attachments request.
*
* @since 4.2.0
*
- * @param array|false $q Optional. Array of query variables to use to build the query or false
- * to use $_GET superglobal. Default false.
+ * @param array|false $q Optional. Array of query variables to use to build the query.
+ * Defaults to the `$_GET` superglobal.
* @return array The parsed query vars.
*/
function wp_edit_attachments_query_vars( $q = false ) {
@@ -1296,7 +1314,8 @@
*
* @since 2.5.0
*
- * @param array|false $q Array of query variables to use to build the query or false to use $_GET superglobal.
+ * @param array|false $q Optional. Array of query variables to use to build the query.
+ * Defaults to the `$_GET` superglobal.
* @return array
*/
function wp_edit_attachments_query( $q = false ) {
@@ -1342,17 +1361,19 @@
* @param string[] $classes An array of postbox classes.
*/
$classes = apply_filters( "postbox_classes_{$screen_id}_{$box_id}", $classes );
+
return implode( ' ', $classes );
}
/**
- * Get a sample permalink based off of the post name.
+ * Returns a sample permalink based on the post name.
*
* @since 2.5.0
*
* @param int|WP_Post $id Post ID or post object.
- * @param string $title Optional. Title to override the post's current title when generating the post name. Default null.
- * @param string $name Optional. Name to override the post name. Default null.
+ * @param string|null $title Optional. Title to override the post's current title
+ * when generating the post name. Default null.
+ * @param string|null $name Optional. Name to override the post name. Default null.
* @return array {
* Array containing the sample permalink with placeholder for the post name, and the post name.
*
@@ -1428,10 +1449,10 @@
* @type string $0 The permalink with placeholder for the post name.
* @type string $1 The post name.
* }
- * @param int $post_id Post ID.
- * @param string $title Post title.
- * @param string $name Post name (slug).
- * @param WP_Post $post Post object.
+ * @param int $post_id Post ID.
+ * @param string $title Post title.
+ * @param string $name Post name (slug).
+ * @param WP_Post $post Post object.
*/
return apply_filters( 'get_sample_permalink', $permalink, $post->ID, $title, $name, $post );
}
@@ -1441,9 +1462,9 @@
*
* @since 2.5.0
*
- * @param int $id Post ID or post object.
- * @param string $new_title Optional. New title. Default null.
- * @param string $new_slug Optional. New slug. Default null.
+ * @param int|WP_Post $id Post ID or post object.
+ * @param string|null $new_title Optional. New title. Default null.
+ * @param string|null $new_slug Optional. New slug. Default null.
* @return string The HTML of the sample permalink slug editor.
*/
function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) {
@@ -1486,7 +1507,7 @@
if ( ! get_option( 'permalink_structure' ) && current_user_can( 'manage_options' )
&& ! ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $id )
) {
- $return .= '<span id="change-permalinks"><a href="options-permalink.php" class="button button-small" target="_blank">' . __( 'Change Permalinks' ) . "</a></span>\n";
+ $return .= '<span id="change-permalinks"><a href="options-permalink.php" class="button button-small">' . __( 'Change Permalink Structure' ) . "</a></span>\n";
}
} else {
if ( mb_strlen( $post_name ) > 34 ) {
@@ -1527,8 +1548,9 @@
*
* @since 2.9.0
*
- * @param int $thumbnail_id ID of the attachment used for thumbnail
- * @param int|WP_Post $post Optional. The post ID or object associated with the thumbnail, defaults to global $post.
+ * @param int|null $thumbnail_id Optional. Thumbnail attachment ID. Default null.
+ * @param int|WP_Post|null $post Optional. The post ID or object associated
+ * with the thumbnail. Defaults to global $post.
* @return string The post thumbnail HTML.
*/
function _wp_post_thumbnail_html( $thumbnail_id = null, $post = null ) {
@@ -1596,7 +1618,7 @@
}
/**
- * Check to see if the post is currently being edited by another user.
+ * Determines whether the post is currently being edited by another user.
*
* @since 2.5.0
*
@@ -1634,13 +1656,18 @@
}
/**
- * Mark the post as currently being edited by the current user
+ * Marks the post as currently being edited by the current user.
*
* @since 2.5.0
*
* @param int|WP_Post $post_id ID or object of the post being edited.
- * @return array|false Array of the lock time and user ID. False if the post does not exist, or
- * there is no current user.
+ * @return array|false {
+ * Array of the lock time and user ID. False if the post does not exist, or there
+ * is no current user.
+ *
+ * @type int $0 The current time as a Unix timestamp.
+ * @type int $1 The ID of the current user.
+ * }
*/
function wp_set_post_lock( $post_id ) {
$post = get_post( $post_id );
@@ -1824,11 +1851,12 @@
}
/**
- * Creates autosave data for the specified post from $_POST data.
+ * Creates autosave data for the specified post from `$_POST` data.
*
* @since 2.6.0
*
- * @param array|int $post_data Associative array containing the post data or int post ID.
+ * @param array|int $post_data Associative array containing the post data, or integer post ID.
+ * If a numeric post ID is provided, will use the `$_POST` superglobal.
* @return int|WP_Error The autosave revision ID. WP_Error or 0 on error.
*/
function wp_create_post_autosave( $post_data ) {
@@ -1949,7 +1977,7 @@
}
/**
- * Save a post submitted with XHR
+ * Saves a post submitted with XHR.
*
* Intended for use with heartbeat and autosave.js
*
@@ -2000,7 +2028,7 @@
}
/**
- * Redirect to previous page.
+ * Redirects to previous page.
*
* @since 2.7.0
*
@@ -2114,7 +2142,7 @@
}
/**
- * Return whether the post can be edited in the block editor.
+ * Returns whether the post can be edited in the block editor.
*
* @since 5.0.0
*
@@ -2148,7 +2176,7 @@
}
/**
- * Return whether a post type is compatible with the block editor.
+ * Returns whether a post type is compatible with the block editor.
*
* The block editor depends on the REST API, and if the post type is not shown in the
* REST API, then it won't work with the block editor.
@@ -2209,6 +2237,7 @@
'styles' => 'styles',
'textdomain' => 'textdomain',
'parent' => 'parent',
+ 'ancestor' => 'ancestor',
'keywords' => 'keywords',
'example' => 'example',
'variations' => 'variations',
@@ -2314,12 +2343,12 @@
}
}
- /**
- * Sadly we probably can not add this data directly into editor settings.
+ /*
+ * Sadly we probably cannot add this data directly into editor settings.
*
- * Some meta boxes need admin_head to fire for meta box registry.
- * admin_head fires after admin_enqueue_scripts, which is where we create our
- * editor instance.
+ * Some meta boxes need `admin_head` to fire for meta box registry.
+ * `admin_head` fires after `admin_enqueue_scripts`, which is where we create
+ * our editor instance.
*/
$script = 'window._wpLoadBlockEditor.then( function() {
wp.data.dispatch( \'core/edit-post\' ).setAvailableMetaBoxesPerLocation( ' . wp_json_encode( $meta_boxes_per_location ) . ' );
@@ -2327,19 +2356,21 @@
wp_add_inline_script( 'wp-edit-post', $script );
- /**
- * When `wp-edit-post` is output in the `<head>`, the inline script needs to be manually printed. Otherwise,
- * meta boxes will not display because inline scripts for `wp-edit-post` will not be printed again after this point.
+ /*
+ * When `wp-edit-post` is output in the `<head>`, the inline script needs to be manually printed.
+ * Otherwise, meta boxes will not display because inline scripts for `wp-edit-post`
+ * will not be printed again after this point.
*/
if ( wp_script_is( 'wp-edit-post', 'done' ) ) {
printf( "<script type='text/javascript'>\n%s\n</script>\n", trim( $script ) );
}
- /**
- * If the 'postcustom' meta box is enabled, then we need to perform some
- * extra initialization on it.
+ /*
+ * If the 'postcustom' meta box is enabled, then we need to perform
+ * some extra initialization on it.
*/
$enable_custom_fields = (bool) get_user_meta( get_current_user_id(), 'enable_custom_fields', true );
+
if ( $enable_custom_fields ) {
$script = "( function( $ ) {
if ( $('#postcustom').length ) {
@@ -2383,8 +2414,9 @@
wp_nonce_field( $nonce_action );
/*
- * Some meta boxes hook into these actions to add hidden input fields in the classic post form. For backwards
- * compatibility, we can capture the output from these actions, and extract the hidden input fields.
+ * Some meta boxes hook into these actions to add hidden input fields in the classic post form.
+ * For backward compatibility, we can capture the output from these actions,
+ * and extract the hidden input fields.
*/
ob_start();
/** This filter is documented in wp-admin/edit-form-advanced.php */
@@ -2423,7 +2455,7 @@
wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false );
/**
- * Add hidden input fields to the meta box save form.
+ * Adds hidden input fields to the meta box save form.
*
* Hook into this action to print `<input type="hidden" ... />` fields, which will be POSTed back to
* the server when meta boxes are saved.
@@ -2434,3 +2466,62 @@
*/
do_action( 'block_editor_meta_box_hidden_fields', $post );
}
+
+/**
+ * Disables block editor for wp_navigation type posts so they can be managed via the UI.
+ *
+ * @since 5.9.0
+ * @access private
+ *
+ * @param bool $value Whether the CPT supports block editor or not.
+ * @param string $post_type Post type.
+ * @return bool Whether the block editor should be disabled or not.
+ */
+function _disable_block_editor_for_navigation_post_type( $value, $post_type ) {
+ if ( 'wp_navigation' === $post_type ) {
+ return false;
+ }
+
+ return $value;
+}
+
+/**
+ * This callback disables the content editor for wp_navigation type posts.
+ * Content editor cannot handle wp_navigation type posts correctly.
+ * We cannot disable the "editor" feature in the wp_navigation's CPT definition
+ * because it disables the ability to save navigation blocks via REST API.
+ *
+ * @since 5.9.0
+ * @access private
+ *
+ * @param WP_Post $post An instance of WP_Post class.
+ */
+function _disable_content_editor_for_navigation_post_type( $post ) {
+ $post_type = get_post_type( $post );
+ if ( 'wp_navigation' !== $post_type ) {
+ return;
+ }
+
+ remove_post_type_support( $post_type, 'editor' );
+}
+
+/**
+ * This callback enables content editor for wp_navigation type posts.
+ * We need to enable it back because we disable it to hide
+ * the content editor for wp_navigation type posts.
+ *
+ * @since 5.9.0
+ * @access private
+ *
+ * @see _disable_content_editor_for_navigation_post_type
+ *
+ * @param WP_Post $post An instance of WP_Post class.
+ */
+function _enable_content_editor_for_navigation_post_type( $post ) {
+ $post_type = get_post_type( $post );
+ if ( 'wp_navigation' !== $post_type ) {
+ return;
+ }
+
+ add_post_type_support( $post_type, 'editor' );
+}