Edit File by line
/home/barbar84/public_h.../wp-inclu...
File: revision.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Post revision functions.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Post_Revisions
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* Determines which fields of posts are to be saved in revisions.
[9] Fix | Delete
*
[10] Fix | Delete
* @since 2.6.0
[11] Fix | Delete
* @since 4.5.0 A `WP_Post` object can now be passed to the `$post` parameter.
[12] Fix | Delete
* @since 4.5.0 The optional `$autosave` parameter was deprecated and renamed to `$deprecated`.
[13] Fix | Delete
* @access private
[14] Fix | Delete
*
[15] Fix | Delete
* @param array|WP_Post $post Optional. A post array or a WP_Post object being processed
[16] Fix | Delete
* for insertion as a post revision. Default empty array.
[17] Fix | Delete
* @param bool $deprecated Not used.
[18] Fix | Delete
* @return array Array of fields that can be versioned.
[19] Fix | Delete
*/
[20] Fix | Delete
function _wp_post_revision_fields( $post = array(), $deprecated = false ) {
[21] Fix | Delete
static $fields = null;
[22] Fix | Delete
[23] Fix | Delete
if ( ! is_array( $post ) ) {
[24] Fix | Delete
$post = get_post( $post, ARRAY_A );
[25] Fix | Delete
}
[26] Fix | Delete
[27] Fix | Delete
if ( is_null( $fields ) ) {
[28] Fix | Delete
// Allow these to be versioned.
[29] Fix | Delete
$fields = array(
[30] Fix | Delete
'post_title' => __( 'Title' ),
[31] Fix | Delete
'post_content' => __( 'Content' ),
[32] Fix | Delete
'post_excerpt' => __( 'Excerpt' ),
[33] Fix | Delete
);
[34] Fix | Delete
}
[35] Fix | Delete
[36] Fix | Delete
/**
[37] Fix | Delete
* Filters the list of fields saved in post revisions.
[38] Fix | Delete
*
[39] Fix | Delete
* Included by default: 'post_title', 'post_content' and 'post_excerpt'.
[40] Fix | Delete
*
[41] Fix | Delete
* Disallowed fields: 'ID', 'post_name', 'post_parent', 'post_date',
[42] Fix | Delete
* 'post_date_gmt', 'post_status', 'post_type', 'comment_count',
[43] Fix | Delete
* and 'post_author'.
[44] Fix | Delete
*
[45] Fix | Delete
* @since 2.6.0
[46] Fix | Delete
* @since 4.5.0 The `$post` parameter was added.
[47] Fix | Delete
*
[48] Fix | Delete
* @param array $fields List of fields to revision. Contains 'post_title',
[49] Fix | Delete
* 'post_content', and 'post_excerpt' by default.
[50] Fix | Delete
* @param array $post A post array being processed for insertion as a post revision.
[51] Fix | Delete
*/
[52] Fix | Delete
$fields = apply_filters( '_wp_post_revision_fields', $fields, $post );
[53] Fix | Delete
[54] Fix | Delete
// WP uses these internally either in versioning or elsewhere - they cannot be versioned.
[55] Fix | Delete
foreach ( array( 'ID', 'post_name', 'post_parent', 'post_date', 'post_date_gmt', 'post_status', 'post_type', 'comment_count', 'post_author' ) as $protect ) {
[56] Fix | Delete
unset( $fields[ $protect ] );
[57] Fix | Delete
}
[58] Fix | Delete
[59] Fix | Delete
return $fields;
[60] Fix | Delete
}
[61] Fix | Delete
[62] Fix | Delete
/**
[63] Fix | Delete
* Returns a post array ready to be inserted into the posts table as a post revision.
[64] Fix | Delete
*
[65] Fix | Delete
* @since 4.5.0
[66] Fix | Delete
* @access private
[67] Fix | Delete
*
[68] Fix | Delete
* @param array|WP_Post $post Optional. A post array or a WP_Post object to be processed
[69] Fix | Delete
* for insertion as a post revision. Default empty array.
[70] Fix | Delete
* @param bool $autosave Optional. Is the revision an autosave? Default false.
[71] Fix | Delete
* @return array Post array ready to be inserted as a post revision.
[72] Fix | Delete
*/
[73] Fix | Delete
function _wp_post_revision_data( $post = array(), $autosave = false ) {
[74] Fix | Delete
if ( ! is_array( $post ) ) {
[75] Fix | Delete
$post = get_post( $post, ARRAY_A );
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
$fields = _wp_post_revision_fields( $post );
[79] Fix | Delete
[80] Fix | Delete
$revision_data = array();
[81] Fix | Delete
[82] Fix | Delete
foreach ( array_intersect( array_keys( $post ), array_keys( $fields ) ) as $field ) {
[83] Fix | Delete
$revision_data[ $field ] = $post[ $field ];
[84] Fix | Delete
}
[85] Fix | Delete
[86] Fix | Delete
$revision_data['post_parent'] = $post['ID'];
[87] Fix | Delete
$revision_data['post_status'] = 'inherit';
[88] Fix | Delete
$revision_data['post_type'] = 'revision';
[89] Fix | Delete
$revision_data['post_name'] = $autosave ? "$post[ID]-autosave-v1" : "$post[ID]-revision-v1"; // "1" is the revisioning system version.
[90] Fix | Delete
$revision_data['post_date'] = isset( $post['post_modified'] ) ? $post['post_modified'] : '';
[91] Fix | Delete
$revision_data['post_date_gmt'] = isset( $post['post_modified_gmt'] ) ? $post['post_modified_gmt'] : '';
[92] Fix | Delete
[93] Fix | Delete
return $revision_data;
[94] Fix | Delete
}
[95] Fix | Delete
[96] Fix | Delete
/**
[97] Fix | Delete
* Creates a revision for the current version of a post.
[98] Fix | Delete
*
[99] Fix | Delete
* Typically used immediately after a post update, as every update is a revision,
[100] Fix | Delete
* and the most recent revision always matches the current post.
[101] Fix | Delete
*
[102] Fix | Delete
* @since 2.6.0
[103] Fix | Delete
*
[104] Fix | Delete
* @param int $post_id The ID of the post to save as a revision.
[105] Fix | Delete
* @return int|WP_Error|void Void or 0 if error, new revision ID, if success.
[106] Fix | Delete
*/
[107] Fix | Delete
function wp_save_post_revision( $post_id ) {
[108] Fix | Delete
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
[109] Fix | Delete
return;
[110] Fix | Delete
}
[111] Fix | Delete
[112] Fix | Delete
$post = get_post( $post_id );
[113] Fix | Delete
if ( ! $post ) {
[114] Fix | Delete
return;
[115] Fix | Delete
}
[116] Fix | Delete
[117] Fix | Delete
if ( ! post_type_supports( $post->post_type, 'revisions' ) ) {
[118] Fix | Delete
return;
[119] Fix | Delete
}
[120] Fix | Delete
[121] Fix | Delete
if ( 'auto-draft' === $post->post_status ) {
[122] Fix | Delete
return;
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
if ( ! wp_revisions_enabled( $post ) ) {
[126] Fix | Delete
return;
[127] Fix | Delete
}
[128] Fix | Delete
[129] Fix | Delete
/*
[130] Fix | Delete
* Compare the proposed update with the last stored revision verifying that
[131] Fix | Delete
* they are different, unless a plugin tells us to always save regardless.
[132] Fix | Delete
* If no previous revisions, save one.
[133] Fix | Delete
*/
[134] Fix | Delete
$revisions = wp_get_post_revisions( $post_id );
[135] Fix | Delete
if ( $revisions ) {
[136] Fix | Delete
// Grab the last revision, but not an autosave.
[137] Fix | Delete
foreach ( $revisions as $revision ) {
[138] Fix | Delete
if ( false !== strpos( $revision->post_name, "{$revision->post_parent}-revision" ) ) {
[139] Fix | Delete
$last_revision = $revision;
[140] Fix | Delete
break;
[141] Fix | Delete
}
[142] Fix | Delete
}
[143] Fix | Delete
[144] Fix | Delete
/**
[145] Fix | Delete
* Filters whether the post has changed since the last revision.
[146] Fix | Delete
*
[147] Fix | Delete
* By default a revision is saved only if one of the revisioned fields has changed.
[148] Fix | Delete
* This filter can override that so a revision is saved even if nothing has changed.
[149] Fix | Delete
*
[150] Fix | Delete
* @since 3.6.0
[151] Fix | Delete
*
[152] Fix | Delete
* @param bool $check_for_changes Whether to check for changes before saving a new revision.
[153] Fix | Delete
* Default true.
[154] Fix | Delete
* @param WP_Post $last_revision The last revision post object.
[155] Fix | Delete
* @param WP_Post $post The post object.
[156] Fix | Delete
*/
[157] Fix | Delete
if ( isset( $last_revision ) && apply_filters( 'wp_save_post_revision_check_for_changes', true, $last_revision, $post ) ) {
[158] Fix | Delete
$post_has_changed = false;
[159] Fix | Delete
[160] Fix | Delete
foreach ( array_keys( _wp_post_revision_fields( $post ) ) as $field ) {
[161] Fix | Delete
if ( normalize_whitespace( $post->$field ) !== normalize_whitespace( $last_revision->$field ) ) {
[162] Fix | Delete
$post_has_changed = true;
[163] Fix | Delete
break;
[164] Fix | Delete
}
[165] Fix | Delete
}
[166] Fix | Delete
[167] Fix | Delete
/**
[168] Fix | Delete
* Filters whether a post has changed.
[169] Fix | Delete
*
[170] Fix | Delete
* By default a revision is saved only if one of the revisioned fields has changed.
[171] Fix | Delete
* This filter allows for additional checks to determine if there were changes.
[172] Fix | Delete
*
[173] Fix | Delete
* @since 4.1.0
[174] Fix | Delete
*
[175] Fix | Delete
* @param bool $post_has_changed Whether the post has changed.
[176] Fix | Delete
* @param WP_Post $last_revision The last revision post object.
[177] Fix | Delete
* @param WP_Post $post The post object.
[178] Fix | Delete
*/
[179] Fix | Delete
$post_has_changed = (bool) apply_filters( 'wp_save_post_revision_post_has_changed', $post_has_changed, $last_revision, $post );
[180] Fix | Delete
[181] Fix | Delete
// Don't save revision if post unchanged.
[182] Fix | Delete
if ( ! $post_has_changed ) {
[183] Fix | Delete
return;
[184] Fix | Delete
}
[185] Fix | Delete
}
[186] Fix | Delete
}
[187] Fix | Delete
[188] Fix | Delete
$return = _wp_put_post_revision( $post );
[189] Fix | Delete
[190] Fix | Delete
// If a limit for the number of revisions to keep has been set,
[191] Fix | Delete
// delete the oldest ones.
[192] Fix | Delete
$revisions_to_keep = wp_revisions_to_keep( $post );
[193] Fix | Delete
[194] Fix | Delete
if ( $revisions_to_keep < 0 ) {
[195] Fix | Delete
return $return;
[196] Fix | Delete
}
[197] Fix | Delete
[198] Fix | Delete
$revisions = wp_get_post_revisions( $post_id, array( 'order' => 'ASC' ) );
[199] Fix | Delete
[200] Fix | Delete
$delete = count( $revisions ) - $revisions_to_keep;
[201] Fix | Delete
[202] Fix | Delete
if ( $delete < 1 ) {
[203] Fix | Delete
return $return;
[204] Fix | Delete
}
[205] Fix | Delete
[206] Fix | Delete
$revisions = array_slice( $revisions, 0, $delete );
[207] Fix | Delete
[208] Fix | Delete
for ( $i = 0; isset( $revisions[ $i ] ); $i++ ) {
[209] Fix | Delete
if ( false !== strpos( $revisions[ $i ]->post_name, 'autosave' ) ) {
[210] Fix | Delete
continue;
[211] Fix | Delete
}
[212] Fix | Delete
[213] Fix | Delete
wp_delete_post_revision( $revisions[ $i ]->ID );
[214] Fix | Delete
}
[215] Fix | Delete
[216] Fix | Delete
return $return;
[217] Fix | Delete
}
[218] Fix | Delete
[219] Fix | Delete
/**
[220] Fix | Delete
* Retrieve the autosaved data of the specified post.
[221] Fix | Delete
*
[222] Fix | Delete
* Returns a post object with the information that was autosaved for the specified post.
[223] Fix | Delete
* If the optional $user_id is passed, returns the autosave for that user, otherwise
[224] Fix | Delete
* returns the latest autosave.
[225] Fix | Delete
*
[226] Fix | Delete
* @since 2.6.0
[227] Fix | Delete
*
[228] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[229] Fix | Delete
*
[230] Fix | Delete
* @param int $post_id The post ID.
[231] Fix | Delete
* @param int $user_id Optional The post author ID.
[232] Fix | Delete
* @return WP_Post|false The autosaved data or false on failure or when no autosave exists.
[233] Fix | Delete
*/
[234] Fix | Delete
function wp_get_post_autosave( $post_id, $user_id = 0 ) {
[235] Fix | Delete
global $wpdb;
[236] Fix | Delete
[237] Fix | Delete
$autosave_name = $post_id . '-autosave-v1';
[238] Fix | Delete
$user_id_query = ( 0 !== $user_id ) ? "AND post_author = $user_id" : null;
[239] Fix | Delete
[240] Fix | Delete
// Construct the autosave query.
[241] Fix | Delete
$autosave_query = "
[242] Fix | Delete
SELECT *
[243] Fix | Delete
FROM $wpdb->posts
[244] Fix | Delete
WHERE post_parent = %d
[245] Fix | Delete
AND post_type = 'revision'
[246] Fix | Delete
AND post_status = 'inherit'
[247] Fix | Delete
AND post_name = %s " . $user_id_query . '
[248] Fix | Delete
ORDER BY post_date DESC
[249] Fix | Delete
LIMIT 1';
[250] Fix | Delete
[251] Fix | Delete
$autosave = $wpdb->get_results(
[252] Fix | Delete
$wpdb->prepare(
[253] Fix | Delete
$autosave_query,
[254] Fix | Delete
$post_id,
[255] Fix | Delete
$autosave_name
[256] Fix | Delete
)
[257] Fix | Delete
);
[258] Fix | Delete
[259] Fix | Delete
if ( ! $autosave ) {
[260] Fix | Delete
return false;
[261] Fix | Delete
}
[262] Fix | Delete
[263] Fix | Delete
return get_post( $autosave[0] );
[264] Fix | Delete
}
[265] Fix | Delete
[266] Fix | Delete
/**
[267] Fix | Delete
* Determines if the specified post is a revision.
[268] Fix | Delete
*
[269] Fix | Delete
* @since 2.6.0
[270] Fix | Delete
*
[271] Fix | Delete
* @param int|WP_Post $post Post ID or post object.
[272] Fix | Delete
* @return int|false ID of revision's parent on success, false if not a revision.
[273] Fix | Delete
*/
[274] Fix | Delete
function wp_is_post_revision( $post ) {
[275] Fix | Delete
$post = wp_get_post_revision( $post );
[276] Fix | Delete
if ( ! $post ) {
[277] Fix | Delete
return false;
[278] Fix | Delete
}
[279] Fix | Delete
[280] Fix | Delete
return (int) $post->post_parent;
[281] Fix | Delete
}
[282] Fix | Delete
[283] Fix | Delete
/**
[284] Fix | Delete
* Determines if the specified post is an autosave.
[285] Fix | Delete
*
[286] Fix | Delete
* @since 2.6.0
[287] Fix | Delete
*
[288] Fix | Delete
* @param int|WP_Post $post Post ID or post object.
[289] Fix | Delete
* @return int|false ID of autosave's parent on success, false if not a revision.
[290] Fix | Delete
*/
[291] Fix | Delete
function wp_is_post_autosave( $post ) {
[292] Fix | Delete
$post = wp_get_post_revision( $post );
[293] Fix | Delete
if ( ! $post ) {
[294] Fix | Delete
return false;
[295] Fix | Delete
}
[296] Fix | Delete
[297] Fix | Delete
if ( false !== strpos( $post->post_name, "{$post->post_parent}-autosave" ) ) {
[298] Fix | Delete
return (int) $post->post_parent;
[299] Fix | Delete
}
[300] Fix | Delete
[301] Fix | Delete
return false;
[302] Fix | Delete
}
[303] Fix | Delete
[304] Fix | Delete
/**
[305] Fix | Delete
* Inserts post data into the posts table as a post revision.
[306] Fix | Delete
*
[307] Fix | Delete
* @since 2.6.0
[308] Fix | Delete
* @access private
[309] Fix | Delete
*
[310] Fix | Delete
* @param int|WP_Post|array|null $post Post ID, post object OR post array.
[311] Fix | Delete
* @param bool $autosave Optional. Is the revision an autosave?
[312] Fix | Delete
* @return int|WP_Error WP_Error or 0 if error, new revision ID if success.
[313] Fix | Delete
*/
[314] Fix | Delete
function _wp_put_post_revision( $post = null, $autosave = false ) {
[315] Fix | Delete
if ( is_object( $post ) ) {
[316] Fix | Delete
$post = get_object_vars( $post );
[317] Fix | Delete
} elseif ( ! is_array( $post ) ) {
[318] Fix | Delete
$post = get_post( $post, ARRAY_A );
[319] Fix | Delete
}
[320] Fix | Delete
[321] Fix | Delete
if ( ! $post || empty( $post['ID'] ) ) {
[322] Fix | Delete
return new WP_Error( 'invalid_post', __( 'Invalid post ID.' ) );
[323] Fix | Delete
}
[324] Fix | Delete
[325] Fix | Delete
if ( isset( $post['post_type'] ) && 'revision' === $post['post_type'] ) {
[326] Fix | Delete
return new WP_Error( 'post_type', __( 'Cannot create a revision of a revision' ) );
[327] Fix | Delete
}
[328] Fix | Delete
[329] Fix | Delete
$post = _wp_post_revision_data( $post, $autosave );
[330] Fix | Delete
$post = wp_slash( $post ); // Since data is from DB.
[331] Fix | Delete
[332] Fix | Delete
$revision_id = wp_insert_post( $post );
[333] Fix | Delete
if ( is_wp_error( $revision_id ) ) {
[334] Fix | Delete
return $revision_id;
[335] Fix | Delete
}
[336] Fix | Delete
[337] Fix | Delete
if ( $revision_id ) {
[338] Fix | Delete
/**
[339] Fix | Delete
* Fires once a revision has been saved.
[340] Fix | Delete
*
[341] Fix | Delete
* @since 2.6.0
[342] Fix | Delete
*
[343] Fix | Delete
* @param int $revision_id Post revision ID.
[344] Fix | Delete
*/
[345] Fix | Delete
do_action( '_wp_put_post_revision', $revision_id );
[346] Fix | Delete
}
[347] Fix | Delete
[348] Fix | Delete
return $revision_id;
[349] Fix | Delete
}
[350] Fix | Delete
[351] Fix | Delete
/**
[352] Fix | Delete
* Gets a post revision.
[353] Fix | Delete
*
[354] Fix | Delete
* @since 2.6.0
[355] Fix | Delete
*
[356] Fix | Delete
* @param int|WP_Post $post The post ID or object.
[357] Fix | Delete
* @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which
[358] Fix | Delete
* correspond to a WP_Post object, an associative array, or a numeric array,
[359] Fix | Delete
* respectively. Default OBJECT.
[360] Fix | Delete
* @param string $filter Optional sanitation filter. See sanitize_post().
[361] Fix | Delete
* @return WP_Post|array|null WP_Post (or array) on success, or null on failure.
[362] Fix | Delete
*/
[363] Fix | Delete
function wp_get_post_revision( &$post, $output = OBJECT, $filter = 'raw' ) {
[364] Fix | Delete
$revision = get_post( $post, OBJECT, $filter );
[365] Fix | Delete
if ( ! $revision ) {
[366] Fix | Delete
return $revision;
[367] Fix | Delete
}
[368] Fix | Delete
if ( 'revision' !== $revision->post_type ) {
[369] Fix | Delete
return null;
[370] Fix | Delete
}
[371] Fix | Delete
[372] Fix | Delete
if ( OBJECT == $output ) {
[373] Fix | Delete
return $revision;
[374] Fix | Delete
} elseif ( ARRAY_A == $output ) {
[375] Fix | Delete
$_revision = get_object_vars( $revision );
[376] Fix | Delete
return $_revision;
[377] Fix | Delete
} elseif ( ARRAY_N == $output ) {
[378] Fix | Delete
$_revision = array_values( get_object_vars( $revision ) );
[379] Fix | Delete
return $_revision;
[380] Fix | Delete
}
[381] Fix | Delete
[382] Fix | Delete
return $revision;
[383] Fix | Delete
}
[384] Fix | Delete
[385] Fix | Delete
/**
[386] Fix | Delete
* Restores a post to the specified revision.
[387] Fix | Delete
*
[388] Fix | Delete
* Can restore a past revision using all fields of the post revision, or only selected fields.
[389] Fix | Delete
*
[390] Fix | Delete
* @since 2.6.0
[391] Fix | Delete
*
[392] Fix | Delete
* @param int|WP_Post $revision_id Revision ID or revision object.
[393] Fix | Delete
* @param array $fields Optional. What fields to restore from. Defaults to all.
[394] Fix | Delete
* @return int|false|null Null if error, false if no fields to restore, (int) post ID if success.
[395] Fix | Delete
*/
[396] Fix | Delete
function wp_restore_post_revision( $revision_id, $fields = null ) {
[397] Fix | Delete
$revision = wp_get_post_revision( $revision_id, ARRAY_A );
[398] Fix | Delete
if ( ! $revision ) {
[399] Fix | Delete
return $revision;
[400] Fix | Delete
}
[401] Fix | Delete
[402] Fix | Delete
if ( ! is_array( $fields ) ) {
[403] Fix | Delete
$fields = array_keys( _wp_post_revision_fields( $revision ) );
[404] Fix | Delete
}
[405] Fix | Delete
[406] Fix | Delete
$update = array();
[407] Fix | Delete
foreach ( array_intersect( array_keys( $revision ), $fields ) as $field ) {
[408] Fix | Delete
$update[ $field ] = $revision[ $field ];
[409] Fix | Delete
}
[410] Fix | Delete
[411] Fix | Delete
if ( ! $update ) {
[412] Fix | Delete
return false;
[413] Fix | Delete
}
[414] Fix | Delete
[415] Fix | Delete
$update['ID'] = $revision['post_parent'];
[416] Fix | Delete
[417] Fix | Delete
$update = wp_slash( $update ); // Since data is from DB.
[418] Fix | Delete
[419] Fix | Delete
$post_id = wp_update_post( $update );
[420] Fix | Delete
if ( ! $post_id || is_wp_error( $post_id ) ) {
[421] Fix | Delete
return $post_id;
[422] Fix | Delete
}
[423] Fix | Delete
[424] Fix | Delete
// Update last edit user.
[425] Fix | Delete
update_post_meta( $post_id, '_edit_last', get_current_user_id() );
[426] Fix | Delete
[427] Fix | Delete
/**
[428] Fix | Delete
* Fires after a post revision has been restored.
[429] Fix | Delete
*
[430] Fix | Delete
* @since 2.6.0
[431] Fix | Delete
*
[432] Fix | Delete
* @param int $post_id Post ID.
[433] Fix | Delete
* @param int $revision_id Post revision ID.
[434] Fix | Delete
*/
[435] Fix | Delete
do_action( 'wp_restore_post_revision', $post_id, $revision['ID'] );
[436] Fix | Delete
[437] Fix | Delete
return $post_id;
[438] Fix | Delete
}
[439] Fix | Delete
[440] Fix | Delete
/**
[441] Fix | Delete
* Deletes a revision.
[442] Fix | Delete
*
[443] Fix | Delete
* Deletes the row from the posts table corresponding to the specified revision.
[444] Fix | Delete
*
[445] Fix | Delete
* @since 2.6.0
[446] Fix | Delete
*
[447] Fix | Delete
* @param int|WP_Post $revision_id Revision ID or revision object.
[448] Fix | Delete
* @return array|false|WP_Post|WP_Error|null Null or WP_Error if error, deleted post if success.
[449] Fix | Delete
*/
[450] Fix | Delete
function wp_delete_post_revision( $revision_id ) {
[451] Fix | Delete
$revision = wp_get_post_revision( $revision_id );
[452] Fix | Delete
if ( ! $revision ) {
[453] Fix | Delete
return $revision;
[454] Fix | Delete
}
[455] Fix | Delete
[456] Fix | Delete
$delete = wp_delete_post( $revision->ID );
[457] Fix | Delete
if ( $delete ) {
[458] Fix | Delete
/**
[459] Fix | Delete
* Fires once a post revision has been deleted.
[460] Fix | Delete
*
[461] Fix | Delete
* @since 2.6.0
[462] Fix | Delete
*
[463] Fix | Delete
* @param int $revision_id Post revision ID.
[464] Fix | Delete
* @param WP_Post $revision Post revision object.
[465] Fix | Delete
*/
[466] Fix | Delete
do_action( 'wp_delete_post_revision', $revision->ID, $revision );
[467] Fix | Delete
}
[468] Fix | Delete
[469] Fix | Delete
return $delete;
[470] Fix | Delete
}
[471] Fix | Delete
[472] Fix | Delete
/**
[473] Fix | Delete
* Returns all revisions of specified post.
[474] Fix | Delete
*
[475] Fix | Delete
* @since 2.6.0
[476] Fix | Delete
*
[477] Fix | Delete
* @see get_children()
[478] Fix | Delete
*
[479] Fix | Delete
* @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global `$post`.
[480] Fix | Delete
* @param array|null $args Optional. Arguments for retrieving post revisions. Default null.
[481] Fix | Delete
* @return array An array of revisions, or an empty array if none.
[482] Fix | Delete
*/
[483] Fix | Delete
function wp_get_post_revisions( $post_id = 0, $args = null ) {
[484] Fix | Delete
$post = get_post( $post_id );
[485] Fix | Delete
if ( ! $post || empty( $post->ID ) ) {
[486] Fix | Delete
return array();
[487] Fix | Delete
}
[488] Fix | Delete
[489] Fix | Delete
$defaults = array(
[490] Fix | Delete
'order' => 'DESC',
[491] Fix | Delete
'orderby' => 'date ID',
[492] Fix | Delete
'check_enabled' => true,
[493] Fix | Delete
);
[494] Fix | Delete
$args = wp_parse_args( $args, $defaults );
[495] Fix | Delete
[496] Fix | Delete
if ( $args['check_enabled'] && ! wp_revisions_enabled( $post ) ) {
[497] Fix | Delete
return array();
[498] Fix | Delete
}
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function