Skip to content

Commit

Permalink
Merge pull request #951 from publishpress/release-3.1.12
Browse files Browse the repository at this point in the history
Release 3.1.12
  • Loading branch information
agapetry authored Mar 23, 2023
2 parents 2e6f38a + 96f5d6d commit c5d7b27
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 30 deletions.
12 changes: 10 additions & 2 deletions admin/admin-posts_rvy.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,17 @@ public function fltAdminPostsListing() {

if ($listed_ids) {
$id_csv = implode("','", array_map('intval', $listed_ids));
$revision_base_status_csv = implode("','", array_map('sanitize_key', rvy_revision_base_statuses()));
$revision_status_csv = implode("','", array_map('sanitize_key', rvy_revision_statuses()));

$revision_base_statuses = array_map('sanitize_key', rvy_revision_base_statuses());

if (!rvy_get_option('pending_revision_unpublished')) {
$published_statuses = get_post_stati( ['public' => true, 'private' => true], 'names', 'or' );
$revision_base_statuses = array_intersect($revision_base_statuses, $published_statuses);
}

$revision_base_status_csv = implode("','", $revision_base_statuses);

$results = $wpdb->get_results(
"SELECT comment_count AS published_post, COUNT(comment_count) AS num_revisions FROM $wpdb->posts WHERE comment_count IN ('$id_csv') AND post_status IN ('$revision_base_status_csv') AND post_mime_type IN ('$revision_status_csv') AND post_type != '' GROUP BY comment_count"
);
Expand Down Expand Up @@ -169,7 +177,7 @@ function revisions_row_action_link($actions = array()) {

if (!empty($this->post_revision_count[$post->ID])) {
if ( 'trash' != $post->post_status && wp_check_post_lock( $post->ID ) === false ) {
$actions['revision_queue'] = "<a href='admin.php?page=revisionary-q&published_post=$post->ID'>" . esc_html__('Revision Queue', 'revisionary') . '</a>';
$actions['revision_queue'] = "<a href='admin.php?page=revisionary-q&published_post={$post->ID}&all=1'>" . esc_html__('Revision Queue', 'revisionary') . '</a>';
}
}

Expand Down
4 changes: 2 additions & 2 deletions admin/history_rvy.php
Original file line number Diff line number Diff line change
Expand Up @@ -1190,12 +1190,12 @@ function actPastRevisionDiffScripts() {

if (rvyRevisionID != rvyLastID) {
<?php if($show_preview_link):?>
var rvyPreviewURL = '<?php echo esc_url($preview_url);?>';
var rvyPreviewURL = '<?php echo esc_url_raw($preview_url);?>';
rvyPreviewURL = rvyPreviewURL.replace("page_id=" + <?php echo esc_attr($post_id);?>, "page_id=" + rvyRevisionID);
rvyPreviewURL = rvyPreviewURL.replace("p=" + <?php echo esc_attr($post_id);?>, "p=" + rvyRevisionID);
<?php endif;?>

var rvyManageURL = '<?php echo esc_url($manage_url);?>';
var rvyManageURL = '<?php echo esc_url_raw($manage_url);?>';
rvyManageURL = rvyManageURL.replace("revision=" + <?php echo esc_attr($post_id);?>, "revision=" + rvyRevisionID);

if(!$('span.rvy-compare-preview').length) {
Expand Down
11 changes: 10 additions & 1 deletion admin/revision-action_rvy.php
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,13 @@ function rvy_apply_revision( $revision_id, $actual_revision_status = '' ) {
clean_post_cache($revision_id);
clean_post_cache($published->ID);

if (defined('LSCWP_V')) {
do_action('litespeed_purge_post', $published->ID);
}

// Passing ignore_revision_ids is not theoretically necessary here since this call occurs after deletion, but avoid any cache clearance timing issues.
revisionary_refresh_revision_flags($published->ID, ['ignore_revision_ids' => $revision_id]);

/**
* Trigger after a revision has been applied.
*
Expand Down Expand Up @@ -1083,6 +1090,8 @@ function rvy_revision_bulk_delete() {
$post_ids = [];

foreach ($delete_revisions as $revision_id) {
$published_post_id = rvy_post_id();

// this function is only used for past revisions (status=inherit)
if ( ! $revision = wp_get_post_revision( $revision_id ) )
continue;
Expand Down Expand Up @@ -1111,7 +1120,7 @@ function rvy_revision_bulk_delete() {
wp_delete_post($revision_id, true);
$delete_count++;

do_action('rvy_delete_revision', $revision_id);
do_action('rvy_delete_revision', $revision_id, $published_post_id);

rvy_delete_past_revisions($revision_id);
}
Expand Down
2 changes: 1 addition & 1 deletion admin/revision-queue_rvy.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@

if (!empty($_REQUEST['post_status'])) {
if ($status_obj = get_post_status_object(sanitize_key($_REQUEST['post_status']))) {
$filters['post_status'] = $status_obj->labels->plural;
$filters['post_status'] = (!empty($status_obj->labels->plural)) ? $status_obj->labels->plural : $status_obj->label;
}
}

Expand Down
2 changes: 1 addition & 1 deletion admin/revision-ui_rvy.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ function rvy_list_post_revisions( $post_id = 0, $status = '', $args = null ) {

$datef = __awp( 'M j, Y @ g:i a' );

$rows .= "<tr class='" . esc_attr($class) . ">";
$rows .= "<tr class='" . esc_attr($class) . "'>";

if ( $post->ID != $revision->ID ) {
if ('inherit' == $revision->post_status) {
Expand Down
23 changes: 16 additions & 7 deletions admin/revisions.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,14 @@
$delete_cap = $type_obj->cap->delete_post;
}

$published_title = "<a href='post.php?action=edit&post=$rvy_post->ID'>$rvy_post->post_title</a>";
?>
<h1><?php printf(esc_html__('Revisions of %s', 'revisionary'), esc_html($published_title));?></h1>
<h1>
<?php printf(
esc_html__('Revisions of %s', 'revisionary'),
"<a href='post.php?action=edit&post=$rvy_post->ID'>" . esc_html($rvy_post->post_title) . "</a>"
);
?>
</h1>
<?php

// Sets up the diff radio buttons
Expand Down Expand Up @@ -222,15 +227,19 @@

if ( $is_administrator ) {
if ($num_revisions->$_revision_status) {
echo "<li class='" . esc_attr($class) . "'><a href='" . esc_url($_link) . "' target='" . esc_attr($target) . "'>"
. sprintf(
echo "<li class='" . esc_attr($class) . "'><a href='" . esc_url($_link) . "' target='" . esc_attr($target) . "'>";

$span_style = ('inherit' == $_revision_status) ? ' style="font-weight:bold"' : '';

printf(
esc_html__( '%1$s %2$s (%3$s)%4$s', 'revisionary' ),
'<span class="count">',
"<span class='count' $span_style>",
esc_html($status_caption),
esc_html(number_format_i18n( $num_revisions->$_revision_status )),
'</span>'
)
. '</a></li>';
) ;

echo '</a></li>&nbsp;&nbsp;';
}
} else {
echo "<li class='" . esc_attr($class) . "'><a href='" . esc_url($_link) . "' target='" . esc_attr($target) . "'>" . esc_html($status_caption) . '</a></li>';
Expand Down
2 changes: 1 addition & 1 deletion front_rvy.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ function act_template_redirect() {

$published_url = ($published_post_id) ? get_permalink($published_post_id) : '';
$diff_url = rvy_admin_url("revision.php?revision=$revision_id");
$queue_url = rvy_admin_url("admin.php?page=revisionary-q&published_post=$published_post_id");
$queue_url = rvy_admin_url("admin.php?page=revisionary-q&published_post={$published_post_id}&all=1");

if ((!rvy_get_option('revisor_hide_others_revisions') && !empty($type_obj) && current_user_can($type_obj->cap->edit_posts)) || current_user_can('read_post', $revision_id)) {
$view_published = ($published_url)
Expand Down
8 changes: 8 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,14 @@ Divi is one of the most popular page-builders in WordPress, and it does integrat

== Changelog ==

= 3.1.12 - 23 Mar 2023 =
* Fixed : Posts were left with invalid "Has Revision" links after publication or deletion of all their revisions
* Fixed : If Revision Submission for Unpublished Posts is disabled but revisions of draft posts were previously created, those caused a "Has Revisions" label without displaying the revisions in Queue
* Fixed : Links to Revision Queue for a specific published post (including "Has Revision" links from Posts listing) failed to list unsubmitted revisions
* Fixed : Revision Compare > Manage : Non-rendered html tags, incorrect table formatting
* Fixed : Compare Past Revisions - invalid link on Preview / Restore button
* Fixed : Request Deletion link was displayed even if revisions are not enabled for post type

= 3.1.11 - 9 Feb 2023 =
* Fixed : Revision preview failure under some conditions
* Fixed : Avoid PHP Warning on Revision Preview if requested revision cannot be loaded
Expand Down
2 changes: 1 addition & 1 deletion revision-workflow_rvy.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ function do_notifications( $notification_type, $status, $post_arr, $args ) {
$message .= esc_html__( 'Preview and Approval: ', 'revisionary' ) . $preview_link . "\r\n\r\n";
}

$message .= esc_html__( 'Revision Queue: ', 'revisionary' ) . rvy_admin_url("admin.php?page=revisionary-q&published_post={$published_post->ID}") . "\r\n\r\n";
$message .= esc_html__( 'Revision Queue: ', 'revisionary' ) . rvy_admin_url("admin.php?page=revisionary-q&published_post={$published_post->ID}&all=1") . "\r\n\r\n";

$message .= sprintf(esc_html__( 'Edit %s: ', 'revisionary' ), pp_revisions_status_label('pending-revision', 'name')) . rvy_admin_url("post.php?action=edit&post={$revision_id}") . "\r\n";
}
Expand Down
2 changes: 2 additions & 0 deletions revisionary_main.php
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,8 @@ function actDeletePost($post_id) {
wp_delete_post($revision_id, true);
}

revisionary_refresh_revision_flags($post_id, ['ignore_revision_ids' => $post_ids]);

$post = get_post($post_id);

if ($post && rvy_in_revision_workflow($post)) {
Expand Down
68 changes: 56 additions & 12 deletions rvy_init.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@

add_action("update_option_rvy_scheduled_publish_cron", '_rvy_existing_schedules_to_cron', 10, 2);

add_action('before_delete_post',
function($delete_post_id) {
if (rvy_in_revision_workflow($delete_post_id)) {
if ($published_post_id = rvy_post_id($delete_post_id)) {
_rvy_delete_revision($delete_post_id, $published_post_id);
}
}
}
);

add_action('rvy_delete_revision', '_rvy_delete_revision', 999, 2);
add_action('untrash_post',
function($post_id) {
revisionary_refresh_revision_flags($post_id);
}
);

add_action('init',
function() {
global $kinsta_cache;
Expand Down Expand Up @@ -97,6 +114,10 @@ function($intend_to_save, $indexable) {
10, 2);
}

function _rvy_delete_revision($revision_id, $published_post_id) {
revisionary_refresh_revision_flags($published_post_id, ['ignore_revision_ids' => $revision_id]);
}

function _rvy_rest_prepare($response, $post, $request) {
if (!rvy_in_revision_workflow($post)) {
return $response;
Expand Down Expand Up @@ -778,17 +799,28 @@ function revisionary_refresh_postmeta($post_id, $args = []) {
revisionary_refresh_revision_flags();
}

function revisionary_refresh_revision_flags() {
function revisionary_refresh_revision_flags($published_post_id = 0, $args = []) {
global $wpdb;

$ignore_revision_ids = (!empty($args['ignore_revision_ids'])) ? (array) $args['ignore_revision_ids'] : [];

$status_csv = implode("','", array_map('sanitize_key', rvy_filtered_statuses()));
$revision_base_status_csv = implode("','", array_map('sanitize_key', rvy_revision_base_statuses()));
$revision_status_csv = implode("','", array_map('sanitize_key', rvy_revision_statuses()));

$arr_have_revisions = $wpdb->get_col(
"SELECT r.comment_count FROM $wpdb->posts r INNER JOIN $wpdb->posts p ON r.comment_count = p.ID"
. " WHERE p.post_status IN ('$status_csv') AND r.post_status IN ('$revision_base_status_csv') AND r.post_mime_type IN ('$revision_status_csv')"
);
$query = "SELECT r.comment_count FROM $wpdb->posts r INNER JOIN $wpdb->posts p ON r.comment_count = p.ID"
. " WHERE p.post_status IN ('$status_csv') AND r.post_status IN ('$revision_base_status_csv') AND r.post_mime_type IN ('$revision_status_csv')";

if ($published_post_id) {
$query = $wpdb->prepare("$query AND p.ID = %d", $published_post_id);
}

if ($ignore_revision_ids) {
$ignore_revisions_csv = implode("','", array_map('sanitize_key', $ignore_revision_ids));
$query .= " AND r.ID NOT IN ('$ignore_revisions_csv')";
}

$arr_have_revisions = $wpdb->get_col($query);

$have_revisions = implode("','", array_map('intval', array_unique($arr_have_revisions)));

Expand All @@ -797,13 +829,25 @@ function revisionary_refresh_revision_flags() {
$wpdb->query("DELETE FROM $wpdb->postmeta WHERE meta_id IN ('$id_csv')");
}

$have_flag_ids = $wpdb->get_col("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_rvy_has_revisions'");
$query = "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_rvy_has_revisions'";

if ($published_post_id) {
$query = $wpdb->prepare("$query AND post_id = %d", $published_post_id);
}

$have_flag_ids = $wpdb->get_col($query);

if ($posts_missing_flag = array_diff($arr_have_revisions, $have_flag_ids)) {
foreach($posts_missing_flag as $post_id) {
rvy_update_post_meta($post_id, '_rvy_has_revisions', true);
}
}

if ($posts_invalid_flag = array_diff($have_flag_ids, $arr_have_revisions)) {
foreach($posts_missing_flag as $post_id) {
rvy_delete_post_meta($post_id, '_rvy_has_revisions');
}
}
}

function rvy_refresh_options() {
Expand Down Expand Up @@ -1388,16 +1432,16 @@ function rvy_preview_url($revision, $args = []) {

if ('revision' == $post_type) {
$post_type = get_post_field('post_type', $revision->post_parent);
} else {
if ($post_type_obj = get_post_type_object($revision->post_type)) {
if (empty($post_type_obj->public) && !defined('FL_BUILDER_VERSION') && !apply_filters('revisionary_private_type_use_preview_url', false, $revision)) { // For non-public types, preview is not available so default to Compare Revisions screen
return apply_filters('revisionary_preview_url', rvy_admin_url("revision.php?revision=$revision->ID"), $revision, $args);
}
}
}

$post_type = sanitize_key($post_type);

if ($post_type_obj = get_post_type_object($revision->post_type)) {
if (empty($post_type_obj->public) && !defined('FL_BUILDER_VERSION') && !apply_filters('revisionary_private_type_use_preview_url', false, $revision)) { // For non-public types, preview is not available so default to Compare Revisions screen
return apply_filters('revisionary_preview_url', rvy_admin_url("revision.php?revision=$revision->ID"), $revision, $args);
}
}

$link_type = rvy_get_option('preview_link_type');

$status_obj = get_post_status_object(get_post_field('post_status', rvy_post_id($revision->ID)));
Expand Down
4 changes: 2 additions & 2 deletions submittee_rvy.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ function default_options( $sitewide = false, $customize_defaults = false ) {
function update_sitewide() {
check_admin_referer( 'rvy-update-options' );

$reviewed_options = isset($_POST['rvy_all_movable_options']) ? array_map('sanitize_key', explode(',', sanitize_text_field($_POST['rvy_all_movable_options']))) : array();
$reviewed_options = isset($_POST['rvy_all_movable_options']) ? array_map('sanitize_key', explode(',', $_POST['rvy_all_movable_options'])) : array();

$options_sitewide = isset($_POST['rvy_options_sitewide']) ? array_map('sanitize_key', (array) sanitize_text_field($_POST['rvy_options_sitewide'])) : array();
$options_sitewide = isset($_POST['rvy_options_sitewide']) ? array_map('sanitize_key', (array) $_POST['rvy_options_sitewide']) : array();

update_site_option( "rvy_options_sitewide_reviewed", $reviewed_options );
update_site_option( "rvy_options_sitewide", $options_sitewide );
Expand Down

0 comments on commit c5d7b27

Please sign in to comment.