Skip to content

Commit

Permalink
Featured Image, Page Template revisions not applied
Browse files Browse the repository at this point in the history
Featured Image and Page Template revisions were not applied (but did work in PublishPress Revisions Pro)

Publishing a revision imported from Revisionary 1.x caused tags and categories to be stripped out
  • Loading branch information
agapetry committed Dec 18, 2019
1 parent c1fee78 commit 59cdb63
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
18 changes: 10 additions & 8 deletions admin/revision-action_rvy.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,12 @@ function rvy_revision_restore() {

// restore previous meta fields

if (!defined('REVISIONARY_PRO_VERSION') || apply_filters('revisionary_copy_core_postmeta', true, $revision, $post)) {
revisionary_copy_meta_field('_thumbnail_id', $revision->ID, $post->ID);
revisionary_copy_meta_field('_wp_page_template', $revision->ID, $post->ID);
if (!defined('REVISIONARY_PRO_VERSION') || apply_filters('revisionary_copy_core_postmeta', true, $revision, $post, false)) {
revisionary_copy_meta_field('_thumbnail_id', $revision->ID, $post->ID, false);
revisionary_copy_meta_field('_wp_page_template', $revision->ID, $post->ID, false);
}

revisionary_copy_terms($revision->ID, $post->ID);
revisionary_copy_terms($revision->ID, $post->ID, false);

/*
if ( $postmeta = $wpdb->get_results( "SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id = '$revision_id'", ARRAY_A ) ) {
Expand Down Expand Up @@ -364,14 +364,16 @@ function rvy_apply_revision( $revision_id, $actual_revision_status = '' ) {
// also copy all stored postmeta from revision
global $revisionary;

if (!defined('REVISIONARY_PRO_VERSION') || apply_filters('revisionary_copy_core_postmeta', true, $revision, $published)) {
revisionary_copy_meta_field('_post_thumbnail', $revision->ID, $post->ID);
revisionary_copy_meta_field('_page_template', $revision->ID, $post->ID);
$is_imported = get_post_meta($revision_id, '_rvy_imported_revision', true);

if (!defined('REVISIONARY_PRO_VERSION') || apply_filters('revisionary_copy_core_postmeta', true, $revision, $published, !$is_imported)) {
revisionary_copy_meta_field('_post_thumbnail', $revision->ID, $published->ID, !$is_imported);
revisionary_copy_meta_field('_page_template', $revision->ID, $published->ID, !$is_imported);
}

// Allow Multiple Authors revisions to be applied to published post. Revision post_author is forced to actual submitting user.
//$skip_taxonomies = (defined('PUBLISHPRESS_MULTIPLE_AUTHORS_VERSION')) ? ['author'] : [];
revisionary_copy_terms($revision_id, $post_id);
revisionary_copy_terms($revision_id, $post_id, !$is_imported);

// @todo save change as past revision?
//$wpdb->delete($wpdb->posts, array('ID' => $revision_id));
Expand Down
14 changes: 8 additions & 6 deletions rvy_init.php
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ function rvy_get_manageable_types() {
add_action( 'wp_ajax_rvy_dismiss_msg', '_revisionary_dashboard_dismiss_msg' );
}

function revisionary_copy_meta_field( $meta_key, $from_post_id, $to_post_id ) {
function revisionary_copy_meta_field( $meta_key, $from_post_id, $to_post_id, $mirror_empty = true ) {
global $wpdb;

if ( ! $to_post_id )
Expand All @@ -614,21 +614,21 @@ function revisionary_copy_meta_field( $meta_key, $from_post_id, $to_post_id ) {
)
) {
update_post_meta($to_post_id, $meta_key, $source_meta->meta_value);
} else {
update_post_meta($to_post_id, $meta_key);
} elseif ($mirror_empty) {
delete_post_meta($to_post_id, $meta_key);
}
}
}

function revisionary_copy_terms( $from_post_id, $to_post_id, $skip_taxonomies = false ) {
function revisionary_copy_terms( $from_post_id, $to_post_id, $mirror_empty = false ) {
global $wpdb;

if ( ! $to_post_id )
return;

if (false===$skip_taxonomies) {
//if (false===$skip_taxonomies) { @todo: $args
$skip_taxonomies = array();
}
//}

if ($skip_taxonomies = apply_filters('revisionary_skip_taxonomies', $skip_taxonomies, $from_post_id, $to_post_id)) {
$tx_join = "INNER JOIN $wpdb->term_taxonomy AS tt ON tt.term_taxonomy_id = tr.term_taxonomy_id ";
Expand All @@ -650,10 +650,12 @@ function revisionary_copy_terms( $from_post_id, $to_post_id, $skip_taxonomies =
}
}

if ($source_terms || $mirror_empty) {
if ( $delete_terms = array_diff($target_terms, $source_terms) ) {
// todo: single query
foreach($delete_terms as $tt_id) {
$wpdb->query("DELETE FROM $wpdb->term_relationships WHERE object_id = '$to_post_id' AND term_taxonomy_id = '$tt_id'");
}
}
}
}
Expand Down

0 comments on commit 59cdb63

Please sign in to comment.