| Current Path : /home/x/b/o/xbodynamge/namtation/wp-content/ |
| Current File : /home/x/b/o/xbodynamge/namtation/wp-content/revision.php.tar |
home/xbodynamge/dev/wp-includes/revision.php 0000604 00000051471 15111427711 0015214 0 ustar 00 <?php
/**
* Post revision functions.
*
* @package WordPress
* @subpackage Post_Revisions
*/
/**
* Determines which fields of posts are to be saved in revisions.
*
* @since 2.6.0
* @since 4.5.0 A `WP_Post` object can now be passed to the `$post` parameter.
* @since 4.5.0 The optional `$autosave` parameter was deprecated and renamed to `$deprecated`.
* @access private
*
* @staticvar array $fields
*
* @param array|WP_Post $post Optional. A post array or a WP_Post object being processed
* for insertion as a post revision. Default empty array.
* @param bool $deprecated Not used.
* @return array Array of fields that can be versioned.
*/
function _wp_post_revision_fields( $post = array(), $deprecated = false ) {
static $fields = null;
if ( ! is_array( $post ) ) {
$post = get_post( $post, ARRAY_A );
}
if ( is_null( $fields ) ) {
// Allow these to be versioned
$fields = array(
'post_title' => __( 'Title' ),
'post_content' => __( 'Content' ),
'post_excerpt' => __( 'Excerpt' ),
);
}
/**
* Filters the list of fields saved in post revisions.
*
* Included by default: 'post_title', 'post_content' and 'post_excerpt'.
*
* Disallowed fields: 'ID', 'post_name', 'post_parent', 'post_date',
* 'post_date_gmt', 'post_status', 'post_type', 'comment_count',
* and 'post_author'.
*
* @since 2.6.0
* @since 4.5.0 The `$post` parameter was added.
*
* @param array $fields List of fields to revision. Contains 'post_title',
* 'post_content', and 'post_excerpt' by default.
* @param array $post A post array being processed for insertion as a post revision.
*/
$fields = apply_filters( '_wp_post_revision_fields', $fields, $post );
// WP uses these internally either in versioning or elsewhere - they cannot be versioned
foreach ( array( 'ID', 'post_name', 'post_parent', 'post_date', 'post_date_gmt', 'post_status', 'post_type', 'comment_count', 'post_author' ) as $protect ) {
unset( $fields[ $protect ] );
}
return $fields;
}
/**
* Returns a post array ready to be inserted into the posts table as a post revision.
*
* @since 4.5.0
* @access private
*
* @param array|WP_Post $post Optional. A post array or a WP_Post object to be processed
* for insertion as a post revision. Default empty array.
* @param bool $autosave Optional. Is the revision an autosave? Default false.
* @return array Post array ready to be inserted as a post revision.
*/
function _wp_post_revision_data( $post = array(), $autosave = false ) {
if ( ! is_array( $post ) ) {
$post = get_post( $post, ARRAY_A );
}
$fields = _wp_post_revision_fields( $post );
$revision_data = array();
foreach ( array_intersect( array_keys( $post ), array_keys( $fields ) ) as $field ) {
$revision_data[ $field ] = $post[ $field ];
}
$revision_data['post_parent'] = $post['ID'];
$revision_data['post_status'] = 'inherit';
$revision_data['post_type'] = 'revision';
$revision_data['post_name'] = $autosave ? "$post[ID]-autosave-v1" : "$post[ID]-revision-v1"; // "1" is the revisioning system version
$revision_data['post_date'] = isset( $post['post_modified'] ) ? $post['post_modified'] : '';
$revision_data['post_date_gmt'] = isset( $post['post_modified_gmt'] ) ? $post['post_modified_gmt'] : '';
return $revision_data;
}
/**
* Creates a revision for the current version of a post.
*
* Typically used immediately after a post update, as every update is a revision,
* and the most recent revision always matches the current post.
*
* @since 2.6.0
*
* @param int $post_id The ID of the post to save as a revision.
* @return int|WP_Error|void Void or 0 if error, new revision ID, if success.
*/
function wp_save_post_revision( $post_id ) {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
if ( ! $post = get_post( $post_id ) )
return;
if ( ! post_type_supports( $post->post_type, 'revisions' ) )
return;
if ( 'auto-draft' == $post->post_status )
return;
if ( ! wp_revisions_enabled( $post ) )
return;
// Compare the proposed update with the last stored revision verifying that
// they are different, unless a plugin tells us to always save regardless.
// If no previous revisions, save one
if ( $revisions = wp_get_post_revisions( $post_id ) ) {
// grab the last revision, but not an autosave
foreach ( $revisions as $revision ) {
if ( false !== strpos( $revision->post_name, "{$revision->post_parent}-revision" ) ) {
$last_revision = $revision;
break;
}
}
/**
* Filters whether the post has changed since the last revision.
*
* By default a revision is saved only if one of the revisioned fields has changed.
* This filter can override that so a revision is saved even if nothing has changed.
*
* @since 3.6.0
*
* @param bool $check_for_changes Whether to check for changes before saving a new revision.
* Default true.
* @param WP_Post $last_revision The last revision post object.
* @param WP_Post $post The post object.
*
*/
if ( isset( $last_revision ) && apply_filters( 'wp_save_post_revision_check_for_changes', $check_for_changes = true, $last_revision, $post ) ) {
$post_has_changed = false;
foreach ( array_keys( _wp_post_revision_fields( $post ) ) as $field ) {
if ( normalize_whitespace( $post->$field ) != normalize_whitespace( $last_revision->$field ) ) {
$post_has_changed = true;
break;
}
}
/**
* Filters whether a post has changed.
*
* By default a revision is saved only if one of the revisioned fields has changed.
* This filter allows for additional checks to determine if there were changes.
*
* @since 4.1.0
*
* @param bool $post_has_changed Whether the post has changed.
* @param WP_Post $last_revision The last revision post object.
* @param WP_Post $post The post object.
*
*/
$post_has_changed = (bool) apply_filters( 'wp_save_post_revision_post_has_changed', $post_has_changed, $last_revision, $post );
//don't save revision if post unchanged
if ( ! $post_has_changed ) {
return;
}
}
}
$return = _wp_put_post_revision( $post );
// If a limit for the number of revisions to keep has been set,
// delete the oldest ones.
$revisions_to_keep = wp_revisions_to_keep( $post );
if ( $revisions_to_keep < 0 )
return $return;
$revisions = wp_get_post_revisions( $post_id, array( 'order' => 'ASC' ) );
$delete = count($revisions) - $revisions_to_keep;
if ( $delete < 1 )
return $return;
$revisions = array_slice( $revisions, 0, $delete );
for ( $i = 0; isset( $revisions[$i] ); $i++ ) {
if ( false !== strpos( $revisions[ $i ]->post_name, 'autosave' ) )
continue;
wp_delete_post_revision( $revisions[ $i ]->ID );
}
return $return;
}
/**
* Retrieve the autosaved data of the specified post.
*
* Returns a post object containing the information that was autosaved for the
* specified post. If the optional $user_id is passed, returns the autosave for that user
* otherwise returns the latest autosave.
*
* @since 2.6.0
*
* @param int $post_id The post ID.
* @param int $user_id Optional The post author ID.
* @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 ) {
$revisions = wp_get_post_revisions( $post_id, array( 'check_enabled' => false ) );
foreach ( $revisions as $revision ) {
if ( false !== strpos( $revision->post_name, "{$post_id}-autosave" ) ) {
if ( $user_id && $user_id != $revision->post_author )
continue;
return $revision;
}
}
return false;
}
/**
* Determines if the specified post is a revision.
*
* @since 2.6.0
*
* @param int|WP_Post $post Post ID or post object.
* @return false|int False if not a revision, ID of revision's parent otherwise.
*/
function wp_is_post_revision( $post ) {
if ( !$post = wp_get_post_revision( $post ) )
return false;
return (int) $post->post_parent;
}
/**
* Determines if the specified post is an autosave.
*
* @since 2.6.0
*
* @param int|WP_Post $post Post ID or post object.
* @return false|int False if not a revision, ID of autosave's parent otherwise
*/
function wp_is_post_autosave( $post ) {
if ( !$post = wp_get_post_revision( $post ) )
return false;
if ( false !== strpos( $post->post_name, "{$post->post_parent}-autosave" ) )
return (int) $post->post_parent;
return false;
}
/**
* Inserts post data into the posts table as a post revision.
*
* @since 2.6.0
* @access private
*
* @param int|WP_Post|array|null $post Post ID, post object OR post array.
* @param bool $autosave Optional. Is the revision an autosave?
* @return int|WP_Error WP_Error or 0 if error, new revision ID if success.
*/
function _wp_put_post_revision( $post = null, $autosave = false ) {
if ( is_object($post) )
$post = get_object_vars( $post );
elseif ( !is_array($post) )
$post = get_post($post, ARRAY_A);
if ( ! $post || empty($post['ID']) )
return new WP_Error( 'invalid_post', __( 'Invalid post ID.' ) );
if ( isset($post['post_type']) && 'revision' == $post['post_type'] )
return new WP_Error( 'post_type', __( 'Cannot create a revision of a revision' ) );
$post = _wp_post_revision_data( $post, $autosave );
$post = wp_slash($post); //since data is from db
$revision_id = wp_insert_post( $post );
if ( is_wp_error($revision_id) )
return $revision_id;
if ( $revision_id ) {
/**
* Fires once a revision has been saved.
*
* @since 2.6.0
*
* @param int $revision_id Post revision ID.
*/
do_action( '_wp_put_post_revision', $revision_id );
}
return $revision_id;
}
/**
* Gets a post revision.
*
* @since 2.6.0
*
* @param int|WP_Post $post The post ID or object.
* @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to
* a WP_Post object, an associative array, or a numeric array, respectively. Default OBJECT.
* @param string $filter Optional sanitation filter. See sanitize_post().
* @return WP_Post|array|null WP_Post (or array) on success, or null on failure.
*/
function wp_get_post_revision(&$post, $output = OBJECT, $filter = 'raw') {
if ( !$revision = get_post( $post, OBJECT, $filter ) )
return $revision;
if ( 'revision' !== $revision->post_type )
return null;
if ( $output == OBJECT ) {
return $revision;
} elseif ( $output == ARRAY_A ) {
$_revision = get_object_vars($revision);
return $_revision;
} elseif ( $output == ARRAY_N ) {
$_revision = array_values(get_object_vars($revision));
return $_revision;
}
return $revision;
}
/**
* Restores a post to the specified revision.
*
* Can restore a past revision using all fields of the post revision, or only selected fields.
*
* @since 2.6.0
*
* @param int|WP_Post $revision_id Revision ID or revision object.
* @param array $fields Optional. What fields to restore from. Defaults to all.
* @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 ) {
if ( !$revision = wp_get_post_revision( $revision_id, ARRAY_A ) )
return $revision;
if ( !is_array( $fields ) )
$fields = array_keys( _wp_post_revision_fields( $revision ) );
$update = array();
foreach ( array_intersect( array_keys( $revision ), $fields ) as $field ) {
$update[$field] = $revision[$field];
}
if ( !$update )
return false;
$update['ID'] = $revision['post_parent'];
$update = wp_slash( $update ); //since data is from db
$post_id = wp_update_post( $update );
if ( ! $post_id || is_wp_error( $post_id ) )
return $post_id;
// Update last edit user
update_post_meta( $post_id, '_edit_last', get_current_user_id() );
/**
* Fires after a post revision has been restored.
*
* @since 2.6.0
*
* @param int $post_id Post ID.
* @param int $revision_id Post revision ID.
*/
do_action( 'wp_restore_post_revision', $post_id, $revision['ID'] );
return $post_id;
}
/**
* Deletes a revision.
*
* Deletes the row from the posts table corresponding to the specified revision.
*
* @since 2.6.0
*
* @param int|WP_Post $revision_id Revision ID or revision object.
* @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 ) {
if ( ! $revision = wp_get_post_revision( $revision_id ) ) {
return $revision;
}
$delete = wp_delete_post( $revision->ID );
if ( $delete ) {
/**
* Fires once a post revision has been deleted.
*
* @since 2.6.0
*
* @param int $revision_id Post revision ID.
* @param object|array $revision Post revision object or array.
*/
do_action( 'wp_delete_post_revision', $revision->ID, $revision );
}
return $delete;
}
/**
* Returns all revisions of specified post.
*
* @since 2.6.0
*
* @see get_children()
*
* @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global `$post`.
* @param array|null $args Optional. Arguments for retrieving post revisions. Default null.
* @return array An array of revisions, or an empty array if none.
*/
function wp_get_post_revisions( $post_id = 0, $args = null ) {
$post = get_post( $post_id );
if ( ! $post || empty( $post->ID ) )
return array();
$defaults = array( 'order' => 'DESC', 'orderby' => 'date ID', 'check_enabled' => true );
$args = wp_parse_args( $args, $defaults );
if ( $args['check_enabled'] && ! wp_revisions_enabled( $post ) )
return array();
$args = array_merge( $args, array( 'post_parent' => $post->ID, 'post_type' => 'revision', 'post_status' => 'inherit' ) );
if ( ! $revisions = get_children( $args ) )
return array();
return $revisions;
}
/**
* Determine if revisions are enabled for a given post.
*
* @since 3.6.0
*
* @param WP_Post $post The post object.
* @return bool True if number of revisions to keep isn't zero, false otherwise.
*/
function wp_revisions_enabled( $post ) {
return wp_revisions_to_keep( $post ) !== 0;
}
/**
* Determine how many revisions to retain for a given post.
*
* By default, an infinite number of revisions are kept.
*
* The constant WP_POST_REVISIONS can be set in wp-config to specify the limit
* of revisions to keep.
*
* @since 3.6.0
*
* @param WP_Post $post The post object.
* @return int The number of revisions to keep.
*/
function wp_revisions_to_keep( $post ) {
$num = WP_POST_REVISIONS;
if ( true === $num )
$num = -1;
else
$num = intval( $num );
if ( ! post_type_supports( $post->post_type, 'revisions' ) )
$num = 0;
/**
* Filters the number of revisions to save for the given post.
*
* Overrides the value of WP_POST_REVISIONS.
*
* @since 3.6.0
*
* @param int $num Number of revisions to store.
* @param WP_Post $post Post object.
*/
return (int) apply_filters( 'wp_revisions_to_keep', $num, $post );
}
/**
* Sets up the post object for preview based on the post autosave.
*
* @since 2.7.0
* @access private
*
* @param WP_Post $post
* @return WP_Post|false
*/
function _set_preview( $post ) {
if ( ! is_object( $post ) ) {
return $post;
}
$preview = wp_get_post_autosave( $post->ID );
if ( ! is_object( $preview ) ) {
return $post;
}
$preview = sanitize_post( $preview );
$post->post_content = $preview->post_content;
$post->post_title = $preview->post_title;
$post->post_excerpt = $preview->post_excerpt;
add_filter( 'get_the_terms', '_wp_preview_terms_filter', 10, 3 );
add_filter( 'get_post_metadata', '_wp_preview_post_thumbnail_filter', 10, 3 );
return $post;
}
/**
* Filters the latest content for preview from the post autosave.
*
* @since 2.7.0
* @access private
*/
function _show_post_preview() {
if ( isset($_GET['preview_id']) && isset($_GET['preview_nonce']) ) {
$id = (int) $_GET['preview_id'];
if ( false === wp_verify_nonce( $_GET['preview_nonce'], 'post_preview_' . $id ) )
wp_die( __('Sorry, you are not allowed to preview drafts.') );
add_filter('the_preview', '_set_preview');
}
}
/**
* Filters terms lookup to set the post format.
*
* @since 3.6.0
* @access private
*
* @param array $terms
* @param int $post_id
* @param string $taxonomy
* @return array
*/
function _wp_preview_terms_filter( $terms, $post_id, $taxonomy ) {
if ( ! $post = get_post() )
return $terms;
if ( empty( $_REQUEST['post_format'] ) || $post->ID != $post_id || 'post_format' != $taxonomy || 'revision' == $post->post_type )
return $terms;
if ( 'standard' == $_REQUEST['post_format'] )
$terms = array();
elseif ( $term = get_term_by( 'slug', 'post-format-' . sanitize_key( $_REQUEST['post_format'] ), 'post_format' ) )
$terms = array( $term ); // Can only have one post format
return $terms;
}
/**
* Filters post thumbnail lookup to set the post thumbnail.
*
* @since 4.6.0
* @access private
*
* @param null|array|string $value The value to return - a single metadata value, or an array of values.
* @param int $post_id Post ID.
* @param string $meta_key Meta key.
* @return null|array The default return value or the post thumbnail meta array.
*/
function _wp_preview_post_thumbnail_filter( $value, $post_id, $meta_key ) {
if ( ! $post = get_post() ) {
return $value;
}
if ( empty( $_REQUEST['_thumbnail_id'] ) ||
empty( $_REQUEST['preview_id'] ) ||
$post->ID != $post_id ||
'_thumbnail_id' != $meta_key ||
'revision' == $post->post_type ||
$post_id != $_REQUEST['preview_id']
) {
return $value;
}
$thumbnail_id = intval( $_REQUEST['_thumbnail_id'] );
if ( $thumbnail_id <= 0 ) {
return '';
}
return strval( $thumbnail_id );
}
/**
* Gets the post revision version.
*
* @since 3.6.0
* @access private
*
* @param WP_Post $revision
* @return int|false
*/
function _wp_get_post_revision_version( $revision ) {
if ( is_object( $revision ) )
$revision = get_object_vars( $revision );
elseif ( !is_array( $revision ) )
return false;
if ( preg_match( '/^\d+-(?:autosave|revision)-v(\d+)$/', $revision['post_name'], $matches ) )
return (int) $matches[1];
return 0;
}
/**
* Upgrade the revisions author, add the current post as a revision and set the revisions version to 1
*
* @since 3.6.0
* @access private
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @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
*/
function _wp_upgrade_revisions_of_post( $post, $revisions ) {
global $wpdb;
// Add post option exclusively
$lock = "revision-upgrade-{$post->ID}";
$now = time();
$result = $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, 'no') /* LOCK */", $lock, $now ) );
if ( ! $result ) {
// If we couldn't get a lock, see how old the previous lock is
$locked = get_option( $lock );
if ( ! $locked ) {
// Can't write to the lock, and can't read the lock.
// Something broken has happened
return false;
}
if ( $locked > $now - 3600 ) {
// Lock is not too old: some other process may be upgrading this post. Bail.
return false;
}
// Lock is too old - update it (below) and continue
}
// If we could get a lock, re-"add" the option to fire all the correct filters.
update_option( $lock, $now );
reset( $revisions );
$add_last = true;
do {
$this_revision = current( $revisions );
$prev_revision = next( $revisions );
$this_revision_version = _wp_get_post_revision_version( $this_revision );
// Something terrible happened
if ( false === $this_revision_version )
continue;
// 1 is the latest revision version, so we're already up to date.
// No need to add a copy of the post as latest revision.
if ( 0 < $this_revision_version ) {
$add_last = false;
continue;
}
// Always update the revision version
$update = array(
'post_name' => preg_replace( '/^(\d+-(?:autosave|revision))[\d-]*$/', '$1-v1', $this_revision->post_name ),
);
// If this revision is the oldest revision of the post, i.e. no $prev_revision,
// the correct post_author is probably $post->post_author, but that's only a good guess.
// Update the revision version only and Leave the author as-is.
if ( $prev_revision ) {
$prev_revision_version = _wp_get_post_revision_version( $prev_revision );
// If the previous revision is already up to date, it no longer has the information we need :(
if ( $prev_revision_version < 1 )
$update['post_author'] = $prev_revision->post_author;
}
// Upgrade this revision
$result = $wpdb->update( $wpdb->posts, $update, array( 'ID' => $this_revision->ID ) );
if ( $result )
wp_cache_delete( $this_revision->ID, 'posts' );
} while ( $prev_revision );
delete_option( $lock );
// Add a copy of the post as latest revision.
if ( $add_last )
wp_save_post_revision( $post->ID );
return true;
}
home/xbodynamge/crosstraining/wp-admin/includes/revision.php 0000604 00000035143 15112370350 0020406 0 ustar 00 <?php
/**
* WordPress Administration Revisions API
*
* @package WordPress
* @subpackage Administration
* @since 3.6.0
*/
/**
* Get the revision UI diff.
*
* @since 3.6.0
*
* @param object|int $post The post object. Also accepts a post ID.
* @param int $compare_from The revision ID to compare from.
* @param int $compare_to The revision ID to come to.
*
* @return array|bool Associative array of a post's revisioned fields and their diffs.
* Or, false on failure.
*/
function wp_get_revision_ui_diff( $post, $compare_from, $compare_to ) {
if ( ! $post = get_post( $post ) )
return false;
if ( $compare_from ) {
if ( ! $compare_from = get_post( $compare_from ) )
return false;
} else {
// If we're dealing with the first revision...
$compare_from = false;
}
if ( ! $compare_to = get_post( $compare_to ) )
return false;
// If comparing revisions, make sure we're dealing with the right post parent.
// The parent post may be a 'revision' when revisions are disabled and we're looking at autosaves.
if ( $compare_from && $compare_from->post_parent !== $post->ID && $compare_from->ID !== $post->ID )
return false;
if ( $compare_to->post_parent !== $post->ID && $compare_to->ID !== $post->ID )
return false;
if ( $compare_from && strtotime( $compare_from->post_date_gmt ) > strtotime( $compare_to->post_date_gmt ) ) {
$temp = $compare_from;
$compare_from = $compare_to;
$compare_to = $temp;
}
// Add default title if title field is empty
if ( $compare_from && empty( $compare_from->post_title ) )
$compare_from->post_title = __( '(no title)' );
if ( empty( $compare_to->post_title ) )
$compare_to->post_title = __( '(no title)' );
$return = array();
foreach ( _wp_post_revision_fields( $post ) as $field => $name ) {
/**
* Contextually filter a post revision field.
*
* The dynamic portion of the hook name, `$field`, corresponds to each of the post
* fields of the revision object being iterated over in a foreach statement.
*
* @since 3.6.0
*
* @param string $compare_from->$field The current revision field to compare to or from.
* @param string $field The current revision field.
* @param WP_Post $compare_from The revision post object to compare to or from.
* @param string null The context of whether the current revision is the old
* or the new one. Values are 'to' or 'from'.
*/
$content_from = $compare_from ? apply_filters( "_wp_post_revision_field_{$field}", $compare_from->$field, $field, $compare_from, 'from' ) : '';
/** This filter is documented in wp-admin/includes/revision.php */
$content_to = apply_filters( "_wp_post_revision_field_{$field}", $compare_to->$field, $field, $compare_to, 'to' );
$args = array(
'show_split_view' => true
);
/**
* Filters revisions text diff options.
*
* Filters the options passed to wp_text_diff() when viewing a post revision.
*
* @since 4.1.0
*
* @param array $args {
* Associative array of options to pass to wp_text_diff().
*
* @type bool $show_split_view True for split view (two columns), false for
* un-split view (single column). Default true.
* }
* @param string $field The current revision field.
* @param WP_Post $compare_from The revision post to compare from.
* @param WP_Post $compare_to The revision post to compare to.
*/
$args = apply_filters( 'revision_text_diff_options', $args, $field, $compare_from, $compare_to );
$diff = wp_text_diff( $content_from, $content_to, $args );
if ( ! $diff && 'post_title' === $field ) {
// It's a better user experience to still show the Title, even if it didn't change.
// No, you didn't see this.
$diff = '<table class="diff"><colgroup><col class="content diffsplit left"><col class="content diffsplit middle"><col class="content diffsplit right"></colgroup><tbody><tr>';
$diff .= '<td>' . esc_html( $compare_from->post_title ) . '</td><td></td><td>' . esc_html( $compare_to->post_title ) . '</td>';
$diff .= '</tr></tbody>';
$diff .= '</table>';
}
if ( $diff ) {
$return[] = array(
'id' => $field,
'name' => $name,
'diff' => $diff,
);
}
}
/**
* Filters the fields displayed in the post revision diff UI.
*
* @since 4.1.0
*
* @param array $return Revision UI fields. Each item is an array of id, name and diff.
* @param WP_Post $compare_from The revision post to compare from.
* @param WP_Post $compare_to The revision post to compare to.
*/
return apply_filters( 'wp_get_revision_ui_diff', $return, $compare_from, $compare_to );
}
/**
* Prepare revisions for JavaScript.
*
* @since 3.6.0
*
* @param object|int $post The post object. Also accepts a post ID.
* @param int $selected_revision_id The selected revision ID.
* @param int $from Optional. The revision ID to compare from.
*
* @return array An associative array of revision data and related settings.
*/
function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null ) {
$post = get_post( $post );
$authors = array();
$now_gmt = time();
$revisions = wp_get_post_revisions( $post->ID, array( 'order' => 'ASC', 'check_enabled' => false ) );
// If revisions are disabled, we only want autosaves and the current post.
if ( ! wp_revisions_enabled( $post ) ) {
foreach ( $revisions as $revision_id => $revision ) {
if ( ! wp_is_post_autosave( $revision ) )
unset( $revisions[ $revision_id ] );
}
$revisions = array( $post->ID => $post ) + $revisions;
}
$show_avatars = get_option( 'show_avatars' );
cache_users( wp_list_pluck( $revisions, 'post_author' ) );
$can_restore = current_user_can( 'edit_post', $post->ID );
$current_id = false;
foreach ( $revisions as $revision ) {
$modified = strtotime( $revision->post_modified );
$modified_gmt = strtotime( $revision->post_modified_gmt . ' +0000' );
if ( $can_restore ) {
$restore_link = str_replace( '&', '&', wp_nonce_url(
add_query_arg(
array( 'revision' => $revision->ID,
'action' => 'restore' ),
admin_url( 'revision.php' )
),
"restore-post_{$revision->ID}"
) );
}
if ( ! isset( $authors[ $revision->post_author ] ) ) {
$authors[ $revision->post_author ] = array(
'id' => (int) $revision->post_author,
'avatar' => $show_avatars ? get_avatar( $revision->post_author, 32 ) : '',
'name' => get_the_author_meta( 'display_name', $revision->post_author ),
);
}
$autosave = (bool) wp_is_post_autosave( $revision );
$current = ! $autosave && $revision->post_modified_gmt === $post->post_modified_gmt;
if ( $current && ! empty( $current_id ) ) {
// If multiple revisions have the same post_modified_gmt, highest ID is current.
if ( $current_id < $revision->ID ) {
$revisions[ $current_id ]['current'] = false;
$current_id = $revision->ID;
} else {
$current = false;
}
} elseif ( $current ) {
$current_id = $revision->ID;
}
$revisions_data = array(
'id' => $revision->ID,
'title' => get_the_title( $post->ID ),
'author' => $authors[ $revision->post_author ],
'date' => date_i18n( __( 'M j, Y @ H:i' ), $modified ),
'dateShort' => date_i18n( _x( 'j M @ H:i', 'revision date short format' ), $modified ),
'timeAgo' => sprintf( __( '%s ago' ), human_time_diff( $modified_gmt, $now_gmt ) ),
'autosave' => $autosave,
'current' => $current,
'restoreUrl' => $can_restore ? $restore_link : false,
);
/**
* Filters the array of revisions used on the revisions screen.
*
* @since 4.4.0
*
* @param array $revisions_data {
* The bootstrapped data for the revisions screen.
*
* @type int $id Revision ID.
* @type string $title Title for the revision's parent WP_Post object.
* @type int $author Revision post author ID.
* @type string $date Date the revision was modified.
* @type string $dateShort Short-form version of the date the revision was modified.
* @type string $timeAgo GMT-aware amount of time ago the revision was modified.
* @type bool $autosave Whether the revision is an autosave.
* @type bool $current Whether the revision is both not an autosave and the post
* modified date matches the revision modified date (GMT-aware).
* @type bool|false $restoreUrl URL if the revision can be restored, false otherwise.
* }
* @param WP_Post $revision The revision's WP_Post object.
* @param WP_Post $post The revision's parent WP_Post object.
*/
$revisions[ $revision->ID ] = apply_filters( 'wp_prepare_revision_for_js', $revisions_data, $revision, $post );
}
/**
* If we only have one revision, the initial revision is missing; This happens
* when we have an autsosave and the user has clicked 'View the Autosave'
*/
if ( 1 === sizeof( $revisions ) ) {
$revisions[ $post->ID ] = array(
'id' => $post->ID,
'title' => get_the_title( $post->ID ),
'author' => $authors[ $post->post_author ],
'date' => date_i18n( __( 'M j, Y @ H:i' ), strtotime( $post->post_modified ) ),
'dateShort' => date_i18n( _x( 'j M @ H:i', 'revision date short format' ), strtotime( $post->post_modified ) ),
'timeAgo' => sprintf( __( '%s ago' ), human_time_diff( strtotime( $post->post_modified_gmt ), $now_gmt ) ),
'autosave' => false,
'current' => true,
'restoreUrl' => false,
);
$current_id = $post->ID;
}
/*
* If a post has been saved since the last revision (no revisioned fields
* were changed), we may not have a "current" revision. Mark the latest
* revision as "current".
*/
if ( empty( $current_id ) ) {
if ( $revisions[ $revision->ID ]['autosave'] ) {
$revision = end( $revisions );
while ( $revision['autosave'] ) {
$revision = prev( $revisions );
}
$current_id = $revision['id'];
} else {
$current_id = $revision->ID;
}
$revisions[ $current_id ]['current'] = true;
}
// Now, grab the initial diff.
$compare_two_mode = is_numeric( $from );
if ( ! $compare_two_mode ) {
$found = array_search( $selected_revision_id, array_keys( $revisions ) );
if ( $found ) {
$from = array_keys( array_slice( $revisions, $found - 1, 1, true ) );
$from = reset( $from );
} else {
$from = 0;
}
}
$from = absint( $from );
$diffs = array( array(
'id' => $from . ':' . $selected_revision_id,
'fields' => wp_get_revision_ui_diff( $post->ID, $from, $selected_revision_id ),
));
return array(
'postId' => $post->ID,
'nonce' => wp_create_nonce( 'revisions-ajax-nonce' ),
'revisionData' => array_values( $revisions ),
'to' => $selected_revision_id,
'from' => $from,
'diffData' => $diffs,
'baseUrl' => parse_url( admin_url( 'revision.php' ), PHP_URL_PATH ),
'compareTwoMode' => absint( $compare_two_mode ), // Apparently booleans are not allowed
'revisionIds' => array_keys( $revisions ),
);
}
/**
* Print JavaScript templates required for the revisions experience.
*
* @since 4.1.0
*
* @global WP_Post $post The global `$post` object.
*/
function wp_print_revision_templates() {
global $post;
?><script id="tmpl-revisions-frame" type="text/html">
<div class="revisions-control-frame"></div>
<div class="revisions-diff-frame"></div>
</script>
<script id="tmpl-revisions-buttons" type="text/html">
<div class="revisions-previous">
<input class="button" type="button" value="<?php echo esc_attr_x( 'Previous', 'Button label for a previous revision' ); ?>" />
</div>
<div class="revisions-next">
<input class="button" type="button" value="<?php echo esc_attr_x( 'Next', 'Button label for a next revision' ); ?>" />
</div>
</script>
<script id="tmpl-revisions-checkbox" type="text/html">
<div class="revision-toggle-compare-mode">
<label>
<input type="checkbox" class="compare-two-revisions"
<#
if ( 'undefined' !== typeof data && data.model.attributes.compareTwoMode ) {
#> checked="checked"<#
}
#>
/>
<?php esc_html_e( 'Compare any two revisions' ); ?>
</label>
</div>
</script>
<script id="tmpl-revisions-meta" type="text/html">
<# if ( ! _.isUndefined( data.attributes ) ) { #>
<div class="diff-title">
<# if ( 'from' === data.type ) { #>
<strong><?php _ex( 'From:', 'Followed by post revision info' ); ?></strong>
<# } else if ( 'to' === data.type ) { #>
<strong><?php _ex( 'To:', 'Followed by post revision info' ); ?></strong>
<# } #>
<div class="author-card<# if ( data.attributes.autosave ) { #> autosave<# } #>">
{{{ data.attributes.author.avatar }}}
<div class="author-info">
<# if ( data.attributes.autosave ) { #>
<span class="byline"><?php printf( __( 'Autosave by %s' ),
'<span class="author-name">{{ data.attributes.author.name }}</span>' ); ?></span>
<# } else if ( data.attributes.current ) { #>
<span class="byline"><?php printf( __( 'Current Revision by %s' ),
'<span class="author-name">{{ data.attributes.author.name }}</span>' ); ?></span>
<# } else { #>
<span class="byline"><?php printf( __( 'Revision by %s' ),
'<span class="author-name">{{ data.attributes.author.name }}</span>' ); ?></span>
<# } #>
<span class="time-ago">{{ data.attributes.timeAgo }}</span>
<span class="date">({{ data.attributes.dateShort }})</span>
</div>
<# if ( 'to' === data.type && data.attributes.restoreUrl ) { #>
<input <?php if ( wp_check_post_lock( $post->ID ) ) { ?>
disabled="disabled"
<?php } else { ?>
<# if ( data.attributes.current ) { #>
disabled="disabled"
<# } #>
<?php } ?>
<# if ( data.attributes.autosave ) { #>
type="button" class="restore-revision button button-primary" value="<?php esc_attr_e( 'Restore This Autosave' ); ?>" />
<# } else { #>
type="button" class="restore-revision button button-primary" value="<?php esc_attr_e( 'Restore This Revision' ); ?>" />
<# } #>
<# } #>
</div>
<# if ( 'tooltip' === data.type ) { #>
<div class="revisions-tooltip-arrow"><span></span></div>
<# } #>
<# } #>
</script>
<script id="tmpl-revisions-diff" type="text/html">
<div class="loading-indicator"><span class="spinner"></span></div>
<div class="diff-error"><?php _e( 'Sorry, something went wrong. The requested comparison could not be loaded.' ); ?></div>
<div class="diff">
<# _.each( data.fields, function( field ) { #>
<h3>{{ field.name }}</h3>
{{{ field.diff }}}
<# }); #>
</div>
</script><?php
}
home/xbodynamge/crosstraining/wp-admin/revision.php 0000604 00000011657 15112463451 0016611 0 ustar 00 <?php
/**
* Revisions administration panel
*
* Requires wp-admin/includes/revision.php.
*
* @package WordPress
* @subpackage Administration
* @since 2.6.0
*
* @param int revision Optional. The revision ID.
* @param string action The action to take.
* Accepts 'restore', 'view' or 'edit'.
* @param int from The revision to compare from.
* @param int to Optional, required if revision missing. The revision to compare to.
*/
/** WordPress Administration Bootstrap */
require_once( dirname( __FILE__ ) . '/admin.php' );
require ABSPATH . 'wp-admin/includes/revision.php';
wp_reset_vars( array( 'revision', 'action', 'from', 'to' ) );
$revision_id = absint( $revision );
$from = is_numeric( $from ) ? absint( $from ) : null;
if ( ! $revision_id )
$revision_id = absint( $to );
$redirect = 'edit.php';
switch ( $action ) {
case 'restore' :
if ( ! $revision = wp_get_post_revision( $revision_id ) )
break;
if ( ! current_user_can( 'edit_post', $revision->post_parent ) )
break;
if ( ! $post = get_post( $revision->post_parent ) )
break;
// Restore if revisions are enabled or this is an autosave.
if ( ! wp_revisions_enabled( $post ) && ! wp_is_post_autosave( $revision ) ) {
$redirect = 'edit.php?post_type=' . $post->post_type;
break;
}
// Don't allow revision restore when post is locked
if ( wp_check_post_lock( $post->ID ) )
break;
check_admin_referer( "restore-post_{$revision->ID}" );
wp_restore_post_revision( $revision->ID );
$redirect = add_query_arg( array( 'message' => 5, 'revision' => $revision->ID ), get_edit_post_link( $post->ID, 'url' ) );
break;
case 'view' :
case 'edit' :
default :
if ( ! $revision = wp_get_post_revision( $revision_id ) )
break;
if ( ! $post = get_post( $revision->post_parent ) )
break;
if ( ! current_user_can( 'read_post', $revision->ID ) || ! current_user_can( 'edit_post', $revision->post_parent ) )
break;
// Revisions disabled and we're not looking at an autosave
if ( ! wp_revisions_enabled( $post ) && ! wp_is_post_autosave( $revision ) ) {
$redirect = 'edit.php?post_type=' . $post->post_type;
break;
}
$post_edit_link = get_edit_post_link();
$post_title = '<a href="' . $post_edit_link . '">' . _draft_or_post_title() . '</a>';
/* translators: 1: Post title */
$h1 = sprintf( __( 'Compare Revisions of “%1$s”' ), $post_title );
$return_to_post = '<a href="' . $post_edit_link . '">' . __( '← Return to editor' ) . '</a>';
$title = __( 'Revisions' );
$redirect = false;
break;
}
// Empty post_type means either malformed object found, or no valid parent was found.
if ( ! $redirect && empty( $post->post_type ) )
$redirect = 'edit.php';
if ( ! empty( $redirect ) ) {
wp_redirect( $redirect );
exit;
}
// This is so that the correct "Edit" menu item is selected.
if ( ! empty( $post->post_type ) && 'post' != $post->post_type )
$parent_file = $submenu_file = 'edit.php?post_type=' . $post->post_type;
else
$parent_file = $submenu_file = 'edit.php';
wp_enqueue_script( 'revisions' );
wp_localize_script( 'revisions', '_wpRevisionsSettings', wp_prepare_revisions_for_js( $post, $revision_id, $from ) );
/* Revisions Help Tab */
$revisions_overview = '<p>' . __( 'This screen is used for managing your content revisions.' ) . '</p>';
$revisions_overview .= '<p>' . __( 'Revisions are saved copies of your post or page, which are periodically created as you update your content. The red text on the left shows the content that was removed. The green text on the right shows the content that was added.' ) . '</p>';
$revisions_overview .= '<p>' . __( 'From this screen you can review, compare, and restore revisions:' ) . '</p>';
$revisions_overview .= '<ul><li>' . __( 'To navigate between revisions, <strong>drag the slider handle left or right</strong> or <strong>use the Previous or Next buttons</strong>.' ) . '</li>';
$revisions_overview .= '<li>' . __( 'Compare two different revisions by <strong>selecting the “Compare any two revisions” box</strong> to the side.' ) . '</li>';
$revisions_overview .= '<li>' . __( 'To restore a revision, <strong>click Restore This Revision</strong>.' ) . '</li></ul>';
get_current_screen()->add_help_tab( array(
'id' => 'revisions-overview',
'title' => __( 'Overview' ),
'content' => $revisions_overview
) );
$revisions_sidebar = '<p><strong>' . __( 'For more information:' ) . '</strong></p>';
$revisions_sidebar .= '<p>' . __( '<a href="https://codex.wordpress.org/Revision_Management">Revisions Management</a>' ) . '</p>';
$revisions_sidebar .= '<p>' . __( '<a href="https://wordpress.org/support/">Support Forums</a>' ) . '</p>';
get_current_screen()->set_help_sidebar( $revisions_sidebar );
require_once( ABSPATH . 'wp-admin/admin-header.php' );
?>
<div class="wrap">
<h1 class="long-header"><?php echo $h1; ?></h1>
<?php echo $return_to_post; ?>
</div>
<?php
wp_print_revision_templates();
require_once( ABSPATH . 'wp-admin/admin-footer.php' );
home/xbodynamge/crosstraining/wp-includes/revision.php 0000604 00000051471 15112655032 0017323 0 ustar 00 <?php
/**
* Post revision functions.
*
* @package WordPress
* @subpackage Post_Revisions
*/
/**
* Determines which fields of posts are to be saved in revisions.
*
* @since 2.6.0
* @since 4.5.0 A `WP_Post` object can now be passed to the `$post` parameter.
* @since 4.5.0 The optional `$autosave` parameter was deprecated and renamed to `$deprecated`.
* @access private
*
* @staticvar array $fields
*
* @param array|WP_Post $post Optional. A post array or a WP_Post object being processed
* for insertion as a post revision. Default empty array.
* @param bool $deprecated Not used.
* @return array Array of fields that can be versioned.
*/
function _wp_post_revision_fields( $post = array(), $deprecated = false ) {
static $fields = null;
if ( ! is_array( $post ) ) {
$post = get_post( $post, ARRAY_A );
}
if ( is_null( $fields ) ) {
// Allow these to be versioned
$fields = array(
'post_title' => __( 'Title' ),
'post_content' => __( 'Content' ),
'post_excerpt' => __( 'Excerpt' ),
);
}
/**
* Filters the list of fields saved in post revisions.
*
* Included by default: 'post_title', 'post_content' and 'post_excerpt'.
*
* Disallowed fields: 'ID', 'post_name', 'post_parent', 'post_date',
* 'post_date_gmt', 'post_status', 'post_type', 'comment_count',
* and 'post_author'.
*
* @since 2.6.0
* @since 4.5.0 The `$post` parameter was added.
*
* @param array $fields List of fields to revision. Contains 'post_title',
* 'post_content', and 'post_excerpt' by default.
* @param array $post A post array being processed for insertion as a post revision.
*/
$fields = apply_filters( '_wp_post_revision_fields', $fields, $post );
// WP uses these internally either in versioning or elsewhere - they cannot be versioned
foreach ( array( 'ID', 'post_name', 'post_parent', 'post_date', 'post_date_gmt', 'post_status', 'post_type', 'comment_count', 'post_author' ) as $protect ) {
unset( $fields[ $protect ] );
}
return $fields;
}
/**
* Returns a post array ready to be inserted into the posts table as a post revision.
*
* @since 4.5.0
* @access private
*
* @param array|WP_Post $post Optional. A post array or a WP_Post object to be processed
* for insertion as a post revision. Default empty array.
* @param bool $autosave Optional. Is the revision an autosave? Default false.
* @return array Post array ready to be inserted as a post revision.
*/
function _wp_post_revision_data( $post = array(), $autosave = false ) {
if ( ! is_array( $post ) ) {
$post = get_post( $post, ARRAY_A );
}
$fields = _wp_post_revision_fields( $post );
$revision_data = array();
foreach ( array_intersect( array_keys( $post ), array_keys( $fields ) ) as $field ) {
$revision_data[ $field ] = $post[ $field ];
}
$revision_data['post_parent'] = $post['ID'];
$revision_data['post_status'] = 'inherit';
$revision_data['post_type'] = 'revision';
$revision_data['post_name'] = $autosave ? "$post[ID]-autosave-v1" : "$post[ID]-revision-v1"; // "1" is the revisioning system version
$revision_data['post_date'] = isset( $post['post_modified'] ) ? $post['post_modified'] : '';
$revision_data['post_date_gmt'] = isset( $post['post_modified_gmt'] ) ? $post['post_modified_gmt'] : '';
return $revision_data;
}
/**
* Creates a revision for the current version of a post.
*
* Typically used immediately after a post update, as every update is a revision,
* and the most recent revision always matches the current post.
*
* @since 2.6.0
*
* @param int $post_id The ID of the post to save as a revision.
* @return int|WP_Error|void Void or 0 if error, new revision ID, if success.
*/
function wp_save_post_revision( $post_id ) {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
if ( ! $post = get_post( $post_id ) )
return;
if ( ! post_type_supports( $post->post_type, 'revisions' ) )
return;
if ( 'auto-draft' == $post->post_status )
return;
if ( ! wp_revisions_enabled( $post ) )
return;
// Compare the proposed update with the last stored revision verifying that
// they are different, unless a plugin tells us to always save regardless.
// If no previous revisions, save one
if ( $revisions = wp_get_post_revisions( $post_id ) ) {
// grab the last revision, but not an autosave
foreach ( $revisions as $revision ) {
if ( false !== strpos( $revision->post_name, "{$revision->post_parent}-revision" ) ) {
$last_revision = $revision;
break;
}
}
/**
* Filters whether the post has changed since the last revision.
*
* By default a revision is saved only if one of the revisioned fields has changed.
* This filter can override that so a revision is saved even if nothing has changed.
*
* @since 3.6.0
*
* @param bool $check_for_changes Whether to check for changes before saving a new revision.
* Default true.
* @param WP_Post $last_revision The last revision post object.
* @param WP_Post $post The post object.
*
*/
if ( isset( $last_revision ) && apply_filters( 'wp_save_post_revision_check_for_changes', $check_for_changes = true, $last_revision, $post ) ) {
$post_has_changed = false;
foreach ( array_keys( _wp_post_revision_fields( $post ) ) as $field ) {
if ( normalize_whitespace( $post->$field ) != normalize_whitespace( $last_revision->$field ) ) {
$post_has_changed = true;
break;
}
}
/**
* Filters whether a post has changed.
*
* By default a revision is saved only if one of the revisioned fields has changed.
* This filter allows for additional checks to determine if there were changes.
*
* @since 4.1.0
*
* @param bool $post_has_changed Whether the post has changed.
* @param WP_Post $last_revision The last revision post object.
* @param WP_Post $post The post object.
*
*/
$post_has_changed = (bool) apply_filters( 'wp_save_post_revision_post_has_changed', $post_has_changed, $last_revision, $post );
//don't save revision if post unchanged
if ( ! $post_has_changed ) {
return;
}
}
}
$return = _wp_put_post_revision( $post );
// If a limit for the number of revisions to keep has been set,
// delete the oldest ones.
$revisions_to_keep = wp_revisions_to_keep( $post );
if ( $revisions_to_keep < 0 )
return $return;
$revisions = wp_get_post_revisions( $post_id, array( 'order' => 'ASC' ) );
$delete = count($revisions) - $revisions_to_keep;
if ( $delete < 1 )
return $return;
$revisions = array_slice( $revisions, 0, $delete );
for ( $i = 0; isset( $revisions[$i] ); $i++ ) {
if ( false !== strpos( $revisions[ $i ]->post_name, 'autosave' ) )
continue;
wp_delete_post_revision( $revisions[ $i ]->ID );
}
return $return;
}
/**
* Retrieve the autosaved data of the specified post.
*
* Returns a post object containing the information that was autosaved for the
* specified post. If the optional $user_id is passed, returns the autosave for that user
* otherwise returns the latest autosave.
*
* @since 2.6.0
*
* @param int $post_id The post ID.
* @param int $user_id Optional The post author ID.
* @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 ) {
$revisions = wp_get_post_revisions( $post_id, array( 'check_enabled' => false ) );
foreach ( $revisions as $revision ) {
if ( false !== strpos( $revision->post_name, "{$post_id}-autosave" ) ) {
if ( $user_id && $user_id != $revision->post_author )
continue;
return $revision;
}
}
return false;
}
/**
* Determines if the specified post is a revision.
*
* @since 2.6.0
*
* @param int|WP_Post $post Post ID or post object.
* @return false|int False if not a revision, ID of revision's parent otherwise.
*/
function wp_is_post_revision( $post ) {
if ( !$post = wp_get_post_revision( $post ) )
return false;
return (int) $post->post_parent;
}
/**
* Determines if the specified post is an autosave.
*
* @since 2.6.0
*
* @param int|WP_Post $post Post ID or post object.
* @return false|int False if not a revision, ID of autosave's parent otherwise
*/
function wp_is_post_autosave( $post ) {
if ( !$post = wp_get_post_revision( $post ) )
return false;
if ( false !== strpos( $post->post_name, "{$post->post_parent}-autosave" ) )
return (int) $post->post_parent;
return false;
}
/**
* Inserts post data into the posts table as a post revision.
*
* @since 2.6.0
* @access private
*
* @param int|WP_Post|array|null $post Post ID, post object OR post array.
* @param bool $autosave Optional. Is the revision an autosave?
* @return int|WP_Error WP_Error or 0 if error, new revision ID if success.
*/
function _wp_put_post_revision( $post = null, $autosave = false ) {
if ( is_object($post) )
$post = get_object_vars( $post );
elseif ( !is_array($post) )
$post = get_post($post, ARRAY_A);
if ( ! $post || empty($post['ID']) )
return new WP_Error( 'invalid_post', __( 'Invalid post ID.' ) );
if ( isset($post['post_type']) && 'revision' == $post['post_type'] )
return new WP_Error( 'post_type', __( 'Cannot create a revision of a revision' ) );
$post = _wp_post_revision_data( $post, $autosave );
$post = wp_slash($post); //since data is from db
$revision_id = wp_insert_post( $post );
if ( is_wp_error($revision_id) )
return $revision_id;
if ( $revision_id ) {
/**
* Fires once a revision has been saved.
*
* @since 2.6.0
*
* @param int $revision_id Post revision ID.
*/
do_action( '_wp_put_post_revision', $revision_id );
}
return $revision_id;
}
/**
* Gets a post revision.
*
* @since 2.6.0
*
* @param int|WP_Post $post The post ID or object.
* @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to
* a WP_Post object, an associative array, or a numeric array, respectively. Default OBJECT.
* @param string $filter Optional sanitation filter. See sanitize_post().
* @return WP_Post|array|null WP_Post (or array) on success, or null on failure.
*/
function wp_get_post_revision(&$post, $output = OBJECT, $filter = 'raw') {
if ( !$revision = get_post( $post, OBJECT, $filter ) )
return $revision;
if ( 'revision' !== $revision->post_type )
return null;
if ( $output == OBJECT ) {
return $revision;
} elseif ( $output == ARRAY_A ) {
$_revision = get_object_vars($revision);
return $_revision;
} elseif ( $output == ARRAY_N ) {
$_revision = array_values(get_object_vars($revision));
return $_revision;
}
return $revision;
}
/**
* Restores a post to the specified revision.
*
* Can restore a past revision using all fields of the post revision, or only selected fields.
*
* @since 2.6.0
*
* @param int|WP_Post $revision_id Revision ID or revision object.
* @param array $fields Optional. What fields to restore from. Defaults to all.
* @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 ) {
if ( !$revision = wp_get_post_revision( $revision_id, ARRAY_A ) )
return $revision;
if ( !is_array( $fields ) )
$fields = array_keys( _wp_post_revision_fields( $revision ) );
$update = array();
foreach ( array_intersect( array_keys( $revision ), $fields ) as $field ) {
$update[$field] = $revision[$field];
}
if ( !$update )
return false;
$update['ID'] = $revision['post_parent'];
$update = wp_slash( $update ); //since data is from db
$post_id = wp_update_post( $update );
if ( ! $post_id || is_wp_error( $post_id ) )
return $post_id;
// Update last edit user
update_post_meta( $post_id, '_edit_last', get_current_user_id() );
/**
* Fires after a post revision has been restored.
*
* @since 2.6.0
*
* @param int $post_id Post ID.
* @param int $revision_id Post revision ID.
*/
do_action( 'wp_restore_post_revision', $post_id, $revision['ID'] );
return $post_id;
}
/**
* Deletes a revision.
*
* Deletes the row from the posts table corresponding to the specified revision.
*
* @since 2.6.0
*
* @param int|WP_Post $revision_id Revision ID or revision object.
* @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 ) {
if ( ! $revision = wp_get_post_revision( $revision_id ) ) {
return $revision;
}
$delete = wp_delete_post( $revision->ID );
if ( $delete ) {
/**
* Fires once a post revision has been deleted.
*
* @since 2.6.0
*
* @param int $revision_id Post revision ID.
* @param object|array $revision Post revision object or array.
*/
do_action( 'wp_delete_post_revision', $revision->ID, $revision );
}
return $delete;
}
/**
* Returns all revisions of specified post.
*
* @since 2.6.0
*
* @see get_children()
*
* @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global `$post`.
* @param array|null $args Optional. Arguments for retrieving post revisions. Default null.
* @return array An array of revisions, or an empty array if none.
*/
function wp_get_post_revisions( $post_id = 0, $args = null ) {
$post = get_post( $post_id );
if ( ! $post || empty( $post->ID ) )
return array();
$defaults = array( 'order' => 'DESC', 'orderby' => 'date ID', 'check_enabled' => true );
$args = wp_parse_args( $args, $defaults );
if ( $args['check_enabled'] && ! wp_revisions_enabled( $post ) )
return array();
$args = array_merge( $args, array( 'post_parent' => $post->ID, 'post_type' => 'revision', 'post_status' => 'inherit' ) );
if ( ! $revisions = get_children( $args ) )
return array();
return $revisions;
}
/**
* Determine if revisions are enabled for a given post.
*
* @since 3.6.0
*
* @param WP_Post $post The post object.
* @return bool True if number of revisions to keep isn't zero, false otherwise.
*/
function wp_revisions_enabled( $post ) {
return wp_revisions_to_keep( $post ) !== 0;
}
/**
* Determine how many revisions to retain for a given post.
*
* By default, an infinite number of revisions are kept.
*
* The constant WP_POST_REVISIONS can be set in wp-config to specify the limit
* of revisions to keep.
*
* @since 3.6.0
*
* @param WP_Post $post The post object.
* @return int The number of revisions to keep.
*/
function wp_revisions_to_keep( $post ) {
$num = WP_POST_REVISIONS;
if ( true === $num )
$num = -1;
else
$num = intval( $num );
if ( ! post_type_supports( $post->post_type, 'revisions' ) )
$num = 0;
/**
* Filters the number of revisions to save for the given post.
*
* Overrides the value of WP_POST_REVISIONS.
*
* @since 3.6.0
*
* @param int $num Number of revisions to store.
* @param WP_Post $post Post object.
*/
return (int) apply_filters( 'wp_revisions_to_keep', $num, $post );
}
/**
* Sets up the post object for preview based on the post autosave.
*
* @since 2.7.0
* @access private
*
* @param WP_Post $post
* @return WP_Post|false
*/
function _set_preview( $post ) {
if ( ! is_object( $post ) ) {
return $post;
}
$preview = wp_get_post_autosave( $post->ID );
if ( ! is_object( $preview ) ) {
return $post;
}
$preview = sanitize_post( $preview );
$post->post_content = $preview->post_content;
$post->post_title = $preview->post_title;
$post->post_excerpt = $preview->post_excerpt;
add_filter( 'get_the_terms', '_wp_preview_terms_filter', 10, 3 );
add_filter( 'get_post_metadata', '_wp_preview_post_thumbnail_filter', 10, 3 );
return $post;
}
/**
* Filters the latest content for preview from the post autosave.
*
* @since 2.7.0
* @access private
*/
function _show_post_preview() {
if ( isset($_GET['preview_id']) && isset($_GET['preview_nonce']) ) {
$id = (int) $_GET['preview_id'];
if ( false === wp_verify_nonce( $_GET['preview_nonce'], 'post_preview_' . $id ) )
wp_die( __('Sorry, you are not allowed to preview drafts.') );
add_filter('the_preview', '_set_preview');
}
}
/**
* Filters terms lookup to set the post format.
*
* @since 3.6.0
* @access private
*
* @param array $terms
* @param int $post_id
* @param string $taxonomy
* @return array
*/
function _wp_preview_terms_filter( $terms, $post_id, $taxonomy ) {
if ( ! $post = get_post() )
return $terms;
if ( empty( $_REQUEST['post_format'] ) || $post->ID != $post_id || 'post_format' != $taxonomy || 'revision' == $post->post_type )
return $terms;
if ( 'standard' == $_REQUEST['post_format'] )
$terms = array();
elseif ( $term = get_term_by( 'slug', 'post-format-' . sanitize_key( $_REQUEST['post_format'] ), 'post_format' ) )
$terms = array( $term ); // Can only have one post format
return $terms;
}
/**
* Filters post thumbnail lookup to set the post thumbnail.
*
* @since 4.6.0
* @access private
*
* @param null|array|string $value The value to return - a single metadata value, or an array of values.
* @param int $post_id Post ID.
* @param string $meta_key Meta key.
* @return null|array The default return value or the post thumbnail meta array.
*/
function _wp_preview_post_thumbnail_filter( $value, $post_id, $meta_key ) {
if ( ! $post = get_post() ) {
return $value;
}
if ( empty( $_REQUEST['_thumbnail_id'] ) ||
empty( $_REQUEST['preview_id'] ) ||
$post->ID != $post_id ||
'_thumbnail_id' != $meta_key ||
'revision' == $post->post_type ||
$post_id != $_REQUEST['preview_id']
) {
return $value;
}
$thumbnail_id = intval( $_REQUEST['_thumbnail_id'] );
if ( $thumbnail_id <= 0 ) {
return '';
}
return strval( $thumbnail_id );
}
/**
* Gets the post revision version.
*
* @since 3.6.0
* @access private
*
* @param WP_Post $revision
* @return int|false
*/
function _wp_get_post_revision_version( $revision ) {
if ( is_object( $revision ) )
$revision = get_object_vars( $revision );
elseif ( !is_array( $revision ) )
return false;
if ( preg_match( '/^\d+-(?:autosave|revision)-v(\d+)$/', $revision['post_name'], $matches ) )
return (int) $matches[1];
return 0;
}
/**
* Upgrade the revisions author, add the current post as a revision and set the revisions version to 1
*
* @since 3.6.0
* @access private
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @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
*/
function _wp_upgrade_revisions_of_post( $post, $revisions ) {
global $wpdb;
// Add post option exclusively
$lock = "revision-upgrade-{$post->ID}";
$now = time();
$result = $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, 'no') /* LOCK */", $lock, $now ) );
if ( ! $result ) {
// If we couldn't get a lock, see how old the previous lock is
$locked = get_option( $lock );
if ( ! $locked ) {
// Can't write to the lock, and can't read the lock.
// Something broken has happened
return false;
}
if ( $locked > $now - 3600 ) {
// Lock is not too old: some other process may be upgrading this post. Bail.
return false;
}
// Lock is too old - update it (below) and continue
}
// If we could get a lock, re-"add" the option to fire all the correct filters.
update_option( $lock, $now );
reset( $revisions );
$add_last = true;
do {
$this_revision = current( $revisions );
$prev_revision = next( $revisions );
$this_revision_version = _wp_get_post_revision_version( $this_revision );
// Something terrible happened
if ( false === $this_revision_version )
continue;
// 1 is the latest revision version, so we're already up to date.
// No need to add a copy of the post as latest revision.
if ( 0 < $this_revision_version ) {
$add_last = false;
continue;
}
// Always update the revision version
$update = array(
'post_name' => preg_replace( '/^(\d+-(?:autosave|revision))[\d-]*$/', '$1-v1', $this_revision->post_name ),
);
// If this revision is the oldest revision of the post, i.e. no $prev_revision,
// the correct post_author is probably $post->post_author, but that's only a good guess.
// Update the revision version only and Leave the author as-is.
if ( $prev_revision ) {
$prev_revision_version = _wp_get_post_revision_version( $prev_revision );
// If the previous revision is already up to date, it no longer has the information we need :(
if ( $prev_revision_version < 1 )
$update['post_author'] = $prev_revision->post_author;
}
// Upgrade this revision
$result = $wpdb->update( $wpdb->posts, $update, array( 'ID' => $this_revision->ID ) );
if ( $result )
wp_cache_delete( $this_revision->ID, 'posts' );
} while ( $prev_revision );
delete_option( $lock );
// Add a copy of the post as latest revision.
if ( $add_last )
wp_save_post_revision( $post->ID );
return true;
}
home/xbodynamge/namtation/wp-admin/includes/revision.php 0000604 00000036465 15113065253 0017527 0 ustar 00 <?php
/**
* WordPress Administration Revisions API
*
* @package WordPress
* @subpackage Administration
* @since 3.6.0
*/
/**
* Get the revision UI diff.
*
* @since 3.6.0
*
* @param object|int $post The post object. Also accepts a post ID.
* @param int $compare_from The revision ID to compare from.
* @param int $compare_to The revision ID to come to.
*
* @return array|bool Associative array of a post's revisioned fields and their diffs.
* Or, false on failure.
*/
function wp_get_revision_ui_diff( $post, $compare_from, $compare_to ) {
if ( ! $post = get_post( $post ) ) {
return false;
}
if ( $compare_from ) {
if ( ! $compare_from = get_post( $compare_from ) ) {
return false;
}
} else {
// If we're dealing with the first revision...
$compare_from = false;
}
if ( ! $compare_to = get_post( $compare_to ) ) {
return false;
}
// If comparing revisions, make sure we're dealing with the right post parent.
// The parent post may be a 'revision' when revisions are disabled and we're looking at autosaves.
if ( $compare_from && $compare_from->post_parent !== $post->ID && $compare_from->ID !== $post->ID ) {
return false;
}
if ( $compare_to->post_parent !== $post->ID && $compare_to->ID !== $post->ID ) {
return false;
}
if ( $compare_from && strtotime( $compare_from->post_date_gmt ) > strtotime( $compare_to->post_date_gmt ) ) {
$temp = $compare_from;
$compare_from = $compare_to;
$compare_to = $temp;
}
// Add default title if title field is empty
if ( $compare_from && empty( $compare_from->post_title ) ) {
$compare_from->post_title = __( '(no title)' );
}
if ( empty( $compare_to->post_title ) ) {
$compare_to->post_title = __( '(no title)' );
}
$return = array();
foreach ( _wp_post_revision_fields( $post ) as $field => $name ) {
/**
* Contextually filter a post revision field.
*
* The dynamic portion of the hook name, `$field`, corresponds to each of the post
* fields of the revision object being iterated over in a foreach statement.
*
* @since 3.6.0
*
* @param string $compare_from->$field The current revision field to compare to or from.
* @param string $field The current revision field.
* @param WP_Post $compare_from The revision post object to compare to or from.
* @param string null The context of whether the current revision is the old
* or the new one. Values are 'to' or 'from'.
*/
$content_from = $compare_from ? apply_filters( "_wp_post_revision_field_{$field}", $compare_from->$field, $field, $compare_from, 'from' ) : '';
/** This filter is documented in wp-admin/includes/revision.php */
$content_to = apply_filters( "_wp_post_revision_field_{$field}", $compare_to->$field, $field, $compare_to, 'to' );
$args = array(
'show_split_view' => true,
);
/**
* Filters revisions text diff options.
*
* Filters the options passed to wp_text_diff() when viewing a post revision.
*
* @since 4.1.0
*
* @param array $args {
* Associative array of options to pass to wp_text_diff().
*
* @type bool $show_split_view True for split view (two columns), false for
* un-split view (single column). Default true.
* }
* @param string $field The current revision field.
* @param WP_Post $compare_from The revision post to compare from.
* @param WP_Post $compare_to The revision post to compare to.
*/
$args = apply_filters( 'revision_text_diff_options', $args, $field, $compare_from, $compare_to );
$diff = wp_text_diff( $content_from, $content_to, $args );
if ( ! $diff && 'post_title' === $field ) {
// It's a better user experience to still show the Title, even if it didn't change.
// No, you didn't see this.
$diff = '<table class="diff"><colgroup><col class="content diffsplit left"><col class="content diffsplit middle"><col class="content diffsplit right"></colgroup><tbody><tr>';
// In split screen mode, show the title before/after side by side.
if ( true === $args['show_split_view'] ) {
$diff .= '<td>' . esc_html( $compare_from->post_title ) . '</td><td></td><td>' . esc_html( $compare_to->post_title ) . '</td>';
} else {
$diff .= '<td>' . esc_html( $compare_from->post_title ) . '</td>';
// In single column mode, only show the title once if unchanged.
if ( $compare_from->post_title !== $compare_to->post_title ) {
$diff .= '</tr><tr><td>' . esc_html( $compare_to->post_title ) . '</td>';
}
}
$diff .= '</tr></tbody>';
$diff .= '</table>';
}
if ( $diff ) {
$return[] = array(
'id' => $field,
'name' => $name,
'diff' => $diff,
);
}
}
/**
* Filters the fields displayed in the post revision diff UI.
*
* @since 4.1.0
*
* @param array[] $return Array of revision UI fields. Each item is an array of id, name, and diff.
* @param WP_Post $compare_from The revision post to compare from.
* @param WP_Post $compare_to The revision post to compare to.
*/
return apply_filters( 'wp_get_revision_ui_diff', $return, $compare_from, $compare_to );
}
/**
* Prepare revisions for JavaScript.
*
* @since 3.6.0
*
* @param object|int $post The post object. Also accepts a post ID.
* @param int $selected_revision_id The selected revision ID.
* @param int $from Optional. The revision ID to compare from.
*
* @return array An associative array of revision data and related settings.
*/
function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null ) {
$post = get_post( $post );
$authors = array();
$now_gmt = time();
$revisions = wp_get_post_revisions(
$post->ID,
array(
'order' => 'ASC',
'check_enabled' => false,
)
);
// If revisions are disabled, we only want autosaves and the current post.
if ( ! wp_revisions_enabled( $post ) ) {
foreach ( $revisions as $revision_id => $revision ) {
if ( ! wp_is_post_autosave( $revision ) ) {
unset( $revisions[ $revision_id ] );
}
}
$revisions = array( $post->ID => $post ) + $revisions;
}
$show_avatars = get_option( 'show_avatars' );
cache_users( wp_list_pluck( $revisions, 'post_author' ) );
$can_restore = current_user_can( 'edit_post', $post->ID );
$current_id = false;
foreach ( $revisions as $revision ) {
$modified = strtotime( $revision->post_modified );
$modified_gmt = strtotime( $revision->post_modified_gmt . ' +0000' );
if ( $can_restore ) {
$restore_link = str_replace(
'&',
'&',
wp_nonce_url(
add_query_arg(
array(
'revision' => $revision->ID,
'action' => 'restore',
),
admin_url( 'revision.php' )
),
"restore-post_{$revision->ID}"
)
);
}
if ( ! isset( $authors[ $revision->post_author ] ) ) {
$authors[ $revision->post_author ] = array(
'id' => (int) $revision->post_author,
'avatar' => $show_avatars ? get_avatar( $revision->post_author, 32 ) : '',
'name' => get_the_author_meta( 'display_name', $revision->post_author ),
);
}
$autosave = (bool) wp_is_post_autosave( $revision );
$current = ! $autosave && $revision->post_modified_gmt === $post->post_modified_gmt;
if ( $current && ! empty( $current_id ) ) {
// If multiple revisions have the same post_modified_gmt, highest ID is current.
if ( $current_id < $revision->ID ) {
$revisions[ $current_id ]['current'] = false;
$current_id = $revision->ID;
} else {
$current = false;
}
} elseif ( $current ) {
$current_id = $revision->ID;
}
$revisions_data = array(
'id' => $revision->ID,
'title' => get_the_title( $post->ID ),
'author' => $authors[ $revision->post_author ],
'date' => date_i18n( __( 'M j, Y @ H:i' ), $modified ),
'dateShort' => date_i18n( _x( 'j M @ H:i', 'revision date short format' ), $modified ),
'timeAgo' => sprintf( __( '%s ago' ), human_time_diff( $modified_gmt, $now_gmt ) ),
'autosave' => $autosave,
'current' => $current,
'restoreUrl' => $can_restore ? $restore_link : false,
);
/**
* Filters the array of revisions used on the revisions screen.
*
* @since 4.4.0
*
* @param array $revisions_data {
* The bootstrapped data for the revisions screen.
*
* @type int $id Revision ID.
* @type string $title Title for the revision's parent WP_Post object.
* @type int $author Revision post author ID.
* @type string $date Date the revision was modified.
* @type string $dateShort Short-form version of the date the revision was modified.
* @type string $timeAgo GMT-aware amount of time ago the revision was modified.
* @type bool $autosave Whether the revision is an autosave.
* @type bool $current Whether the revision is both not an autosave and the post
* modified date matches the revision modified date (GMT-aware).
* @type bool|false $restoreUrl URL if the revision can be restored, false otherwise.
* }
* @param WP_Post $revision The revision's WP_Post object.
* @param WP_Post $post The revision's parent WP_Post object.
*/
$revisions[ $revision->ID ] = apply_filters( 'wp_prepare_revision_for_js', $revisions_data, $revision, $post );
}
/**
* If we only have one revision, the initial revision is missing; This happens
* when we have an autsosave and the user has clicked 'View the Autosave'
*/
if ( 1 === sizeof( $revisions ) ) {
$revisions[ $post->ID ] = array(
'id' => $post->ID,
'title' => get_the_title( $post->ID ),
'author' => $authors[ $post->post_author ],
'date' => date_i18n( __( 'M j, Y @ H:i' ), strtotime( $post->post_modified ) ),
'dateShort' => date_i18n( _x( 'j M @ H:i', 'revision date short format' ), strtotime( $post->post_modified ) ),
'timeAgo' => sprintf( __( '%s ago' ), human_time_diff( strtotime( $post->post_modified_gmt ), $now_gmt ) ),
'autosave' => false,
'current' => true,
'restoreUrl' => false,
);
$current_id = $post->ID;
}
/*
* If a post has been saved since the last revision (no revisioned fields
* were changed), we may not have a "current" revision. Mark the latest
* revision as "current".
*/
if ( empty( $current_id ) ) {
if ( $revisions[ $revision->ID ]['autosave'] ) {
$revision = end( $revisions );
while ( $revision['autosave'] ) {
$revision = prev( $revisions );
}
$current_id = $revision['id'];
} else {
$current_id = $revision->ID;
}
$revisions[ $current_id ]['current'] = true;
}
// Now, grab the initial diff.
$compare_two_mode = is_numeric( $from );
if ( ! $compare_two_mode ) {
$found = array_search( $selected_revision_id, array_keys( $revisions ) );
if ( $found ) {
$from = array_keys( array_slice( $revisions, $found - 1, 1, true ) );
$from = reset( $from );
} else {
$from = 0;
}
}
$from = absint( $from );
$diffs = array(
array(
'id' => $from . ':' . $selected_revision_id,
'fields' => wp_get_revision_ui_diff( $post->ID, $from, $selected_revision_id ),
),
);
return array(
'postId' => $post->ID,
'nonce' => wp_create_nonce( 'revisions-ajax-nonce' ),
'revisionData' => array_values( $revisions ),
'to' => $selected_revision_id,
'from' => $from,
'diffData' => $diffs,
'baseUrl' => parse_url( admin_url( 'revision.php' ), PHP_URL_PATH ),
'compareTwoMode' => absint( $compare_two_mode ), // Apparently booleans are not allowed
'revisionIds' => array_keys( $revisions ),
);
}
/**
* Print JavaScript templates required for the revisions experience.
*
* @since 4.1.0
*
* @global WP_Post $post The global `$post` object.
*/
function wp_print_revision_templates() {
global $post;
?><script id="tmpl-revisions-frame" type="text/html">
<div class="revisions-control-frame"></div>
<div class="revisions-diff-frame"></div>
</script>
<script id="tmpl-revisions-buttons" type="text/html">
<div class="revisions-previous">
<input class="button" type="button" value="<?php echo esc_attr_x( 'Previous', 'Button label for a previous revision' ); ?>" />
</div>
<div class="revisions-next">
<input class="button" type="button" value="<?php echo esc_attr_x( 'Next', 'Button label for a next revision' ); ?>" />
</div>
</script>
<script id="tmpl-revisions-checkbox" type="text/html">
<div class="revision-toggle-compare-mode">
<label>
<input type="checkbox" class="compare-two-revisions"
<#
if ( 'undefined' !== typeof data && data.model.attributes.compareTwoMode ) {
#> checked="checked"<#
}
#>
/>
<?php esc_html_e( 'Compare any two revisions' ); ?>
</label>
</div>
</script>
<script id="tmpl-revisions-meta" type="text/html">
<# if ( ! _.isUndefined( data.attributes ) ) { #>
<div class="diff-title">
<# if ( 'from' === data.type ) { #>
<strong><?php _ex( 'From:', 'Followed by post revision info' ); ?></strong>
<# } else if ( 'to' === data.type ) { #>
<strong><?php _ex( 'To:', 'Followed by post revision info' ); ?></strong>
<# } #>
<div class="author-card<# if ( data.attributes.autosave ) { #> autosave<# } #>">
{{{ data.attributes.author.avatar }}}
<div class="author-info">
<# if ( data.attributes.autosave ) { #>
<span class="byline">
<?php
printf(
__( 'Autosave by %s' ),
'<span class="author-name">{{ data.attributes.author.name }}</span>'
);
?>
</span>
<# } else if ( data.attributes.current ) { #>
<span class="byline">
<?php
printf(
__( 'Current Revision by %s' ),
'<span class="author-name">{{ data.attributes.author.name }}</span>'
);
?>
</span>
<# } else { #>
<span class="byline">
<?php
printf(
__( 'Revision by %s' ),
'<span class="author-name">{{ data.attributes.author.name }}</span>'
);
?>
</span>
<# } #>
<span class="time-ago">{{ data.attributes.timeAgo }}</span>
<span class="date">({{ data.attributes.dateShort }})</span>
</div>
<# if ( 'to' === data.type && data.attributes.restoreUrl ) { #>
<input <?php if ( wp_check_post_lock( $post->ID ) ) { ?>
disabled="disabled"
<?php } else { ?>
<# if ( data.attributes.current ) { #>
disabled="disabled"
<# } #>
<?php } ?>
<# if ( data.attributes.autosave ) { #>
type="button" class="restore-revision button button-primary" value="<?php esc_attr_e( 'Restore This Autosave' ); ?>" />
<# } else { #>
type="button" class="restore-revision button button-primary" value="<?php esc_attr_e( 'Restore This Revision' ); ?>" />
<# } #>
<# } #>
</div>
<# if ( 'tooltip' === data.type ) { #>
<div class="revisions-tooltip-arrow"><span></span></div>
<# } #>
<# } #>
</script>
<script id="tmpl-revisions-diff" type="text/html">
<div class="loading-indicator"><span class="spinner"></span></div>
<div class="diff-error"><?php _e( 'Sorry, something went wrong. The requested comparison could not be loaded.' ); ?></div>
<div class="diff">
<# _.each( data.fields, function( field ) { #>
<h3>{{ field.name }}</h3>
{{{ field.diff }}}
<# }); #>
</div>
</script>
<?php
}
home/xbodynamge/www/wp-admin/revision.php 0000604 00000011657 15113154655 0014554 0 ustar 00 <?php
/**
* Revisions administration panel
*
* Requires wp-admin/includes/revision.php.
*
* @package WordPress
* @subpackage Administration
* @since 2.6.0
*
* @param int revision Optional. The revision ID.
* @param string action The action to take.
* Accepts 'restore', 'view' or 'edit'.
* @param int from The revision to compare from.
* @param int to Optional, required if revision missing. The revision to compare to.
*/
/** WordPress Administration Bootstrap */
require_once( dirname( __FILE__ ) . '/admin.php' );
require ABSPATH . 'wp-admin/includes/revision.php';
wp_reset_vars( array( 'revision', 'action', 'from', 'to' ) );
$revision_id = absint( $revision );
$from = is_numeric( $from ) ? absint( $from ) : null;
if ( ! $revision_id )
$revision_id = absint( $to );
$redirect = 'edit.php';
switch ( $action ) {
case 'restore' :
if ( ! $revision = wp_get_post_revision( $revision_id ) )
break;
if ( ! current_user_can( 'edit_post', $revision->post_parent ) )
break;
if ( ! $post = get_post( $revision->post_parent ) )
break;
// Restore if revisions are enabled or this is an autosave.
if ( ! wp_revisions_enabled( $post ) && ! wp_is_post_autosave( $revision ) ) {
$redirect = 'edit.php?post_type=' . $post->post_type;
break;
}
// Don't allow revision restore when post is locked
if ( wp_check_post_lock( $post->ID ) )
break;
check_admin_referer( "restore-post_{$revision->ID}" );
wp_restore_post_revision( $revision->ID );
$redirect = add_query_arg( array( 'message' => 5, 'revision' => $revision->ID ), get_edit_post_link( $post->ID, 'url' ) );
break;
case 'view' :
case 'edit' :
default :
if ( ! $revision = wp_get_post_revision( $revision_id ) )
break;
if ( ! $post = get_post( $revision->post_parent ) )
break;
if ( ! current_user_can( 'read_post', $revision->ID ) || ! current_user_can( 'edit_post', $revision->post_parent ) )
break;
// Revisions disabled and we're not looking at an autosave
if ( ! wp_revisions_enabled( $post ) && ! wp_is_post_autosave( $revision ) ) {
$redirect = 'edit.php?post_type=' . $post->post_type;
break;
}
$post_edit_link = get_edit_post_link();
$post_title = '<a href="' . $post_edit_link . '">' . _draft_or_post_title() . '</a>';
/* translators: 1: Post title */
$h1 = sprintf( __( 'Compare Revisions of “%1$s”' ), $post_title );
$return_to_post = '<a href="' . $post_edit_link . '">' . __( '← Return to editor' ) . '</a>';
$title = __( 'Revisions' );
$redirect = false;
break;
}
// Empty post_type means either malformed object found, or no valid parent was found.
if ( ! $redirect && empty( $post->post_type ) )
$redirect = 'edit.php';
if ( ! empty( $redirect ) ) {
wp_redirect( $redirect );
exit;
}
// This is so that the correct "Edit" menu item is selected.
if ( ! empty( $post->post_type ) && 'post' != $post->post_type )
$parent_file = $submenu_file = 'edit.php?post_type=' . $post->post_type;
else
$parent_file = $submenu_file = 'edit.php';
wp_enqueue_script( 'revisions' );
wp_localize_script( 'revisions', '_wpRevisionsSettings', wp_prepare_revisions_for_js( $post, $revision_id, $from ) );
/* Revisions Help Tab */
$revisions_overview = '<p>' . __( 'This screen is used for managing your content revisions.' ) . '</p>';
$revisions_overview .= '<p>' . __( 'Revisions are saved copies of your post or page, which are periodically created as you update your content. The red text on the left shows the content that was removed. The green text on the right shows the content that was added.' ) . '</p>';
$revisions_overview .= '<p>' . __( 'From this screen you can review, compare, and restore revisions:' ) . '</p>';
$revisions_overview .= '<ul><li>' . __( 'To navigate between revisions, <strong>drag the slider handle left or right</strong> or <strong>use the Previous or Next buttons</strong>.' ) . '</li>';
$revisions_overview .= '<li>' . __( 'Compare two different revisions by <strong>selecting the “Compare any two revisions” box</strong> to the side.' ) . '</li>';
$revisions_overview .= '<li>' . __( 'To restore a revision, <strong>click Restore This Revision</strong>.' ) . '</li></ul>';
get_current_screen()->add_help_tab( array(
'id' => 'revisions-overview',
'title' => __( 'Overview' ),
'content' => $revisions_overview
) );
$revisions_sidebar = '<p><strong>' . __( 'For more information:' ) . '</strong></p>';
$revisions_sidebar .= '<p>' . __( '<a href="https://codex.wordpress.org/Revision_Management">Revisions Management</a>' ) . '</p>';
$revisions_sidebar .= '<p>' . __( '<a href="https://wordpress.org/support/">Support Forums</a>' ) . '</p>';
get_current_screen()->set_help_sidebar( $revisions_sidebar );
require_once( ABSPATH . 'wp-admin/admin-header.php' );
?>
<div class="wrap">
<h1 class="long-header"><?php echo $h1; ?></h1>
<?php echo $return_to_post; ?>
</div>
<?php
wp_print_revision_templates();
require_once( ABSPATH . 'wp-admin/admin-footer.php' );
home/xbodynamge/www/wp-includes/revision.php 0000604 00000051471 15113161117 0015257 0 ustar 00 <?php
/**
* Post revision functions.
*
* @package WordPress
* @subpackage Post_Revisions
*/
/**
* Determines which fields of posts are to be saved in revisions.
*
* @since 2.6.0
* @since 4.5.0 A `WP_Post` object can now be passed to the `$post` parameter.
* @since 4.5.0 The optional `$autosave` parameter was deprecated and renamed to `$deprecated`.
* @access private
*
* @staticvar array $fields
*
* @param array|WP_Post $post Optional. A post array or a WP_Post object being processed
* for insertion as a post revision. Default empty array.
* @param bool $deprecated Not used.
* @return array Array of fields that can be versioned.
*/
function _wp_post_revision_fields( $post = array(), $deprecated = false ) {
static $fields = null;
if ( ! is_array( $post ) ) {
$post = get_post( $post, ARRAY_A );
}
if ( is_null( $fields ) ) {
// Allow these to be versioned
$fields = array(
'post_title' => __( 'Title' ),
'post_content' => __( 'Content' ),
'post_excerpt' => __( 'Excerpt' ),
);
}
/**
* Filters the list of fields saved in post revisions.
*
* Included by default: 'post_title', 'post_content' and 'post_excerpt'.
*
* Disallowed fields: 'ID', 'post_name', 'post_parent', 'post_date',
* 'post_date_gmt', 'post_status', 'post_type', 'comment_count',
* and 'post_author'.
*
* @since 2.6.0
* @since 4.5.0 The `$post` parameter was added.
*
* @param array $fields List of fields to revision. Contains 'post_title',
* 'post_content', and 'post_excerpt' by default.
* @param array $post A post array being processed for insertion as a post revision.
*/
$fields = apply_filters( '_wp_post_revision_fields', $fields, $post );
// WP uses these internally either in versioning or elsewhere - they cannot be versioned
foreach ( array( 'ID', 'post_name', 'post_parent', 'post_date', 'post_date_gmt', 'post_status', 'post_type', 'comment_count', 'post_author' ) as $protect ) {
unset( $fields[ $protect ] );
}
return $fields;
}
/**
* Returns a post array ready to be inserted into the posts table as a post revision.
*
* @since 4.5.0
* @access private
*
* @param array|WP_Post $post Optional. A post array or a WP_Post object to be processed
* for insertion as a post revision. Default empty array.
* @param bool $autosave Optional. Is the revision an autosave? Default false.
* @return array Post array ready to be inserted as a post revision.
*/
function _wp_post_revision_data( $post = array(), $autosave = false ) {
if ( ! is_array( $post ) ) {
$post = get_post( $post, ARRAY_A );
}
$fields = _wp_post_revision_fields( $post );
$revision_data = array();
foreach ( array_intersect( array_keys( $post ), array_keys( $fields ) ) as $field ) {
$revision_data[ $field ] = $post[ $field ];
}
$revision_data['post_parent'] = $post['ID'];
$revision_data['post_status'] = 'inherit';
$revision_data['post_type'] = 'revision';
$revision_data['post_name'] = $autosave ? "$post[ID]-autosave-v1" : "$post[ID]-revision-v1"; // "1" is the revisioning system version
$revision_data['post_date'] = isset( $post['post_modified'] ) ? $post['post_modified'] : '';
$revision_data['post_date_gmt'] = isset( $post['post_modified_gmt'] ) ? $post['post_modified_gmt'] : '';
return $revision_data;
}
/**
* Creates a revision for the current version of a post.
*
* Typically used immediately after a post update, as every update is a revision,
* and the most recent revision always matches the current post.
*
* @since 2.6.0
*
* @param int $post_id The ID of the post to save as a revision.
* @return int|WP_Error|void Void or 0 if error, new revision ID, if success.
*/
function wp_save_post_revision( $post_id ) {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
if ( ! $post = get_post( $post_id ) )
return;
if ( ! post_type_supports( $post->post_type, 'revisions' ) )
return;
if ( 'auto-draft' == $post->post_status )
return;
if ( ! wp_revisions_enabled( $post ) )
return;
// Compare the proposed update with the last stored revision verifying that
// they are different, unless a plugin tells us to always save regardless.
// If no previous revisions, save one
if ( $revisions = wp_get_post_revisions( $post_id ) ) {
// grab the last revision, but not an autosave
foreach ( $revisions as $revision ) {
if ( false !== strpos( $revision->post_name, "{$revision->post_parent}-revision" ) ) {
$last_revision = $revision;
break;
}
}
/**
* Filters whether the post has changed since the last revision.
*
* By default a revision is saved only if one of the revisioned fields has changed.
* This filter can override that so a revision is saved even if nothing has changed.
*
* @since 3.6.0
*
* @param bool $check_for_changes Whether to check for changes before saving a new revision.
* Default true.
* @param WP_Post $last_revision The last revision post object.
* @param WP_Post $post The post object.
*
*/
if ( isset( $last_revision ) && apply_filters( 'wp_save_post_revision_check_for_changes', $check_for_changes = true, $last_revision, $post ) ) {
$post_has_changed = false;
foreach ( array_keys( _wp_post_revision_fields( $post ) ) as $field ) {
if ( normalize_whitespace( $post->$field ) != normalize_whitespace( $last_revision->$field ) ) {
$post_has_changed = true;
break;
}
}
/**
* Filters whether a post has changed.
*
* By default a revision is saved only if one of the revisioned fields has changed.
* This filter allows for additional checks to determine if there were changes.
*
* @since 4.1.0
*
* @param bool $post_has_changed Whether the post has changed.
* @param WP_Post $last_revision The last revision post object.
* @param WP_Post $post The post object.
*
*/
$post_has_changed = (bool) apply_filters( 'wp_save_post_revision_post_has_changed', $post_has_changed, $last_revision, $post );
//don't save revision if post unchanged
if ( ! $post_has_changed ) {
return;
}
}
}
$return = _wp_put_post_revision( $post );
// If a limit for the number of revisions to keep has been set,
// delete the oldest ones.
$revisions_to_keep = wp_revisions_to_keep( $post );
if ( $revisions_to_keep < 0 )
return $return;
$revisions = wp_get_post_revisions( $post_id, array( 'order' => 'ASC' ) );
$delete = count($revisions) - $revisions_to_keep;
if ( $delete < 1 )
return $return;
$revisions = array_slice( $revisions, 0, $delete );
for ( $i = 0; isset( $revisions[$i] ); $i++ ) {
if ( false !== strpos( $revisions[ $i ]->post_name, 'autosave' ) )
continue;
wp_delete_post_revision( $revisions[ $i ]->ID );
}
return $return;
}
/**
* Retrieve the autosaved data of the specified post.
*
* Returns a post object containing the information that was autosaved for the
* specified post. If the optional $user_id is passed, returns the autosave for that user
* otherwise returns the latest autosave.
*
* @since 2.6.0
*
* @param int $post_id The post ID.
* @param int $user_id Optional The post author ID.
* @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 ) {
$revisions = wp_get_post_revisions( $post_id, array( 'check_enabled' => false ) );
foreach ( $revisions as $revision ) {
if ( false !== strpos( $revision->post_name, "{$post_id}-autosave" ) ) {
if ( $user_id && $user_id != $revision->post_author )
continue;
return $revision;
}
}
return false;
}
/**
* Determines if the specified post is a revision.
*
* @since 2.6.0
*
* @param int|WP_Post $post Post ID or post object.
* @return false|int False if not a revision, ID of revision's parent otherwise.
*/
function wp_is_post_revision( $post ) {
if ( !$post = wp_get_post_revision( $post ) )
return false;
return (int) $post->post_parent;
}
/**
* Determines if the specified post is an autosave.
*
* @since 2.6.0
*
* @param int|WP_Post $post Post ID or post object.
* @return false|int False if not a revision, ID of autosave's parent otherwise
*/
function wp_is_post_autosave( $post ) {
if ( !$post = wp_get_post_revision( $post ) )
return false;
if ( false !== strpos( $post->post_name, "{$post->post_parent}-autosave" ) )
return (int) $post->post_parent;
return false;
}
/**
* Inserts post data into the posts table as a post revision.
*
* @since 2.6.0
* @access private
*
* @param int|WP_Post|array|null $post Post ID, post object OR post array.
* @param bool $autosave Optional. Is the revision an autosave?
* @return int|WP_Error WP_Error or 0 if error, new revision ID if success.
*/
function _wp_put_post_revision( $post = null, $autosave = false ) {
if ( is_object($post) )
$post = get_object_vars( $post );
elseif ( !is_array($post) )
$post = get_post($post, ARRAY_A);
if ( ! $post || empty($post['ID']) )
return new WP_Error( 'invalid_post', __( 'Invalid post ID.' ) );
if ( isset($post['post_type']) && 'revision' == $post['post_type'] )
return new WP_Error( 'post_type', __( 'Cannot create a revision of a revision' ) );
$post = _wp_post_revision_data( $post, $autosave );
$post = wp_slash($post); //since data is from db
$revision_id = wp_insert_post( $post );
if ( is_wp_error($revision_id) )
return $revision_id;
if ( $revision_id ) {
/**
* Fires once a revision has been saved.
*
* @since 2.6.0
*
* @param int $revision_id Post revision ID.
*/
do_action( '_wp_put_post_revision', $revision_id );
}
return $revision_id;
}
/**
* Gets a post revision.
*
* @since 2.6.0
*
* @param int|WP_Post $post The post ID or object.
* @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to
* a WP_Post object, an associative array, or a numeric array, respectively. Default OBJECT.
* @param string $filter Optional sanitation filter. See sanitize_post().
* @return WP_Post|array|null WP_Post (or array) on success, or null on failure.
*/
function wp_get_post_revision(&$post, $output = OBJECT, $filter = 'raw') {
if ( !$revision = get_post( $post, OBJECT, $filter ) )
return $revision;
if ( 'revision' !== $revision->post_type )
return null;
if ( $output == OBJECT ) {
return $revision;
} elseif ( $output == ARRAY_A ) {
$_revision = get_object_vars($revision);
return $_revision;
} elseif ( $output == ARRAY_N ) {
$_revision = array_values(get_object_vars($revision));
return $_revision;
}
return $revision;
}
/**
* Restores a post to the specified revision.
*
* Can restore a past revision using all fields of the post revision, or only selected fields.
*
* @since 2.6.0
*
* @param int|WP_Post $revision_id Revision ID or revision object.
* @param array $fields Optional. What fields to restore from. Defaults to all.
* @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 ) {
if ( !$revision = wp_get_post_revision( $revision_id, ARRAY_A ) )
return $revision;
if ( !is_array( $fields ) )
$fields = array_keys( _wp_post_revision_fields( $revision ) );
$update = array();
foreach ( array_intersect( array_keys( $revision ), $fields ) as $field ) {
$update[$field] = $revision[$field];
}
if ( !$update )
return false;
$update['ID'] = $revision['post_parent'];
$update = wp_slash( $update ); //since data is from db
$post_id = wp_update_post( $update );
if ( ! $post_id || is_wp_error( $post_id ) )
return $post_id;
// Update last edit user
update_post_meta( $post_id, '_edit_last', get_current_user_id() );
/**
* Fires after a post revision has been restored.
*
* @since 2.6.0
*
* @param int $post_id Post ID.
* @param int $revision_id Post revision ID.
*/
do_action( 'wp_restore_post_revision', $post_id, $revision['ID'] );
return $post_id;
}
/**
* Deletes a revision.
*
* Deletes the row from the posts table corresponding to the specified revision.
*
* @since 2.6.0
*
* @param int|WP_Post $revision_id Revision ID or revision object.
* @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 ) {
if ( ! $revision = wp_get_post_revision( $revision_id ) ) {
return $revision;
}
$delete = wp_delete_post( $revision->ID );
if ( $delete ) {
/**
* Fires once a post revision has been deleted.
*
* @since 2.6.0
*
* @param int $revision_id Post revision ID.
* @param object|array $revision Post revision object or array.
*/
do_action( 'wp_delete_post_revision', $revision->ID, $revision );
}
return $delete;
}
/**
* Returns all revisions of specified post.
*
* @since 2.6.0
*
* @see get_children()
*
* @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global `$post`.
* @param array|null $args Optional. Arguments for retrieving post revisions. Default null.
* @return array An array of revisions, or an empty array if none.
*/
function wp_get_post_revisions( $post_id = 0, $args = null ) {
$post = get_post( $post_id );
if ( ! $post || empty( $post->ID ) )
return array();
$defaults = array( 'order' => 'DESC', 'orderby' => 'date ID', 'check_enabled' => true );
$args = wp_parse_args( $args, $defaults );
if ( $args['check_enabled'] && ! wp_revisions_enabled( $post ) )
return array();
$args = array_merge( $args, array( 'post_parent' => $post->ID, 'post_type' => 'revision', 'post_status' => 'inherit' ) );
if ( ! $revisions = get_children( $args ) )
return array();
return $revisions;
}
/**
* Determine if revisions are enabled for a given post.
*
* @since 3.6.0
*
* @param WP_Post $post The post object.
* @return bool True if number of revisions to keep isn't zero, false otherwise.
*/
function wp_revisions_enabled( $post ) {
return wp_revisions_to_keep( $post ) !== 0;
}
/**
* Determine how many revisions to retain for a given post.
*
* By default, an infinite number of revisions are kept.
*
* The constant WP_POST_REVISIONS can be set in wp-config to specify the limit
* of revisions to keep.
*
* @since 3.6.0
*
* @param WP_Post $post The post object.
* @return int The number of revisions to keep.
*/
function wp_revisions_to_keep( $post ) {
$num = WP_POST_REVISIONS;
if ( true === $num )
$num = -1;
else
$num = intval( $num );
if ( ! post_type_supports( $post->post_type, 'revisions' ) )
$num = 0;
/**
* Filters the number of revisions to save for the given post.
*
* Overrides the value of WP_POST_REVISIONS.
*
* @since 3.6.0
*
* @param int $num Number of revisions to store.
* @param WP_Post $post Post object.
*/
return (int) apply_filters( 'wp_revisions_to_keep', $num, $post );
}
/**
* Sets up the post object for preview based on the post autosave.
*
* @since 2.7.0
* @access private
*
* @param WP_Post $post
* @return WP_Post|false
*/
function _set_preview( $post ) {
if ( ! is_object( $post ) ) {
return $post;
}
$preview = wp_get_post_autosave( $post->ID );
if ( ! is_object( $preview ) ) {
return $post;
}
$preview = sanitize_post( $preview );
$post->post_content = $preview->post_content;
$post->post_title = $preview->post_title;
$post->post_excerpt = $preview->post_excerpt;
add_filter( 'get_the_terms', '_wp_preview_terms_filter', 10, 3 );
add_filter( 'get_post_metadata', '_wp_preview_post_thumbnail_filter', 10, 3 );
return $post;
}
/**
* Filters the latest content for preview from the post autosave.
*
* @since 2.7.0
* @access private
*/
function _show_post_preview() {
if ( isset($_GET['preview_id']) && isset($_GET['preview_nonce']) ) {
$id = (int) $_GET['preview_id'];
if ( false === wp_verify_nonce( $_GET['preview_nonce'], 'post_preview_' . $id ) )
wp_die( __('Sorry, you are not allowed to preview drafts.') );
add_filter('the_preview', '_set_preview');
}
}
/**
* Filters terms lookup to set the post format.
*
* @since 3.6.0
* @access private
*
* @param array $terms
* @param int $post_id
* @param string $taxonomy
* @return array
*/
function _wp_preview_terms_filter( $terms, $post_id, $taxonomy ) {
if ( ! $post = get_post() )
return $terms;
if ( empty( $_REQUEST['post_format'] ) || $post->ID != $post_id || 'post_format' != $taxonomy || 'revision' == $post->post_type )
return $terms;
if ( 'standard' == $_REQUEST['post_format'] )
$terms = array();
elseif ( $term = get_term_by( 'slug', 'post-format-' . sanitize_key( $_REQUEST['post_format'] ), 'post_format' ) )
$terms = array( $term ); // Can only have one post format
return $terms;
}
/**
* Filters post thumbnail lookup to set the post thumbnail.
*
* @since 4.6.0
* @access private
*
* @param null|array|string $value The value to return - a single metadata value, or an array of values.
* @param int $post_id Post ID.
* @param string $meta_key Meta key.
* @return null|array The default return value or the post thumbnail meta array.
*/
function _wp_preview_post_thumbnail_filter( $value, $post_id, $meta_key ) {
if ( ! $post = get_post() ) {
return $value;
}
if ( empty( $_REQUEST['_thumbnail_id'] ) ||
empty( $_REQUEST['preview_id'] ) ||
$post->ID != $post_id ||
'_thumbnail_id' != $meta_key ||
'revision' == $post->post_type ||
$post_id != $_REQUEST['preview_id']
) {
return $value;
}
$thumbnail_id = intval( $_REQUEST['_thumbnail_id'] );
if ( $thumbnail_id <= 0 ) {
return '';
}
return strval( $thumbnail_id );
}
/**
* Gets the post revision version.
*
* @since 3.6.0
* @access private
*
* @param WP_Post $revision
* @return int|false
*/
function _wp_get_post_revision_version( $revision ) {
if ( is_object( $revision ) )
$revision = get_object_vars( $revision );
elseif ( !is_array( $revision ) )
return false;
if ( preg_match( '/^\d+-(?:autosave|revision)-v(\d+)$/', $revision['post_name'], $matches ) )
return (int) $matches[1];
return 0;
}
/**
* Upgrade the revisions author, add the current post as a revision and set the revisions version to 1
*
* @since 3.6.0
* @access private
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @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
*/
function _wp_upgrade_revisions_of_post( $post, $revisions ) {
global $wpdb;
// Add post option exclusively
$lock = "revision-upgrade-{$post->ID}";
$now = time();
$result = $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, 'no') /* LOCK */", $lock, $now ) );
if ( ! $result ) {
// If we couldn't get a lock, see how old the previous lock is
$locked = get_option( $lock );
if ( ! $locked ) {
// Can't write to the lock, and can't read the lock.
// Something broken has happened
return false;
}
if ( $locked > $now - 3600 ) {
// Lock is not too old: some other process may be upgrading this post. Bail.
return false;
}
// Lock is too old - update it (below) and continue
}
// If we could get a lock, re-"add" the option to fire all the correct filters.
update_option( $lock, $now );
reset( $revisions );
$add_last = true;
do {
$this_revision = current( $revisions );
$prev_revision = next( $revisions );
$this_revision_version = _wp_get_post_revision_version( $this_revision );
// Something terrible happened
if ( false === $this_revision_version )
continue;
// 1 is the latest revision version, so we're already up to date.
// No need to add a copy of the post as latest revision.
if ( 0 < $this_revision_version ) {
$add_last = false;
continue;
}
// Always update the revision version
$update = array(
'post_name' => preg_replace( '/^(\d+-(?:autosave|revision))[\d-]*$/', '$1-v1', $this_revision->post_name ),
);
// If this revision is the oldest revision of the post, i.e. no $prev_revision,
// the correct post_author is probably $post->post_author, but that's only a good guess.
// Update the revision version only and Leave the author as-is.
if ( $prev_revision ) {
$prev_revision_version = _wp_get_post_revision_version( $prev_revision );
// If the previous revision is already up to date, it no longer has the information we need :(
if ( $prev_revision_version < 1 )
$update['post_author'] = $prev_revision->post_author;
}
// Upgrade this revision
$result = $wpdb->update( $wpdb->posts, $update, array( 'ID' => $this_revision->ID ) );
if ( $result )
wp_cache_delete( $this_revision->ID, 'posts' );
} while ( $prev_revision );
delete_option( $lock );
// Add a copy of the post as latest revision.
if ( $add_last )
wp_save_post_revision( $post->ID );
return true;
}
home/xbodynamge/lebauwcentre/wp-admin/revision.php 0000604 00000012060 15113200761 0016363 0 ustar 00 <?php
/**
* Revisions administration panel
*
* Requires wp-admin/includes/revision.php.
*
* @package WordPress
* @subpackage Administration
* @since 2.6.0
*/
/** WordPress Administration Bootstrap */
require_once( dirname( __FILE__ ) . '/admin.php' );
require ABSPATH . 'wp-admin/includes/revision.php';
/**
* @global int $revision Optional. The revision ID.
* @global string $action The action to take.
* Accepts 'restore', 'view' or 'edit'.
* @global int $from The revision to compare from.
* @global int $to Optional, required if revision missing. The revision to compare to.
*/
wp_reset_vars( array( 'revision', 'action', 'from', 'to' ) );
$revision_id = absint( $revision );
$from = is_numeric( $from ) ? absint( $from ) : null;
if ( ! $revision_id ) {
$revision_id = absint( $to );
}
$redirect = 'edit.php';
switch ( $action ) {
case 'restore':
if ( ! $revision = wp_get_post_revision( $revision_id ) ) {
break;
}
if ( ! current_user_can( 'edit_post', $revision->post_parent ) ) {
break;
}
if ( ! $post = get_post( $revision->post_parent ) ) {
break;
}
// Restore if revisions are enabled or this is an autosave.
if ( ! wp_revisions_enabled( $post ) && ! wp_is_post_autosave( $revision ) ) {
$redirect = 'edit.php?post_type=' . $post->post_type;
break;
}
// Don't allow revision restore when post is locked
if ( wp_check_post_lock( $post->ID ) ) {
break;
}
check_admin_referer( "restore-post_{$revision->ID}" );
wp_restore_post_revision( $revision->ID );
$redirect = add_query_arg(
array(
'message' => 5,
'revision' => $revision->ID,
),
get_edit_post_link( $post->ID, 'url' )
);
break;
case 'view':
case 'edit':
default:
if ( ! $revision = wp_get_post_revision( $revision_id ) ) {
break;
}
if ( ! $post = get_post( $revision->post_parent ) ) {
break;
}
if ( ! current_user_can( 'read_post', $revision->ID ) || ! current_user_can( 'edit_post', $revision->post_parent ) ) {
break;
}
// Revisions disabled and we're not looking at an autosave
if ( ! wp_revisions_enabled( $post ) && ! wp_is_post_autosave( $revision ) ) {
$redirect = 'edit.php?post_type=' . $post->post_type;
break;
}
$post_edit_link = get_edit_post_link();
$post_title = '<a href="' . $post_edit_link . '">' . _draft_or_post_title() . '</a>';
/* translators: %s: post title */
$h1 = sprintf( __( 'Compare Revisions of “%s”' ), $post_title );
$return_to_post = '<a href="' . $post_edit_link . '">' . __( '← Return to editor' ) . '</a>';
$title = __( 'Revisions' );
$redirect = false;
break;
}
// Empty post_type means either malformed object found, or no valid parent was found.
if ( ! $redirect && empty( $post->post_type ) ) {
$redirect = 'edit.php';
}
if ( ! empty( $redirect ) ) {
wp_redirect( $redirect );
exit;
}
// This is so that the correct "Edit" menu item is selected.
if ( ! empty( $post->post_type ) && 'post' != $post->post_type ) {
$parent_file = $submenu_file = 'edit.php?post_type=' . $post->post_type;
} else {
$parent_file = $submenu_file = 'edit.php';
}
wp_enqueue_script( 'revisions' );
wp_localize_script( 'revisions', '_wpRevisionsSettings', wp_prepare_revisions_for_js( $post, $revision_id, $from ) );
/* Revisions Help Tab */
$revisions_overview = '<p>' . __( 'This screen is used for managing your content revisions.' ) . '</p>';
$revisions_overview .= '<p>' . __( 'Revisions are saved copies of your post or page, which are periodically created as you update your content. The red text on the left shows the content that was removed. The green text on the right shows the content that was added.' ) . '</p>';
$revisions_overview .= '<p>' . __( 'From this screen you can review, compare, and restore revisions:' ) . '</p>';
$revisions_overview .= '<ul><li>' . __( 'To navigate between revisions, <strong>drag the slider handle left or right</strong> or <strong>use the Previous or Next buttons</strong>.' ) . '</li>';
$revisions_overview .= '<li>' . __( 'Compare two different revisions by <strong>selecting the “Compare any two revisions” box</strong> to the side.' ) . '</li>';
$revisions_overview .= '<li>' . __( 'To restore a revision, <strong>click Restore This Revision</strong>.' ) . '</li></ul>';
get_current_screen()->add_help_tab(
array(
'id' => 'revisions-overview',
'title' => __( 'Overview' ),
'content' => $revisions_overview,
)
);
$revisions_sidebar = '<p><strong>' . __( 'For more information:' ) . '</strong></p>';
$revisions_sidebar .= '<p>' . __( '<a href="https://codex.wordpress.org/Revision_Management">Revisions Management</a>' ) . '</p>';
$revisions_sidebar .= '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>';
get_current_screen()->set_help_sidebar( $revisions_sidebar );
require_once( ABSPATH . 'wp-admin/admin-header.php' );
?>
<div class="wrap">
<h1 class="long-header"><?php echo $h1; ?></h1>
<?php echo $return_to_post; ?>
</div>
<?php
wp_print_revision_templates();
require_once( ABSPATH . 'wp-admin/admin-footer.php' );
home/xbodynamge/dev/wp-admin/revision.php 0000604 00000011657 15113366452 0014506 0 ustar 00 <?php
/**
* Revisions administration panel
*
* Requires wp-admin/includes/revision.php.
*
* @package WordPress
* @subpackage Administration
* @since 2.6.0
*
* @param int revision Optional. The revision ID.
* @param string action The action to take.
* Accepts 'restore', 'view' or 'edit'.
* @param int from The revision to compare from.
* @param int to Optional, required if revision missing. The revision to compare to.
*/
/** WordPress Administration Bootstrap */
require_once( dirname( __FILE__ ) . '/admin.php' );
require ABSPATH . 'wp-admin/includes/revision.php';
wp_reset_vars( array( 'revision', 'action', 'from', 'to' ) );
$revision_id = absint( $revision );
$from = is_numeric( $from ) ? absint( $from ) : null;
if ( ! $revision_id )
$revision_id = absint( $to );
$redirect = 'edit.php';
switch ( $action ) {
case 'restore' :
if ( ! $revision = wp_get_post_revision( $revision_id ) )
break;
if ( ! current_user_can( 'edit_post', $revision->post_parent ) )
break;
if ( ! $post = get_post( $revision->post_parent ) )
break;
// Restore if revisions are enabled or this is an autosave.
if ( ! wp_revisions_enabled( $post ) && ! wp_is_post_autosave( $revision ) ) {
$redirect = 'edit.php?post_type=' . $post->post_type;
break;
}
// Don't allow revision restore when post is locked
if ( wp_check_post_lock( $post->ID ) )
break;
check_admin_referer( "restore-post_{$revision->ID}" );
wp_restore_post_revision( $revision->ID );
$redirect = add_query_arg( array( 'message' => 5, 'revision' => $revision->ID ), get_edit_post_link( $post->ID, 'url' ) );
break;
case 'view' :
case 'edit' :
default :
if ( ! $revision = wp_get_post_revision( $revision_id ) )
break;
if ( ! $post = get_post( $revision->post_parent ) )
break;
if ( ! current_user_can( 'read_post', $revision->ID ) || ! current_user_can( 'edit_post', $revision->post_parent ) )
break;
// Revisions disabled and we're not looking at an autosave
if ( ! wp_revisions_enabled( $post ) && ! wp_is_post_autosave( $revision ) ) {
$redirect = 'edit.php?post_type=' . $post->post_type;
break;
}
$post_edit_link = get_edit_post_link();
$post_title = '<a href="' . $post_edit_link . '">' . _draft_or_post_title() . '</a>';
/* translators: 1: Post title */
$h1 = sprintf( __( 'Compare Revisions of “%1$s”' ), $post_title );
$return_to_post = '<a href="' . $post_edit_link . '">' . __( '← Return to editor' ) . '</a>';
$title = __( 'Revisions' );
$redirect = false;
break;
}
// Empty post_type means either malformed object found, or no valid parent was found.
if ( ! $redirect && empty( $post->post_type ) )
$redirect = 'edit.php';
if ( ! empty( $redirect ) ) {
wp_redirect( $redirect );
exit;
}
// This is so that the correct "Edit" menu item is selected.
if ( ! empty( $post->post_type ) && 'post' != $post->post_type )
$parent_file = $submenu_file = 'edit.php?post_type=' . $post->post_type;
else
$parent_file = $submenu_file = 'edit.php';
wp_enqueue_script( 'revisions' );
wp_localize_script( 'revisions', '_wpRevisionsSettings', wp_prepare_revisions_for_js( $post, $revision_id, $from ) );
/* Revisions Help Tab */
$revisions_overview = '<p>' . __( 'This screen is used for managing your content revisions.' ) . '</p>';
$revisions_overview .= '<p>' . __( 'Revisions are saved copies of your post or page, which are periodically created as you update your content. The red text on the left shows the content that was removed. The green text on the right shows the content that was added.' ) . '</p>';
$revisions_overview .= '<p>' . __( 'From this screen you can review, compare, and restore revisions:' ) . '</p>';
$revisions_overview .= '<ul><li>' . __( 'To navigate between revisions, <strong>drag the slider handle left or right</strong> or <strong>use the Previous or Next buttons</strong>.' ) . '</li>';
$revisions_overview .= '<li>' . __( 'Compare two different revisions by <strong>selecting the “Compare any two revisions” box</strong> to the side.' ) . '</li>';
$revisions_overview .= '<li>' . __( 'To restore a revision, <strong>click Restore This Revision</strong>.' ) . '</li></ul>';
get_current_screen()->add_help_tab( array(
'id' => 'revisions-overview',
'title' => __( 'Overview' ),
'content' => $revisions_overview
) );
$revisions_sidebar = '<p><strong>' . __( 'For more information:' ) . '</strong></p>';
$revisions_sidebar .= '<p>' . __( '<a href="https://codex.wordpress.org/Revision_Management">Revisions Management</a>' ) . '</p>';
$revisions_sidebar .= '<p>' . __( '<a href="https://wordpress.org/support/">Support Forums</a>' ) . '</p>';
get_current_screen()->set_help_sidebar( $revisions_sidebar );
require_once( ABSPATH . 'wp-admin/admin-header.php' );
?>
<div class="wrap">
<h1 class="long-header"><?php echo $h1; ?></h1>
<?php echo $return_to_post; ?>
</div>
<?php
wp_print_revision_templates();
require_once( ABSPATH . 'wp-admin/admin-footer.php' );
home/xbodynamge/namtation/wp-includes/revision.php 0000604 00000052122 15113427735 0016432 0 ustar 00 <?php
/**
* Post revision functions.
*
* @package WordPress
* @subpackage Post_Revisions
*/
/**
* Determines which fields of posts are to be saved in revisions.
*
* @since 2.6.0
* @since 4.5.0 A `WP_Post` object can now be passed to the `$post` parameter.
* @since 4.5.0 The optional `$autosave` parameter was deprecated and renamed to `$deprecated`.
* @access private
*
* @staticvar array $fields
*
* @param array|WP_Post $post Optional. A post array or a WP_Post object being processed
* for insertion as a post revision. Default empty array.
* @param bool $deprecated Not used.
* @return array Array of fields that can be versioned.
*/
function _wp_post_revision_fields( $post = array(), $deprecated = false ) {
static $fields = null;
if ( ! is_array( $post ) ) {
$post = get_post( $post, ARRAY_A );
}
if ( is_null( $fields ) ) {
// Allow these to be versioned
$fields = array(
'post_title' => __( 'Title' ),
'post_content' => __( 'Content' ),
'post_excerpt' => __( 'Excerpt' ),
);
}
/**
* Filters the list of fields saved in post revisions.
*
* Included by default: 'post_title', 'post_content' and 'post_excerpt'.
*
* Disallowed fields: 'ID', 'post_name', 'post_parent', 'post_date',
* 'post_date_gmt', 'post_status', 'post_type', 'comment_count',
* and 'post_author'.
*
* @since 2.6.0
* @since 4.5.0 The `$post` parameter was added.
*
* @param array $fields List of fields to revision. Contains 'post_title',
* 'post_content', and 'post_excerpt' by default.
* @param array $post A post array being processed for insertion as a post revision.
*/
$fields = apply_filters( '_wp_post_revision_fields', $fields, $post );
// WP uses these internally either in versioning or elsewhere - they cannot be versioned
foreach ( array( 'ID', 'post_name', 'post_parent', 'post_date', 'post_date_gmt', 'post_status', 'post_type', 'comment_count', 'post_author' ) as $protect ) {
unset( $fields[ $protect ] );
}
return $fields;
}
/**
* Returns a post array ready to be inserted into the posts table as a post revision.
*
* @since 4.5.0
* @access private
*
* @param array|WP_Post $post Optional. A post array or a WP_Post object to be processed
* for insertion as a post revision. Default empty array.
* @param bool $autosave Optional. Is the revision an autosave? Default false.
* @return array Post array ready to be inserted as a post revision.
*/
function _wp_post_revision_data( $post = array(), $autosave = false ) {
if ( ! is_array( $post ) ) {
$post = get_post( $post, ARRAY_A );
}
$fields = _wp_post_revision_fields( $post );
$revision_data = array();
foreach ( array_intersect( array_keys( $post ), array_keys( $fields ) ) as $field ) {
$revision_data[ $field ] = $post[ $field ];
}
$revision_data['post_parent'] = $post['ID'];
$revision_data['post_status'] = 'inherit';
$revision_data['post_type'] = 'revision';
$revision_data['post_name'] = $autosave ? "$post[ID]-autosave-v1" : "$post[ID]-revision-v1"; // "1" is the revisioning system version
$revision_data['post_date'] = isset( $post['post_modified'] ) ? $post['post_modified'] : '';
$revision_data['post_date_gmt'] = isset( $post['post_modified_gmt'] ) ? $post['post_modified_gmt'] : '';
return $revision_data;
}
/**
* Creates a revision for the current version of a post.
*
* Typically used immediately after a post update, as every update is a revision,
* and the most recent revision always matches the current post.
*
* @since 2.6.0
*
* @param int $post_id The ID of the post to save as a revision.
* @return int|WP_Error|void Void or 0 if error, new revision ID, if success.
*/
function wp_save_post_revision( $post_id ) {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
if ( ! $post = get_post( $post_id ) ) {
return;
}
if ( ! post_type_supports( $post->post_type, 'revisions' ) ) {
return;
}
if ( 'auto-draft' == $post->post_status ) {
return;
}
if ( ! wp_revisions_enabled( $post ) ) {
return;
}
// Compare the proposed update with the last stored revision verifying that
// they are different, unless a plugin tells us to always save regardless.
// If no previous revisions, save one
if ( $revisions = wp_get_post_revisions( $post_id ) ) {
// grab the last revision, but not an autosave
foreach ( $revisions as $revision ) {
if ( false !== strpos( $revision->post_name, "{$revision->post_parent}-revision" ) ) {
$last_revision = $revision;
break;
}
}
/**
* Filters whether the post has changed since the last revision.
*
* By default a revision is saved only if one of the revisioned fields has changed.
* This filter can override that so a revision is saved even if nothing has changed.
*
* @since 3.6.0
*
* @param bool $check_for_changes Whether to check for changes before saving a new revision.
* Default true.
* @param WP_Post $last_revision The last revision post object.
* @param WP_Post $post The post object.
*/
if ( isset( $last_revision ) && apply_filters( 'wp_save_post_revision_check_for_changes', $check_for_changes = true, $last_revision, $post ) ) {
$post_has_changed = false;
foreach ( array_keys( _wp_post_revision_fields( $post ) ) as $field ) {
if ( normalize_whitespace( $post->$field ) != normalize_whitespace( $last_revision->$field ) ) {
$post_has_changed = true;
break;
}
}
/**
* Filters whether a post has changed.
*
* By default a revision is saved only if one of the revisioned fields has changed.
* This filter allows for additional checks to determine if there were changes.
*
* @since 4.1.0
*
* @param bool $post_has_changed Whether the post has changed.
* @param WP_Post $last_revision The last revision post object.
* @param WP_Post $post The post object.
*/
$post_has_changed = (bool) apply_filters( 'wp_save_post_revision_post_has_changed', $post_has_changed, $last_revision, $post );
//don't save revision if post unchanged
if ( ! $post_has_changed ) {
return;
}
}
}
$return = _wp_put_post_revision( $post );
// If a limit for the number of revisions to keep has been set,
// delete the oldest ones.
$revisions_to_keep = wp_revisions_to_keep( $post );
if ( $revisions_to_keep < 0 ) {
return $return;
}
$revisions = wp_get_post_revisions( $post_id, array( 'order' => 'ASC' ) );
$delete = count( $revisions ) - $revisions_to_keep;
if ( $delete < 1 ) {
return $return;
}
$revisions = array_slice( $revisions, 0, $delete );
for ( $i = 0; isset( $revisions[ $i ] ); $i++ ) {
if ( false !== strpos( $revisions[ $i ]->post_name, 'autosave' ) ) {
continue;
}
wp_delete_post_revision( $revisions[ $i ]->ID );
}
return $return;
}
/**
* Retrieve the autosaved data of the specified post.
*
* Returns a post object containing the information that was autosaved for the
* specified post. If the optional $user_id is passed, returns the autosave for that user
* otherwise returns the latest autosave.
*
* @since 2.6.0
*
* @param int $post_id The post ID.
* @param int $user_id Optional The post author ID.
* @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 ) {
$revisions = wp_get_post_revisions( $post_id, array( 'check_enabled' => false ) );
foreach ( $revisions as $revision ) {
if ( false !== strpos( $revision->post_name, "{$post_id}-autosave" ) ) {
if ( $user_id && $user_id != $revision->post_author ) {
continue;
}
return $revision;
}
}
return false;
}
/**
* Determines if the specified post is a revision.
*
* @since 2.6.0
*
* @param int|WP_Post $post Post ID or post object.
* @return false|int False if not a revision, ID of revision's parent otherwise.
*/
function wp_is_post_revision( $post ) {
if ( ! $post = wp_get_post_revision( $post ) ) {
return false;
}
return (int) $post->post_parent;
}
/**
* Determines if the specified post is an autosave.
*
* @since 2.6.0
*
* @param int|WP_Post $post Post ID or post object.
* @return false|int False if not a revision, ID of autosave's parent otherwise
*/
function wp_is_post_autosave( $post ) {
if ( ! $post = wp_get_post_revision( $post ) ) {
return false;
}
if ( false !== strpos( $post->post_name, "{$post->post_parent}-autosave" ) ) {
return (int) $post->post_parent;
}
return false;
}
/**
* Inserts post data into the posts table as a post revision.
*
* @since 2.6.0
* @access private
*
* @param int|WP_Post|array|null $post Post ID, post object OR post array.
* @param bool $autosave Optional. Is the revision an autosave?
* @return int|WP_Error WP_Error or 0 if error, new revision ID if success.
*/
function _wp_put_post_revision( $post = null, $autosave = false ) {
if ( is_object( $post ) ) {
$post = get_object_vars( $post );
} elseif ( ! is_array( $post ) ) {
$post = get_post( $post, ARRAY_A );
}
if ( ! $post || empty( $post['ID'] ) ) {
return new WP_Error( 'invalid_post', __( 'Invalid post ID.' ) );
}
if ( isset( $post['post_type'] ) && 'revision' == $post['post_type'] ) {
return new WP_Error( 'post_type', __( 'Cannot create a revision of a revision' ) );
}
$post = _wp_post_revision_data( $post, $autosave );
$post = wp_slash( $post ); //since data is from db
$revision_id = wp_insert_post( $post );
if ( is_wp_error( $revision_id ) ) {
return $revision_id;
}
if ( $revision_id ) {
/**
* Fires once a revision has been saved.
*
* @since 2.6.0
*
* @param int $revision_id Post revision ID.
*/
do_action( '_wp_put_post_revision', $revision_id );
}
return $revision_id;
}
/**
* Gets a post revision.
*
* @since 2.6.0
*
* @param int|WP_Post $post The post ID or object.
* @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to
* a WP_Post object, an associative array, or a numeric array, respectively. Default OBJECT.
* @param string $filter Optional sanitation filter. See sanitize_post().
* @return WP_Post|array|null WP_Post (or array) on success, or null on failure.
*/
function wp_get_post_revision( &$post, $output = OBJECT, $filter = 'raw' ) {
if ( ! $revision = get_post( $post, OBJECT, $filter ) ) {
return $revision;
}
if ( 'revision' !== $revision->post_type ) {
return null;
}
if ( $output == OBJECT ) {
return $revision;
} elseif ( $output == ARRAY_A ) {
$_revision = get_object_vars( $revision );
return $_revision;
} elseif ( $output == ARRAY_N ) {
$_revision = array_values( get_object_vars( $revision ) );
return $_revision;
}
return $revision;
}
/**
* Restores a post to the specified revision.
*
* Can restore a past revision using all fields of the post revision, or only selected fields.
*
* @since 2.6.0
*
* @param int|WP_Post $revision_id Revision ID or revision object.
* @param array $fields Optional. What fields to restore from. Defaults to all.
* @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 ) {
if ( ! $revision = wp_get_post_revision( $revision_id, ARRAY_A ) ) {
return $revision;
}
if ( ! is_array( $fields ) ) {
$fields = array_keys( _wp_post_revision_fields( $revision ) );
}
$update = array();
foreach ( array_intersect( array_keys( $revision ), $fields ) as $field ) {
$update[ $field ] = $revision[ $field ];
}
if ( ! $update ) {
return false;
}
$update['ID'] = $revision['post_parent'];
$update = wp_slash( $update ); //since data is from db
$post_id = wp_update_post( $update );
if ( ! $post_id || is_wp_error( $post_id ) ) {
return $post_id;
}
// Update last edit user
update_post_meta( $post_id, '_edit_last', get_current_user_id() );
/**
* Fires after a post revision has been restored.
*
* @since 2.6.0
*
* @param int $post_id Post ID.
* @param int $revision_id Post revision ID.
*/
do_action( 'wp_restore_post_revision', $post_id, $revision['ID'] );
return $post_id;
}
/**
* Deletes a revision.
*
* Deletes the row from the posts table corresponding to the specified revision.
*
* @since 2.6.0
*
* @param int|WP_Post $revision_id Revision ID or revision object.
* @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 ) {
if ( ! $revision = wp_get_post_revision( $revision_id ) ) {
return $revision;
}
$delete = wp_delete_post( $revision->ID );
if ( $delete ) {
/**
* Fires once a post revision has been deleted.
*
* @since 2.6.0
*
* @param int $revision_id Post revision ID.
* @param object|array $revision Post revision object or array.
*/
do_action( 'wp_delete_post_revision', $revision->ID, $revision );
}
return $delete;
}
/**
* Returns all revisions of specified post.
*
* @since 2.6.0
*
* @see get_children()
*
* @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global `$post`.
* @param array|null $args Optional. Arguments for retrieving post revisions. Default null.
* @return array An array of revisions, or an empty array if none.
*/
function wp_get_post_revisions( $post_id = 0, $args = null ) {
$post = get_post( $post_id );
if ( ! $post || empty( $post->ID ) ) {
return array();
}
$defaults = array(
'order' => 'DESC',
'orderby' => 'date ID',
'check_enabled' => true,
);
$args = wp_parse_args( $args, $defaults );
if ( $args['check_enabled'] && ! wp_revisions_enabled( $post ) ) {
return array();
}
$args = array_merge(
$args,
array(
'post_parent' => $post->ID,
'post_type' => 'revision',
'post_status' => 'inherit',
)
);
if ( ! $revisions = get_children( $args ) ) {
return array();
}
return $revisions;
}
/**
* Determine if revisions are enabled for a given post.
*
* @since 3.6.0
*
* @param WP_Post $post The post object.
* @return bool True if number of revisions to keep isn't zero, false otherwise.
*/
function wp_revisions_enabled( $post ) {
return wp_revisions_to_keep( $post ) !== 0;
}
/**
* Determine how many revisions to retain for a given post.
*
* By default, an infinite number of revisions are kept.
*
* The constant WP_POST_REVISIONS can be set in wp-config to specify the limit
* of revisions to keep.
*
* @since 3.6.0
*
* @param WP_Post $post The post object.
* @return int The number of revisions to keep.
*/
function wp_revisions_to_keep( $post ) {
$num = WP_POST_REVISIONS;
if ( true === $num ) {
$num = -1;
} else {
$num = intval( $num );
}
if ( ! post_type_supports( $post->post_type, 'revisions' ) ) {
$num = 0;
}
/**
* Filters the number of revisions to save for the given post.
*
* Overrides the value of WP_POST_REVISIONS.
*
* @since 3.6.0
*
* @param int $num Number of revisions to store.
* @param WP_Post $post Post object.
*/
return (int) apply_filters( 'wp_revisions_to_keep', $num, $post );
}
/**
* Sets up the post object for preview based on the post autosave.
*
* @since 2.7.0
* @access private
*
* @param WP_Post $post
* @return WP_Post|false
*/
function _set_preview( $post ) {
if ( ! is_object( $post ) ) {
return $post;
}
$preview = wp_get_post_autosave( $post->ID );
if ( ! is_object( $preview ) ) {
return $post;
}
$preview = sanitize_post( $preview );
$post->post_content = $preview->post_content;
$post->post_title = $preview->post_title;
$post->post_excerpt = $preview->post_excerpt;
add_filter( 'get_the_terms', '_wp_preview_terms_filter', 10, 3 );
add_filter( 'get_post_metadata', '_wp_preview_post_thumbnail_filter', 10, 3 );
return $post;
}
/**
* Filters the latest content for preview from the post autosave.
*
* @since 2.7.0
* @access private
*/
function _show_post_preview() {
if ( isset( $_GET['preview_id'] ) && isset( $_GET['preview_nonce'] ) ) {
$id = (int) $_GET['preview_id'];
if ( false === wp_verify_nonce( $_GET['preview_nonce'], 'post_preview_' . $id ) ) {
wp_die( __( 'Sorry, you are not allowed to preview drafts.' ), 403 );
}
add_filter( 'the_preview', '_set_preview' );
}
}
/**
* Filters terms lookup to set the post format.
*
* @since 3.6.0
* @access private
*
* @param array $terms
* @param int $post_id
* @param string $taxonomy
* @return array
*/
function _wp_preview_terms_filter( $terms, $post_id, $taxonomy ) {
if ( ! $post = get_post() ) {
return $terms;
}
if ( empty( $_REQUEST['post_format'] ) || $post->ID != $post_id || 'post_format' != $taxonomy || 'revision' == $post->post_type ) {
return $terms;
}
if ( 'standard' == $_REQUEST['post_format'] ) {
$terms = array();
} elseif ( $term = get_term_by( 'slug', 'post-format-' . sanitize_key( $_REQUEST['post_format'] ), 'post_format' ) ) {
$terms = array( $term ); // Can only have one post format
}
return $terms;
}
/**
* Filters post thumbnail lookup to set the post thumbnail.
*
* @since 4.6.0
* @access private
*
* @param null|array|string $value The value to return - a single metadata value, or an array of values.
* @param int $post_id Post ID.
* @param string $meta_key Meta key.
* @return null|array The default return value or the post thumbnail meta array.
*/
function _wp_preview_post_thumbnail_filter( $value, $post_id, $meta_key ) {
if ( ! $post = get_post() ) {
return $value;
}
if ( empty( $_REQUEST['_thumbnail_id'] ) ||
empty( $_REQUEST['preview_id'] ) ||
$post->ID != $post_id ||
'_thumbnail_id' != $meta_key ||
'revision' == $post->post_type ||
$post_id != $_REQUEST['preview_id'] ) {
return $value;
}
$thumbnail_id = intval( $_REQUEST['_thumbnail_id'] );
if ( $thumbnail_id <= 0 ) {
return '';
}
return strval( $thumbnail_id );
}
/**
* Gets the post revision version.
*
* @since 3.6.0
* @access private
*
* @param WP_Post $revision
* @return int|false
*/
function _wp_get_post_revision_version( $revision ) {
if ( is_object( $revision ) ) {
$revision = get_object_vars( $revision );
} elseif ( ! is_array( $revision ) ) {
return false;
}
if ( preg_match( '/^\d+-(?:autosave|revision)-v(\d+)$/', $revision['post_name'], $matches ) ) {
return (int) $matches[1];
}
return 0;
}
/**
* Upgrade the revisions author, add the current post as a revision and set the revisions version to 1
*
* @since 3.6.0
* @access private
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @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
*/
function _wp_upgrade_revisions_of_post( $post, $revisions ) {
global $wpdb;
// Add post option exclusively
$lock = "revision-upgrade-{$post->ID}";
$now = time();
$result = $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, 'no') /* LOCK */", $lock, $now ) );
if ( ! $result ) {
// If we couldn't get a lock, see how old the previous lock is
$locked = get_option( $lock );
if ( ! $locked ) {
// Can't write to the lock, and can't read the lock.
// Something broken has happened
return false;
}
if ( $locked > $now - 3600 ) {
// Lock is not too old: some other process may be upgrading this post. Bail.
return false;
}
// Lock is too old - update it (below) and continue
}
// If we could get a lock, re-"add" the option to fire all the correct filters.
update_option( $lock, $now );
reset( $revisions );
$add_last = true;
do {
$this_revision = current( $revisions );
$prev_revision = next( $revisions );
$this_revision_version = _wp_get_post_revision_version( $this_revision );
// Something terrible happened
if ( false === $this_revision_version ) {
continue;
}
// 1 is the latest revision version, so we're already up to date.
// No need to add a copy of the post as latest revision.
if ( 0 < $this_revision_version ) {
$add_last = false;
continue;
}
// Always update the revision version
$update = array(
'post_name' => preg_replace( '/^(\d+-(?:autosave|revision))[\d-]*$/', '$1-v1', $this_revision->post_name ),
);
// If this revision is the oldest revision of the post, i.e. no $prev_revision,
// the correct post_author is probably $post->post_author, but that's only a good guess.
// Update the revision version only and Leave the author as-is.
if ( $prev_revision ) {
$prev_revision_version = _wp_get_post_revision_version( $prev_revision );
// If the previous revision is already up to date, it no longer has the information we need :(
if ( $prev_revision_version < 1 ) {
$update['post_author'] = $prev_revision->post_author;
}
}
// Upgrade this revision
$result = $wpdb->update( $wpdb->posts, $update, array( 'ID' => $this_revision->ID ) );
if ( $result ) {
wp_cache_delete( $this_revision->ID, 'posts' );
}
} while ( $prev_revision );
delete_option( $lock );
// Add a copy of the post as latest revision.
if ( $add_last ) {
wp_save_post_revision( $post->ID );
}
return true;
}
home/xbodynamge/lebauwcentre/wp-includes/revision.php 0000604 00000052122 15113507127 0017112 0 ustar 00 <?php
/**
* Post revision functions.
*
* @package WordPress
* @subpackage Post_Revisions
*/
/**
* Determines which fields of posts are to be saved in revisions.
*
* @since 2.6.0
* @since 4.5.0 A `WP_Post` object can now be passed to the `$post` parameter.
* @since 4.5.0 The optional `$autosave` parameter was deprecated and renamed to `$deprecated`.
* @access private
*
* @staticvar array $fields
*
* @param array|WP_Post $post Optional. A post array or a WP_Post object being processed
* for insertion as a post revision. Default empty array.
* @param bool $deprecated Not used.
* @return array Array of fields that can be versioned.
*/
function _wp_post_revision_fields( $post = array(), $deprecated = false ) {
static $fields = null;
if ( ! is_array( $post ) ) {
$post = get_post( $post, ARRAY_A );
}
if ( is_null( $fields ) ) {
// Allow these to be versioned
$fields = array(
'post_title' => __( 'Title' ),
'post_content' => __( 'Content' ),
'post_excerpt' => __( 'Excerpt' ),
);
}
/**
* Filters the list of fields saved in post revisions.
*
* Included by default: 'post_title', 'post_content' and 'post_excerpt'.
*
* Disallowed fields: 'ID', 'post_name', 'post_parent', 'post_date',
* 'post_date_gmt', 'post_status', 'post_type', 'comment_count',
* and 'post_author'.
*
* @since 2.6.0
* @since 4.5.0 The `$post` parameter was added.
*
* @param array $fields List of fields to revision. Contains 'post_title',
* 'post_content', and 'post_excerpt' by default.
* @param array $post A post array being processed for insertion as a post revision.
*/
$fields = apply_filters( '_wp_post_revision_fields', $fields, $post );
// WP uses these internally either in versioning or elsewhere - they cannot be versioned
foreach ( array( 'ID', 'post_name', 'post_parent', 'post_date', 'post_date_gmt', 'post_status', 'post_type', 'comment_count', 'post_author' ) as $protect ) {
unset( $fields[ $protect ] );
}
return $fields;
}
/**
* Returns a post array ready to be inserted into the posts table as a post revision.
*
* @since 4.5.0
* @access private
*
* @param array|WP_Post $post Optional. A post array or a WP_Post object to be processed
* for insertion as a post revision. Default empty array.
* @param bool $autosave Optional. Is the revision an autosave? Default false.
* @return array Post array ready to be inserted as a post revision.
*/
function _wp_post_revision_data( $post = array(), $autosave = false ) {
if ( ! is_array( $post ) ) {
$post = get_post( $post, ARRAY_A );
}
$fields = _wp_post_revision_fields( $post );
$revision_data = array();
foreach ( array_intersect( array_keys( $post ), array_keys( $fields ) ) as $field ) {
$revision_data[ $field ] = $post[ $field ];
}
$revision_data['post_parent'] = $post['ID'];
$revision_data['post_status'] = 'inherit';
$revision_data['post_type'] = 'revision';
$revision_data['post_name'] = $autosave ? "$post[ID]-autosave-v1" : "$post[ID]-revision-v1"; // "1" is the revisioning system version
$revision_data['post_date'] = isset( $post['post_modified'] ) ? $post['post_modified'] : '';
$revision_data['post_date_gmt'] = isset( $post['post_modified_gmt'] ) ? $post['post_modified_gmt'] : '';
return $revision_data;
}
/**
* Creates a revision for the current version of a post.
*
* Typically used immediately after a post update, as every update is a revision,
* and the most recent revision always matches the current post.
*
* @since 2.6.0
*
* @param int $post_id The ID of the post to save as a revision.
* @return int|WP_Error|void Void or 0 if error, new revision ID, if success.
*/
function wp_save_post_revision( $post_id ) {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
if ( ! $post = get_post( $post_id ) ) {
return;
}
if ( ! post_type_supports( $post->post_type, 'revisions' ) ) {
return;
}
if ( 'auto-draft' == $post->post_status ) {
return;
}
if ( ! wp_revisions_enabled( $post ) ) {
return;
}
// Compare the proposed update with the last stored revision verifying that
// they are different, unless a plugin tells us to always save regardless.
// If no previous revisions, save one
if ( $revisions = wp_get_post_revisions( $post_id ) ) {
// grab the last revision, but not an autosave
foreach ( $revisions as $revision ) {
if ( false !== strpos( $revision->post_name, "{$revision->post_parent}-revision" ) ) {
$last_revision = $revision;
break;
}
}
/**
* Filters whether the post has changed since the last revision.
*
* By default a revision is saved only if one of the revisioned fields has changed.
* This filter can override that so a revision is saved even if nothing has changed.
*
* @since 3.6.0
*
* @param bool $check_for_changes Whether to check for changes before saving a new revision.
* Default true.
* @param WP_Post $last_revision The last revision post object.
* @param WP_Post $post The post object.
*/
if ( isset( $last_revision ) && apply_filters( 'wp_save_post_revision_check_for_changes', $check_for_changes = true, $last_revision, $post ) ) {
$post_has_changed = false;
foreach ( array_keys( _wp_post_revision_fields( $post ) ) as $field ) {
if ( normalize_whitespace( $post->$field ) != normalize_whitespace( $last_revision->$field ) ) {
$post_has_changed = true;
break;
}
}
/**
* Filters whether a post has changed.
*
* By default a revision is saved only if one of the revisioned fields has changed.
* This filter allows for additional checks to determine if there were changes.
*
* @since 4.1.0
*
* @param bool $post_has_changed Whether the post has changed.
* @param WP_Post $last_revision The last revision post object.
* @param WP_Post $post The post object.
*/
$post_has_changed = (bool) apply_filters( 'wp_save_post_revision_post_has_changed', $post_has_changed, $last_revision, $post );
//don't save revision if post unchanged
if ( ! $post_has_changed ) {
return;
}
}
}
$return = _wp_put_post_revision( $post );
// If a limit for the number of revisions to keep has been set,
// delete the oldest ones.
$revisions_to_keep = wp_revisions_to_keep( $post );
if ( $revisions_to_keep < 0 ) {
return $return;
}
$revisions = wp_get_post_revisions( $post_id, array( 'order' => 'ASC' ) );
$delete = count( $revisions ) - $revisions_to_keep;
if ( $delete < 1 ) {
return $return;
}
$revisions = array_slice( $revisions, 0, $delete );
for ( $i = 0; isset( $revisions[ $i ] ); $i++ ) {
if ( false !== strpos( $revisions[ $i ]->post_name, 'autosave' ) ) {
continue;
}
wp_delete_post_revision( $revisions[ $i ]->ID );
}
return $return;
}
/**
* Retrieve the autosaved data of the specified post.
*
* Returns a post object containing the information that was autosaved for the
* specified post. If the optional $user_id is passed, returns the autosave for that user
* otherwise returns the latest autosave.
*
* @since 2.6.0
*
* @param int $post_id The post ID.
* @param int $user_id Optional The post author ID.
* @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 ) {
$revisions = wp_get_post_revisions( $post_id, array( 'check_enabled' => false ) );
foreach ( $revisions as $revision ) {
if ( false !== strpos( $revision->post_name, "{$post_id}-autosave" ) ) {
if ( $user_id && $user_id != $revision->post_author ) {
continue;
}
return $revision;
}
}
return false;
}
/**
* Determines if the specified post is a revision.
*
* @since 2.6.0
*
* @param int|WP_Post $post Post ID or post object.
* @return false|int False if not a revision, ID of revision's parent otherwise.
*/
function wp_is_post_revision( $post ) {
if ( ! $post = wp_get_post_revision( $post ) ) {
return false;
}
return (int) $post->post_parent;
}
/**
* Determines if the specified post is an autosave.
*
* @since 2.6.0
*
* @param int|WP_Post $post Post ID or post object.
* @return false|int False if not a revision, ID of autosave's parent otherwise
*/
function wp_is_post_autosave( $post ) {
if ( ! $post = wp_get_post_revision( $post ) ) {
return false;
}
if ( false !== strpos( $post->post_name, "{$post->post_parent}-autosave" ) ) {
return (int) $post->post_parent;
}
return false;
}
/**
* Inserts post data into the posts table as a post revision.
*
* @since 2.6.0
* @access private
*
* @param int|WP_Post|array|null $post Post ID, post object OR post array.
* @param bool $autosave Optional. Is the revision an autosave?
* @return int|WP_Error WP_Error or 0 if error, new revision ID if success.
*/
function _wp_put_post_revision( $post = null, $autosave = false ) {
if ( is_object( $post ) ) {
$post = get_object_vars( $post );
} elseif ( ! is_array( $post ) ) {
$post = get_post( $post, ARRAY_A );
}
if ( ! $post || empty( $post['ID'] ) ) {
return new WP_Error( 'invalid_post', __( 'Invalid post ID.' ) );
}
if ( isset( $post['post_type'] ) && 'revision' == $post['post_type'] ) {
return new WP_Error( 'post_type', __( 'Cannot create a revision of a revision' ) );
}
$post = _wp_post_revision_data( $post, $autosave );
$post = wp_slash( $post ); //since data is from db
$revision_id = wp_insert_post( $post );
if ( is_wp_error( $revision_id ) ) {
return $revision_id;
}
if ( $revision_id ) {
/**
* Fires once a revision has been saved.
*
* @since 2.6.0
*
* @param int $revision_id Post revision ID.
*/
do_action( '_wp_put_post_revision', $revision_id );
}
return $revision_id;
}
/**
* Gets a post revision.
*
* @since 2.6.0
*
* @param int|WP_Post $post The post ID or object.
* @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to
* a WP_Post object, an associative array, or a numeric array, respectively. Default OBJECT.
* @param string $filter Optional sanitation filter. See sanitize_post().
* @return WP_Post|array|null WP_Post (or array) on success, or null on failure.
*/
function wp_get_post_revision( &$post, $output = OBJECT, $filter = 'raw' ) {
if ( ! $revision = get_post( $post, OBJECT, $filter ) ) {
return $revision;
}
if ( 'revision' !== $revision->post_type ) {
return null;
}
if ( $output == OBJECT ) {
return $revision;
} elseif ( $output == ARRAY_A ) {
$_revision = get_object_vars( $revision );
return $_revision;
} elseif ( $output == ARRAY_N ) {
$_revision = array_values( get_object_vars( $revision ) );
return $_revision;
}
return $revision;
}
/**
* Restores a post to the specified revision.
*
* Can restore a past revision using all fields of the post revision, or only selected fields.
*
* @since 2.6.0
*
* @param int|WP_Post $revision_id Revision ID or revision object.
* @param array $fields Optional. What fields to restore from. Defaults to all.
* @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 ) {
if ( ! $revision = wp_get_post_revision( $revision_id, ARRAY_A ) ) {
return $revision;
}
if ( ! is_array( $fields ) ) {
$fields = array_keys( _wp_post_revision_fields( $revision ) );
}
$update = array();
foreach ( array_intersect( array_keys( $revision ), $fields ) as $field ) {
$update[ $field ] = $revision[ $field ];
}
if ( ! $update ) {
return false;
}
$update['ID'] = $revision['post_parent'];
$update = wp_slash( $update ); //since data is from db
$post_id = wp_update_post( $update );
if ( ! $post_id || is_wp_error( $post_id ) ) {
return $post_id;
}
// Update last edit user
update_post_meta( $post_id, '_edit_last', get_current_user_id() );
/**
* Fires after a post revision has been restored.
*
* @since 2.6.0
*
* @param int $post_id Post ID.
* @param int $revision_id Post revision ID.
*/
do_action( 'wp_restore_post_revision', $post_id, $revision['ID'] );
return $post_id;
}
/**
* Deletes a revision.
*
* Deletes the row from the posts table corresponding to the specified revision.
*
* @since 2.6.0
*
* @param int|WP_Post $revision_id Revision ID or revision object.
* @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 ) {
if ( ! $revision = wp_get_post_revision( $revision_id ) ) {
return $revision;
}
$delete = wp_delete_post( $revision->ID );
if ( $delete ) {
/**
* Fires once a post revision has been deleted.
*
* @since 2.6.0
*
* @param int $revision_id Post revision ID.
* @param object|array $revision Post revision object or array.
*/
do_action( 'wp_delete_post_revision', $revision->ID, $revision );
}
return $delete;
}
/**
* Returns all revisions of specified post.
*
* @since 2.6.0
*
* @see get_children()
*
* @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global `$post`.
* @param array|null $args Optional. Arguments for retrieving post revisions. Default null.
* @return array An array of revisions, or an empty array if none.
*/
function wp_get_post_revisions( $post_id = 0, $args = null ) {
$post = get_post( $post_id );
if ( ! $post || empty( $post->ID ) ) {
return array();
}
$defaults = array(
'order' => 'DESC',
'orderby' => 'date ID',
'check_enabled' => true,
);
$args = wp_parse_args( $args, $defaults );
if ( $args['check_enabled'] && ! wp_revisions_enabled( $post ) ) {
return array();
}
$args = array_merge(
$args,
array(
'post_parent' => $post->ID,
'post_type' => 'revision',
'post_status' => 'inherit',
)
);
if ( ! $revisions = get_children( $args ) ) {
return array();
}
return $revisions;
}
/**
* Determine if revisions are enabled for a given post.
*
* @since 3.6.0
*
* @param WP_Post $post The post object.
* @return bool True if number of revisions to keep isn't zero, false otherwise.
*/
function wp_revisions_enabled( $post ) {
return wp_revisions_to_keep( $post ) !== 0;
}
/**
* Determine how many revisions to retain for a given post.
*
* By default, an infinite number of revisions are kept.
*
* The constant WP_POST_REVISIONS can be set in wp-config to specify the limit
* of revisions to keep.
*
* @since 3.6.0
*
* @param WP_Post $post The post object.
* @return int The number of revisions to keep.
*/
function wp_revisions_to_keep( $post ) {
$num = WP_POST_REVISIONS;
if ( true === $num ) {
$num = -1;
} else {
$num = intval( $num );
}
if ( ! post_type_supports( $post->post_type, 'revisions' ) ) {
$num = 0;
}
/**
* Filters the number of revisions to save for the given post.
*
* Overrides the value of WP_POST_REVISIONS.
*
* @since 3.6.0
*
* @param int $num Number of revisions to store.
* @param WP_Post $post Post object.
*/
return (int) apply_filters( 'wp_revisions_to_keep', $num, $post );
}
/**
* Sets up the post object for preview based on the post autosave.
*
* @since 2.7.0
* @access private
*
* @param WP_Post $post
* @return WP_Post|false
*/
function _set_preview( $post ) {
if ( ! is_object( $post ) ) {
return $post;
}
$preview = wp_get_post_autosave( $post->ID );
if ( ! is_object( $preview ) ) {
return $post;
}
$preview = sanitize_post( $preview );
$post->post_content = $preview->post_content;
$post->post_title = $preview->post_title;
$post->post_excerpt = $preview->post_excerpt;
add_filter( 'get_the_terms', '_wp_preview_terms_filter', 10, 3 );
add_filter( 'get_post_metadata', '_wp_preview_post_thumbnail_filter', 10, 3 );
return $post;
}
/**
* Filters the latest content for preview from the post autosave.
*
* @since 2.7.0
* @access private
*/
function _show_post_preview() {
if ( isset( $_GET['preview_id'] ) && isset( $_GET['preview_nonce'] ) ) {
$id = (int) $_GET['preview_id'];
if ( false === wp_verify_nonce( $_GET['preview_nonce'], 'post_preview_' . $id ) ) {
wp_die( __( 'Sorry, you are not allowed to preview drafts.' ), 403 );
}
add_filter( 'the_preview', '_set_preview' );
}
}
/**
* Filters terms lookup to set the post format.
*
* @since 3.6.0
* @access private
*
* @param array $terms
* @param int $post_id
* @param string $taxonomy
* @return array
*/
function _wp_preview_terms_filter( $terms, $post_id, $taxonomy ) {
if ( ! $post = get_post() ) {
return $terms;
}
if ( empty( $_REQUEST['post_format'] ) || $post->ID != $post_id || 'post_format' != $taxonomy || 'revision' == $post->post_type ) {
return $terms;
}
if ( 'standard' == $_REQUEST['post_format'] ) {
$terms = array();
} elseif ( $term = get_term_by( 'slug', 'post-format-' . sanitize_key( $_REQUEST['post_format'] ), 'post_format' ) ) {
$terms = array( $term ); // Can only have one post format
}
return $terms;
}
/**
* Filters post thumbnail lookup to set the post thumbnail.
*
* @since 4.6.0
* @access private
*
* @param null|array|string $value The value to return - a single metadata value, or an array of values.
* @param int $post_id Post ID.
* @param string $meta_key Meta key.
* @return null|array The default return value or the post thumbnail meta array.
*/
function _wp_preview_post_thumbnail_filter( $value, $post_id, $meta_key ) {
if ( ! $post = get_post() ) {
return $value;
}
if ( empty( $_REQUEST['_thumbnail_id'] ) ||
empty( $_REQUEST['preview_id'] ) ||
$post->ID != $post_id ||
'_thumbnail_id' != $meta_key ||
'revision' == $post->post_type ||
$post_id != $_REQUEST['preview_id'] ) {
return $value;
}
$thumbnail_id = intval( $_REQUEST['_thumbnail_id'] );
if ( $thumbnail_id <= 0 ) {
return '';
}
return strval( $thumbnail_id );
}
/**
* Gets the post revision version.
*
* @since 3.6.0
* @access private
*
* @param WP_Post $revision
* @return int|false
*/
function _wp_get_post_revision_version( $revision ) {
if ( is_object( $revision ) ) {
$revision = get_object_vars( $revision );
} elseif ( ! is_array( $revision ) ) {
return false;
}
if ( preg_match( '/^\d+-(?:autosave|revision)-v(\d+)$/', $revision['post_name'], $matches ) ) {
return (int) $matches[1];
}
return 0;
}
/**
* Upgrade the revisions author, add the current post as a revision and set the revisions version to 1
*
* @since 3.6.0
* @access private
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @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
*/
function _wp_upgrade_revisions_of_post( $post, $revisions ) {
global $wpdb;
// Add post option exclusively
$lock = "revision-upgrade-{$post->ID}";
$now = time();
$result = $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, 'no') /* LOCK */", $lock, $now ) );
if ( ! $result ) {
// If we couldn't get a lock, see how old the previous lock is
$locked = get_option( $lock );
if ( ! $locked ) {
// Can't write to the lock, and can't read the lock.
// Something broken has happened
return false;
}
if ( $locked > $now - 3600 ) {
// Lock is not too old: some other process may be upgrading this post. Bail.
return false;
}
// Lock is too old - update it (below) and continue
}
// If we could get a lock, re-"add" the option to fire all the correct filters.
update_option( $lock, $now );
reset( $revisions );
$add_last = true;
do {
$this_revision = current( $revisions );
$prev_revision = next( $revisions );
$this_revision_version = _wp_get_post_revision_version( $this_revision );
// Something terrible happened
if ( false === $this_revision_version ) {
continue;
}
// 1 is the latest revision version, so we're already up to date.
// No need to add a copy of the post as latest revision.
if ( 0 < $this_revision_version ) {
$add_last = false;
continue;
}
// Always update the revision version
$update = array(
'post_name' => preg_replace( '/^(\d+-(?:autosave|revision))[\d-]*$/', '$1-v1', $this_revision->post_name ),
);
// If this revision is the oldest revision of the post, i.e. no $prev_revision,
// the correct post_author is probably $post->post_author, but that's only a good guess.
// Update the revision version only and Leave the author as-is.
if ( $prev_revision ) {
$prev_revision_version = _wp_get_post_revision_version( $prev_revision );
// If the previous revision is already up to date, it no longer has the information we need :(
if ( $prev_revision_version < 1 ) {
$update['post_author'] = $prev_revision->post_author;
}
}
// Upgrade this revision
$result = $wpdb->update( $wpdb->posts, $update, array( 'ID' => $this_revision->ID ) );
if ( $result ) {
wp_cache_delete( $this_revision->ID, 'posts' );
}
} while ( $prev_revision );
delete_option( $lock );
// Add a copy of the post as latest revision.
if ( $add_last ) {
wp_save_post_revision( $post->ID );
}
return true;
}
home/xbodynamge/namtation/wp-admin/revision.php 0000604 00000012060 15113511351 0015675 0 ustar 00 <?php
/**
* Revisions administration panel
*
* Requires wp-admin/includes/revision.php.
*
* @package WordPress
* @subpackage Administration
* @since 2.6.0
*/
/** WordPress Administration Bootstrap */
require_once( dirname( __FILE__ ) . '/admin.php' );
require ABSPATH . 'wp-admin/includes/revision.php';
/**
* @global int $revision Optional. The revision ID.
* @global string $action The action to take.
* Accepts 'restore', 'view' or 'edit'.
* @global int $from The revision to compare from.
* @global int $to Optional, required if revision missing. The revision to compare to.
*/
wp_reset_vars( array( 'revision', 'action', 'from', 'to' ) );
$revision_id = absint( $revision );
$from = is_numeric( $from ) ? absint( $from ) : null;
if ( ! $revision_id ) {
$revision_id = absint( $to );
}
$redirect = 'edit.php';
switch ( $action ) {
case 'restore':
if ( ! $revision = wp_get_post_revision( $revision_id ) ) {
break;
}
if ( ! current_user_can( 'edit_post', $revision->post_parent ) ) {
break;
}
if ( ! $post = get_post( $revision->post_parent ) ) {
break;
}
// Restore if revisions are enabled or this is an autosave.
if ( ! wp_revisions_enabled( $post ) && ! wp_is_post_autosave( $revision ) ) {
$redirect = 'edit.php?post_type=' . $post->post_type;
break;
}
// Don't allow revision restore when post is locked
if ( wp_check_post_lock( $post->ID ) ) {
break;
}
check_admin_referer( "restore-post_{$revision->ID}" );
wp_restore_post_revision( $revision->ID );
$redirect = add_query_arg(
array(
'message' => 5,
'revision' => $revision->ID,
),
get_edit_post_link( $post->ID, 'url' )
);
break;
case 'view':
case 'edit':
default:
if ( ! $revision = wp_get_post_revision( $revision_id ) ) {
break;
}
if ( ! $post = get_post( $revision->post_parent ) ) {
break;
}
if ( ! current_user_can( 'read_post', $revision->ID ) || ! current_user_can( 'edit_post', $revision->post_parent ) ) {
break;
}
// Revisions disabled and we're not looking at an autosave
if ( ! wp_revisions_enabled( $post ) && ! wp_is_post_autosave( $revision ) ) {
$redirect = 'edit.php?post_type=' . $post->post_type;
break;
}
$post_edit_link = get_edit_post_link();
$post_title = '<a href="' . $post_edit_link . '">' . _draft_or_post_title() . '</a>';
/* translators: %s: post title */
$h1 = sprintf( __( 'Compare Revisions of “%s”' ), $post_title );
$return_to_post = '<a href="' . $post_edit_link . '">' . __( '← Return to editor' ) . '</a>';
$title = __( 'Revisions' );
$redirect = false;
break;
}
// Empty post_type means either malformed object found, or no valid parent was found.
if ( ! $redirect && empty( $post->post_type ) ) {
$redirect = 'edit.php';
}
if ( ! empty( $redirect ) ) {
wp_redirect( $redirect );
exit;
}
// This is so that the correct "Edit" menu item is selected.
if ( ! empty( $post->post_type ) && 'post' != $post->post_type ) {
$parent_file = $submenu_file = 'edit.php?post_type=' . $post->post_type;
} else {
$parent_file = $submenu_file = 'edit.php';
}
wp_enqueue_script( 'revisions' );
wp_localize_script( 'revisions', '_wpRevisionsSettings', wp_prepare_revisions_for_js( $post, $revision_id, $from ) );
/* Revisions Help Tab */
$revisions_overview = '<p>' . __( 'This screen is used for managing your content revisions.' ) . '</p>';
$revisions_overview .= '<p>' . __( 'Revisions are saved copies of your post or page, which are periodically created as you update your content. The red text on the left shows the content that was removed. The green text on the right shows the content that was added.' ) . '</p>';
$revisions_overview .= '<p>' . __( 'From this screen you can review, compare, and restore revisions:' ) . '</p>';
$revisions_overview .= '<ul><li>' . __( 'To navigate between revisions, <strong>drag the slider handle left or right</strong> or <strong>use the Previous or Next buttons</strong>.' ) . '</li>';
$revisions_overview .= '<li>' . __( 'Compare two different revisions by <strong>selecting the “Compare any two revisions” box</strong> to the side.' ) . '</li>';
$revisions_overview .= '<li>' . __( 'To restore a revision, <strong>click Restore This Revision</strong>.' ) . '</li></ul>';
get_current_screen()->add_help_tab(
array(
'id' => 'revisions-overview',
'title' => __( 'Overview' ),
'content' => $revisions_overview,
)
);
$revisions_sidebar = '<p><strong>' . __( 'For more information:' ) . '</strong></p>';
$revisions_sidebar .= '<p>' . __( '<a href="https://codex.wordpress.org/Revision_Management">Revisions Management</a>' ) . '</p>';
$revisions_sidebar .= '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>';
get_current_screen()->set_help_sidebar( $revisions_sidebar );
require_once( ABSPATH . 'wp-admin/admin-header.php' );
?>
<div class="wrap">
<h1 class="long-header"><?php echo $h1; ?></h1>
<?php echo $return_to_post; ?>
</div>
<?php
wp_print_revision_templates();
require_once( ABSPATH . 'wp-admin/admin-footer.php' );
home/xbodynamge/www/wp-admin/includes/revision.php 0000604 00000035143 15113554213 0016350 0 ustar 00 <?php
/**
* WordPress Administration Revisions API
*
* @package WordPress
* @subpackage Administration
* @since 3.6.0
*/
/**
* Get the revision UI diff.
*
* @since 3.6.0
*
* @param object|int $post The post object. Also accepts a post ID.
* @param int $compare_from The revision ID to compare from.
* @param int $compare_to The revision ID to come to.
*
* @return array|bool Associative array of a post's revisioned fields and their diffs.
* Or, false on failure.
*/
function wp_get_revision_ui_diff( $post, $compare_from, $compare_to ) {
if ( ! $post = get_post( $post ) )
return false;
if ( $compare_from ) {
if ( ! $compare_from = get_post( $compare_from ) )
return false;
} else {
// If we're dealing with the first revision...
$compare_from = false;
}
if ( ! $compare_to = get_post( $compare_to ) )
return false;
// If comparing revisions, make sure we're dealing with the right post parent.
// The parent post may be a 'revision' when revisions are disabled and we're looking at autosaves.
if ( $compare_from && $compare_from->post_parent !== $post->ID && $compare_from->ID !== $post->ID )
return false;
if ( $compare_to->post_parent !== $post->ID && $compare_to->ID !== $post->ID )
return false;
if ( $compare_from && strtotime( $compare_from->post_date_gmt ) > strtotime( $compare_to->post_date_gmt ) ) {
$temp = $compare_from;
$compare_from = $compare_to;
$compare_to = $temp;
}
// Add default title if title field is empty
if ( $compare_from && empty( $compare_from->post_title ) )
$compare_from->post_title = __( '(no title)' );
if ( empty( $compare_to->post_title ) )
$compare_to->post_title = __( '(no title)' );
$return = array();
foreach ( _wp_post_revision_fields( $post ) as $field => $name ) {
/**
* Contextually filter a post revision field.
*
* The dynamic portion of the hook name, `$field`, corresponds to each of the post
* fields of the revision object being iterated over in a foreach statement.
*
* @since 3.6.0
*
* @param string $compare_from->$field The current revision field to compare to or from.
* @param string $field The current revision field.
* @param WP_Post $compare_from The revision post object to compare to or from.
* @param string null The context of whether the current revision is the old
* or the new one. Values are 'to' or 'from'.
*/
$content_from = $compare_from ? apply_filters( "_wp_post_revision_field_{$field}", $compare_from->$field, $field, $compare_from, 'from' ) : '';
/** This filter is documented in wp-admin/includes/revision.php */
$content_to = apply_filters( "_wp_post_revision_field_{$field}", $compare_to->$field, $field, $compare_to, 'to' );
$args = array(
'show_split_view' => true
);
/**
* Filters revisions text diff options.
*
* Filters the options passed to wp_text_diff() when viewing a post revision.
*
* @since 4.1.0
*
* @param array $args {
* Associative array of options to pass to wp_text_diff().
*
* @type bool $show_split_view True for split view (two columns), false for
* un-split view (single column). Default true.
* }
* @param string $field The current revision field.
* @param WP_Post $compare_from The revision post to compare from.
* @param WP_Post $compare_to The revision post to compare to.
*/
$args = apply_filters( 'revision_text_diff_options', $args, $field, $compare_from, $compare_to );
$diff = wp_text_diff( $content_from, $content_to, $args );
if ( ! $diff && 'post_title' === $field ) {
// It's a better user experience to still show the Title, even if it didn't change.
// No, you didn't see this.
$diff = '<table class="diff"><colgroup><col class="content diffsplit left"><col class="content diffsplit middle"><col class="content diffsplit right"></colgroup><tbody><tr>';
$diff .= '<td>' . esc_html( $compare_from->post_title ) . '</td><td></td><td>' . esc_html( $compare_to->post_title ) . '</td>';
$diff .= '</tr></tbody>';
$diff .= '</table>';
}
if ( $diff ) {
$return[] = array(
'id' => $field,
'name' => $name,
'diff' => $diff,
);
}
}
/**
* Filters the fields displayed in the post revision diff UI.
*
* @since 4.1.0
*
* @param array $return Revision UI fields. Each item is an array of id, name and diff.
* @param WP_Post $compare_from The revision post to compare from.
* @param WP_Post $compare_to The revision post to compare to.
*/
return apply_filters( 'wp_get_revision_ui_diff', $return, $compare_from, $compare_to );
}
/**
* Prepare revisions for JavaScript.
*
* @since 3.6.0
*
* @param object|int $post The post object. Also accepts a post ID.
* @param int $selected_revision_id The selected revision ID.
* @param int $from Optional. The revision ID to compare from.
*
* @return array An associative array of revision data and related settings.
*/
function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null ) {
$post = get_post( $post );
$authors = array();
$now_gmt = time();
$revisions = wp_get_post_revisions( $post->ID, array( 'order' => 'ASC', 'check_enabled' => false ) );
// If revisions are disabled, we only want autosaves and the current post.
if ( ! wp_revisions_enabled( $post ) ) {
foreach ( $revisions as $revision_id => $revision ) {
if ( ! wp_is_post_autosave( $revision ) )
unset( $revisions[ $revision_id ] );
}
$revisions = array( $post->ID => $post ) + $revisions;
}
$show_avatars = get_option( 'show_avatars' );
cache_users( wp_list_pluck( $revisions, 'post_author' ) );
$can_restore = current_user_can( 'edit_post', $post->ID );
$current_id = false;
foreach ( $revisions as $revision ) {
$modified = strtotime( $revision->post_modified );
$modified_gmt = strtotime( $revision->post_modified_gmt . ' +0000' );
if ( $can_restore ) {
$restore_link = str_replace( '&', '&', wp_nonce_url(
add_query_arg(
array( 'revision' => $revision->ID,
'action' => 'restore' ),
admin_url( 'revision.php' )
),
"restore-post_{$revision->ID}"
) );
}
if ( ! isset( $authors[ $revision->post_author ] ) ) {
$authors[ $revision->post_author ] = array(
'id' => (int) $revision->post_author,
'avatar' => $show_avatars ? get_avatar( $revision->post_author, 32 ) : '',
'name' => get_the_author_meta( 'display_name', $revision->post_author ),
);
}
$autosave = (bool) wp_is_post_autosave( $revision );
$current = ! $autosave && $revision->post_modified_gmt === $post->post_modified_gmt;
if ( $current && ! empty( $current_id ) ) {
// If multiple revisions have the same post_modified_gmt, highest ID is current.
if ( $current_id < $revision->ID ) {
$revisions[ $current_id ]['current'] = false;
$current_id = $revision->ID;
} else {
$current = false;
}
} elseif ( $current ) {
$current_id = $revision->ID;
}
$revisions_data = array(
'id' => $revision->ID,
'title' => get_the_title( $post->ID ),
'author' => $authors[ $revision->post_author ],
'date' => date_i18n( __( 'M j, Y @ H:i' ), $modified ),
'dateShort' => date_i18n( _x( 'j M @ H:i', 'revision date short format' ), $modified ),
'timeAgo' => sprintf( __( '%s ago' ), human_time_diff( $modified_gmt, $now_gmt ) ),
'autosave' => $autosave,
'current' => $current,
'restoreUrl' => $can_restore ? $restore_link : false,
);
/**
* Filters the array of revisions used on the revisions screen.
*
* @since 4.4.0
*
* @param array $revisions_data {
* The bootstrapped data for the revisions screen.
*
* @type int $id Revision ID.
* @type string $title Title for the revision's parent WP_Post object.
* @type int $author Revision post author ID.
* @type string $date Date the revision was modified.
* @type string $dateShort Short-form version of the date the revision was modified.
* @type string $timeAgo GMT-aware amount of time ago the revision was modified.
* @type bool $autosave Whether the revision is an autosave.
* @type bool $current Whether the revision is both not an autosave and the post
* modified date matches the revision modified date (GMT-aware).
* @type bool|false $restoreUrl URL if the revision can be restored, false otherwise.
* }
* @param WP_Post $revision The revision's WP_Post object.
* @param WP_Post $post The revision's parent WP_Post object.
*/
$revisions[ $revision->ID ] = apply_filters( 'wp_prepare_revision_for_js', $revisions_data, $revision, $post );
}
/**
* If we only have one revision, the initial revision is missing; This happens
* when we have an autsosave and the user has clicked 'View the Autosave'
*/
if ( 1 === sizeof( $revisions ) ) {
$revisions[ $post->ID ] = array(
'id' => $post->ID,
'title' => get_the_title( $post->ID ),
'author' => $authors[ $post->post_author ],
'date' => date_i18n( __( 'M j, Y @ H:i' ), strtotime( $post->post_modified ) ),
'dateShort' => date_i18n( _x( 'j M @ H:i', 'revision date short format' ), strtotime( $post->post_modified ) ),
'timeAgo' => sprintf( __( '%s ago' ), human_time_diff( strtotime( $post->post_modified_gmt ), $now_gmt ) ),
'autosave' => false,
'current' => true,
'restoreUrl' => false,
);
$current_id = $post->ID;
}
/*
* If a post has been saved since the last revision (no revisioned fields
* were changed), we may not have a "current" revision. Mark the latest
* revision as "current".
*/
if ( empty( $current_id ) ) {
if ( $revisions[ $revision->ID ]['autosave'] ) {
$revision = end( $revisions );
while ( $revision['autosave'] ) {
$revision = prev( $revisions );
}
$current_id = $revision['id'];
} else {
$current_id = $revision->ID;
}
$revisions[ $current_id ]['current'] = true;
}
// Now, grab the initial diff.
$compare_two_mode = is_numeric( $from );
if ( ! $compare_two_mode ) {
$found = array_search( $selected_revision_id, array_keys( $revisions ) );
if ( $found ) {
$from = array_keys( array_slice( $revisions, $found - 1, 1, true ) );
$from = reset( $from );
} else {
$from = 0;
}
}
$from = absint( $from );
$diffs = array( array(
'id' => $from . ':' . $selected_revision_id,
'fields' => wp_get_revision_ui_diff( $post->ID, $from, $selected_revision_id ),
));
return array(
'postId' => $post->ID,
'nonce' => wp_create_nonce( 'revisions-ajax-nonce' ),
'revisionData' => array_values( $revisions ),
'to' => $selected_revision_id,
'from' => $from,
'diffData' => $diffs,
'baseUrl' => parse_url( admin_url( 'revision.php' ), PHP_URL_PATH ),
'compareTwoMode' => absint( $compare_two_mode ), // Apparently booleans are not allowed
'revisionIds' => array_keys( $revisions ),
);
}
/**
* Print JavaScript templates required for the revisions experience.
*
* @since 4.1.0
*
* @global WP_Post $post The global `$post` object.
*/
function wp_print_revision_templates() {
global $post;
?><script id="tmpl-revisions-frame" type="text/html">
<div class="revisions-control-frame"></div>
<div class="revisions-diff-frame"></div>
</script>
<script id="tmpl-revisions-buttons" type="text/html">
<div class="revisions-previous">
<input class="button" type="button" value="<?php echo esc_attr_x( 'Previous', 'Button label for a previous revision' ); ?>" />
</div>
<div class="revisions-next">
<input class="button" type="button" value="<?php echo esc_attr_x( 'Next', 'Button label for a next revision' ); ?>" />
</div>
</script>
<script id="tmpl-revisions-checkbox" type="text/html">
<div class="revision-toggle-compare-mode">
<label>
<input type="checkbox" class="compare-two-revisions"
<#
if ( 'undefined' !== typeof data && data.model.attributes.compareTwoMode ) {
#> checked="checked"<#
}
#>
/>
<?php esc_html_e( 'Compare any two revisions' ); ?>
</label>
</div>
</script>
<script id="tmpl-revisions-meta" type="text/html">
<# if ( ! _.isUndefined( data.attributes ) ) { #>
<div class="diff-title">
<# if ( 'from' === data.type ) { #>
<strong><?php _ex( 'From:', 'Followed by post revision info' ); ?></strong>
<# } else if ( 'to' === data.type ) { #>
<strong><?php _ex( 'To:', 'Followed by post revision info' ); ?></strong>
<# } #>
<div class="author-card<# if ( data.attributes.autosave ) { #> autosave<# } #>">
{{{ data.attributes.author.avatar }}}
<div class="author-info">
<# if ( data.attributes.autosave ) { #>
<span class="byline"><?php printf( __( 'Autosave by %s' ),
'<span class="author-name">{{ data.attributes.author.name }}</span>' ); ?></span>
<# } else if ( data.attributes.current ) { #>
<span class="byline"><?php printf( __( 'Current Revision by %s' ),
'<span class="author-name">{{ data.attributes.author.name }}</span>' ); ?></span>
<# } else { #>
<span class="byline"><?php printf( __( 'Revision by %s' ),
'<span class="author-name">{{ data.attributes.author.name }}</span>' ); ?></span>
<# } #>
<span class="time-ago">{{ data.attributes.timeAgo }}</span>
<span class="date">({{ data.attributes.dateShort }})</span>
</div>
<# if ( 'to' === data.type && data.attributes.restoreUrl ) { #>
<input <?php if ( wp_check_post_lock( $post->ID ) ) { ?>
disabled="disabled"
<?php } else { ?>
<# if ( data.attributes.current ) { #>
disabled="disabled"
<# } #>
<?php } ?>
<# if ( data.attributes.autosave ) { #>
type="button" class="restore-revision button button-primary" value="<?php esc_attr_e( 'Restore This Autosave' ); ?>" />
<# } else { #>
type="button" class="restore-revision button button-primary" value="<?php esc_attr_e( 'Restore This Revision' ); ?>" />
<# } #>
<# } #>
</div>
<# if ( 'tooltip' === data.type ) { #>
<div class="revisions-tooltip-arrow"><span></span></div>
<# } #>
<# } #>
</script>
<script id="tmpl-revisions-diff" type="text/html">
<div class="loading-indicator"><span class="spinner"></span></div>
<div class="diff-error"><?php _e( 'Sorry, something went wrong. The requested comparison could not be loaded.' ); ?></div>
<div class="diff">
<# _.each( data.fields, function( field ) { #>
<h3>{{ field.name }}</h3>
{{{ field.diff }}}
<# }); #>
</div>
</script><?php
}
home/xbodynamge/lebauwcentre/wp-admin/includes/revision.php 0000604 00000036465 15113607054 0020216 0 ustar 00 <?php
/**
* WordPress Administration Revisions API
*
* @package WordPress
* @subpackage Administration
* @since 3.6.0
*/
/**
* Get the revision UI diff.
*
* @since 3.6.0
*
* @param object|int $post The post object. Also accepts a post ID.
* @param int $compare_from The revision ID to compare from.
* @param int $compare_to The revision ID to come to.
*
* @return array|bool Associative array of a post's revisioned fields and their diffs.
* Or, false on failure.
*/
function wp_get_revision_ui_diff( $post, $compare_from, $compare_to ) {
if ( ! $post = get_post( $post ) ) {
return false;
}
if ( $compare_from ) {
if ( ! $compare_from = get_post( $compare_from ) ) {
return false;
}
} else {
// If we're dealing with the first revision...
$compare_from = false;
}
if ( ! $compare_to = get_post( $compare_to ) ) {
return false;
}
// If comparing revisions, make sure we're dealing with the right post parent.
// The parent post may be a 'revision' when revisions are disabled and we're looking at autosaves.
if ( $compare_from && $compare_from->post_parent !== $post->ID && $compare_from->ID !== $post->ID ) {
return false;
}
if ( $compare_to->post_parent !== $post->ID && $compare_to->ID !== $post->ID ) {
return false;
}
if ( $compare_from && strtotime( $compare_from->post_date_gmt ) > strtotime( $compare_to->post_date_gmt ) ) {
$temp = $compare_from;
$compare_from = $compare_to;
$compare_to = $temp;
}
// Add default title if title field is empty
if ( $compare_from && empty( $compare_from->post_title ) ) {
$compare_from->post_title = __( '(no title)' );
}
if ( empty( $compare_to->post_title ) ) {
$compare_to->post_title = __( '(no title)' );
}
$return = array();
foreach ( _wp_post_revision_fields( $post ) as $field => $name ) {
/**
* Contextually filter a post revision field.
*
* The dynamic portion of the hook name, `$field`, corresponds to each of the post
* fields of the revision object being iterated over in a foreach statement.
*
* @since 3.6.0
*
* @param string $compare_from->$field The current revision field to compare to or from.
* @param string $field The current revision field.
* @param WP_Post $compare_from The revision post object to compare to or from.
* @param string null The context of whether the current revision is the old
* or the new one. Values are 'to' or 'from'.
*/
$content_from = $compare_from ? apply_filters( "_wp_post_revision_field_{$field}", $compare_from->$field, $field, $compare_from, 'from' ) : '';
/** This filter is documented in wp-admin/includes/revision.php */
$content_to = apply_filters( "_wp_post_revision_field_{$field}", $compare_to->$field, $field, $compare_to, 'to' );
$args = array(
'show_split_view' => true,
);
/**
* Filters revisions text diff options.
*
* Filters the options passed to wp_text_diff() when viewing a post revision.
*
* @since 4.1.0
*
* @param array $args {
* Associative array of options to pass to wp_text_diff().
*
* @type bool $show_split_view True for split view (two columns), false for
* un-split view (single column). Default true.
* }
* @param string $field The current revision field.
* @param WP_Post $compare_from The revision post to compare from.
* @param WP_Post $compare_to The revision post to compare to.
*/
$args = apply_filters( 'revision_text_diff_options', $args, $field, $compare_from, $compare_to );
$diff = wp_text_diff( $content_from, $content_to, $args );
if ( ! $diff && 'post_title' === $field ) {
// It's a better user experience to still show the Title, even if it didn't change.
// No, you didn't see this.
$diff = '<table class="diff"><colgroup><col class="content diffsplit left"><col class="content diffsplit middle"><col class="content diffsplit right"></colgroup><tbody><tr>';
// In split screen mode, show the title before/after side by side.
if ( true === $args['show_split_view'] ) {
$diff .= '<td>' . esc_html( $compare_from->post_title ) . '</td><td></td><td>' . esc_html( $compare_to->post_title ) . '</td>';
} else {
$diff .= '<td>' . esc_html( $compare_from->post_title ) . '</td>';
// In single column mode, only show the title once if unchanged.
if ( $compare_from->post_title !== $compare_to->post_title ) {
$diff .= '</tr><tr><td>' . esc_html( $compare_to->post_title ) . '</td>';
}
}
$diff .= '</tr></tbody>';
$diff .= '</table>';
}
if ( $diff ) {
$return[] = array(
'id' => $field,
'name' => $name,
'diff' => $diff,
);
}
}
/**
* Filters the fields displayed in the post revision diff UI.
*
* @since 4.1.0
*
* @param array[] $return Array of revision UI fields. Each item is an array of id, name, and diff.
* @param WP_Post $compare_from The revision post to compare from.
* @param WP_Post $compare_to The revision post to compare to.
*/
return apply_filters( 'wp_get_revision_ui_diff', $return, $compare_from, $compare_to );
}
/**
* Prepare revisions for JavaScript.
*
* @since 3.6.0
*
* @param object|int $post The post object. Also accepts a post ID.
* @param int $selected_revision_id The selected revision ID.
* @param int $from Optional. The revision ID to compare from.
*
* @return array An associative array of revision data and related settings.
*/
function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null ) {
$post = get_post( $post );
$authors = array();
$now_gmt = time();
$revisions = wp_get_post_revisions(
$post->ID,
array(
'order' => 'ASC',
'check_enabled' => false,
)
);
// If revisions are disabled, we only want autosaves and the current post.
if ( ! wp_revisions_enabled( $post ) ) {
foreach ( $revisions as $revision_id => $revision ) {
if ( ! wp_is_post_autosave( $revision ) ) {
unset( $revisions[ $revision_id ] );
}
}
$revisions = array( $post->ID => $post ) + $revisions;
}
$show_avatars = get_option( 'show_avatars' );
cache_users( wp_list_pluck( $revisions, 'post_author' ) );
$can_restore = current_user_can( 'edit_post', $post->ID );
$current_id = false;
foreach ( $revisions as $revision ) {
$modified = strtotime( $revision->post_modified );
$modified_gmt = strtotime( $revision->post_modified_gmt . ' +0000' );
if ( $can_restore ) {
$restore_link = str_replace(
'&',
'&',
wp_nonce_url(
add_query_arg(
array(
'revision' => $revision->ID,
'action' => 'restore',
),
admin_url( 'revision.php' )
),
"restore-post_{$revision->ID}"
)
);
}
if ( ! isset( $authors[ $revision->post_author ] ) ) {
$authors[ $revision->post_author ] = array(
'id' => (int) $revision->post_author,
'avatar' => $show_avatars ? get_avatar( $revision->post_author, 32 ) : '',
'name' => get_the_author_meta( 'display_name', $revision->post_author ),
);
}
$autosave = (bool) wp_is_post_autosave( $revision );
$current = ! $autosave && $revision->post_modified_gmt === $post->post_modified_gmt;
if ( $current && ! empty( $current_id ) ) {
// If multiple revisions have the same post_modified_gmt, highest ID is current.
if ( $current_id < $revision->ID ) {
$revisions[ $current_id ]['current'] = false;
$current_id = $revision->ID;
} else {
$current = false;
}
} elseif ( $current ) {
$current_id = $revision->ID;
}
$revisions_data = array(
'id' => $revision->ID,
'title' => get_the_title( $post->ID ),
'author' => $authors[ $revision->post_author ],
'date' => date_i18n( __( 'M j, Y @ H:i' ), $modified ),
'dateShort' => date_i18n( _x( 'j M @ H:i', 'revision date short format' ), $modified ),
'timeAgo' => sprintf( __( '%s ago' ), human_time_diff( $modified_gmt, $now_gmt ) ),
'autosave' => $autosave,
'current' => $current,
'restoreUrl' => $can_restore ? $restore_link : false,
);
/**
* Filters the array of revisions used on the revisions screen.
*
* @since 4.4.0
*
* @param array $revisions_data {
* The bootstrapped data for the revisions screen.
*
* @type int $id Revision ID.
* @type string $title Title for the revision's parent WP_Post object.
* @type int $author Revision post author ID.
* @type string $date Date the revision was modified.
* @type string $dateShort Short-form version of the date the revision was modified.
* @type string $timeAgo GMT-aware amount of time ago the revision was modified.
* @type bool $autosave Whether the revision is an autosave.
* @type bool $current Whether the revision is both not an autosave and the post
* modified date matches the revision modified date (GMT-aware).
* @type bool|false $restoreUrl URL if the revision can be restored, false otherwise.
* }
* @param WP_Post $revision The revision's WP_Post object.
* @param WP_Post $post The revision's parent WP_Post object.
*/
$revisions[ $revision->ID ] = apply_filters( 'wp_prepare_revision_for_js', $revisions_data, $revision, $post );
}
/**
* If we only have one revision, the initial revision is missing; This happens
* when we have an autsosave and the user has clicked 'View the Autosave'
*/
if ( 1 === sizeof( $revisions ) ) {
$revisions[ $post->ID ] = array(
'id' => $post->ID,
'title' => get_the_title( $post->ID ),
'author' => $authors[ $post->post_author ],
'date' => date_i18n( __( 'M j, Y @ H:i' ), strtotime( $post->post_modified ) ),
'dateShort' => date_i18n( _x( 'j M @ H:i', 'revision date short format' ), strtotime( $post->post_modified ) ),
'timeAgo' => sprintf( __( '%s ago' ), human_time_diff( strtotime( $post->post_modified_gmt ), $now_gmt ) ),
'autosave' => false,
'current' => true,
'restoreUrl' => false,
);
$current_id = $post->ID;
}
/*
* If a post has been saved since the last revision (no revisioned fields
* were changed), we may not have a "current" revision. Mark the latest
* revision as "current".
*/
if ( empty( $current_id ) ) {
if ( $revisions[ $revision->ID ]['autosave'] ) {
$revision = end( $revisions );
while ( $revision['autosave'] ) {
$revision = prev( $revisions );
}
$current_id = $revision['id'];
} else {
$current_id = $revision->ID;
}
$revisions[ $current_id ]['current'] = true;
}
// Now, grab the initial diff.
$compare_two_mode = is_numeric( $from );
if ( ! $compare_two_mode ) {
$found = array_search( $selected_revision_id, array_keys( $revisions ) );
if ( $found ) {
$from = array_keys( array_slice( $revisions, $found - 1, 1, true ) );
$from = reset( $from );
} else {
$from = 0;
}
}
$from = absint( $from );
$diffs = array(
array(
'id' => $from . ':' . $selected_revision_id,
'fields' => wp_get_revision_ui_diff( $post->ID, $from, $selected_revision_id ),
),
);
return array(
'postId' => $post->ID,
'nonce' => wp_create_nonce( 'revisions-ajax-nonce' ),
'revisionData' => array_values( $revisions ),
'to' => $selected_revision_id,
'from' => $from,
'diffData' => $diffs,
'baseUrl' => parse_url( admin_url( 'revision.php' ), PHP_URL_PATH ),
'compareTwoMode' => absint( $compare_two_mode ), // Apparently booleans are not allowed
'revisionIds' => array_keys( $revisions ),
);
}
/**
* Print JavaScript templates required for the revisions experience.
*
* @since 4.1.0
*
* @global WP_Post $post The global `$post` object.
*/
function wp_print_revision_templates() {
global $post;
?><script id="tmpl-revisions-frame" type="text/html">
<div class="revisions-control-frame"></div>
<div class="revisions-diff-frame"></div>
</script>
<script id="tmpl-revisions-buttons" type="text/html">
<div class="revisions-previous">
<input class="button" type="button" value="<?php echo esc_attr_x( 'Previous', 'Button label for a previous revision' ); ?>" />
</div>
<div class="revisions-next">
<input class="button" type="button" value="<?php echo esc_attr_x( 'Next', 'Button label for a next revision' ); ?>" />
</div>
</script>
<script id="tmpl-revisions-checkbox" type="text/html">
<div class="revision-toggle-compare-mode">
<label>
<input type="checkbox" class="compare-two-revisions"
<#
if ( 'undefined' !== typeof data && data.model.attributes.compareTwoMode ) {
#> checked="checked"<#
}
#>
/>
<?php esc_html_e( 'Compare any two revisions' ); ?>
</label>
</div>
</script>
<script id="tmpl-revisions-meta" type="text/html">
<# if ( ! _.isUndefined( data.attributes ) ) { #>
<div class="diff-title">
<# if ( 'from' === data.type ) { #>
<strong><?php _ex( 'From:', 'Followed by post revision info' ); ?></strong>
<# } else if ( 'to' === data.type ) { #>
<strong><?php _ex( 'To:', 'Followed by post revision info' ); ?></strong>
<# } #>
<div class="author-card<# if ( data.attributes.autosave ) { #> autosave<# } #>">
{{{ data.attributes.author.avatar }}}
<div class="author-info">
<# if ( data.attributes.autosave ) { #>
<span class="byline">
<?php
printf(
__( 'Autosave by %s' ),
'<span class="author-name">{{ data.attributes.author.name }}</span>'
);
?>
</span>
<# } else if ( data.attributes.current ) { #>
<span class="byline">
<?php
printf(
__( 'Current Revision by %s' ),
'<span class="author-name">{{ data.attributes.author.name }}</span>'
);
?>
</span>
<# } else { #>
<span class="byline">
<?php
printf(
__( 'Revision by %s' ),
'<span class="author-name">{{ data.attributes.author.name }}</span>'
);
?>
</span>
<# } #>
<span class="time-ago">{{ data.attributes.timeAgo }}</span>
<span class="date">({{ data.attributes.dateShort }})</span>
</div>
<# if ( 'to' === data.type && data.attributes.restoreUrl ) { #>
<input <?php if ( wp_check_post_lock( $post->ID ) ) { ?>
disabled="disabled"
<?php } else { ?>
<# if ( data.attributes.current ) { #>
disabled="disabled"
<# } #>
<?php } ?>
<# if ( data.attributes.autosave ) { #>
type="button" class="restore-revision button button-primary" value="<?php esc_attr_e( 'Restore This Autosave' ); ?>" />
<# } else { #>
type="button" class="restore-revision button button-primary" value="<?php esc_attr_e( 'Restore This Revision' ); ?>" />
<# } #>
<# } #>
</div>
<# if ( 'tooltip' === data.type ) { #>
<div class="revisions-tooltip-arrow"><span></span></div>
<# } #>
<# } #>
</script>
<script id="tmpl-revisions-diff" type="text/html">
<div class="loading-indicator"><span class="spinner"></span></div>
<div class="diff-error"><?php _e( 'Sorry, something went wrong. The requested comparison could not be loaded.' ); ?></div>
<div class="diff">
<# _.each( data.fields, function( field ) { #>
<h3>{{ field.name }}</h3>
{{{ field.diff }}}
<# }); #>
</div>
</script>
<?php
}
home/xbodynamge/dev/wp-admin/includes/revision.php 0000604 00000035143 15114024601 0016274 0 ustar 00 <?php
/**
* WordPress Administration Revisions API
*
* @package WordPress
* @subpackage Administration
* @since 3.6.0
*/
/**
* Get the revision UI diff.
*
* @since 3.6.0
*
* @param object|int $post The post object. Also accepts a post ID.
* @param int $compare_from The revision ID to compare from.
* @param int $compare_to The revision ID to come to.
*
* @return array|bool Associative array of a post's revisioned fields and their diffs.
* Or, false on failure.
*/
function wp_get_revision_ui_diff( $post, $compare_from, $compare_to ) {
if ( ! $post = get_post( $post ) )
return false;
if ( $compare_from ) {
if ( ! $compare_from = get_post( $compare_from ) )
return false;
} else {
// If we're dealing with the first revision...
$compare_from = false;
}
if ( ! $compare_to = get_post( $compare_to ) )
return false;
// If comparing revisions, make sure we're dealing with the right post parent.
// The parent post may be a 'revision' when revisions are disabled and we're looking at autosaves.
if ( $compare_from && $compare_from->post_parent !== $post->ID && $compare_from->ID !== $post->ID )
return false;
if ( $compare_to->post_parent !== $post->ID && $compare_to->ID !== $post->ID )
return false;
if ( $compare_from && strtotime( $compare_from->post_date_gmt ) > strtotime( $compare_to->post_date_gmt ) ) {
$temp = $compare_from;
$compare_from = $compare_to;
$compare_to = $temp;
}
// Add default title if title field is empty
if ( $compare_from && empty( $compare_from->post_title ) )
$compare_from->post_title = __( '(no title)' );
if ( empty( $compare_to->post_title ) )
$compare_to->post_title = __( '(no title)' );
$return = array();
foreach ( _wp_post_revision_fields( $post ) as $field => $name ) {
/**
* Contextually filter a post revision field.
*
* The dynamic portion of the hook name, `$field`, corresponds to each of the post
* fields of the revision object being iterated over in a foreach statement.
*
* @since 3.6.0
*
* @param string $compare_from->$field The current revision field to compare to or from.
* @param string $field The current revision field.
* @param WP_Post $compare_from The revision post object to compare to or from.
* @param string null The context of whether the current revision is the old
* or the new one. Values are 'to' or 'from'.
*/
$content_from = $compare_from ? apply_filters( "_wp_post_revision_field_{$field}", $compare_from->$field, $field, $compare_from, 'from' ) : '';
/** This filter is documented in wp-admin/includes/revision.php */
$content_to = apply_filters( "_wp_post_revision_field_{$field}", $compare_to->$field, $field, $compare_to, 'to' );
$args = array(
'show_split_view' => true
);
/**
* Filters revisions text diff options.
*
* Filters the options passed to wp_text_diff() when viewing a post revision.
*
* @since 4.1.0
*
* @param array $args {
* Associative array of options to pass to wp_text_diff().
*
* @type bool $show_split_view True for split view (two columns), false for
* un-split view (single column). Default true.
* }
* @param string $field The current revision field.
* @param WP_Post $compare_from The revision post to compare from.
* @param WP_Post $compare_to The revision post to compare to.
*/
$args = apply_filters( 'revision_text_diff_options', $args, $field, $compare_from, $compare_to );
$diff = wp_text_diff( $content_from, $content_to, $args );
if ( ! $diff && 'post_title' === $field ) {
// It's a better user experience to still show the Title, even if it didn't change.
// No, you didn't see this.
$diff = '<table class="diff"><colgroup><col class="content diffsplit left"><col class="content diffsplit middle"><col class="content diffsplit right"></colgroup><tbody><tr>';
$diff .= '<td>' . esc_html( $compare_from->post_title ) . '</td><td></td><td>' . esc_html( $compare_to->post_title ) . '</td>';
$diff .= '</tr></tbody>';
$diff .= '</table>';
}
if ( $diff ) {
$return[] = array(
'id' => $field,
'name' => $name,
'diff' => $diff,
);
}
}
/**
* Filters the fields displayed in the post revision diff UI.
*
* @since 4.1.0
*
* @param array $return Revision UI fields. Each item is an array of id, name and diff.
* @param WP_Post $compare_from The revision post to compare from.
* @param WP_Post $compare_to The revision post to compare to.
*/
return apply_filters( 'wp_get_revision_ui_diff', $return, $compare_from, $compare_to );
}
/**
* Prepare revisions for JavaScript.
*
* @since 3.6.0
*
* @param object|int $post The post object. Also accepts a post ID.
* @param int $selected_revision_id The selected revision ID.
* @param int $from Optional. The revision ID to compare from.
*
* @return array An associative array of revision data and related settings.
*/
function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null ) {
$post = get_post( $post );
$authors = array();
$now_gmt = time();
$revisions = wp_get_post_revisions( $post->ID, array( 'order' => 'ASC', 'check_enabled' => false ) );
// If revisions are disabled, we only want autosaves and the current post.
if ( ! wp_revisions_enabled( $post ) ) {
foreach ( $revisions as $revision_id => $revision ) {
if ( ! wp_is_post_autosave( $revision ) )
unset( $revisions[ $revision_id ] );
}
$revisions = array( $post->ID => $post ) + $revisions;
}
$show_avatars = get_option( 'show_avatars' );
cache_users( wp_list_pluck( $revisions, 'post_author' ) );
$can_restore = current_user_can( 'edit_post', $post->ID );
$current_id = false;
foreach ( $revisions as $revision ) {
$modified = strtotime( $revision->post_modified );
$modified_gmt = strtotime( $revision->post_modified_gmt . ' +0000' );
if ( $can_restore ) {
$restore_link = str_replace( '&', '&', wp_nonce_url(
add_query_arg(
array( 'revision' => $revision->ID,
'action' => 'restore' ),
admin_url( 'revision.php' )
),
"restore-post_{$revision->ID}"
) );
}
if ( ! isset( $authors[ $revision->post_author ] ) ) {
$authors[ $revision->post_author ] = array(
'id' => (int) $revision->post_author,
'avatar' => $show_avatars ? get_avatar( $revision->post_author, 32 ) : '',
'name' => get_the_author_meta( 'display_name', $revision->post_author ),
);
}
$autosave = (bool) wp_is_post_autosave( $revision );
$current = ! $autosave && $revision->post_modified_gmt === $post->post_modified_gmt;
if ( $current && ! empty( $current_id ) ) {
// If multiple revisions have the same post_modified_gmt, highest ID is current.
if ( $current_id < $revision->ID ) {
$revisions[ $current_id ]['current'] = false;
$current_id = $revision->ID;
} else {
$current = false;
}
} elseif ( $current ) {
$current_id = $revision->ID;
}
$revisions_data = array(
'id' => $revision->ID,
'title' => get_the_title( $post->ID ),
'author' => $authors[ $revision->post_author ],
'date' => date_i18n( __( 'M j, Y @ H:i' ), $modified ),
'dateShort' => date_i18n( _x( 'j M @ H:i', 'revision date short format' ), $modified ),
'timeAgo' => sprintf( __( '%s ago' ), human_time_diff( $modified_gmt, $now_gmt ) ),
'autosave' => $autosave,
'current' => $current,
'restoreUrl' => $can_restore ? $restore_link : false,
);
/**
* Filters the array of revisions used on the revisions screen.
*
* @since 4.4.0
*
* @param array $revisions_data {
* The bootstrapped data for the revisions screen.
*
* @type int $id Revision ID.
* @type string $title Title for the revision's parent WP_Post object.
* @type int $author Revision post author ID.
* @type string $date Date the revision was modified.
* @type string $dateShort Short-form version of the date the revision was modified.
* @type string $timeAgo GMT-aware amount of time ago the revision was modified.
* @type bool $autosave Whether the revision is an autosave.
* @type bool $current Whether the revision is both not an autosave and the post
* modified date matches the revision modified date (GMT-aware).
* @type bool|false $restoreUrl URL if the revision can be restored, false otherwise.
* }
* @param WP_Post $revision The revision's WP_Post object.
* @param WP_Post $post The revision's parent WP_Post object.
*/
$revisions[ $revision->ID ] = apply_filters( 'wp_prepare_revision_for_js', $revisions_data, $revision, $post );
}
/**
* If we only have one revision, the initial revision is missing; This happens
* when we have an autsosave and the user has clicked 'View the Autosave'
*/
if ( 1 === sizeof( $revisions ) ) {
$revisions[ $post->ID ] = array(
'id' => $post->ID,
'title' => get_the_title( $post->ID ),
'author' => $authors[ $post->post_author ],
'date' => date_i18n( __( 'M j, Y @ H:i' ), strtotime( $post->post_modified ) ),
'dateShort' => date_i18n( _x( 'j M @ H:i', 'revision date short format' ), strtotime( $post->post_modified ) ),
'timeAgo' => sprintf( __( '%s ago' ), human_time_diff( strtotime( $post->post_modified_gmt ), $now_gmt ) ),
'autosave' => false,
'current' => true,
'restoreUrl' => false,
);
$current_id = $post->ID;
}
/*
* If a post has been saved since the last revision (no revisioned fields
* were changed), we may not have a "current" revision. Mark the latest
* revision as "current".
*/
if ( empty( $current_id ) ) {
if ( $revisions[ $revision->ID ]['autosave'] ) {
$revision = end( $revisions );
while ( $revision['autosave'] ) {
$revision = prev( $revisions );
}
$current_id = $revision['id'];
} else {
$current_id = $revision->ID;
}
$revisions[ $current_id ]['current'] = true;
}
// Now, grab the initial diff.
$compare_two_mode = is_numeric( $from );
if ( ! $compare_two_mode ) {
$found = array_search( $selected_revision_id, array_keys( $revisions ) );
if ( $found ) {
$from = array_keys( array_slice( $revisions, $found - 1, 1, true ) );
$from = reset( $from );
} else {
$from = 0;
}
}
$from = absint( $from );
$diffs = array( array(
'id' => $from . ':' . $selected_revision_id,
'fields' => wp_get_revision_ui_diff( $post->ID, $from, $selected_revision_id ),
));
return array(
'postId' => $post->ID,
'nonce' => wp_create_nonce( 'revisions-ajax-nonce' ),
'revisionData' => array_values( $revisions ),
'to' => $selected_revision_id,
'from' => $from,
'diffData' => $diffs,
'baseUrl' => parse_url( admin_url( 'revision.php' ), PHP_URL_PATH ),
'compareTwoMode' => absint( $compare_two_mode ), // Apparently booleans are not allowed
'revisionIds' => array_keys( $revisions ),
);
}
/**
* Print JavaScript templates required for the revisions experience.
*
* @since 4.1.0
*
* @global WP_Post $post The global `$post` object.
*/
function wp_print_revision_templates() {
global $post;
?><script id="tmpl-revisions-frame" type="text/html">
<div class="revisions-control-frame"></div>
<div class="revisions-diff-frame"></div>
</script>
<script id="tmpl-revisions-buttons" type="text/html">
<div class="revisions-previous">
<input class="button" type="button" value="<?php echo esc_attr_x( 'Previous', 'Button label for a previous revision' ); ?>" />
</div>
<div class="revisions-next">
<input class="button" type="button" value="<?php echo esc_attr_x( 'Next', 'Button label for a next revision' ); ?>" />
</div>
</script>
<script id="tmpl-revisions-checkbox" type="text/html">
<div class="revision-toggle-compare-mode">
<label>
<input type="checkbox" class="compare-two-revisions"
<#
if ( 'undefined' !== typeof data && data.model.attributes.compareTwoMode ) {
#> checked="checked"<#
}
#>
/>
<?php esc_html_e( 'Compare any two revisions' ); ?>
</label>
</div>
</script>
<script id="tmpl-revisions-meta" type="text/html">
<# if ( ! _.isUndefined( data.attributes ) ) { #>
<div class="diff-title">
<# if ( 'from' === data.type ) { #>
<strong><?php _ex( 'From:', 'Followed by post revision info' ); ?></strong>
<# } else if ( 'to' === data.type ) { #>
<strong><?php _ex( 'To:', 'Followed by post revision info' ); ?></strong>
<# } #>
<div class="author-card<# if ( data.attributes.autosave ) { #> autosave<# } #>">
{{{ data.attributes.author.avatar }}}
<div class="author-info">
<# if ( data.attributes.autosave ) { #>
<span class="byline"><?php printf( __( 'Autosave by %s' ),
'<span class="author-name">{{ data.attributes.author.name }}</span>' ); ?></span>
<# } else if ( data.attributes.current ) { #>
<span class="byline"><?php printf( __( 'Current Revision by %s' ),
'<span class="author-name">{{ data.attributes.author.name }}</span>' ); ?></span>
<# } else { #>
<span class="byline"><?php printf( __( 'Revision by %s' ),
'<span class="author-name">{{ data.attributes.author.name }}</span>' ); ?></span>
<# } #>
<span class="time-ago">{{ data.attributes.timeAgo }}</span>
<span class="date">({{ data.attributes.dateShort }})</span>
</div>
<# if ( 'to' === data.type && data.attributes.restoreUrl ) { #>
<input <?php if ( wp_check_post_lock( $post->ID ) ) { ?>
disabled="disabled"
<?php } else { ?>
<# if ( data.attributes.current ) { #>
disabled="disabled"
<# } #>
<?php } ?>
<# if ( data.attributes.autosave ) { #>
type="button" class="restore-revision button button-primary" value="<?php esc_attr_e( 'Restore This Autosave' ); ?>" />
<# } else { #>
type="button" class="restore-revision button button-primary" value="<?php esc_attr_e( 'Restore This Revision' ); ?>" />
<# } #>
<# } #>
</div>
<# if ( 'tooltip' === data.type ) { #>
<div class="revisions-tooltip-arrow"><span></span></div>
<# } #>
<# } #>
</script>
<script id="tmpl-revisions-diff" type="text/html">
<div class="loading-indicator"><span class="spinner"></span></div>
<div class="diff-error"><?php _e( 'Sorry, something went wrong. The requested comparison could not be loaded.' ); ?></div>
<div class="diff">
<# _.each( data.fields, function( field ) { #>
<h3>{{ field.name }}</h3>
{{{ field.diff }}}
<# }); #>
</div>
</script><?php
}