From 34276cbbcc06904ef8c073723d762789f5dfe608 Mon Sep 17 00:00:00 2001 From: Kevin Behrens <43488774+agapetry@users.noreply.github.com> Date: Tue, 29 Dec 2020 15:04:16 -0500 Subject: [PATCH 01/14] Non-public post types display ineffective preview link If the 'revisionary_supported_post_types' filter is used to enable revisions for a non-public post type, that post type has ineffective revision preview links. Suppress the link where appropriate and default rvy_preview_url() output to Compare Revisions screen as a fallback. Fixes #309 --- admin/PostEditSubmitMetabox.php | 5 ++++- admin/class-list-table_rvy.php | 2 +- admin/history_rvy.php | 7 +++++-- admin/post-edit-block-ui_rvy.php | 8 +++++++- admin/post-edit_rvy.php | 28 ++++++++++++++++++++++++---- revision-workflow_rvy.php | 4 +++- rvy_init.php | 6 ++++++ 7 files changed, 50 insertions(+), 10 deletions(-) diff --git a/admin/PostEditSubmitMetabox.php b/admin/PostEditSubmitMetabox.php index bc836d85..5d5bc811 100644 --- a/admin/PostEditSubmitMetabox.php +++ b/admin/PostEditSubmitMetabox.php @@ -173,7 +173,10 @@ public static function post_preview_button($post, $args) $type_obj = get_post_type_object($post->post_type); $can_publish = $type_obj && agp_user_can($type_obj->cap->edit_post, rvy_post_id($post->ID), '', array('skip_revision_allowance' => true)); - if ($can_publish) { + + if ($type_obj && empty($type_obj->public)) { + return; + } elseif ($can_publish) { $preview_button = ('future-revision' == $post->post_status) ? __('View / Publish', 'revisionary') : __('View / Approve', 'revisionary'); $preview_title = __('View / moderate saved revision', 'revisionary'); } else { diff --git a/admin/class-list-table_rvy.php b/admin/class-list-table_rvy.php index c34b2e78..86361817 100644 --- a/admin/class-list-table_rvy.php +++ b/admin/class-list-table_rvy.php @@ -1122,7 +1122,7 @@ protected function handle_row_actions( $post, $column_name, $primary ) { } if ( is_post_type_viewable( $post_type_object ) ) { - if ( $can_read_post ) { + if ($can_read_post && $post_type_object && !empty($post_type_object->public)) { if (rvy_get_option('revision_preview_links') || current_user_can('administrator') || is_super_admin()) { $preview_link = rvy_preview_url($post); diff --git a/admin/history_rvy.php b/admin/history_rvy.php index 96eb5a83..8ea36f23 100644 --- a/admin/history_rvy.php +++ b/admin/history_rvy.php @@ -877,7 +877,8 @@ private function prepare_revisions_for_js( $post, $selected_revision_id, $from = if ($can_restore) { $published_post_id = rvy_post_id($revision->ID); - if (rvy_get_option('compare_revisions_direct_approval') && agp_user_can( 'edit_post', $published_post_id, '', ['skip_revision_allowance' => true] ) ) { + // For non-public types, force direct approval because preview is not available + if ((($type_obj && empty($type_obj->public)) || rvy_get_option('compare_revisions_direct_approval')) && agp_user_can( 'edit_post', $published_post_id, '', ['skip_revision_allowance' => true] ) ) { $redirect_arg = ( ! empty($_REQUEST['rvy_redirect']) ) ? "&rvy_redirect=" . esc_url($_REQUEST['rvy_redirect']) : ''; if (in_array($revision->post_status, ['pending-revision'])) { @@ -1044,7 +1045,9 @@ function actRevisionDiffScripts() { $type_obj = get_post_type_object($post_type); } - $direct_approval = rvy_get_option('compare_revisions_direct_approval') && agp_user_can( 'edit_post', rvy_post_id($post_id), '', ['skip_revision_allowance' => true] ); + // For non-public types, force direct approval because preview is not available + $direct_approval = (($type_obj && empty($type_obj->public)) || rvy_get_option('compare_revisions_direct_approval')) + && agp_user_can('edit_post', rvy_post_id($post_id), '', ['skip_revision_allowance' => true]); if ($post_id) { $can_approve = agp_user_can('edit_post', rvy_post_id($post_id), 0, ['skip_revision_allowance' => true]); diff --git a/admin/post-edit-block-ui_rvy.php b/admin/post-edit-block-ui_rvy.php index e9ba79bf..c0b84754 100644 --- a/admin/post-edit-block-ui_rvy.php +++ b/admin/post-edit-block-ui_rvy.php @@ -42,8 +42,13 @@ public static function act_object_guten_scripts() { if (rvy_get_option('revision_preview_links') || current_user_can('administrator') || is_super_admin()) { $view_link = rvy_preview_url($post); + $can_publish = agp_user_can($type_obj->cap->edit_post, rvy_post_id($post->ID), '', array('skip_revision_allowance' => true)); - if ($can_publish = agp_user_can($type_obj->cap->edit_post, rvy_post_id($post->ID), '', array('skip_revision_allowance' => true))) { + if ($type_obj && empty($type_obj->public)) { + $view_link = ''; + $view_caption = ''; + $view_title = ''; + } elseif ($can_publish) { $view_caption = ('future-revision' == $post->post_status) ? __('View / Publish', 'revisionary') : __('View / Approve', 'revisionary'); $view_title = __('View / moderate saved revision', 'revisionary'); } else { @@ -173,6 +178,7 @@ public static function act_object_guten_scripts() { 'prePublish' => __( 'Workflow…', 'revisionary' ), 'redirectURL' => admin_url("edit.php?post_type={$post_type}&revision_submitted={$status}&post_id={$post_id}"), 'revisableStatuses' => rvy_filtered_statuses('names'), + 'editRevisionURL' => $editRevisionURL, ); if (defined('REVISIONARY_DISABLE_SUBMISSION_REDIRECT') || !apply_filters('revisionary_do_submission_redirect', true)) { diff --git a/admin/post-edit_rvy.php b/admin/post-edit_rvy.php index efa19db9..7dd5a467 100644 --- a/admin/post-edit_rvy.php +++ b/admin/post-edit_rvy.php @@ -92,7 +92,13 @@ function act_admin_head() { $view_link = rvy_preview_url($post); - if ($can_publish = agp_user_can($type_obj->cap->edit_post, rvy_post_id($post->ID), '', array('skip_revision_allowance' => true))) { + $can_publish = agp_user_can($type_obj->cap->edit_post, rvy_post_id($post->ID), '', array('skip_revision_allowance' => true)); + + if ($type_obj && empty($type_obj->public)) { + $view_link = ''; + $view_caption = ''; + $view_title = ''; + } elseif ($can_publish) { $view_caption = ('future-revision' == $post->post_status) ? __('View / Publish', 'revisionary') : __('View / Approve', 'revisionary'); $view_title = __('View / moderate saved revision', 'revisionary'); } else { @@ -237,7 +243,11 @@ public function fltPreviewLink($url, $_post = false) { $url = add_query_arg('_thumbnail_id', $revisionary->last_autosave_id[$_post->ID], $url); } } elseif ($post && rvy_is_revision_status($post->post_status)) { - $url = rvy_preview_url($post); + $type_obj = get_post_type_object($post->post_type); + + if ($type_obj && !empty($type_obj->public)) { + $url = rvy_preview_url($post); + } } return $url; @@ -247,10 +257,15 @@ public function fltPreviewLabel($preview_caption) { global $post; $type_obj = get_post_type_object($post->post_type); + + if ($type_obj && empty($type_obj->public)) { + return $preview_caption; + } + $can_publish = $type_obj && agp_user_can($type_obj->cap->edit_post, rvy_post_id($post->ID), '', array('skip_revision_allowance' => true)); if ($can_publish) { $preview_caption = ('future-revision' == $post->post_status) ? __('View / Publish', 'revisionary') : __('View / Approve', 'revisionary'); - } else { + } elseif ($type_obj && !empty($type_obj->public)) { $preview_caption = __('View'); } @@ -261,10 +276,15 @@ public function fltPreviewTitle($preview_title) { global $post; $type_obj = get_post_type_object($post->post_type); + + if ($type_obj && empty($type_obj->public)) { + return $preview_title; + } + $can_publish = $type_obj && agp_user_can($type_obj->cap->edit_post, rvy_post_id($post->ID), '', array('skip_revision_allowance' => true)); if ($can_publish) { $preview_title = __('View / moderate saved revision', 'revisionary'); - } else { + } elseif ($type_obj && !empty($type_obj->public)) { $preview_title = __('View saved revision', 'revisionary'); } diff --git a/revision-workflow_rvy.php b/revision-workflow_rvy.php index 6b501718..ebeaa024 100644 --- a/revision-workflow_rvy.php +++ b/revision-workflow_rvy.php @@ -240,7 +240,9 @@ function get_revision_msg( $revision, $args = array() ) { $msg .= '