Add missing doc blocks to revision.php.

Clarify `@return` values where necessary.
In `wp_delete_post_revision()`, `wp_delete_post()` doesn't return `WP_Error`, so that check can be removed.
`wp_revisions_to_keep()` always returns an `int`, so `wp_revisions_enabled()` can use strict comparison.
 
See #32444.

Built from https://develop.svn.wordpress.org/trunk@32621


git-svn-id: http://core.svn.wordpress.org/trunk@32591 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2015-05-27 18:38:24 +00:00
parent 1ef11d7789
commit 5ee54c05ac
3 changed files with 52 additions and 40 deletions

View File

@ -2608,7 +2608,7 @@ function wp_delete_post( $postid = 0, $force_delete = false ) {
return $post; return $post;
if ( !$force_delete && ( $post->post_type == 'post' || $post->post_type == 'page') && get_post_status( $postid ) != 'trash' && EMPTY_TRASH_DAYS ) if ( !$force_delete && ( $post->post_type == 'post' || $post->post_type == 'page') && get_post_status( $postid ) != 'trash' && EMPTY_TRASH_DAYS )
return wp_trash_post($postid); return wp_trash_post( $postid );
if ( $post->post_type == 'attachment' ) if ( $post->post_type == 'attachment' )
return wp_delete_attachment( $postid, $force_delete ); return wp_delete_attachment( $postid, $force_delete );

View File

@ -16,8 +16,10 @@
* @since 2.6.0 * @since 2.6.0
* @access private * @access private
* *
* @param array $post Optional a post array to be processed for insertion as a post revision. * @staticvar array|false $fields
* @param bool $autosave optional Is the revision an autosave? *
* @param array $post Optional. A post array to be processed for insertion as a post revision.
* @param bool $autosave Optional. Is the revision an autosave?
* @return array Post array ready to be inserted as a post revision or array of fields that can be versioned. * @return array Post array ready to be inserted as a post revision or array of fields that can be versioned.
*/ */
function _wp_post_revision_fields( $post = null, $autosave = false ) { function _wp_post_revision_fields( $post = null, $autosave = false ) {
@ -77,8 +79,8 @@ function _wp_post_revision_fields( $post = null, $autosave = false ) {
* *
* @since 2.6.0 * @since 2.6.0
* *
* @param int $post_id The ID of the post to save as a revision. * @param int $post_id The ID of the post to save as a revision.
* @return null|int Null or 0 if error, new revision ID, if success. * @return int|WP_Error|void Void or 0 if error, new revision ID, if success.
*/ */
function wp_save_post_revision( $post_id ) { function wp_save_post_revision( $post_id ) {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
@ -192,8 +194,8 @@ function wp_save_post_revision( $post_id ) {
* @since 2.6.0 * @since 2.6.0
* *
* @param int $post_id The post ID. * @param int $post_id The post ID.
* @param int $user_id optional The post author ID. * @param int $user_id Optional The post author ID.
* @return object|bool The autosaved data or false on failure or when no autosave exists. * @return WP_Post|false The autosaved data or false on failure or when no autosave exists.
*/ */
function wp_get_post_autosave( $post_id, $user_id = 0 ) { function wp_get_post_autosave( $post_id, $user_id = 0 ) {
$revisions = wp_get_post_revisions( $post_id, array( 'check_enabled' => false ) ); $revisions = wp_get_post_revisions( $post_id, array( 'check_enabled' => false ) );
@ -215,8 +217,8 @@ function wp_get_post_autosave( $post_id, $user_id = 0 ) {
* *
* @since 2.6.0 * @since 2.6.0
* *
* @param int|object $post Post ID or post object. * @param int|WP_Post $post Post ID or post object.
* @return bool|int False if not a revision, ID of revision's parent otherwise. * @return false|int False if not a revision, ID of revision's parent otherwise.
*/ */
function wp_is_post_revision( $post ) { function wp_is_post_revision( $post ) {
if ( !$post = wp_get_post_revision( $post ) ) if ( !$post = wp_get_post_revision( $post ) )
@ -230,8 +232,8 @@ function wp_is_post_revision( $post ) {
* *
* @since 2.6.0 * @since 2.6.0
* *
* @param int|object $post Post ID or post object. * @param int|WP_Post $post Post ID or post object.
* @return bool|int False if not a revision, ID of autosave's parent otherwise * @return false|int False if not a revision, ID of autosave's parent otherwise
*/ */
function wp_is_post_autosave( $post ) { function wp_is_post_autosave( $post ) {
if ( !$post = wp_get_post_revision( $post ) ) if ( !$post = wp_get_post_revision( $post ) )
@ -249,9 +251,9 @@ function wp_is_post_autosave( $post ) {
* @since 2.6.0 * @since 2.6.0
* @access private * @access private
* *
* @param int|object|array $post Post ID, post object OR post array. * @param int|WP_Post|array|null $post Post ID, post object OR post array.
* @param bool $autosave Optional. Is the revision an autosave? * @param bool $autosave Optional. Is the revision an autosave?
* @return mixed WP_Error or 0 if error, new revision ID if success. * @return int|WP_Error WP_Error or 0 if error, new revision ID if success.
*/ */
function _wp_put_post_revision( $post = null, $autosave = false ) { function _wp_put_post_revision( $post = null, $autosave = false ) {
if ( is_object($post) ) if ( is_object($post) )
@ -291,10 +293,10 @@ function _wp_put_post_revision( $post = null, $autosave = false ) {
* *
* @since 2.6.0 * @since 2.6.0
* *
* @param int|object $post The post ID or object. * @param int|WP_Post $post The post ID or object.
* @param string $output Optional. OBJECT, ARRAY_A, or ARRAY_N. * @param string $output Optional. OBJECT, ARRAY_A, or ARRAY_N.
* @param string $filter Optional sanitation filter. @see sanitize_post(). * @param string $filter Optional sanitation filter. @see sanitize_post().
* @return mixed Null if error or post object if success. * @return WP_Post|array|null Null if error or post object if success.
*/ */
function wp_get_post_revision(&$post, $output = OBJECT, $filter = 'raw') { function wp_get_post_revision(&$post, $output = OBJECT, $filter = 'raw') {
if ( !$revision = get_post( $post, OBJECT, $filter ) ) if ( !$revision = get_post( $post, OBJECT, $filter ) )
@ -322,9 +324,9 @@ function wp_get_post_revision(&$post, $output = OBJECT, $filter = 'raw') {
* *
* @since 2.6.0 * @since 2.6.0
* *
* @param int|object $revision_id Revision ID or revision object. * @param int|WP_Post $revision_id Revision ID or revision object.
* @param array $fields Optional. What fields to restore from. Defaults to all. * @param array $fields Optional. What fields to restore from. Defaults to all.
* @return mixed Null if error, false if no fields to restore, (int) post ID if success. * @return int|false|null Null if error, false if no fields to restore, (int) post ID if success.
*/ */
function wp_restore_post_revision( $revision_id, $fields = null ) { function wp_restore_post_revision( $revision_id, $fields = null ) {
if ( !$revision = wp_get_post_revision( $revision_id, ARRAY_A ) ) if ( !$revision = wp_get_post_revision( $revision_id, ARRAY_A ) )
@ -380,17 +382,15 @@ function wp_restore_post_revision( $revision_id, $fields = null ) {
* *
* @since 2.6.0 * @since 2.6.0
* *
* @param int|object $revision_id Revision ID or revision object. * @param int|WP_Post $revision_id Revision ID or revision object.
* @return mixed Null or WP_Error if error, deleted post if success. * @return array|false|WP_Post|WP_Error|null Null or WP_Error if error, deleted post if success.
*/ */
function wp_delete_post_revision( $revision_id ) { function wp_delete_post_revision( $revision_id ) {
if ( !$revision = wp_get_post_revision( $revision_id ) ) if ( ! $revision = wp_get_post_revision( $revision_id ) ) {
return $revision; return $revision;
}
$delete = wp_delete_post( $revision->ID ); $delete = wp_delete_post( $revision->ID );
if ( is_wp_error( $delete ) )
return $delete;
if ( $delete ) { if ( $delete ) {
/** /**
* Fires once a post revision has been deleted. * Fires once a post revision has been deleted.
@ -442,7 +442,7 @@ function wp_get_post_revisions( $post_id = 0, $args = null ) {
* @return bool True if number of revisions to keep isn't zero, false otherwise. * @return bool True if number of revisions to keep isn't zero, false otherwise.
*/ */
function wp_revisions_enabled( $post ) { function wp_revisions_enabled( $post ) {
return wp_revisions_to_keep( $post ) != 0; return wp_revisions_to_keep( $post ) !== 0;
} }
/** /**
@ -487,18 +487,21 @@ function wp_revisions_to_keep( $post ) {
* *
* @since 2.7.0 * @since 2.7.0
* @access private * @access private
*
* @param WP_Post $post
* @return WP_Post|false
*/ */
function _set_preview($post) { function _set_preview( $post ) {
if ( ! is_object( $post ) ) {
if ( ! is_object($post) )
return $post; return $post;
}
$preview = wp_get_post_autosave($post->ID); $preview = wp_get_post_autosave( $post->ID );
if ( ! is_object( $preview ) ) {
if ( ! is_object($preview) )
return $post; return $post;
}
$preview = sanitize_post($preview); $preview = sanitize_post( $preview );
$post->post_content = $preview->post_content; $post->post_content = $preview->post_content;
$post->post_title = $preview->post_title; $post->post_title = $preview->post_title;
@ -516,7 +519,6 @@ function _set_preview($post) {
* @access private * @access private
*/ */
function _show_post_preview() { function _show_post_preview() {
if ( isset($_GET['preview_id']) && isset($_GET['preview_nonce']) ) { if ( isset($_GET['preview_id']) && isset($_GET['preview_nonce']) ) {
$id = (int) $_GET['preview_id']; $id = (int) $_GET['preview_id'];
@ -532,6 +534,11 @@ function _show_post_preview() {
* *
* @since 3.6.0 * @since 3.6.0
* @access private * @access private
*
* @param array $terms
* @param int $post_id
* @param string $taxonomy
* @return array
*/ */
function _wp_preview_terms_filter( $terms, $post_id, $taxonomy ) { function _wp_preview_terms_filter( $terms, $post_id, $taxonomy ) {
if ( ! $post = get_post() ) if ( ! $post = get_post() )
@ -553,7 +560,10 @@ function _wp_preview_terms_filter( $terms, $post_id, $taxonomy ) {
* *
* @since 3.6.0 * @since 3.6.0
* @access private * @access private
*/ *
* @param WP_Post $revision
* @return int|false
*/
function _wp_get_post_revision_version( $revision ) { function _wp_get_post_revision_version( $revision ) {
if ( is_object( $revision ) ) if ( is_object( $revision ) )
$revision = get_object_vars( $revision ); $revision = get_object_vars( $revision );
@ -572,8 +582,10 @@ function _wp_get_post_revision_version( $revision ) {
* @since 3.6.0 * @since 3.6.0
* @access private * @access private
* *
* @param WP_Post $post Post object * @global wpdb $wpdb
* @param array $revisions Current revisions of the post *
* @param WP_Post $post Post object
* @param array $revisions Current revisions of the post
* @return bool true if the revisions were upgraded, false if problems * @return bool true if the revisions were upgraded, false if problems
*/ */
function _wp_upgrade_revisions_of_post( $post, $revisions ) { function _wp_upgrade_revisions_of_post( $post, $revisions ) {

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.3-alpha-32620'; $wp_version = '4.3-alpha-32621';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.