Skip to content

Commit

Permalink
Merge pull request #323 from publishpress/release/2.4.9
Browse files Browse the repository at this point in the history
Release/2.4.9
  • Loading branch information
agapetry authored Jan 14, 2021
2 parents bc0df5a + a9aed9f commit 1a6a97c
Show file tree
Hide file tree
Showing 14 changed files with 175 additions and 24 deletions.
5 changes: 4 additions & 1 deletion admin/PostEditSubmitMetabox.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion admin/admin_rvy.php
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ function admin_head() {
<script type="text/javascript">
/* <![CDATA[ */
jQuery(document).ready( function($) {
$('#rvy-rev-checkall').click(function() {
$('#rvy-rev-checkall').on('click', function() {
$('.rvy-rev-chk').attr( 'checked', this.checked );
});
});
Expand Down
2 changes: 1 addition & 1 deletion admin/class-list-table_rvy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
7 changes: 5 additions & 2 deletions admin/history_rvy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand Down Expand Up @@ -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]);
Expand Down
22 changes: 21 additions & 1 deletion admin/post-edit-block-ui_rvy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -166,13 +171,28 @@ public static function act_object_guten_scripts() {
//div.editor-post-publish-panel button.editor-post-publish-button
wp_enqueue_script( 'rvy_object_edit', RVY_URLPATH . "/admin/rvy_post-block-edit-revisor{$suffix}.js", array('jquery', 'jquery-form'), RVY_VERSION, true );

$userRevision = (defined('REVISIONARY_GUTEN_NOTICE')) ? revisionary()->getUserRevision($post_id, ['force_query' => true]) : false;

if ($userRevision) {
$editRevisionURL = (defined('REVISIONARY_GUTEN_NOTICE_LINK_WORKAROUND')) ? admin_url('post.php') . "?post=$userRevision&action=edit" : '';
$punc = $editRevisionURL ? ':' : '.';
$revisionExistsCaption = sprintf( __("You've already submitted a revision%s", 'revisionary'), $punc);
$editRevisionCaption = __('Edit the Revision', 'revisionary');
} else {
$editRevisionURL = $revisionExistsCaption = $editRevisionCaption = '';
}

$status = 'pending-revision';
$args = array(
'publish' => __('Submit Revision', 'revisionary'),
'saveAs' => __('Submit Revision', 'revisionary'),
'prePublish' => __( 'Workflow&hellip;', 'revisionary' ),
'redirectURL' => admin_url("edit.php?post_type={$post_type}&revision_submitted={$status}&post_id={$post_id}"),
'revisableStatuses' => rvy_filtered_statuses('names'),
'userRevision' => $userRevision,
'editRevisionURL' => $editRevisionURL,
'revisionExistsCaption' => $revisionExistsCaption,
'editRevisionCaption' => $editRevisionCaption,
);

if (defined('REVISIONARY_DISABLE_SUBMISSION_REDIRECT') || !apply_filters('revisionary_do_submission_redirect', true)) {
Expand Down
2 changes: 1 addition & 1 deletion admin/post-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jQuery(document).ready( function($) {
if ( ! $('#timestampdiv a.now-timestamp').length ) {
$('#timestampdiv a.cancel-timestamp').after('<a href="#timestamp_now" class="now-timestamp hide-if-no-js button-now">' + rvyPostEdit.nowCaption + '</a>');
}
$('#timestampdiv a.now-timestamp').click(function(){
$('#timestampdiv a.now-timestamp').on('click', function(){
var nowDate = new Date();
var month = nowDate.getMonth() + 1;
if ( month.toString().length < 2 ) {
Expand Down
46 changes: 42 additions & 4 deletions admin/post-edit_rvy.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,27 @@ function __construct() {

add_filter('revisionary_apply_revision_allowance', [$this, 'fltRevisionAllowance'], 5, 2);

add_action('all_admin_notices', [$this, 'actRevisionExistsNotice']);

add_action('admin_head', [$this, 'actAdminBarPreventPostClobber'], 5);
}

function actRevisionExistsNotice() {
global $post, $current_user, $wpdb;

if (empty($post) || agp_user_can('edit_post', $post->ID, '', ['skip_revision_allowance' => true])) {
return;
}

if ($revision_id = revisionary()->getUserRevision($post->ID)) {
$url = admin_url('post.php') . "?post=$revision_id&action=edit";
$type_obj = get_post_type_object($post->post_type);
$type_label = (!empty($type_obj) && !empty($type_obj->labels->singular_name)) ? $type_obj->labels->singular_name : 'post';
$message = sprintf(__('You have already submitted a revision for this %s. %sEdit the revision%s.', 'revisionary'), $type_label, "<a href='$url'>", '</a>');
echo "<div id='message' class='notice notice-warning' style='color:black'>" . $message . '</div>';
}
}

function fltPostUpdatedMessage($messages) {
global $post;

Expand Down Expand Up @@ -92,7 +110,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 {
Expand Down Expand Up @@ -237,7 +261,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;
Expand All @@ -247,10 +275,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');
}

Expand All @@ -261,10 +294,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');
}

Expand Down
56 changes: 53 additions & 3 deletions admin/rvy_post-block-edit-revisor.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,23 +137,72 @@ jQuery(document).ready( function($) {
}

$('select.editor-post-author__select').parent().hide();
$('div.edit-post-last-revision__panel').hide();
//$('div.edit-post-last-revision__panel').hide();
$('div.edit-post-post-visibility').hide();
$('button.editor-post-trash').hide();
$('button.editor-post-switch-to-draft').hide();

$('div.components-notice-list').hide(); // autosave notice
$('div.edit-post-post-status div.components-base-control__field input[type="checkbox"]').hide().next('label').hide(); // stick to top
if (rvyObjEdit.userRevision) {
if ($('button.editor-post-publish-button:visible').length && !$('div.have-revision-notice').length) {
// @todo: Gutenberg does not allow manually inserted html to contain links
var html = '<div class="components-notice is-warning" style="padding:0 0 0 8px"><div class="components-notice__content">'
+ rvyObjEdit.revisionExistsCaption;
/*
+ '<a class="components-button is-link">'
+ rvyObjEdit.editRevisionCaption
+ '</a>'
*/

if (rvyObjEdit.editRevisionURL) {
html += ' <strong>' + rvyObjEdit.editRevisionURL + '</strong>';
}

html += '</div></div> ';

$('div.edit-post-header-toolbar__left').after('<div class="have-revision-notice">' + html + '</div>');
}

/*
// @todo: Gutenberg does not allow this to be displayed to Revisors
wp.data.dispatch('core/notices').createInfoNotice(
'info', // Can be one of: success, info, warning, error.
rvyObjEdit.revisionExistsCaption,
{
id: 'rvyRevisionExistsNotice',
isDismissible: false,
// Any actions the user can perform.
actions: [
{
url: rvyObjEdit.editRevisionURL,
label: rvyObjEdit.editRevisionCaption,
},
//{
// label: ' or ',
//},
//{
// url: another_url,
// label: __('Another action'),
//},
]
}
);
*/
}
}
}
var RvyInitInterval = setInterval(RvyInitializeBlockEditorModifications, 50);


var RvyHideElements = function() {
var ediv = 'div.edit-post-sidebar ';

if ( $(ediv + 'div.edit-post-post-visibility,' + ediv + 'div.edit-post-last-revision__panel,' + ediv + 'div.editor-post-link,' + ediv + 'select.editor-post-author__select:visible,' + ediv + 'div.components-base-control__field input[type="checkbox"]:visible,' + ediv + 'button.editor-post-switch-to-draft,' + ediv + 'button.editor-post-trash').length ) {
//if ( $(ediv + 'div.edit-post-post-visibility,' + ediv + 'div.edit-post-last-revision__panel,' + ediv + 'div.editor-post-link,' + ediv + 'select.editor-post-author__select:visible,' + ediv + 'div.components-base-control__field input[type="checkbox"]:visible,' + ediv + 'button.editor-post-switch-to-draft,' + ediv + 'button.editor-post-trash').length ) {
if ( $(ediv + 'div.edit-post-post-visibility,' + ediv + 'div.editor-post-link,' + ediv + 'select.editor-post-author__select:visible,' + ediv + 'div.components-base-control__field input[type="checkbox"]:visible,' + ediv + 'button.editor-post-switch-to-draft,' + ediv + 'button.editor-post-trash').length ) {
$(ediv + 'select.editor-post-author__select').parent().hide();
$(ediv + 'div.edit-post-last-revision__panel').hide();
//$(ediv + 'div.edit-post-last-revision__panel').hide();
$(ediv + 'div.edit-post-post-visibility').hide();
$(ediv + 'button.editor-post-trash').hide();
$(ediv + 'button.editor-post-switch-to-draft').hide();
Expand All @@ -164,6 +213,7 @@ jQuery(document).ready( function($) {
}
var RvyHideInterval = setInterval(RvyHideElements, 50);


/*
// If Publish button is clicked, current post status will be set to [user's next/max status progression]
// So set Publish button caption to "Save As %s" to show that no further progression is needed / offered.
Expand Down
6 changes: 4 additions & 2 deletions admin/rvy_post-block-edit-revisor.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions classes/PublishPress/Revisionary.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,21 @@ public function deleteOption($option_basename, $args = []) {
return rvy_delete_option($option_basename, $sitewide);
}
}

public function getUserRevision($post_id, $args = []) {
global $wpdb, $current_user;

$args = (array) $args;
$user_id = (!empty($args['user_id'])) ? $args['user_id'] : $current_user->ID;

if (empty($args['force_query']) && !get_post_meta($post_id, '_rvy_has_revisions')) {
return false;
}

$revision_id = $wpdb->get_var(
"SELECT ID FROM $wpdb->posts WHERE comment_count = '$post_id' AND post_author = '$user_id' AND post_status IN ('pending-revision', 'future-revision') ORDER BY ID DESC LIMIT 1"
);

return $revision_id;
}
}
Loading

0 comments on commit 1a6a97c

Please sign in to comment.