--- a/wp/wp-admin/includes/post.php Tue Oct 22 16:11:46 2019 +0200
+++ b/wp/wp-admin/includes/post.php Tue Dec 15 13:49:49 2020 +0100
@@ -13,9 +13,9 @@
*
* @since 2.6.0
*
- * @param bool $update Are we updating a pre-existing post?
+ * @param bool $update Are we updating a pre-existing post?
* @param array $post_data Array of post data. Defaults to the contents of $_POST.
- * @return object|bool WP_Error on failure, true on success.
+ * @return array|WP_Error Array of post data on success, WP_Error on failure.
*/
function _wp_translate_postdata( $update = false, $post_data = null ) {
@@ -30,13 +30,13 @@
$ptype = get_post_type_object( $post_data['post_type'] );
if ( $update && ! current_user_can( 'edit_post', $post_data['ID'] ) ) {
- if ( 'page' == $post_data['post_type'] ) {
+ if ( 'page' === $post_data['post_type'] ) {
return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to edit pages as this user.' ) );
} else {
return new WP_Error( 'edit_others_posts', __( 'Sorry, you are not allowed to edit posts as this user.' ) );
}
} elseif ( ! $update && ! current_user_can( $ptype->cap->create_posts ) ) {
- if ( 'page' == $post_data['post_type'] ) {
+ if ( 'page' === $post_data['post_type'] ) {
return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to create pages as this user.' ) );
} else {
return new WP_Error( 'edit_others_posts', __( 'Sorry, you are not allowed to create posts as this user.' ) );
@@ -75,13 +75,13 @@
&& ! current_user_can( $ptype->cap->edit_others_posts ) ) {
if ( $update ) {
- if ( 'page' == $post_data['post_type'] ) {
+ if ( 'page' === $post_data['post_type'] ) {
return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to edit pages as this user.' ) );
} else {
return new WP_Error( 'edit_others_posts', __( 'Sorry, you are not allowed to edit posts as this user.' ) );
}
} else {
- if ( 'page' == $post_data['post_type'] ) {
+ if ( 'page' === $post_data['post_type'] ) {
return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to create pages as this user.' ) );
} else {
return new WP_Error( 'edit_others_posts', __( 'Sorry, you are not allowed to create posts as this user.' ) );
@@ -92,7 +92,7 @@
if ( ! empty( $post_data['post_status'] ) ) {
$post_data['post_status'] = sanitize_key( $post_data['post_status'] );
- // No longer an auto-draft
+ // No longer an auto-draft.
if ( 'auto-draft' === $post_data['post_status'] ) {
$post_data['post_status'] = 'draft';
}
@@ -102,20 +102,22 @@
}
}
- // What to do based on which button they pressed
- if ( isset( $post_data['saveasdraft'] ) && '' != $post_data['saveasdraft'] ) {
+ // What to do based on which button they pressed.
+ if ( isset( $post_data['saveasdraft'] ) && '' !== $post_data['saveasdraft'] ) {
$post_data['post_status'] = 'draft';
}
- if ( isset( $post_data['saveasprivate'] ) && '' != $post_data['saveasprivate'] ) {
+ if ( isset( $post_data['saveasprivate'] ) && '' !== $post_data['saveasprivate'] ) {
$post_data['post_status'] = 'private';
}
- if ( isset( $post_data['publish'] ) && ( '' != $post_data['publish'] ) && ( ! isset( $post_data['post_status'] ) || $post_data['post_status'] != 'private' ) ) {
+ if ( isset( $post_data['publish'] ) && ( '' !== $post_data['publish'] )
+ && ( ! isset( $post_data['post_status'] ) || 'private' !== $post_data['post_status'] )
+ ) {
$post_data['post_status'] = 'publish';
}
- if ( isset( $post_data['advanced'] ) && '' != $post_data['advanced'] ) {
+ if ( isset( $post_data['advanced'] ) && '' !== $post_data['advanced'] ) {
$post_data['post_status'] = 'draft';
}
- if ( isset( $post_data['pending'] ) && '' != $post_data['pending'] ) {
+ if ( isset( $post_data['pending'] ) && '' !== $post_data['pending'] ) {
$post_data['post_status'] = 'pending';
}
@@ -126,16 +128,19 @@
}
$previous_status = $post_id ? get_post_field( 'post_status', $post_id ) : false;
- if ( isset( $post_data['post_status'] ) && 'private' == $post_data['post_status'] && ! current_user_can( $ptype->cap->publish_posts ) ) {
+ if ( isset( $post_data['post_status'] ) && 'private' === $post_data['post_status'] && ! current_user_can( $ptype->cap->publish_posts ) ) {
$post_data['post_status'] = $previous_status ? $previous_status : 'pending';
}
$published_statuses = array( 'publish', 'future' );
- // Posts 'submitted for approval' present are submitted to $_POST the same as if they were being published.
+ // Posts 'submitted for approval' are submitted to $_POST the same as if they were being published.
// Change status from 'publish' to 'pending' if user lacks permissions to publish or to resave published posts.
- if ( isset( $post_data['post_status'] ) && ( in_array( $post_data['post_status'], $published_statuses ) && ! current_user_can( $ptype->cap->publish_posts ) ) ) {
- if ( ! in_array( $previous_status, $published_statuses ) || ! current_user_can( 'edit_post', $post_id ) ) {
+ if ( isset( $post_data['post_status'] )
+ && ( in_array( $post_data['post_status'], $published_statuses, true )
+ && ! current_user_can( $ptype->cap->publish_posts ) )
+ ) {
+ if ( ! in_array( $previous_status, $published_statuses, true ) || ! current_user_can( 'edit_post', $post_id ) ) {
$post_data['post_status'] = 'pending';
}
}
@@ -170,10 +175,10 @@
$hh = $post_data['hh'];
$mn = $post_data['mn'];
$ss = $post_data['ss'];
- $aa = ( $aa <= 0 ) ? date( 'Y' ) : $aa;
- $mm = ( $mm <= 0 ) ? date( 'n' ) : $mm;
+ $aa = ( $aa <= 0 ) ? gmdate( 'Y' ) : $aa;
+ $mm = ( $mm <= 0 ) ? gmdate( 'n' ) : $mm;
$jj = ( $jj > 31 ) ? 31 : $jj;
- $jj = ( $jj <= 0 ) ? date( 'j' ) : $jj;
+ $jj = ( $jj <= 0 ) ? gmdate( 'j' ) : $jj;
$hh = ( $hh > 23 ) ? $hh - 24 : $hh;
$mn = ( $mn > 59 ) ? $mn - 60 : $mn;
$ss = ( $ss > 59 ) ? $ss - 60 : $ss;
@@ -201,14 +206,14 @@
* @since 5.0.1
*
* @param array $post_data Array of post data. Defaults to the contents of $_POST.
- * @return object|bool WP_Error on failure, true on success.
+ * @return array|WP_Error Array of post data on success, WP_Error on failure.
*/
function _wp_get_allowed_postdata( $post_data = null ) {
if ( empty( $post_data ) ) {
$post_data = $_POST;
}
- // Pass through errors
+ // Pass through errors.
if ( is_wp_error( $post_data ) ) {
return $post_data;
}
@@ -219,11 +224,16 @@
/**
* Update 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.
+ *
* @since 1.5.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
- * @param array $post_data Optional.
+ * @param array $post_data Optional. Defaults to the $_POST global.
* @return int Post ID.
*/
function edit_post( $post_data = null ) {
@@ -244,14 +254,14 @@
if ( ! empty( $post_data['post_status'] ) ) {
$post_data['post_status'] = sanitize_key( $post_data['post_status'] );
- if ( 'inherit' == $post_data['post_status'] ) {
+ if ( 'inherit' === $post_data['post_status'] ) {
unset( $post_data['post_status'] );
}
}
$ptype = get_post_type_object( $post_data['post_type'] );
if ( ! current_user_can( 'edit_post', $post_ID ) ) {
- if ( 'page' == $post_data['post_type'] ) {
+ if ( 'page' === $post_data['post_type'] ) {
wp_die( __( 'Sorry, you are not allowed to edit this page.' ) );
} else {
wp_die( __( 'Sorry, you are not allowed to edit this post.' ) );
@@ -268,7 +278,7 @@
);
$revision = current( $revisions );
- // Check if the revisions have been upgraded
+ // Check if the revisions have been upgraded.
if ( $revisions && _wp_get_post_revision_version( $revision ) < 1 ) {
_wp_upgrade_revisions_of_post( $post, wp_get_post_revisions( $post_ID ) );
}
@@ -296,7 +306,7 @@
}
$translated = _wp_get_allowed_postdata( $post_data );
- // Post Formats
+ // Post formats.
if ( isset( $post_data['post_format'] ) ) {
set_post_format( $post_ID, $post_data['post_format'] );
}
@@ -336,10 +346,11 @@
wp_update_attachment_metadata( $post_ID, $id3data );
}
- // Meta Stuff
+ // Meta stuff.
if ( isset( $post_data['meta'] ) && $post_data['meta'] ) {
foreach ( $post_data['meta'] as $key => $value ) {
- if ( ! $meta = get_post_meta_by_id( $key ) ) {
+ $meta = get_post_meta_by_id( $key );
+ if ( ! $meta ) {
continue;
}
if ( $meta->post_id != $post_ID ) {
@@ -357,7 +368,8 @@
if ( isset( $post_data['deletemeta'] ) && $post_data['deletemeta'] ) {
foreach ( $post_data['deletemeta'] as $key => $value ) {
- if ( ! $meta = get_post_meta_by_id( $key ) ) {
+ $meta = get_post_meta_by_id( $key );
+ if ( ! $meta ) {
continue;
}
if ( $meta->post_id != $post_ID ) {
@@ -370,13 +382,15 @@
}
}
- // Attachment stuff
- if ( 'attachment' == $post_data['post_type'] ) {
+ // Attachment stuff.
+ if ( 'attachment' === $post_data['post_type'] ) {
if ( isset( $post_data['_wp_attachment_image_alt'] ) ) {
$image_alt = wp_unslash( $post_data['_wp_attachment_image_alt'] );
- if ( $image_alt != get_post_meta( $post_ID, '_wp_attachment_image_alt', true ) ) {
+
+ if ( get_post_meta( $post_ID, '_wp_attachment_image_alt', true ) !== $image_alt ) {
$image_alt = wp_strip_all_tags( $image_alt, true );
- // update_meta expects slashed.
+
+ // update_post_meta() expects slashed.
update_post_meta( $post_ID, '_wp_attachment_image_alt', wp_slash( $image_alt ) );
}
}
@@ -403,7 +417,8 @@
update_post_meta( $post_ID, '_edit_last', get_current_user_id() );
$success = wp_update_post( $translated );
- // If the save failed, see if we can sanity check the main fields and try again
+
+ // If the save failed, see if we can sanity check the main fields and try again.
if ( ! $success && is_callable( array( $wpdb, 'strip_invalid_text_for_column' ) ) ) {
$fields = array( 'post_title', 'post_content', 'post_excerpt' );
@@ -416,7 +431,7 @@
wp_update_post( $translated );
}
- // Now that we have an ID we can fix any attachment anchor hrefs
+ // Now that we have an ID we can fix any attachment anchor hrefs.
_fix_attachment_links( $post_ID );
wp_set_post_lock( $post_ID );
@@ -459,7 +474,7 @@
}
if ( ! current_user_can( $ptype->cap->edit_posts ) ) {
- if ( 'page' == $ptype->name ) {
+ if ( 'page' === $ptype->name ) {
wp_die( __( 'Sorry, you are not allowed to edit pages.' ) );
} else {
wp_die( __( 'Sorry, you are not allowed to edit posts.' ) );
@@ -477,7 +492,7 @@
if ( ! empty( $post_data['post_status'] ) ) {
$post_data['post_status'] = sanitize_key( $post_data['post_status'] );
- if ( 'inherit' == $post_data['post_status'] ) {
+ if ( 'inherit' === $post_data['post_status'] ) {
unset( $post_data['post_status'] );
}
}
@@ -500,7 +515,7 @@
);
foreach ( $reset as $field ) {
- if ( isset( $post_data[ $field ] ) && ( '' == $post_data[ $field ] || -1 == $post_data[ $field ] ) ) {
+ if ( isset( $post_data[ $field ] ) && ( '' === $post_data[ $field ] || -1 == $post_data[ $field ] ) ) {
unset( $post_data[ $field ] );
}
}
@@ -531,7 +546,8 @@
}
}
- if ( isset( $post_data['post_parent'] ) && ( $parent = (int) $post_data['post_parent'] ) ) {
+ if ( isset( $post_data['post_parent'] ) && (int) $post_data['post_parent'] ) {
+ $parent = (int) $post_data['post_parent'];
$pages = $wpdb->get_results( "SELECT ID, post_parent FROM $wpdb->posts WHERE post_type = 'page'" );
$children = array();
@@ -539,15 +555,17 @@
$children[] = $parent;
foreach ( $pages as $page ) {
- if ( $page->ID == $parent ) {
- $parent = $page->post_parent;
+ if ( (int) $page->ID === $parent ) {
+ $parent = (int) $page->post_parent;
break;
}
}
}
}
- $updated = $skipped = $locked = array();
+ $updated = array();
+ $skipped = array();
+ $locked = array();
$shared_post_data = $post_data;
foreach ( $post_IDs as $post_ID ) {
@@ -556,7 +574,10 @@
$post_type_object = get_post_type_object( get_post_type( $post_ID ) );
- if ( ! isset( $post_type_object ) || ( isset( $children ) && in_array( $post_ID, $children ) ) || ! current_user_can( 'edit_post', $post_ID ) ) {
+ if ( ! isset( $post_type_object )
+ || ( isset( $children ) && in_array( $post_ID, $children, true ) )
+ || ! current_user_can( 'edit_post', $post_ID )
+ ) {
$skipped[] = $post_ID;
continue;
}
@@ -585,7 +606,7 @@
$post_data['tax_input'][ $tax_name ] = array_merge( $current_terms, $new_terms );
}
- if ( isset( $new_cats ) && in_array( 'category', $tax_names ) ) {
+ if ( isset( $new_cats ) && in_array( 'category', $tax_names, true ) ) {
$cats = (array) wp_get_post_categories( $post_ID );
$post_data['post_category'] = array_unique( array_merge( $cats, $new_cats ) );
unset( $post_data['tax_input']['category'] );
@@ -618,7 +639,7 @@
$updated[] = wp_update_post( $post_data );
if ( isset( $post_data['sticky'] ) && current_user_can( $ptype->cap->edit_others_posts ) ) {
- if ( 'sticky' == $post_data['sticky'] ) {
+ if ( 'sticky' === $post_data['sticky'] ) {
stick_post( $post_ID );
} else {
unstick_post( $post_ID );
@@ -671,7 +692,7 @@
set_post_format( $post, get_option( 'default_post_format' ) );
}
- // Schedule auto-draft cleanup
+ // Schedule auto-draft cleanup.
if ( ! wp_next_scheduled( 'wp_scheduled_auto_draft_delete' ) ) {
wp_schedule_event( time(), 'daily', 'wp_scheduled_auto_draft_delete' );
}
@@ -799,7 +820,7 @@
}
if ( ! current_user_can( $ptype->cap->edit_posts ) ) {
- if ( 'page' == $ptype->name ) {
+ if ( 'page' === $ptype->name ) {
return new WP_Error( 'edit_pages', __( 'Sorry, you are not allowed to create pages on this site.' ) );
} else {
return new WP_Error( 'edit_posts', __( 'Sorry, you are not allowed to create posts or drafts on this site.' ) );
@@ -811,7 +832,7 @@
// Clear out any data in internal vars.
unset( $_POST['filter'] );
- // Edit don't write if we have a post id.
+ // Edit, don't write, if we have a post ID.
if ( isset( $_POST['post_ID'] ) ) {
return edit_post();
}
@@ -852,7 +873,7 @@
add_post_meta( $post_ID, '_edit_last', $GLOBALS['current_user']->ID );
- // Now that we have an ID we can fix any attachment anchor hrefs
+ // Now that we have an ID we can fix any attachment anchor hrefs.
_fix_attachment_links( $post_ID );
wp_set_post_lock( $post_ID );
@@ -877,7 +898,7 @@
}
//
-// Post Meta
+// Post Meta.
//
/**
@@ -898,17 +919,17 @@
$metavalue = trim( $metavalue );
}
- if ( ( ( '#NONE#' != $metakeyselect ) && ! empty( $metakeyselect ) ) || ! empty( $metakeyinput ) ) {
+ if ( ( ( '#NONE#' !== $metakeyselect ) && ! empty( $metakeyselect ) ) || ! empty( $metakeyinput ) ) {
/*
* We have a key/value pair. If both the select and the input
* for the key have data, the input takes precedence.
*/
- if ( '#NONE#' != $metakeyselect ) {
+ if ( '#NONE#' !== $metakeyselect ) {
$metakey = $metakeyselect;
}
if ( $metakeyinput ) {
- $metakey = $metakeyinput; // default
+ $metakey = $metakeyinput; // Default.
}
if ( is_protected_meta( $metakey, 'post' ) || ! current_user_can( 'add_post_meta', $post_ID, $metakey ) ) {
@@ -921,7 +942,7 @@
}
return false;
-} // add_meta
+}
/**
* Delete post meta data by meta ID.
@@ -1012,7 +1033,7 @@
}
//
-// Private
+// Private.
//
/**
@@ -1029,17 +1050,17 @@
$content = $post['post_content'];
// Don't run if no pretty permalinks or post is not published, scheduled, or privately published.
- if ( ! get_option( 'permalink_structure' ) || ! in_array( $post['post_status'], array( 'publish', 'future', 'private' ) ) ) {
+ if ( ! get_option( 'permalink_structure' ) || ! in_array( $post['post_status'], array( 'publish', 'future', 'private' ), true ) ) {
return;
}
- // Short if there aren't any links or no '?attachment_id=' strings (strpos cannot be zero)
+ // Short if there aren't any links or no '?attachment_id=' strings (strpos cannot be zero).
if ( ! strpos( $content, '?attachment_id=' ) || ! preg_match_all( '/<a ([^>]+)>[\s\S]+?<\/a>/', $content, $link_matches ) ) {
return;
}
$site_url = get_bloginfo( 'url' );
- $site_url = substr( $site_url, (int) strpos( $site_url, '://' ) ); // remove the http(s)
+ $site_url = substr( $site_url, (int) strpos( $site_url, '://' ) ); // Remove the http(s).
$replace = '';
foreach ( $link_matches[1] as $key => $value ) {
@@ -1049,7 +1070,7 @@
continue;
}
- $quote = $url_match[1]; // the quote (single or double)
+ $quote = $url_match[1]; // The quote (single or double).
$url_id = (int) $url_match[2];
$rel_id = (int) $rel_match[1];
@@ -1077,8 +1098,8 @@
*
* @since 2.5.0
*
- * @param string $type The post_type you want the statuses for
- * @return array As array of all the statuses for the supplied post type
+ * @param string $type The post_type you want the statuses for. Default 'post'.
+ * @return string[] An array of all the statuses for the supplied post type.
*/
function get_available_post_statuses( $type = 'post' ) {
$stati = wp_count_posts( $type );
@@ -1102,7 +1123,7 @@
$q['cat'] = isset( $q['cat'] ) ? (int) $q['cat'] : 0;
$post_stati = get_post_stati();
- if ( isset( $q['post_type'] ) && in_array( $q['post_type'], get_post_types() ) ) {
+ if ( isset( $q['post_type'] ) && in_array( $q['post_type'], get_post_types(), true ) ) {
$post_type = $q['post_type'];
} else {
$post_type = 'post';
@@ -1112,7 +1133,7 @@
$post_status = '';
$perm = '';
- if ( isset( $q['post_status'] ) && in_array( $q['post_status'], $post_stati ) ) {
+ if ( isset( $q['post_status'] ) && in_array( $q['post_status'], $post_stati, true ) ) {
$post_status = $q['post_status'];
$perm = 'readable';
}
@@ -1121,7 +1142,7 @@
if ( isset( $q['orderby'] ) ) {
$orderby = $q['orderby'];
- } elseif ( isset( $q['post_status'] ) && in_array( $q['post_status'], array( 'pending', 'draft' ) ) ) {
+ } elseif ( isset( $q['post_status'] ) && in_array( $q['post_status'], array( 'pending', 'draft' ), true ) ) {
$orderby = 'modified';
}
@@ -1129,7 +1150,7 @@
if ( isset( $q['order'] ) ) {
$order = $q['order'];
- } elseif ( isset( $q['post_status'] ) && 'pending' == $q['post_status'] ) {
+ } elseif ( isset( $q['post_status'] ) && 'pending' === $q['post_status'] ) {
$order = 'ASC';
}
@@ -1206,8 +1227,8 @@
$states .= ',private';
}
- $q['post_status'] = isset( $q['status'] ) && 'trash' == $q['status'] ? 'trash' : $states;
- $q['post_status'] = isset( $q['attachment-filter'] ) && 'trash' == $q['attachment-filter'] ? 'trash' : $states;
+ $q['post_status'] = isset( $q['status'] ) && 'trash' === $q['status'] ? 'trash' : $states;
+ $q['post_status'] = isset( $q['attachment-filter'] ) && 'trash' === $q['attachment-filter'] ? 'trash' : $states;
$media_per_page = (int) get_user_option( 'upload_per_page' );
if ( empty( $media_per_page ) || $media_per_page < 1 ) {
@@ -1229,17 +1250,17 @@
}
foreach ( array_keys( $post_mime_types ) as $type ) {
- if ( isset( $q['attachment-filter'] ) && "post_mime_type:$type" == $q['attachment-filter'] ) {
+ if ( isset( $q['attachment-filter'] ) && "post_mime_type:$type" === $q['attachment-filter'] ) {
$q['post_mime_type'] = $type;
break;
}
}
- if ( isset( $q['detached'] ) || ( isset( $q['attachment-filter'] ) && 'detached' == $q['attachment-filter'] ) ) {
+ if ( isset( $q['detached'] ) || ( isset( $q['attachment-filter'] ) && 'detached' === $q['attachment-filter'] ) ) {
$q['post_parent'] = 0;
}
- if ( isset( $q['mine'] ) || ( isset( $q['attachment-filter'] ) && 'mine' == $q['attachment-filter'] ) ) {
+ if ( isset( $q['mine'] ) || ( isset( $q['attachment-filter'] ) && 'mine' === $q['attachment-filter'] ) ) {
$q['author'] = get_current_user_id();
}
@@ -1281,11 +1302,12 @@
function postbox_classes( $box_id, $screen_id ) {
if ( isset( $_GET['edit'] ) && $_GET['edit'] == $box_id ) {
$classes = array( '' );
- } elseif ( $closed = get_user_option( 'closedpostboxes_' . $screen_id ) ) {
+ } elseif ( get_user_option( 'closedpostboxes_' . $screen_id ) ) {
+ $closed = get_user_option( 'closedpostboxes_' . $screen_id );
if ( ! is_array( $closed ) ) {
$classes = array( '' );
} else {
- $classes = in_array( $box_id, $closed ) ? array( 'closed' ) : array( '' );
+ $classes = in_array( $box_id, $closed, true ) ? array( 'closed' ) : array( '' );
}
} else {
$classes = array( '' );
@@ -1313,7 +1335,12 @@
* @param int $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.
- * @return array Array containing the sample permalink with placeholder for the post name, and the post name.
+ * @return array {
+ * Array containing the sample permalink with placeholder for the post name, and the post name.
+ *
+ * @type string $0 The permalink with placeholder for the post name.
+ * @type string $1 The post name.
+ * }
*/
function get_sample_permalink( $id, $title = null, $name = null ) {
$post = get_post( $id );
@@ -1328,13 +1355,13 @@
$original_name = $post->post_name;
// Hack: get_permalink() would return ugly permalink for drafts, so we will fake that our post is published.
- if ( in_array( $post->post_status, array( 'draft', 'pending', 'future' ) ) ) {
+ if ( in_array( $post->post_status, array( 'draft', 'pending', 'future' ), true ) ) {
$post->post_status = 'publish';
$post->post_name = sanitize_title( $post->post_name ? $post->post_name : $post->post_title, $post->ID );
}
- // If the user wants to set a new name -- override the current one
- // Note: if empty name is supplied -- use the title instead, see #6072
+ // If the user wants to set a new name -- override the current one.
+ // Note: if empty name is supplied -- use the title instead, see #6072.
if ( ! is_null( $name ) ) {
$post->post_name = sanitize_title( $name ? $name : $title, $post->ID );
}
@@ -1345,10 +1372,10 @@
$permalink = get_permalink( $post, true );
- // Replace custom post_type Token with generic pagename token for ease of use.
+ // Replace custom post_type token with generic pagename token for ease of use.
$permalink = str_replace( "%$post->post_type%", '%pagename%', $permalink );
- // Handle page hierarchy
+ // Handle page hierarchy.
if ( $ptype->hierarchical ) {
$uri = get_page_uri( $post );
if ( $uri ) {
@@ -1377,7 +1404,12 @@
*
* @since 4.4.0
*
- * @param array $permalink Array containing the sample permalink with placeholder for the post name, and the post name.
+ * @param array $permalink {
+ * Array containing the sample permalink with placeholder for the post name, and the post name.
+ *
+ * @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).
@@ -1415,13 +1447,13 @@
if ( 'publish' === $post->post_status || 'attachment' === $post->post_type ) {
$view_link = get_permalink( $post );
} else {
- // Allow non-published (private, future) to be viewed at a pretty permalink, in case $post->post_name is set
+ // Allow non-published (private, future) to be viewed at a pretty permalink, in case $post->post_name is set.
$view_link = str_replace( array( '%pagename%', '%postname%' ), $post->post_name, $permalink );
}
}
}
- // Permalinks without a post/page name placeholder don't have anything to edit
+ // Permalinks without a post/page name placeholder don't have anything to edit.
if ( false === strpos( $permalink, '%postname%' ) && false === strpos( $permalink, '%pagename%' ) ) {
$return = '<strong>' . __( 'Permalink:' ) . "</strong>\n";
@@ -1432,8 +1464,10 @@
$return .= '<span id="sample-permalink">' . $permalink . "</span>\n";
}
- // Encourage a pretty permalink setting
- if ( '' == get_option( 'permalink_structure' ) && current_user_can( 'manage_options' ) && ! ( 'page' == get_option( 'show_on_front' ) && $id == get_option( 'page_on_front' ) ) ) {
+ // Encourage a pretty permalink setting.
+ 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";
}
} else {
@@ -1471,13 +1505,13 @@
}
/**
- * Output HTML for the post thumbnail meta-box.
+ * Returns HTML for the post thumbnail meta box.
*
* @since 2.9.0
*
- * @param int $thumbnail_id ID of the attachment used for thumbnail
- * @param mixed $post The post ID or object associated with the thumbnail, defaults to global $post.
- * @return string html
+ * @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.
+ * @return string The post thumbnail HTML.
*/
function _wp_post_thumbnail_html( $thumbnail_id = null, $post = null ) {
$_wp_additional_image_sizes = wp_get_additional_image_sizes();
@@ -1498,7 +1532,7 @@
$size = isset( $_wp_additional_image_sizes['post-thumbnail'] ) ? 'post-thumbnail' : array( 266, 266 );
/**
- * Filters the size used to display the post thumbnail image in the 'Featured Image' meta box.
+ * Filters the size used to display the post thumbnail image in the 'Featured image' meta box.
*
* Note: When a theme adds 'post-thumbnail' support, a special 'post-thumbnail'
* image size is registered, which differs from the 'thumbnail' image size
@@ -1556,11 +1590,13 @@
* the user with lock does not exist, or the post is locked by current user.
*/
function wp_check_post_lock( $post_id ) {
- if ( ! $post = get_post( $post_id ) ) {
+ $post = get_post( $post_id );
+ if ( ! $post ) {
return false;
}
- if ( ! $lock = get_post_meta( $post->ID, '_edit_lock', true ) ) {
+ $lock = get_post_meta( $post->ID, '_edit_lock', true );
+ if ( ! $lock ) {
return false;
}
@@ -1575,7 +1611,7 @@
/** This filter is documented in wp-admin/includes/ajax-actions.php */
$time_window = apply_filters( 'wp_check_post_lock_window', 150 );
- if ( $time && $time > time() - $time_window && $user != get_current_user_id() ) {
+ if ( $time && $time > time() - $time_window && get_current_user_id() != $user ) {
return $user;
}
@@ -1592,11 +1628,13 @@
* there is no current user.
*/
function wp_set_post_lock( $post_id ) {
- if ( ! $post = get_post( $post_id ) ) {
+ $post = get_post( $post_id );
+ if ( ! $post ) {
return false;
}
- if ( 0 == ( $user_id = get_current_user_id() ) ) {
+ $user_id = get_current_user_id();
+ if ( 0 == $user_id ) {
return false;
}
@@ -1612,30 +1650,30 @@
* Outputs the HTML for the notice to say that someone else is editing or has taken over editing of this post.
*
* @since 2.8.5
- * @return none
*/
function _admin_notice_post_locked() {
- if ( ! $post = get_post() ) {
+ $post = get_post();
+ if ( ! $post ) {
return;
}
- $user = null;
- if ( $user_id = wp_check_post_lock( $post->ID ) ) {
+ $user = null;
+ $user_id = wp_check_post_lock( $post->ID );
+ if ( $user_id ) {
$user = get_userdata( $user_id );
}
if ( $user ) {
-
/**
* Filters whether to show the post locked dialog.
*
- * Returning a falsey value to the filter will short-circuit displaying the dialog.
+ * Returning false from the filter will prevent the dialog from being displayed.
*
* @since 3.6.0
*
- * @param bool $display Whether to display the dialog. Default true.
- * @param WP_Post $post Post object.
- * @param WP_User|bool $user WP_User object on success, false otherwise.
+ * @param bool $display Whether to display the dialog. Default true.
+ * @param WP_Post $post Post object.
+ * @param WP_User $user The user with the lock for the post.
*/
if ( ! apply_filters( 'show_post_locked_dialog', true, $post, $user ) ) {
return;
@@ -1646,14 +1684,14 @@
$locked = false;
}
- if ( $locked && ( $sendback = wp_get_referer() ) &&
- false === strpos( $sendback, 'post.php' ) && false === strpos( $sendback, 'post-new.php' ) ) {
+ $sendback = wp_get_referer();
+ if ( $locked && $sendback && false === strpos( $sendback, 'post.php' ) && false === strpos( $sendback, 'post-new.php' ) ) {
$sendback_text = __( 'Go back' );
} else {
$sendback = admin_url( 'edit.php' );
- if ( 'post' != $post->post_type ) {
+ if ( 'post' !== $post->post_type ) {
$sendback = add_query_arg( 'post_type', $post->post_type, $sendback );
}
@@ -1671,8 +1709,8 @@
if ( $locked ) {
$query_args = array();
if ( get_post_type_object( $post->post_type )->public ) {
- if ( 'publish' == $post->post_status || $user->ID != $post->post_author ) {
- // Latest content is in autosave
+ if ( 'publish' === $post->post_status || $user->ID != $post->post_author ) {
+ // Latest content is in autosave.
$nonce = wp_create_nonce( 'post_preview_' . $post->ID );
$query_args['preview_id'] = $post->ID;
$query_args['preview_nonce'] = $nonce;
@@ -1684,14 +1722,14 @@
/**
* Filters whether to allow the post lock to be overridden.
*
- * Returning a falsey value to the filter will disable the ability
+ * Returning false from the filter will disable the ability
* to override the post lock.
*
* @since 3.6.0
*
- * @param bool $override Whether to allow overriding post locks. Default true.
+ * @param bool $override Whether to allow the post lock to be overridden. Default true.
* @param WP_Post $post Post object.
- * @param WP_User $user User object.
+ * @param WP_User $user The user with the lock for the post.
*/
$override = apply_filters( 'override_post_lock', true, $post, $user );
$tab_last = $override ? '' : ' wp-tab-last';
@@ -1702,10 +1740,10 @@
<p class="currently-editing wp-tab-first" tabindex="0">
<?php
if ( $override ) {
- /* translators: %s: user's display name */
+ /* translators: %s: User's display name. */
printf( __( '%s is already editing this post. Do you want to take over?' ), esc_html( $user->display_name ) );
} else {
- /* translators: %s: user's display name */
+ /* translators: %s: User's display name. */
printf( __( '%s is already editing this post.' ), esc_html( $user->display_name ) );
}
?>
@@ -1715,10 +1753,12 @@
* Fires inside the post locked dialog before the buttons are displayed.
*
* @since 3.6.0
+ * @since 5.4.0 The $user parameter was added.
*
* @param WP_Post $post Post object.
+ * @param WP_User $user The user with the lock for the post.
*/
- do_action( 'post_locked_dialog', $post );
+ do_action( 'post_locked_dialog', $post, $user );
?>
<p>
<a class="button" href="<?php echo esc_url( $sendback ); ?>"><?php echo $sendback_text; ?></a>
@@ -1727,7 +1767,7 @@
<?php
}
- // Allow plugins to prevent some users overriding the post lock
+ // Allow plugins to prevent some users overriding the post lock.
if ( $override ) {
?>
<a class="button button-primary wp-tab-last" href="<?php echo esc_url( add_query_arg( 'get-post-lock', '1', wp_nonce_url( get_edit_post_link( $post->ID, 'url' ), 'lock-post_' . $post->ID ) ) ); ?>"><?php _e( 'Take over' ); ?></a>
@@ -1773,8 +1813,8 @@
*
* @since 2.6.0
*
- * @param mixed $post_data Associative array containing the post data or int post ID.
- * @return mixed The autosave revision ID. WP_Error or 0 on error.
+ * @param array|int $post_data Associative array containing the post data or int post ID.
+ * @return int|WP_Error The autosave revision ID. WP_Error or 0 on error.
*/
function wp_create_post_autosave( $post_data ) {
if ( is_numeric( $post_data ) ) {
@@ -1793,16 +1833,18 @@
$post_author = get_current_user_id();
// Store one autosave per author. If there is already an autosave, overwrite it.
- if ( $old_autosave = wp_get_post_autosave( $post_id, $post_author ) ) {
+ $old_autosave = wp_get_post_autosave( $post_id, $post_author );
+ if ( $old_autosave ) {
$new_autosave = _wp_post_revision_data( $post_data, true );
$new_autosave['ID'] = $old_autosave->ID;
$new_autosave['post_author'] = $post_author;
+ $post = get_post( $post_id );
+
// If the new autosave has the same content as the post, delete the autosave.
- $post = get_post( $post_id );
$autosave_is_different = false;
foreach ( array_intersect( array_keys( $new_autosave ), array_keys( _wp_post_revision_fields( $post ) ) ) as $field ) {
- if ( normalize_whitespace( $new_autosave[ $field ] ) != normalize_whitespace( $post->$field ) ) {
+ if ( normalize_whitespace( $new_autosave[ $field ] ) !== normalize_whitespace( $post->$field ) ) {
$autosave_is_different = true;
break;
}
@@ -1828,7 +1870,7 @@
// _wp_put_post_revision() expects unescaped.
$post_data = wp_unslash( $post_data );
- // Otherwise create the new autosave as a special post revision
+ // Otherwise create the new autosave as a special post revision.
return _wp_put_post_revision( $post_data, true );
}
@@ -1844,7 +1886,8 @@
$post_ID = (int) $_POST['post_ID'];
$_POST['ID'] = $post_ID;
- if ( ! $post = get_post( $post_ID ) ) {
+ $post = get_post( $post_ID );
+ if ( ! $post ) {
wp_die( __( 'Sorry, you are not allowed to edit this post.' ) );
}
@@ -1854,12 +1897,14 @@
$is_autosave = false;
- if ( ! wp_check_post_lock( $post->ID ) && get_current_user_id() == $post->post_author && ( 'draft' == $post->post_status || 'auto-draft' == $post->post_status ) ) {
+ if ( ! wp_check_post_lock( $post->ID ) && get_current_user_id() == $post->post_author
+ && ( 'draft' === $post->post_status || 'auto-draft' === $post->post_status )
+ ) {
$saved_post_id = edit_post();
} else {
$is_autosave = true;
- if ( isset( $_POST['post_status'] ) && 'auto-draft' == $_POST['post_status'] ) {
+ if ( isset( $_POST['post_status'] ) && 'auto-draft' === $_POST['post_status'] ) {
$_POST['post_status'] = 'draft';
}
@@ -1900,13 +1945,14 @@
* The ID can be the draft post_id or the autosave revision post_id.
*/
function wp_autosave( $post_data ) {
- // Back-compat
+ // Back-compat.
if ( ! defined( 'DOING_AUTOSAVE' ) ) {
define( 'DOING_AUTOSAVE', true );
}
- $post_id = (int) $post_data['post_id'];
- $post_data['ID'] = $post_data['post_ID'] = $post_id;
+ $post_id = (int) $post_data['post_id'];
+ $post_data['ID'] = $post_id;
+ $post_data['post_ID'] = $post_id;
if ( false === wp_verify_nonce( $post_data['_wpnonce'], 'update-post_' . $post_id ) ) {
return new WP_Error( 'invalid_nonce', __( 'Error while saving.' ) );
@@ -1918,19 +1964,22 @@
return new WP_Error( 'edit_posts', __( 'Sorry, you are not allowed to edit this item.' ) );
}
- if ( 'auto-draft' == $post->post_status ) {
+ if ( 'auto-draft' === $post->post_status ) {
$post_data['post_status'] = 'draft';
}
- if ( $post_data['post_type'] != 'page' && ! empty( $post_data['catslist'] ) ) {
+ if ( 'page' !== $post_data['post_type'] && ! empty( $post_data['catslist'] ) ) {
$post_data['post_category'] = explode( ',', $post_data['catslist'] );
}
- if ( ! wp_check_post_lock( $post->ID ) && get_current_user_id() == $post->post_author && ( 'auto-draft' == $post->post_status || 'draft' == $post->post_status ) ) {
- // Drafts and auto-drafts are just overwritten by autosave for the same user if the post is not locked
+ if ( ! wp_check_post_lock( $post->ID ) && get_current_user_id() == $post->post_author
+ && ( 'auto-draft' === $post->post_status || 'draft' === $post->post_status )
+ ) {
+ // Drafts and auto-drafts are just overwritten by autosave for the same user if the post is not locked.
return edit_post( wp_slash( $post_data ) );
} else {
- // Non drafts or other users drafts are not overwritten. The autosave is stored in a special post revision for each user.
+ // Non-drafts or other users' drafts are not overwritten.
+ // The autosave is stored in a special post revision for each user.
return wp_create_post_autosave( wp_slash( $post_data ) );
}
}
@@ -1938,6 +1987,8 @@
/**
* Redirect to previous page.
*
+ * @since 2.7.0
+ *
* @param int $post_id Optional. Post ID.
*/
function redirect_post( $post_id = '' ) {
@@ -1956,7 +2007,7 @@
$message = 6;
}
} else {
- $message = 'draft' == $status ? 10 : 1;
+ $message = 'draft' === $status ? 10 : 1;
}
$location = add_query_arg( 'message', $message, get_edit_post_link( $post_id, 'url' ) );
@@ -1989,8 +2040,9 @@
*
* @since 5.1.0
*
- * @param mixed $terms Raw term data from the 'tax_input' field.
- * @return array
+ * @param string $taxonomy The taxonomy name.
+ * @param array $terms Raw term data from the 'tax_input' field.
+ * @return int[] Array of sanitized term IDs.
*/
function taxonomy_meta_box_sanitize_cb_checkboxes( $taxonomy, $terms ) {
return array_map( 'intval', $terms );
@@ -2001,7 +2053,8 @@
*
* @since 5.1.0
*
- * @param mixed $terms Raw term data from the 'tax_input' field.
+ * @param string $taxonomy The taxonomy name.
+ * @param array|string $terms Raw term data from the 'tax_input' field.
* @return array
*/
function taxonomy_meta_box_sanitize_cb_input( $taxonomy, $terms ) {
@@ -2026,8 +2079,8 @@
}
$_term = get_terms(
- $taxonomy,
array(
+ 'taxonomy' => $taxonomy,
'name' => $term,
'fields' => 'ids',
'hide_empty' => false,
@@ -2126,38 +2179,38 @@
* @since 5.0.0
*
* @param WP_Post $post Post object.
- * @return array Array of block categories.
+ * @return array[] Array of block categories.
*/
function get_block_categories( $post ) {
$default_categories = array(
array(
- 'slug' => 'common',
- 'title' => __( 'Common Blocks' ),
+ 'slug' => 'text',
+ 'title' => _x( 'Text', 'block category' ),
'icon' => null,
),
array(
- 'slug' => 'formatting',
- 'title' => __( 'Formatting' ),
+ 'slug' => 'media',
+ 'title' => _x( 'Media', 'block category' ),
'icon' => null,
),
array(
- 'slug' => 'layout',
- 'title' => __( 'Layout Elements' ),
+ 'slug' => 'design',
+ 'title' => _x( 'Design', 'block category' ),
'icon' => null,
),
array(
'slug' => 'widgets',
- 'title' => __( 'Widgets' ),
+ 'title' => _x( 'Widgets', 'block category' ),
'icon' => null,
),
array(
'slug' => 'embed',
- 'title' => __( 'Embeds' ),
+ 'title' => _x( 'Embeds', 'block category' ),
'icon' => null,
),
array(
'slug' => 'reusable',
- 'title' => __( 'Reusable Blocks' ),
+ 'title' => _x( 'Reusable Blocks', 'block category' ),
'icon' => null,
),
);
@@ -2167,7 +2220,7 @@
*
* @since 5.0.0
*
- * @param array $default_categories Array of block categories.
+ * @param array[] $default_categories Array of block categories.
* @param WP_Post $post Post being loaded.
*/
return apply_filters( 'block_categories', $default_categories, $post );
@@ -2186,11 +2239,25 @@
function get_block_editor_server_block_settings() {
$block_registry = WP_Block_Type_Registry::get_instance();
$blocks = array();
- $keys_to_pick = array( 'title', 'description', 'icon', 'category', 'keywords', 'supports', 'attributes' );
+ $fields_to_pick = array(
+ 'title' => 'title',
+ 'description' => 'description',
+ 'icon' => 'icon',
+ 'category' => 'category',
+ 'keywords' => 'keywords',
+ 'parent' => 'parent',
+ 'supports' => 'supports',
+ 'attributes' => 'attributes',
+ 'provides_context' => 'providesContext',
+ 'uses_context' => 'usesContext',
+ 'styles' => 'styles',
+ 'textdomain' => 'textdomain',
+ 'example' => 'example',
+ );
foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) {
- foreach ( $keys_to_pick as $key ) {
- if ( ! isset( $block_type->{ $key } ) ) {
+ foreach ( $fields_to_pick as $field => $key ) {
+ if ( ! isset( $block_type->{ $field } ) ) {
continue;
}
@@ -2198,7 +2265,7 @@
$blocks[ $block_name ] = array();
}
- $blocks[ $block_name ][ $key ] = $block_type->{ $key };
+ $blocks[ $block_name ][ $key ] = $block_type->{ $field };
}
}
@@ -2404,7 +2471,7 @@
*
* @since 5.0.0
*
- * @params WP_Post $post The post that is being edited.
+ * @param WP_Post $post The post that is being edited.
*/
do_action( 'block_editor_meta_box_hidden_fields', $post );
}