wp/wp-includes/revision.php
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 19 3d72ae0968f4
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
   225  * If the optional $user_id is passed, returns the autosave for that user, otherwise
   225  * If the optional $user_id is passed, returns the autosave for that user, otherwise
   226  * returns the latest autosave.
   226  * returns the latest autosave.
   227  *
   227  *
   228  * @since 2.6.0
   228  * @since 2.6.0
   229  *
   229  *
       
   230  * @global wpdb $wpdb WordPress database abstraction object.
       
   231  *
   230  * @param int $post_id The post ID.
   232  * @param int $post_id The post ID.
   231  * @param int $user_id Optional The post author ID.
   233  * @param int $user_id Optional The post author ID.
   232  * @return WP_Post|false The autosaved data or false on failure or when no autosave exists.
   234  * @return WP_Post|false The autosaved data or false on failure or when no autosave exists.
   233  */
   235  */
   234 function wp_get_post_autosave( $post_id, $user_id = 0 ) {
   236 function wp_get_post_autosave( $post_id, $user_id = 0 ) {
   327 	}
   329 	}
   328 
   330 
   329 	$post = _wp_post_revision_data( $post, $autosave );
   331 	$post = _wp_post_revision_data( $post, $autosave );
   330 	$post = wp_slash( $post ); // Since data is from DB.
   332 	$post = wp_slash( $post ); // Since data is from DB.
   331 
   333 
   332 	$revision_id = wp_insert_post( $post );
   334 	$revision_id = wp_insert_post( $post, true );
   333 	if ( is_wp_error( $revision_id ) ) {
   335 	if ( is_wp_error( $revision_id ) ) {
   334 		return $revision_id;
   336 		return $revision_id;
   335 	}
   337 	}
   336 
   338 
   337 	if ( $revision_id ) {
   339 	if ( $revision_id ) {
   367 	}
   369 	}
   368 	if ( 'revision' !== $revision->post_type ) {
   370 	if ( 'revision' !== $revision->post_type ) {
   369 		return null;
   371 		return null;
   370 	}
   372 	}
   371 
   373 
   372 	if ( OBJECT == $output ) {
   374 	if ( OBJECT === $output ) {
   373 		return $revision;
   375 		return $revision;
   374 	} elseif ( ARRAY_A == $output ) {
   376 	} elseif ( ARRAY_A === $output ) {
   375 		$_revision = get_object_vars( $revision );
   377 		$_revision = get_object_vars( $revision );
   376 		return $_revision;
   378 		return $_revision;
   377 	} elseif ( ARRAY_N == $output ) {
   379 	} elseif ( ARRAY_N === $output ) {
   378 		$_revision = array_values( get_object_vars( $revision ) );
   380 		$_revision = array_values( get_object_vars( $revision ) );
   379 		return $_revision;
   381 		return $_revision;
   380 	}
   382 	}
   381 
   383 
   382 	return $revision;
   384 	return $revision;
   543 	$num = WP_POST_REVISIONS;
   545 	$num = WP_POST_REVISIONS;
   544 
   546 
   545 	if ( true === $num ) {
   547 	if ( true === $num ) {
   546 		$num = -1;
   548 		$num = -1;
   547 	} else {
   549 	} else {
   548 		$num = intval( $num );
   550 		$num = (int) $num;
   549 	}
   551 	}
   550 
   552 
   551 	if ( ! post_type_supports( $post->post_type, 'revisions' ) ) {
   553 	if ( ! post_type_supports( $post->post_type, 'revisions' ) ) {
   552 		$num = 0;
   554 		$num = 0;
   553 	}
   555 	}
   560 	 * @since 3.6.0
   562 	 * @since 3.6.0
   561 	 *
   563 	 *
   562 	 * @param int     $num  Number of revisions to store.
   564 	 * @param int     $num  Number of revisions to store.
   563 	 * @param WP_Post $post Post object.
   565 	 * @param WP_Post $post Post object.
   564 	 */
   566 	 */
   565 	return (int) apply_filters( 'wp_revisions_to_keep', $num, $post );
   567 	$num = apply_filters( 'wp_revisions_to_keep', $num, $post );
       
   568 
       
   569 	/**
       
   570 	 * Filters the number of revisions to save for the given post by its post type.
       
   571 	 *
       
   572 	 * Overrides both the value of WP_POST_REVISIONS and the {@see 'wp_revisions_to_keep'} filter.
       
   573 	 *
       
   574 	 * The dynamic portion of the hook name, `$post->post_type`, refers to
       
   575 	 * the post type slug.
       
   576 	 *
       
   577 	 * @since 5.8.0
       
   578 	 *
       
   579 	 * @param int     $num  Number of revisions to store.
       
   580 	 * @param WP_Post $post Post object.
       
   581 	 */
       
   582 	$num = apply_filters( "wp_{$post->post_type}_revisions_to_keep", $num, $post );
       
   583 
       
   584 	return (int) $num;
   566 }
   585 }
   567 
   586 
   568 /**
   587 /**
   569  * Sets up the post object for preview based on the post autosave.
   588  * Sets up the post object for preview based on the post autosave.
   570  *
   589  *
   674 		$post_id != $_REQUEST['preview_id'] ) {
   693 		$post_id != $_REQUEST['preview_id'] ) {
   675 
   694 
   676 		return $value;
   695 		return $value;
   677 	}
   696 	}
   678 
   697 
   679 	$thumbnail_id = intval( $_REQUEST['_thumbnail_id'] );
   698 	$thumbnail_id = (int) $_REQUEST['_thumbnail_id'];
   680 	if ( $thumbnail_id <= 0 ) {
   699 	if ( $thumbnail_id <= 0 ) {
   681 		return '';
   700 		return '';
   682 	}
   701 	}
   683 
   702 
   684 	return strval( $thumbnail_id );
   703 	return (string) $thumbnail_id;
   685 }
   704 }
   686 
   705 
   687 /**
   706 /**
   688  * Gets the post revision version.
   707  * Gets the post revision version.
   689  *
   708  *