Skip to content

Commit

Permalink
Merge pull request #1336 from publishpress/release-3.5.13
Browse files Browse the repository at this point in the history
Release 3.5.13
  • Loading branch information
agapetry authored Sep 26, 2024
2 parents 0029975 + 6b10cfc commit 4efbceb
Show file tree
Hide file tree
Showing 27 changed files with 437 additions and 170 deletions.
13 changes: 13 additions & 0 deletions admin/admin-init_rvy.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,19 @@ function get_current_screen() {
add_action( 'wp_loaded', 'rvy_revision_delete' );

} elseif ( ! empty($_GET['action']) && ('revise' == $_GET['action']) ) {
if (!empty($_REQUEST['post'])) {
$post_id = intval($_REQUEST['post']);
$arr = rvy_post_revision_blocked($post_id);
}

if (!empty($arr) && is_array($arr) && !empty($arr['code'])) {
if (!empty($_REQUEST['referer'])) {
$url = add_query_arg('revision_action', $arr['code'], $_REQUEST['referer']);
wp_redirect($url);
exit;
}
}

require_once( dirname(__FILE__).'/revision-action_rvy.php');
add_action( 'wp_loaded', 'rvy_revision_create' );

Expand Down
27 changes: 17 additions & 10 deletions admin/admin-posts_rvy.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,27 @@ function __construct() {
function revision_action_notice() {
if ( ! empty($_GET['restored_post'] ) ) {
?>
<div class='updated'><?php esc_html_e('The revision was restored.', 'revisionary');?>
<div class='updated' style="padding-top: 10px; padding-bottom: 10px"><?php esc_html_e('The revision was restored.', 'revisionary');?>
</div>
<?php
} elseif ( ! empty($_GET['scheduled'] ) ) {
?>
<div class='updated'><?php esc_html_e('The revision was scheduled for publication.', 'revisionary');?>
<div class='updated' style="padding-top: 10px; padding-bottom: 10px"><?php esc_html_e('The revision was scheduled for publication.', 'revisionary');?>
</div>
<?php
} elseif ( ! empty($_GET['published_post'] ) ) {
?>
<div class='updated'><?php esc_html_e('The revision was published.', 'revisionary');?>
<div class='updated' style="padding-top: 10px; padding-bottom: 10px"><?php esc_html_e('The revision was published.', 'revisionary');?>
</div>
<?php
} elseif ( !empty($_GET['revision_action']) && ('blocked_unfiltered' == $_GET['revision_action'] ) ) {
?>
<div class='error' style="padding-top: 10px; padding-bottom: 10px"><?php printf(esc_html__('The unfiltered_html capability is required to create a revision of this post. See %sdocumentation%s.', 'revisionary'), '<a href="https://publishpress.com/knowledge-base/troubleshooting-revisionary/" target="_blank">', '</a>');?>
</div>
<?php
} elseif ( !empty($_GET['revision_action']) && ('blocked_revision_limit' == $_GET['revision_action'] ) ) {
?>
<div class='error' style="padding-top: 10px; padding-bottom: 10px"><?php esc_html_e('The post already has a revision in process.', 'revisionary');?>
</div>
<?php
}
Expand Down Expand Up @@ -177,17 +187,14 @@ function revisions_row_action_link($actions = array()) {

$status_obj = get_post_status_object($post->post_status);

if (empty($actions['view'])) {

}

if (!empty($status_obj->public) || !empty($status_obj->private) || rvy_get_option('pending_revision_unpublished')) {
if (rvy_get_option('pending_revisions') && current_user_can('copy_post', $post->ID) && rvy_post_revision_supported($post)) {
if (rvy_get_option('pending_revisions') && current_user_can('copy_post', $post->ID) && rvy_post_revision_supported($post, ['context' => 'admin_posts'])) {
$referer_arg = '&referer=' . esc_url_raw($_SERVER['REQUEST_URI']);

$redirect_arg = ( ! empty($_REQUEST['rvy_redirect']) ) ? "&rvy_redirect=" . esc_url_raw($_REQUEST['rvy_redirect']) : '';
$url = rvy_admin_url("admin.php?page=rvy-revisions&amp;post={$post->ID}&amp;action=revise$redirect_arg");
$url = rvy_admin_url("admin.php?page=rvy-revisions&amp;post={$post->ID}&amp;action=revise{$referer_arg}$redirect_arg");

$caption = (isset($actions['edit']) || !rvy_get_option('caption_copy_as_edit')) ? pp_revisions_status_label('draft-revision', 'submit') : esc_html__('Edit');

$caption = str_replace(' ', '&nbsp;', $caption);

$actions['create_revision'] = "<a href='$url'>" . $caption . '</a>';
Expand Down
8 changes: 7 additions & 1 deletion admin/class-list-table_rvy.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,10 @@ function($exception_ops, $args) {
}

function fltFixMimeTypeClause($where) {
return str_replace("-revision/%'", "-revision'", $where);
$where = str_replace("-revision/%'", "-revision'", $where);
$where = preg_replace("#post_mime_type LIKE '([a-z0-9_\-]*)/%'#", "post_mime_type LIKE '$1'", $where);

return $where;
}

function flt_presspermit_posts_clauses_intercept( $intercept, $clauses, $_wp_query, $args) {
Expand Down Expand Up @@ -515,6 +518,9 @@ function revisions_where_filter($where, $args = []) {
$where_append .= " AND $p.comment_count IN (SELECT ID FROM $wpdb->posts WHERE post_status IN ('$status_csv'))";
}

$revision_status_csv = implode("','", array_map('sanitize_key', rvy_revision_statuses()));
$where_append .= " AND $p.post_mime_type IN ('$revision_status_csv')";

$where .= " AND $where_append";

return $where;
Expand Down
97 changes: 97 additions & 0 deletions admin/edit-revision-classic-ui_rvy.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
class RevisionaryEditRevisionClassicUI {
function __construct () {
add_action('admin_head', [$this, 'hide_admin_divs']);
add_action('admin_head', [$this, 'actDeleteDuplicateRevision']);

add_filter('post_updated_messages', [$this, 'fltPostUpdatedMessage']);

Expand All @@ -16,6 +17,31 @@ function __construct () {

add_filter('presspermit_editor_ui_status', [$this, 'fltEditorUIstatus'], 10, 3);
add_filter('presspermit_post_editor_immediate_caption', [$this, 'fltImmediateCaption'], 10, 2);

add_action('post_submitbox_misc_actions', [$this, 'actSubmitboxActions'], 1);
}

function actDeleteDuplicateRevision() {
global $wpdb, $post;

if ($post) {
$last_id = $post->ID - 1;

$last_post = $wpdb->get_row(
$wpdb->prepare(
"SELECT * FROM $wpdb->posts WHERE ID = %d",
$last_id
)
);

if ($last_post
&& ($last_post->post_author == $post->post_author)
&& in_array($last_post->post_mime_type, ['draft-revision', 'pending-revision', 'future-revision'])
&& ($last_post->comment_count == $post->comment_count)
) {
wp_delete_post($last_id);
}
}
}

function hide_admin_divs() {
Expand Down Expand Up @@ -114,4 +140,75 @@ function fltPostUpdatedMessage($messages) {

return $messages;
}

function actSubmitboxActions($post) {
global $action;

$post_type_object = get_post_type_object($post->post_type);

if ($post_type_object && !current_user_can($post_type_object->cap->publish_posts)) : // Contributors don't get to choose the date of publish.
/* translators: Publish box date string. 1: Date, 2: Time. See https://www.php.net/manual/datetime.format.php */
$date_string = __( '%1$s at %2$s' );
/* translators: Publish box date format, see https://www.php.net/manual/datetime.format.php */
$date_format = _x( 'M j, Y', 'publish box date format' );
/* translators: Publish box time format, see https://www.php.net/manual/datetime.format.php */
$time_format = _x( 'H:i', 'publish box time format' );

if ( 0 !== $post->ID ) {
if ( 'future' === $post->post_status ) { // Scheduled for publishing at a future date.
/* translators: Post date information. %s: Date on which the post is currently scheduled to be published. */
$stamp = __( 'Scheduled for: %s' );
} elseif ( 'publish' === $post->post_status || 'private' === $post->post_status ) { // Already published.
/* translators: Post date information. %s: Date on which the post was published. */
$stamp = __( 'Published on: %s' );
} elseif ( '0000-00-00 00:00:00' === $post->post_date_gmt ) { // Draft, 1 or more saves, no date specified.
$stamp = __( 'Publish <b>immediately</b>' );
} elseif ( time() < strtotime( $post->post_date_gmt . ' +0000' ) ) { // Draft, 1 or more saves, future date specified.
/* translators: Post date information. %s: Date on which the post is to be published. */
$stamp = __( 'Schedule for: %s' );
} else { // Draft, 1 or more saves, date specified.
/* translators: Post date information. %s: Date on which the post is to be published. */
$stamp = __( 'Publish on: %s' );
}
$date = sprintf(
$date_string,
date_i18n( $date_format, strtotime( $post->post_date ) ),
date_i18n( $time_format, strtotime( $post->post_date ) )
);
} else { // Draft (no saves, and thus no date specified).
$stamp = __( 'Publish <b>immediately</b>' );
$date = sprintf(
$date_string,
date_i18n( $date_format, strtotime( current_time( 'mysql' ) ) ),
date_i18n( $time_format, strtotime( current_time( 'mysql' ) ) )
);
}

?>
<div class="misc-pub-section curtime misc-pub-curtime">
<span id="timestamp">
<?php printf( $stamp, '<b>' . $date . '</b>' ); ?>
</span>
<a href="#edit_timestamp" class="edit-timestamp hide-if-no-js" role="button">
<span aria-hidden="true"><?php _e( 'Edit' ); ?></span>
<span class="screen-reader-text">
<?php
/* translators: Hidden accessibility text. */
_e( 'Edit date and time' );
?>
</span>
</a>
<fieldset id="timestampdiv" class="hide-if-js">
<legend class="screen-reader-text">
<?php
/* translators: Hidden accessibility text. */
_e( 'Date and time' );
?>
</legend>
<?php touch_time( ( 'edit' === $action ), 1 ); ?>
</fieldset>
</div>
<?php
endif;
}
}
2 changes: 1 addition & 1 deletion admin/history_rvy.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function actDisableProblemQueries(WP_Query $query) {
}

public function actLoadRevision() {
global $wpdb, $post;
global $wpdb, $post, $title;

if (!empty($_REQUEST['revision']) && is_scalar($_REQUEST['revision']) && !empty($_REQUEST['post_id']) && !is_numeric($_REQUEST['revision']) && rvy_is_revision_status(sanitize_key($_REQUEST['revision']))) {
$revision_status = sanitize_key($_REQUEST['revision']);
Expand Down
2 changes: 1 addition & 1 deletion admin/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ function options_ui( $sitewide = false, $customize_defaults = false ) {
?>

<?php
$hint = esc_html__( 'If checked, users lacking site-wide publishing capabilities will also be checked for the edit_others_drafts capability', 'revisionary' );
$hint = esc_html__('If checked, the edit_others_drafts capability will be required for users lacking site-wide publishing capabilities', 'revisionary');
$this->option_checkbox( 'require_edit_others_drafts', $tab, $section, $hint, '' );
?>

Expand Down
18 changes: 13 additions & 5 deletions admin/post-edit_rvy.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,20 @@ function act_admin_head() {
if (rvy_post_revision_supported($post)) {
$status_obj = get_post_status_object($post->post_status);

if (('future' != $post->post_status) && (!empty($status_obj->public) || !empty($status_obj->private) || rvy_get_option('pending_revision_unpublished'))) {
wp_enqueue_script('rvy_object_edit', RVY_URLPATH . "/admin/rvy_post-classic-edit{$suffix}.js", ['jquery', 'jquery-form'], PUBLISHPRESS_REVISIONS_VERSION, true);
if (('future' != $post->post_status) && (!empty($status_obj->public) || !empty($status_obj->private) || rvy_get_option('pending_revision_unpublished'))) {
wp_enqueue_script('rvy_object_edit', RVY_URLPATH . "/admin/rvy_post-classic-edit{$suffix}.js", ['jquery', 'jquery-form'], PUBLISHPRESS_REVISIONS_VERSION, true);

$args = \PublishPress\Revisions\PostEditorWorkflowUI::postLinkParams(compact('post', 'do_pending_revisions', 'do_scheduled_revisions'));
wp_localize_script( 'rvy_object_edit', 'rvyObjEdit', $args );
}
$args = \PublishPress\Revisions\PostEditorWorkflowUI::postLinkParams(compact('post', 'do_pending_revisions', 'do_scheduled_revisions'));

$wp_timezone = wp_timezone();
$utc_timezone = new DateTimeZone('UTC');
$wp_time = new DateTime("now", $wp_timezone);
$utc_time = new DateTime("now", new DateTimeZone('UTC'));

$args['timezoneOffset'] = 0 - $wp_timezone->getOffset($utc_time);

wp_localize_script( 'rvy_object_edit', 'rvyObjEdit', $args );
}
} else {
return;
}
Expand Down
6 changes: 4 additions & 2 deletions admin/post-editor-workflow-ui_rvy.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,10 @@ public static function revisionLinkParams($args = []) {
if ($block_editor) {
$vars['updateCaption'] = esc_html__('Update Revision', 'revisionary');
} else {
if (!$vars['updateCaption'] = pp_revisions_status_label($post->post_mime_type, 'update')) {
$vars['updateCaption'] = pp_revisions_label('update_revision');
if (!defined('PUBLISHPRESS_STATUSES_PRO_VERSION')) {
if (!$vars['updateCaption'] = pp_revisions_status_label($post->post_mime_type, 'update')) {
$vars['updateCaption'] = pp_revisions_label('update_revision');
}
}
}

Expand Down
11 changes: 11 additions & 0 deletions admin/revision-action_rvy.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,17 @@ function rvy_revision_approve($revision_id = 0, $args = []) {
}

clean_post_cache($post->ID);

if ($post && rvy_get_option('publish_by_revision')) {
if (empty($post->post_name)) {
$data = [];
$data['post_name'] = wp_unique_post_slug(sanitize_title($post->post_title, $post->ID), $post->ID, 'publish', $post->post_type, $post->post_parent);

$wpdb->update($wpdb->posts, ['post_name' => $data['post_name']], ['ID' => $post->ID]);
clean_post_cache($post->ID);
}
}

$published_url = get_permalink($post->ID);

$db_action = false;
Expand Down
18 changes: 17 additions & 1 deletion admin/revisions.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,23 @@

if ( empty($revision_id) && ! $left && ! $right ) {
echo( '<div><br />' );
esc_html_e( 'No revision specified.', 'revisionary');

if (!empty($_REQUEST['action']) && ('revise' == $_REQUEST['action'])) {
// Fallback error message, in case redirect is missed
if (!empty($_REQUEST['post'])) {
$post_id = intval($_REQUEST['post']);
$arr = rvy_post_revision_blocked($post_id);
}

if (!empty($arr) && is_array($arr) && !empty($arr['description'])) {
echo $arr['description'];
} else {
esc_html_e( 'Revision of this post is not allowed.', 'revisionary');
}
} else {
esc_html_e( 'No revision specified.', 'revisionary');
}

echo( '</div>' );
return;
}
Expand Down
26 changes: 19 additions & 7 deletions admin/rvy_post-block-edit.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,32 @@ jQuery(document).ready( function($) {

var rvyCreationDisabled = false;

$(document).on('click', 'div.postbox-container', function() {
$(document).on('click', 'div.postbox-container,div.acf-postbox', function() {
rvyCreationDisabled = true;
$('button.revision-approve').prop('disabled', 'disabled');
$('button.revision-schedule').prop('disabled', 'disabled');
$('a.revision-approve').attr('title', rvyObjEdit.actionDisabledTitle);
$('a.revision-schedule').attr('title', rvyObjEdit.scheduleDisabledTitle);
});

$(document).on('click', 'button.editor-post-publish-button', function() {
rvyCreationDisabled = false;
$('button.revision-approve').prop('disabled', false);
$('button.revision-schedule').prop('disabled', false);
$('a.revision-approve').attr('title', rvyObjEdit.actionTitle);
$('a.revision-schedule').attr('title', rvyObjEdit.scheduleTitle);
var intSaveWatch = setInterval(() => {
if (wp.data.select('core/editor').isSavingPost()) {
rvyCreationDisabled = false;
$('button.revision-approve').prop('disabled', false);
$('button.revision-schedule').prop('disabled', false);
$('a.revision-approve').attr('title', rvyObjEdit.actionTitle);
$('a.revision-schedule').attr('title', rvyObjEdit.scheduleTitle);
}
}, 5000);

$(document).on('click', 'button.editor-post-publish-button,button.editor-post-save-draft', function() {
setInterval(() => {
rvyCreationDisabled = false;
$('button.revision-approve').prop('disabled', false);
$('button.revision-schedule').prop('disabled', false);
$('a.revision-approve').attr('title', rvyObjEdit.actionTitle);
$('a.revision-schedule').attr('title', rvyObjEdit.scheduleTitle);
}, 2000);
});

var rvyIsAutosaveStarted = false;
Expand Down
2 changes: 1 addition & 1 deletion admin/rvy_post-block-edit.js

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

Loading

0 comments on commit 4efbceb

Please sign in to comment.