mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-12 12:50:28 +00:00
Code is Poetry.
WordPress' code just... wasn't. This is now dealt with. Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS. Fixes #41057. git-svn-id: https://develop.svn.wordpress.org/trunk@42343 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -20,38 +20,45 @@
|
||||
* Or, false on failure.
|
||||
*/
|
||||
function wp_get_revision_ui_diff( $post, $compare_from, $compare_to ) {
|
||||
if ( ! $post = get_post( $post ) )
|
||||
if ( ! $post = get_post( $post ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $compare_from ) {
|
||||
if ( ! $compare_from = get_post( $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 ) )
|
||||
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 )
|
||||
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 )
|
||||
}
|
||||
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;
|
||||
$temp = $compare_from;
|
||||
$compare_from = $compare_to;
|
||||
$compare_to = $temp;
|
||||
$compare_to = $temp;
|
||||
}
|
||||
|
||||
// Add default title if title field is empty
|
||||
if ( $compare_from && empty( $compare_from->post_title ) )
|
||||
if ( $compare_from && empty( $compare_from->post_title ) ) {
|
||||
$compare_from->post_title = __( '(no title)' );
|
||||
if ( empty( $compare_to->post_title ) )
|
||||
}
|
||||
if ( empty( $compare_to->post_title ) ) {
|
||||
$compare_to->post_title = __( '(no title)' );
|
||||
}
|
||||
|
||||
$return = array();
|
||||
|
||||
@@ -76,7 +83,7 @@ function wp_get_revision_ui_diff( $post, $compare_from, $compare_to ) {
|
||||
$content_to = apply_filters( "_wp_post_revision_field_{$field}", $compare_to->$field, $field, $compare_to, 'to' );
|
||||
|
||||
$args = array(
|
||||
'show_split_view' => true
|
||||
'show_split_view' => true,
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -103,7 +110,7 @@ function wp_get_revision_ui_diff( $post, $compare_from, $compare_to ) {
|
||||
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 = '<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>';
|
||||
@@ -111,7 +118,7 @@ function wp_get_revision_ui_diff( $post, $compare_from, $compare_to ) {
|
||||
|
||||
if ( $diff ) {
|
||||
$return[] = array(
|
||||
'id' => $field,
|
||||
'id' => $field,
|
||||
'name' => $name,
|
||||
'diff' => $diff,
|
||||
);
|
||||
@@ -143,16 +150,22 @@ function wp_get_revision_ui_diff( $post, $compare_from, $compare_to ) {
|
||||
* @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 );
|
||||
$post = get_post( $post );
|
||||
$authors = array();
|
||||
$now_gmt = time();
|
||||
|
||||
$revisions = wp_get_post_revisions( $post->ID, array( 'order' => 'ASC', 'check_enabled' => false ) );
|
||||
$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 ) )
|
||||
if ( ! wp_is_post_autosave( $revision ) ) {
|
||||
unset( $revisions[ $revision_id ] );
|
||||
}
|
||||
}
|
||||
$revisions = array( $post->ID => $post ) + $revisions;
|
||||
}
|
||||
@@ -162,37 +175,41 @@ function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null
|
||||
cache_users( wp_list_pluck( $revisions, 'post_author' ) );
|
||||
|
||||
$can_restore = current_user_can( 'edit_post', $post->ID );
|
||||
$current_id = false;
|
||||
$current_id = false;
|
||||
|
||||
foreach ( $revisions as $revision ) {
|
||||
$modified = strtotime( $revision->post_modified );
|
||||
$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' ),
|
||||
$restore_link = str_replace(
|
||||
'&', '&', wp_nonce_url(
|
||||
add_query_arg(
|
||||
array(
|
||||
'revision' => $revision->ID,
|
||||
'action' => 'restore',
|
||||
),
|
||||
admin_url( 'revision.php' )
|
||||
),
|
||||
"restore-post_{$revision->ID}"
|
||||
) );
|
||||
),
|
||||
"restore-post_{$revision->ID}"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! isset( $authors[ $revision->post_author ] ) ) {
|
||||
$authors[ $revision->post_author ] = array(
|
||||
'id' => (int) $revision->post_author,
|
||||
'id' => (int) $revision->post_author,
|
||||
'avatar' => $show_avatars ? get_avatar( $revision->post_author, 32 ) : '',
|
||||
'name' => get_the_author_meta( 'display_name', $revision->post_author ),
|
||||
'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;
|
||||
$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;
|
||||
$current_id = $revision->ID;
|
||||
} else {
|
||||
$current = false;
|
||||
}
|
||||
@@ -253,7 +270,7 @@ function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null
|
||||
'current' => true,
|
||||
'restoreUrl' => false,
|
||||
);
|
||||
$current_id = $post->ID;
|
||||
$current_id = $post->ID;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -288,21 +305,23 @@ function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null
|
||||
|
||||
$from = absint( $from );
|
||||
|
||||
$diffs = array( array(
|
||||
'id' => $from . ':' . $selected_revision_id,
|
||||
'fields' => wp_get_revision_ui_diff( $post->ID, $from, $selected_revision_id ),
|
||||
));
|
||||
$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 ),
|
||||
'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 ),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -357,14 +376,32 @@ function wp_print_revision_templates() {
|
||||
{{{ 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>
|
||||
<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>
|
||||
<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="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>
|
||||
@@ -399,5 +436,6 @@ function wp_print_revision_templates() {
|
||||
{{{ field.diff }}}
|
||||
<# }); #>
|
||||
</div>
|
||||
</script><?php
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user