_wp_post_revision_data

Returns a post array ready to be inserted into the posts table as a post revision.

Description

(array) _wp_post_revision_data( (array) $post = array(), (bool) $autosave = false ); 

Returns (array)

Post array ready to be inserted as a post revision.

Parameters (2)

0. $post — Optional. (array) => array()
A post array or a WP_Post object to be processed for insertion as a post revision. Default empty array.
1. $autosave — Optional. (bool) => false
Is the revision an autosave? Default false.

Usage

  1. if ( !function_exists( '_wp_post_revision_data' ) ) { 
  2. require_once ABSPATH . WPINC . '/revision.php'; 
  3.  
  4. // Optional. A post array or a WP_Post object to be processed 
  5. // for insertion as a post revision. Default empty array. 
  6. $post = array(); 
  7.  
  8. // Optional. Is the revision an autosave? Default false. 
  9. $autosave = false; 
  10.  
  11. // NOTICE! Understand what this does before running. 
  12. $result = _wp_post_revision_data($post, $autosave); 
  13.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/revision.php  
  1. function _wp_post_revision_data( $post = array(), $autosave = false ) { 
  2. if ( ! is_array( $post ) ) { 
  3. $post = get_post( $post, ARRAY_A ); 
  4.  
  5. $fields = _wp_post_revision_fields( $post ); 
  6.  
  7. $revision_data = array(); 
  8.  
  9. foreach ( array_intersect( array_keys( $post ), array_keys( $fields ) ) as $field ) { 
  10. $revision_data[ $field ] = $post[ $field ]; 
  11.  
  12. $revision_data['post_parent'] = $post['ID']; 
  13. $revision_data['post_status'] = 'inherit'; 
  14. $revision_data['post_type'] = 'revision'; 
  15. $revision_data['post_name'] = $autosave ? "$post[ID]-autosave-v1" : "$post[ID]-revision-v1"; // "1" is the revisioning system version 
  16. $revision_data['post_date'] = isset( $post['post_modified'] ) ? $post['post_modified'] : ''; 
  17. $revision_data['post_date_gmt'] = isset( $post['post_modified_gmt'] ) ? $post['post_modified_gmt'] : ''; 
  18.  
  19. return $revision_data;