You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

728 lines
21 KiB

  1. <?php
  2. /**
  3. * Post revision functions.
  4. *
  5. * @package WordPress
  6. * @subpackage Post_Revisions
  7. */
  8. /**
  9. * Determines which fields of posts are to be saved in revisions.
  10. *
  11. * @since 2.6.0
  12. * @since 4.5.0 A `WP_Post` object can now be passed to the `$post` parameter.
  13. * @since 4.5.0 The optional `$autosave` parameter was deprecated and renamed to `$deprecated`.
  14. * @access private
  15. *
  16. * @staticvar array $fields
  17. *
  18. * @param array|WP_Post $post Optional. A post array or a WP_Post object being processed
  19. * for insertion as a post revision. Default empty array.
  20. * @param bool $deprecated Not used.
  21. * @return array Array of fields that can be versioned.
  22. */
  23. function _wp_post_revision_fields( $post = array(), $deprecated = false ) {
  24. static $fields = null;
  25. if ( ! is_array( $post ) ) {
  26. $post = get_post( $post, ARRAY_A );
  27. }
  28. if ( is_null( $fields ) ) {
  29. // Allow these to be versioned
  30. $fields = array(
  31. 'post_title' => __( 'Title' ),
  32. 'post_content' => __( 'Content' ),
  33. 'post_excerpt' => __( 'Excerpt' ),
  34. );
  35. }
  36. /**
  37. * Filters the list of fields saved in post revisions.
  38. *
  39. * Included by default: 'post_title', 'post_content' and 'post_excerpt'.
  40. *
  41. * Disallowed fields: 'ID', 'post_name', 'post_parent', 'post_date',
  42. * 'post_date_gmt', 'post_status', 'post_type', 'comment_count',
  43. * and 'post_author'.
  44. *
  45. * @since 2.6.0
  46. * @since 4.5.0 The `$post` parameter was added.
  47. *
  48. * @param array $fields List of fields to revision. Contains 'post_title',
  49. * 'post_content', and 'post_excerpt' by default.
  50. * @param array $post A post array being processed for insertion as a post revision.
  51. */
  52. $fields = apply_filters( '_wp_post_revision_fields', $fields, $post );
  53. // WP uses these internally either in versioning or elsewhere - they cannot be versioned
  54. foreach ( array( 'ID', 'post_name', 'post_parent', 'post_date', 'post_date_gmt', 'post_status', 'post_type', 'comment_count', 'post_author' ) as $protect ) {
  55. unset( $fields[ $protect ] );
  56. }
  57. return $fields;
  58. }
  59. /**
  60. * Returns a post array ready to be inserted into the posts table as a post revision.
  61. *
  62. * @since 4.5.0
  63. * @access private
  64. *
  65. * @param array|WP_Post $post Optional. A post array or a WP_Post object to be processed
  66. * for insertion as a post revision. Default empty array.
  67. * @param bool $autosave Optional. Is the revision an autosave? Default false.
  68. * @return array Post array ready to be inserted as a post revision.
  69. */
  70. function _wp_post_revision_data( $post = array(), $autosave = false ) {
  71. if ( ! is_array( $post ) ) {
  72. $post = get_post( $post, ARRAY_A );
  73. }
  74. $fields = _wp_post_revision_fields( $post );
  75. $revision_data = array();
  76. foreach ( array_intersect( array_keys( $post ), array_keys( $fields ) ) as $field ) {
  77. $revision_data[ $field ] = $post[ $field ];
  78. }
  79. $revision_data['post_parent'] = $post['ID'];
  80. $revision_data['post_status'] = 'inherit';
  81. $revision_data['post_type'] = 'revision';
  82. $revision_data['post_name'] = $autosave ? "$post[ID]-autosave-v1" : "$post[ID]-revision-v1"; // "1" is the revisioning system version
  83. $revision_data['post_date'] = isset( $post['post_modified'] ) ? $post['post_modified'] : '';
  84. $revision_data['post_date_gmt'] = isset( $post['post_modified_gmt'] ) ? $post['post_modified_gmt'] : '';
  85. return $revision_data;
  86. }
  87. /**
  88. * Creates a revision for the current version of a post.
  89. *
  90. * Typically used immediately after a post update, as every update is a revision,
  91. * and the most recent revision always matches the current post.
  92. *
  93. * @since 2.6.0
  94. *
  95. * @param int $post_id The ID of the post to save as a revision.
  96. * @return int|WP_Error|void Void or 0 if error, new revision ID, if success.
  97. */
  98. function wp_save_post_revision( $post_id ) {
  99. if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
  100. return;
  101. if ( ! $post = get_post( $post_id ) )
  102. return;
  103. if ( ! post_type_supports( $post->post_type, 'revisions' ) )
  104. return;
  105. if ( 'auto-draft' == $post->post_status )
  106. return;
  107. if ( ! wp_revisions_enabled( $post ) )
  108. return;
  109. // Compare the proposed update with the last stored revision verifying that
  110. // they are different, unless a plugin tells us to always save regardless.
  111. // If no previous revisions, save one
  112. if ( $revisions = wp_get_post_revisions( $post_id ) ) {
  113. // grab the last revision, but not an autosave
  114. foreach ( $revisions as $revision ) {
  115. if ( false !== strpos( $revision->post_name, "{$revision->post_parent}-revision" ) ) {
  116. $last_revision = $revision;
  117. break;
  118. }
  119. }
  120. /**
  121. * Filters whether the post has changed since the last revision.
  122. *
  123. * By default a revision is saved only if one of the revisioned fields has changed.
  124. * This filter can override that so a revision is saved even if nothing has changed.
  125. *
  126. * @since 3.6.0
  127. *
  128. * @param bool $check_for_changes Whether to check for changes before saving a new revision.
  129. * Default true.
  130. * @param WP_Post $last_revision The last revision post object.
  131. * @param WP_Post $post The post object.
  132. *
  133. */
  134. if ( isset( $last_revision ) && apply_filters( 'wp_save_post_revision_check_for_changes', $check_for_changes = true, $last_revision, $post ) ) {
  135. $post_has_changed = false;
  136. foreach ( array_keys( _wp_post_revision_fields( $post ) ) as $field ) {
  137. if ( normalize_whitespace( $post->$field ) != normalize_whitespace( $last_revision->$field ) ) {
  138. $post_has_changed = true;
  139. break;
  140. }
  141. }
  142. /**
  143. * Filters whether a post has changed.
  144. *
  145. * By default a revision is saved only if one of the revisioned fields has changed.
  146. * This filter allows for additional checks to determine if there were changes.
  147. *
  148. * @since 4.1.0
  149. *
  150. * @param bool $post_has_changed Whether the post has changed.
  151. * @param WP_Post $last_revision The last revision post object.
  152. * @param WP_Post $post The post object.
  153. *
  154. */
  155. $post_has_changed = (bool) apply_filters( 'wp_save_post_revision_post_has_changed', $post_has_changed, $last_revision, $post );
  156. //don't save revision if post unchanged
  157. if ( ! $post_has_changed ) {
  158. return;
  159. }
  160. }
  161. }
  162. $return = _wp_put_post_revision( $post );
  163. // If a limit for the number of revisions to keep has been set,
  164. // delete the oldest ones.
  165. $revisions_to_keep = wp_revisions_to_keep( $post );
  166. if ( $revisions_to_keep < 0 )
  167. return $return;
  168. $revisions = wp_get_post_revisions( $post_id, array( 'order' => 'ASC' ) );
  169. $delete = count($revisions) - $revisions_to_keep;
  170. if ( $delete < 1 )
  171. return $return;
  172. $revisions = array_slice( $revisions, 0, $delete );
  173. for ( $i = 0; isset( $revisions[$i] ); $i++ ) {
  174. if ( false !== strpos( $revisions[ $i ]->post_name, 'autosave' ) )
  175. continue;
  176. wp_delete_post_revision( $revisions[ $i ]->ID );
  177. }
  178. return $return;
  179. }
  180. /**
  181. * Retrieve the autosaved data of the specified post.
  182. *
  183. * Returns a post object containing the information that was autosaved for the
  184. * specified post. If the optional $user_id is passed, returns the autosave for that user
  185. * otherwise returns the latest autosave.
  186. *
  187. * @since 2.6.0
  188. *
  189. * @param int $post_id The post ID.
  190. * @param int $user_id Optional The post author ID.
  191. * @return WP_Post|false The autosaved data or false on failure or when no autosave exists.
  192. */
  193. function wp_get_post_autosave( $post_id, $user_id = 0 ) {
  194. $revisions = wp_get_post_revisions( $post_id, array( 'check_enabled' => false ) );
  195. foreach ( $revisions as $revision ) {
  196. if ( false !== strpos( $revision->post_name, "{$post_id}-autosave" ) ) {
  197. if ( $user_id && $user_id != $revision->post_author )
  198. continue;
  199. return $revision;
  200. }
  201. }
  202. return false;
  203. }
  204. /**
  205. * Determines if the specified post is a revision.
  206. *
  207. * @since 2.6.0
  208. *
  209. * @param int|WP_Post $post Post ID or post object.
  210. * @return false|int False if not a revision, ID of revision's parent otherwise.
  211. */
  212. function wp_is_post_revision( $post ) {
  213. if ( !$post = wp_get_post_revision( $post ) )
  214. return false;
  215. return (int) $post->post_parent;
  216. }
  217. /**
  218. * Determines if the specified post is an autosave.
  219. *
  220. * @since 2.6.0
  221. *
  222. * @param int|WP_Post $post Post ID or post object.
  223. * @return false|int False if not a revision, ID of autosave's parent otherwise
  224. */
  225. function wp_is_post_autosave( $post ) {
  226. if ( !$post = wp_get_post_revision( $post ) )
  227. return false;
  228. if ( false !== strpos( $post->post_name, "{$post->post_parent}-autosave" ) )
  229. return (int) $post->post_parent;
  230. return false;
  231. }
  232. /**
  233. * Inserts post data into the posts table as a post revision.
  234. *
  235. * @since 2.6.0
  236. * @access private
  237. *
  238. * @param int|WP_Post|array|null $post Post ID, post object OR post array.
  239. * @param bool $autosave Optional. Is the revision an autosave?
  240. * @return int|WP_Error WP_Error or 0 if error, new revision ID if success.
  241. */
  242. function _wp_put_post_revision( $post = null, $autosave = false ) {
  243. if ( is_object($post) )
  244. $post = get_object_vars( $post );
  245. elseif ( !is_array($post) )
  246. $post = get_post($post, ARRAY_A);
  247. if ( ! $post || empty($post['ID']) )
  248. return new WP_Error( 'invalid_post', __( 'Invalid post ID.' ) );
  249. if ( isset($post['post_type']) && 'revision' == $post['post_type'] )
  250. return new WP_Error( 'post_type', __( 'Cannot create a revision of a revision' ) );
  251. $post = _wp_post_revision_data( $post, $autosave );
  252. $post = wp_slash($post); //since data is from db
  253. $revision_id = wp_insert_post( $post );
  254. if ( is_wp_error($revision_id) )
  255. return $revision_id;
  256. if ( $revision_id ) {
  257. /**
  258. * Fires once a revision has been saved.
  259. *
  260. * @since 2.6.0
  261. *
  262. * @param int $revision_id Post revision ID.
  263. */
  264. do_action( '_wp_put_post_revision', $revision_id );
  265. }
  266. return $revision_id;
  267. }
  268. /**
  269. * Gets a post revision.
  270. *
  271. * @since 2.6.0
  272. *
  273. * @param int|WP_Post $post The post ID or object.
  274. * @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to
  275. * a WP_Post object, an associative array, or a numeric array, respectively. Default OBJECT.
  276. * @param string $filter Optional sanitation filter. See sanitize_post().
  277. * @return WP_Post|array|null WP_Post (or array) on success, or null on failure.
  278. */
  279. function wp_get_post_revision(&$post, $output = OBJECT, $filter = 'raw') {
  280. if ( !$revision = get_post( $post, OBJECT, $filter ) )
  281. return $revision;
  282. if ( 'revision' !== $revision->post_type )
  283. return null;
  284. if ( $output == OBJECT ) {
  285. return $revision;
  286. } elseif ( $output == ARRAY_A ) {
  287. $_revision = get_object_vars($revision);
  288. return $_revision;
  289. } elseif ( $output == ARRAY_N ) {
  290. $_revision = array_values(get_object_vars($revision));
  291. return $_revision;
  292. }
  293. return $revision;
  294. }
  295. /**
  296. * Restores a post to the specified revision.
  297. *
  298. * Can restore a past revision using all fields of the post revision, or only selected fields.
  299. *
  300. * @since 2.6.0
  301. *
  302. * @param int|WP_Post $revision_id Revision ID or revision object.
  303. * @param array $fields Optional. What fields to restore from. Defaults to all.
  304. * @return int|false|null Null if error, false if no fields to restore, (int) post ID if success.
  305. */
  306. function wp_restore_post_revision( $revision_id, $fields = null ) {
  307. if ( !$revision = wp_get_post_revision( $revision_id, ARRAY_A ) )
  308. return $revision;
  309. if ( !is_array( $fields ) )
  310. $fields = array_keys( _wp_post_revision_fields( $revision ) );
  311. $update = array();
  312. foreach ( array_intersect( array_keys( $revision ), $fields ) as $field ) {
  313. $update[$field] = $revision[$field];
  314. }
  315. if ( !$update )
  316. return false;
  317. $update['ID'] = $revision['post_parent'];
  318. $update = wp_slash( $update ); //since data is from db
  319. $post_id = wp_update_post( $update );
  320. if ( ! $post_id || is_wp_error( $post_id ) )
  321. return $post_id;
  322. // Update last edit user
  323. update_post_meta( $post_id, '_edit_last', get_current_user_id() );
  324. /**
  325. * Fires after a post revision has been restored.
  326. *
  327. * @since 2.6.0
  328. *
  329. * @param int $post_id Post ID.
  330. * @param int $revision_id Post revision ID.
  331. */
  332. do_action( 'wp_restore_post_revision', $post_id, $revision['ID'] );
  333. return $post_id;
  334. }
  335. /**
  336. * Deletes a revision.
  337. *
  338. * Deletes the row from the posts table corresponding to the specified revision.
  339. *
  340. * @since 2.6.0
  341. *
  342. * @param int|WP_Post $revision_id Revision ID or revision object.
  343. * @return array|false|WP_Post|WP_Error|null Null or WP_Error if error, deleted post if success.
  344. */
  345. function wp_delete_post_revision( $revision_id ) {
  346. if ( ! $revision = wp_get_post_revision( $revision_id ) ) {
  347. return $revision;
  348. }
  349. $delete = wp_delete_post( $revision->ID );
  350. if ( $delete ) {
  351. /**
  352. * Fires once a post revision has been deleted.
  353. *
  354. * @since 2.6.0
  355. *
  356. * @param int $revision_id Post revision ID.
  357. * @param object|array $revision Post revision object or array.
  358. */
  359. do_action( 'wp_delete_post_revision', $revision->ID, $revision );
  360. }
  361. return $delete;
  362. }
  363. /**
  364. * Returns all revisions of specified post.
  365. *
  366. * @since 2.6.0
  367. *
  368. * @see get_children()
  369. *
  370. * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global `$post`.
  371. * @param array|null $args Optional. Arguments for retrieving post revisions. Default null.
  372. * @return array An array of revisions, or an empty array if none.
  373. */
  374. function wp_get_post_revisions( $post_id = 0, $args = null ) {
  375. $post = get_post( $post_id );
  376. if ( ! $post || empty( $post->ID ) )
  377. return array();
  378. $defaults = array( 'order' => 'DESC', 'orderby' => 'date ID', 'check_enabled' => true );
  379. $args = wp_parse_args( $args, $defaults );
  380. if ( $args['check_enabled'] && ! wp_revisions_enabled( $post ) )
  381. return array();
  382. $args = array_merge( $args, array( 'post_parent' => $post->ID, 'post_type' => 'revision', 'post_status' => 'inherit' ) );
  383. if ( ! $revisions = get_children( $args ) )
  384. return array();
  385. return $revisions;
  386. }
  387. /**
  388. * Determine if revisions are enabled for a given post.
  389. *
  390. * @since 3.6.0
  391. *
  392. * @param WP_Post $post The post object.
  393. * @return bool True if number of revisions to keep isn't zero, false otherwise.
  394. */
  395. function wp_revisions_enabled( $post ) {
  396. return wp_revisions_to_keep( $post ) !== 0;
  397. }
  398. /**
  399. * Determine how many revisions to retain for a given post.
  400. *
  401. * By default, an infinite number of revisions are kept.
  402. *
  403. * The constant WP_POST_REVISIONS can be set in wp-config to specify the limit
  404. * of revisions to keep.
  405. *
  406. * @since 3.6.0
  407. *
  408. * @param WP_Post $post The post object.
  409. * @return int The number of revisions to keep.
  410. */
  411. function wp_revisions_to_keep( $post ) {
  412. $num = WP_POST_REVISIONS;
  413. if ( true === $num )
  414. $num = -1;
  415. else
  416. $num = intval( $num );
  417. if ( ! post_type_supports( $post->post_type, 'revisions' ) )
  418. $num = 0;
  419. /**
  420. * Filters the number of revisions to save for the given post.
  421. *
  422. * Overrides the value of WP_POST_REVISIONS.
  423. *
  424. * @since 3.6.0
  425. *
  426. * @param int $num Number of revisions to store.
  427. * @param WP_Post $post Post object.
  428. */
  429. return (int) apply_filters( 'wp_revisions_to_keep', $num, $post );
  430. }
  431. /**
  432. * Sets up the post object for preview based on the post autosave.
  433. *
  434. * @since 2.7.0
  435. * @access private
  436. *
  437. * @param WP_Post $post
  438. * @return WP_Post|false
  439. */
  440. function _set_preview( $post ) {
  441. if ( ! is_object( $post ) ) {
  442. return $post;
  443. }
  444. $preview = wp_get_post_autosave( $post->ID );
  445. if ( ! is_object( $preview ) ) {
  446. return $post;
  447. }
  448. $preview = sanitize_post( $preview );
  449. $post->post_content = $preview->post_content;
  450. $post->post_title = $preview->post_title;
  451. $post->post_excerpt = $preview->post_excerpt;
  452. add_filter( 'get_the_terms', '_wp_preview_terms_filter', 10, 3 );
  453. add_filter( 'get_post_metadata', '_wp_preview_post_thumbnail_filter', 10, 3 );
  454. return $post;
  455. }
  456. /**
  457. * Filters the latest content for preview from the post autosave.
  458. *
  459. * @since 2.7.0
  460. * @access private
  461. */
  462. function _show_post_preview() {
  463. if ( isset($_GET['preview_id']) && isset($_GET['preview_nonce']) ) {
  464. $id = (int) $_GET['preview_id'];
  465. if ( false === wp_verify_nonce( $_GET['preview_nonce'], 'post_preview_' . $id ) )
  466. wp_die( __('Sorry, you are not allowed to preview drafts.') );
  467. add_filter('the_preview', '_set_preview');
  468. }
  469. }
  470. /**
  471. * Filters terms lookup to set the post format.
  472. *
  473. * @since 3.6.0
  474. * @access private
  475. *
  476. * @param array $terms
  477. * @param int $post_id
  478. * @param string $taxonomy
  479. * @return array
  480. */
  481. function _wp_preview_terms_filter( $terms, $post_id, $taxonomy ) {
  482. if ( ! $post = get_post() )
  483. return $terms;
  484. if ( empty( $_REQUEST['post_format'] ) || $post->ID != $post_id || 'post_format' != $taxonomy || 'revision' == $post->post_type )
  485. return $terms;
  486. if ( 'standard' == $_REQUEST['post_format'] )
  487. $terms = array();
  488. elseif ( $term = get_term_by( 'slug', 'post-format-' . sanitize_key( $_REQUEST['post_format'] ), 'post_format' ) )
  489. $terms = array( $term ); // Can only have one post format
  490. return $terms;
  491. }
  492. /**
  493. * Filters post thumbnail lookup to set the post thumbnail.
  494. *
  495. * @since 4.6.0
  496. * @access private
  497. *
  498. * @param null|array|string $value The value to return - a single metadata value, or an array of values.
  499. * @param int $post_id Post ID.
  500. * @param string $meta_key Meta key.
  501. * @return null|array The default return value or the post thumbnail meta array.
  502. */
  503. function _wp_preview_post_thumbnail_filter( $value, $post_id, $meta_key ) {
  504. if ( ! $post = get_post() ) {
  505. return $value;
  506. }
  507. if ( empty( $_REQUEST['_thumbnail_id'] ) ||
  508. empty( $_REQUEST['preview_id'] ) ||
  509. $post->ID != $post_id ||
  510. '_thumbnail_id' != $meta_key ||
  511. 'revision' == $post->post_type ||
  512. $post_id != $_REQUEST['preview_id']
  513. ) {
  514. return $value;
  515. }
  516. $thumbnail_id = intval( $_REQUEST['_thumbnail_id'] );
  517. if ( $thumbnail_id <= 0 ) {
  518. return '';
  519. }
  520. return strval( $thumbnail_id );
  521. }
  522. /**
  523. * Gets the post revision version.
  524. *
  525. * @since 3.6.0
  526. * @access private
  527. *
  528. * @param WP_Post $revision
  529. * @return int|false
  530. */
  531. function _wp_get_post_revision_version( $revision ) {
  532. if ( is_object( $revision ) )
  533. $revision = get_object_vars( $revision );
  534. elseif ( !is_array( $revision ) )
  535. return false;
  536. if ( preg_match( '/^\d+-(?:autosave|revision)-v(\d+)$/', $revision['post_name'], $matches ) )
  537. return (int) $matches[1];
  538. return 0;
  539. }
  540. /**
  541. * Upgrade the revisions author, add the current post as a revision and set the revisions version to 1
  542. *
  543. * @since 3.6.0
  544. * @access private
  545. *
  546. * @global wpdb $wpdb WordPress database abstraction object.
  547. *
  548. * @param WP_Post $post Post object
  549. * @param array $revisions Current revisions of the post
  550. * @return bool true if the revisions were upgraded, false if problems
  551. */
  552. function _wp_upgrade_revisions_of_post( $post, $revisions ) {
  553. global $wpdb;
  554. // Add post option exclusively
  555. $lock = "revision-upgrade-{$post->ID}";
  556. $now = time();
  557. $result = $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, 'no') /* LOCK */", $lock, $now ) );
  558. if ( ! $result ) {
  559. // If we couldn't get a lock, see how old the previous lock is
  560. $locked = get_option( $lock );
  561. if ( ! $locked ) {
  562. // Can't write to the lock, and can't read the lock.
  563. // Something broken has happened
  564. return false;
  565. }
  566. if ( $locked > $now - 3600 ) {
  567. // Lock is not too old: some other process may be upgrading this post. Bail.
  568. return false;
  569. }
  570. // Lock is too old - update it (below) and continue
  571. }
  572. // If we could get a lock, re-"add" the option to fire all the correct filters.
  573. update_option( $lock, $now );
  574. reset( $revisions );
  575. $add_last = true;
  576. do {
  577. $this_revision = current( $revisions );
  578. $prev_revision = next( $revisions );
  579. $this_revision_version = _wp_get_post_revision_version( $this_revision );
  580. // Something terrible happened
  581. if ( false === $this_revision_version )
  582. continue;
  583. // 1 is the latest revision version, so we're already up to date.
  584. // No need to add a copy of the post as latest revision.
  585. if ( 0 < $this_revision_version ) {
  586. $add_last = false;
  587. continue;
  588. }
  589. // Always update the revision version
  590. $update = array(
  591. 'post_name' => preg_replace( '/^(\d+-(?:autosave|revision))[\d-]*$/', '$1-v1', $this_revision->post_name ),
  592. );
  593. // If this revision is the oldest revision of the post, i.e. no $prev_revision,
  594. // the correct post_author is probably $post->post_author, but that's only a good guess.
  595. // Update the revision version only and Leave the author as-is.
  596. if ( $prev_revision ) {
  597. $prev_revision_version = _wp_get_post_revision_version( $prev_revision );
  598. // If the previous revision is already up to date, it no longer has the information we need :(
  599. if ( $prev_revision_version < 1 )
  600. $update['post_author'] = $prev_revision->post_author;
  601. }
  602. // Upgrade this revision
  603. $result = $wpdb->update( $wpdb->posts, $update, array( 'ID' => $this_revision->ID ) );
  604. if ( $result )
  605. wp_cache_delete( $this_revision->ID, 'posts' );
  606. } while ( $prev_revision );
  607. delete_option( $lock );
  608. // Add a copy of the post as latest revision.
  609. if ( $add_last )
  610. wp_save_post_revision( $post->ID );
  611. return true;
  612. }