Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/revisionary/admin/class-list-table_rvy.php
+++ b/revisionary/admin/class-list-table_rvy.php
@@ -435,10 +435,7 @@
}
function fltFixMimeTypeClause($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;
+ return rvy_revision_mime_where($where);
}
function fltScheduledOnlyWhere( $where ) {
--- a/revisionary/admin/options.php
+++ b/revisionary/admin/options.php
@@ -81,116 +81,125 @@
$this->subsection_options = false;
}
- function option_checkbox( $option_name, $tab_name, $section_name, $hint_text, $unused_arg = '', $args = '') {
- $return = array( 'in_scope' => false, 'val' => '', 'subcaption' => '', 'style' => '', 'hide' => false, 'no_escape' => false, 'disabled' => false );
-
- if ( ! is_array($args) )
- $args = array();
-
- if (!empty($this->form_options[$tab_name][$section_name]) && in_array($option_name, $this->form_options[$tab_name][$section_name], true)) {
- $this->all_options []= $option_name;
-
-
- $return['val'] = (isset($args['val'])) ? $args['val'] : rvy_get_option($option_name, $this->sitewide, $this->customize_defaults, ['bypass_condition_check' => true]);
-
-
- echo "<div class='agp-vspaced_input'";
-
- if (!empty($args['style'])) {
- echo " style='" . esc_attr($args['style']) . "'";
- } elseif (!empty($args['hide'])) {
- echo " style='display:none'";
- }
-
- echo ">";
-
- echo "<label for='" . esc_attr($option_name) . "'><input name='" . esc_attr($option_name) . "' type='checkbox' id='" . esc_attr($option_name) . "' value='1' " . checked('1', $return['val'], false) . disabled('1', !empty($args['disabled']), false) . " autocomplete='off' " . " /> ";
-
- if (!empty($args['no_escape'])) {
- echo $this->option_captions[$option_name]; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
- } else {
- echo esc_html($this->option_captions[$option_name]);
- }
-
- echo "</label>";
-
- if ( ! empty( $args['after_label'] ) ) {
- echo wp_kses_post( $args['after_label'] );
- }
-
- if ( $hint_text && $this->display_hints ) {
- echo "<div class='rvy-subtext'>";
-
- if (!empty($args['no_escape'])) {
- echo $hint_text; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
- } else {
- echo esc_html($hint_text);
- }
-
- echo "</div>";
- }
-
- if ( ! empty($args['subcaption']) )
- echo $args['subcaption']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
-
- echo "</div>";
-
- $return['in_scope'] = true;
- $this->section_options = true;
- $this->subsection_options = true;
- }
-
- return $return;
- }
- function closeSubsection() {
- if (!$this->subsection_options) :?>
- <h4>
- <?php esc_html_e('All settings on this tab are assigned network-wide.', 'revisionary'); ?>
- </h4>
- <?php endif;
- }
-
- function register_option($option_name) {
- if (!in_array($option_name, $this->all_options, true)) {
- $this->all_options []= $option_name;
- }
- }
-
-function options_ui( $sitewide = false, $customize_defaults = false ) {
-
-global $revisionary, $wpdb, $wp_version;
-global $rvy_options_sitewide, $rvy_default_options;
-
-if ( ! current_user_can( 'manage_options' ) || ( $sitewide && ! is_super_admin() ) )
- wp_die('');
-
-?>
-<div class="wrap pressshack-admin-wrapper">
-<?php
-
-if ( $sitewide )
- $customize_defaults = false; // this is intended only for storing custom default values for site-specific options
-
-rvy_refresh_default_options();
+ /** Native setting captions and groups, shared with non-browser clients. */
+ /** Native field identifiers and captions shared by the form and typed clients. */
+ public function getNativeFieldChoices(bool $copy = false): array
+ {
+ $fields = [
+ 'post_content' => __('Content', 'revisionary'), 'post_title' => __('Title', 'revisionary'),
+ 'post_date' => __('Date', 'revisionary'), 'post_status' => __('Status', 'revisionary'),
+ 'post_parent' => __('Parent', 'revisionary'), 'post_name' => __('Slug', 'revisionary'),
+ 'post_excerpt' => __('Excerpt', 'revisionary'), 'post_author' => __('Author', 'revisionary'),
+ '_thumbnail_id' => __('Thumbnail', 'revisionary'), '_wp_page_template' => __('Template', 'revisionary'),
+ 'category' => __('Categories', 'revisionary'), 'post_tag' => __('Tags', 'revisionary'),
+ 'taxonomies' => __('Taxonomies', 'revisionary'),
+ ];
+ if (!$copy) { return $fields; }
+ $choices = [];
+ foreach ($fields as $key => $label) {
+ $key = match ($key) { '_thumbnail_id' => 'post_thumbnail', '_wp_page_template' => 'post_template', default => $key };
+ $choices[$key] = $label;
+ }
+ return $choices;
+ }
-$this->all_options = array();
+ /**
+ * Settings that require a particular workflow, integration or editor.
+ * Keep this independent of rendering so API clients can validate without
+ * running settings screen hooks that perform maintenance or emit markup.
+ */
+ public function nativeSettingAvailability(): array
+ {
+ global $wp_version;
+
+ $pending = (bool) rvy_get_option('pending_revisions');
+ $scheduled = (bool) rvy_get_option('scheduled_revisions');
+ $preview = (bool) rvy_get_option('revision_preview_links');
+ $pro = defined('PUBLISHPRESS_REVISIONS_PRO_VERSION');
+ $planner = defined('PUBLISHPRESS_VERSION');
+ $modernPlanner = $planner && version_compare(PUBLISHPRESS_VERSION, '4.6-beta', '>=');
+ $plannerNotifications = (bool) rvy_get_option('use_publishpress_notifications');
+ $legacyControls = $modernPlanner || !$pro || !$planner || !$plannerNotifications;
+ $legacyEmail = $legacyControls && rvy_get_option('legacy_notifications');
+ $wp7 = version_compare($wp_version, '7.0', '>=');
+ $available = [
+ 'async_scheduled_publish' => $scheduled && rvy_get_option('legacy_scheduled_publication') && !function_exists('relevanssi_query'),
+ 'revision_limit_compat_mode' => (bool) rvy_get_option('revision_limit_per_post'),
+ 'rev_publication_delete_ed_comments' => $planner,
+ 'use_publishpress_notifications' => $pro && $modernPlanner,
+ 'planner_notifications_access_limited' => $pro && $legacyControls && $plannerNotifications
+ && defined('PRESSPERMIT_VERSION') && defined('RVY_CONTENT_ROLES'),
+ 'legacy_notifications' => $legacyControls,
+ 'revision_update_notifications' => $legacyEmail && $pending
+ && (rvy_get_option('pending_rev_notify_admin') || rvy_get_option('pending_rev_notify_author')),
+ 'use_notification_buffer' => (bool) $legacyEmail,
+ 'visual_compare' => $wp7 && !rvy_visual_compare_disabled(),
+ 'visual_compare_javascript' => $wp7,
+ 'rvy_compare_other_internal_fields' => $wp7 && rvy_use_visual_compare(),
+ 'preview_link_type' => $preview,
+ 'preview_link_alternate_preview_arg' => $preview && !(defined('RVY_PREVIEW_ARG_LOCKED') && defined('RVY_PREVIEW_ARG')),
+ 'home_preview_set_home_flag' => $preview,
+ 'apply_post_exceptions' => defined('PRESSPERMIT_VERSION') && version_compare(PRESSPERMIT_VERSION, '4.4.3-beta2', '>='),
+ 'revision_edit_disable_rank_math' => class_exists('RankMath'),
+ 'enable_classic_metaboxes' => $wp7,
+ 'archive_postmeta_on_edit' => $pro,
+ 'revision_restore_require_cap' => $pro,
+ 'past_revisions_order_by' => $pro,
+ 'pending_revision_unpublished' => $pro && $pending,
+ 'publish_by_revision' => $pro && $pending && rvy_get_option('pending_revision_unpublished'),
+ 'unfiltered_preview_links' => $pro && $preview,
+ ];
+ $available += array_fill_keys([
+ 'revise_posts_capability', 'revision_editor_bg_color', 'pending_revision_update_post_date',
+ 'pending_revision_update_modified_date', 'auto_submit_revisions_any_user',
+ 'auto_submit_revisions', 'compare_revisions_direct_approval',
+ ], $pending);
+ $available += array_fill_keys([
+ 'scheduled_revision_update_post_date', 'scheduled_revision_update_modified_date', 'scheduled_publish_cron',
+ ], $scheduled);
+ $available += array_fill_keys([
+ 'revision_queue_capability', 'manage_unsubmitted_capability', 'revisor_lock_others_revisions',
+ 'revisor_hide_others_revisions', 'admin_revisions_to_own_posts', 'view_filters_include_unsubmitted_revisions',
+ 'admin_menu_pending_count_icon', 'front_end_indicator',
+ ], $pending || $scheduled);
+ $available['deletion_queue'] = $pro && ($pending || $scheduled);
+ $available += array_fill_keys([
+ 'pending_rev_notify_admin', 'pending_rev_notify_author', 'pending_rev_notify_revisor',
+ 'rev_approval_notify_admin', 'rev_approval_notify_author', 'rev_approval_notify_revisor',
+ ], $legacyEmail && $pending);
+ $available += array_fill_keys([
+ 'publish_scheduled_notify_admin', 'publish_scheduled_notify_author', 'publish_scheduled_notify_revisor',
+ ], $legacyEmail && $scheduled);
-$this->tab_captions = array( 'features' => esc_html__( 'Settings', 'revisionary' ), 'optscope' => esc_html__( 'Setting Scope', 'revisionary' ) );
+ return $available;
+ }
-$this->section_captions = array(
- 'features' => array(
- 'post_types' => esc_html__('Features', 'revisionary'),
- 'archive' => esc_html__('Past Revisions', 'revisionary'),
- 'working_copy' => esc_html__('New Revisions', 'revisionary'),
- 'revisions' => esc_html__('Options', 'revisionary'),
- 'integrations' => esc_html__('Integrations', 'revisionary'),
- 'statuses' => esc_html__('Statuses', 'revisionary'),
- 'notifications' => esc_html__('Notifications', 'revisionary'),
- )
-);
+ public function nativeSettingChoices(): array
+ {
+ $notification = [
+ 0 => __('Never', 'revisionary'),
+ 1 => __('By default', 'revisionary'),
+ 'always' => __('Always', 'revisionary'),
+ ];
+ return [
+ 'pending_rev_notify_admin' => $notification,
+ 'pending_rev_notify_author' => $notification,
+ 'preview_link_type' => [
+ '' => __('Published Post Slug', 'revisionary'),
+ 'revision_slug' => __('Revision Slug', 'revisionary'),
+ 'id_only' => __('Revision ID only', 'revisionary'),
+ ],
+ 'past_revisions_order_by' => ['' => __('Post Date', 'revisionary'), 'modified' => __('Modification Date', 'revisionary')],
+ 'revision_limit_per_post' => [
+ 0 => __('Allow any number of Revisions per post.', 'revisionary'),
+ 1 => __('Prevent Revision creation if another was already created.', 'revisionary'),
+ 'submitted' => __('Prevent Revision creation if another was already submitted.', 'revisionary'),
+ ],
+ ];
+ }
-// TODO: replace individual _e calls with these (and section, tab captions)
+ public function getNativeSettingsDefinition() {
$pending_revision_singular = pp_revisions_status_label('pending-revision', 'name');
$pending_revision_plural = rvy_get_option('revision_statuses_noun_labels') ? pp_revisions_status_label('pending-revision', 'plural') : esc_html__('Revision Submission', 'revisionary');
$pending_revision_basic = pp_revisions_status_label('pending-revision', 'basic');
@@ -239,7 +248,7 @@
'use_publishpress_notifications' => (defined('PUBLISHPRESS_VERSION'))
? sprintf(__('Use %1$sPlanner Notifications%2$s', 'revisionary'), "<strong><a class='planner-notif-link' href='$pp_notif_url'>", '</a></strong>')
: sprintf(__('Use %1$sPlanner Notifications%2$s', 'revisionary'), '', ''),
-
+
'pending_rev_notify_author' => sprintf(esc_html__('Email original Author when a %s is submitted', 'revisionary'), $pending_revision_basic),
'rev_approval_notify_author' => sprintf(esc_html__('Email the original Author when a %s is approved', 'revisionary'), $pending_revision_singular),
'rev_approval_notify_revisor' => sprintf(esc_html__('Email the Revisor when a %s is approved', 'revisionary'), $pending_revision_singular),
@@ -257,7 +266,7 @@
'home_preview_set_home_flag' => esc_html__('Theme Compat: For front page revision preview, set home flag', 'revisionary'),
'compare_revisions_direct_approval' => esc_html__('Approve Button on Compare screen', 'revisionary'),
'copy_revision_comments_to_post' => esc_html__('Copy revision comments to published post', 'revisionary'),
- 'past_revisions_order_by' => esc_html__('Compare Past Revisions ordering:', 'revisionary'),
+ 'past_revisions_order_by' => esc_html__('Compare Past Revisions ordering:', 'revisionary'),
'view_filters_include_unsubmitted_revisions' => sprintf(esc_html__('List %s for "My Activity" or "Revisions to My Posts" view', 'revisionary'), pp_revisions_status_label('draft-revision', 'plural')),
'archive_postmeta' => esc_html__('Archive a copy of custom fields when a submitted or scheduled revision is published', 'revisionary'),
'archive_postmeta_on_edit' => esc_html__('Archive a copy of custom fields with each Past Revision', 'revisionary'),
@@ -299,7 +308,7 @@
'post_types' => ['enabled_post_types', 'enabled_fields', 'enabled_post_types_archive', 'enabled_post_types_copy', 'enabled_fields_copy'],
'statuses' => [true],
'archive' => ['num_revisions', 'archive_postmeta', 'archive_postmeta_on_edit', 'extended_archive', 'revision_archive_deletion', 'revision_restore_require_cap', 'past_revisions_order_by'],
- 'working_copy' => ['duplicate_posts_capability', 'copy_posts_capability', 'revisor_role_add_custom_rolecaps', 'revision_limit_per_post', 'create_revision_reuse_unsubmitted', 'revision_limit_compat_mode', 'submit_permission_enables_creation', 'allow_post_author_revision', 'create_revision_direct_link', 'query_loop_revision_editor_allowance', 'revision_unfiltered_html_check', 'auto_submit_revisions', 'auto_submit_revisions_any_user', 'caption_copy_as_edit', 'permissions_compat_mode', 'pending_revisions', 'revise_posts_capability', 'pending_revision_update_post_date', 'pending_revision_update_modified_date', 'scheduled_revisions', 'scheduled_publish_cron', 'async_scheduled_publish', 'wp_cron_usage_detected', 'scheduled_revision_update_post_date', 'scheduled_revision_update_modified_date', 'approve_capability', 'approve_button_verbose', 'trigger_post_update_actions', 'copy_revision_comments_to_post', 'rev_publication_delete_ed_comments', 'revision_statuses_noun_labels', 'revision_queue_capability', 'manage_unsubmitted_capability', 'revisor_lock_others_revisions', 'revisor_hide_others_revisions', 'admin_menu_pending_count_icon', 'front_end_indicator', 'admin_revisions_to_own_posts', 'view_filters_include_unsubmitted_revisions', 'deletion_queue', 'compare_revisions_direct_approval', 'use_publishpress_notifications', 'planner_notifications_access_limited', 'legacy_notifications', 'pending_rev_notify_admin', 'pending_rev_notify_author', 'revision_update_notifications', 'rev_approval_notify_admin', 'rev_approval_notify_author', 'rev_approval_notify_revisor', 'publish_scheduled_notify_admin', 'publish_scheduled_notify_author', 'publish_scheduled_notify_revisor', 'use_notification_buffer'],
+ 'working_copy' => ['duplicate_posts_capability', 'copy_posts_capability', 'revisor_role_add_custom_rolecaps', 'revision_limit_per_post', 'create_revision_reuse_unsubmitted', 'revision_limit_compat_mode', 'submit_permission_enables_creation', 'allow_post_author_revision', 'create_revision_direct_link', 'query_loop_revision_editor_allowance', 'revision_unfiltered_html_check', 'auto_submit_revisions', 'auto_submit_revisions_any_user', 'revision_editor_bg_color', 'caption_copy_as_edit', 'permissions_compat_mode', 'pending_revisions', 'revise_posts_capability', 'pending_revision_update_post_date', 'pending_revision_update_modified_date', 'scheduled_revisions', 'scheduled_publish_cron', 'async_scheduled_publish', 'wp_cron_usage_detected', 'scheduled_revision_update_post_date', 'scheduled_revision_update_modified_date', 'approve_capability', 'approve_button_verbose', 'trigger_post_update_actions', 'copy_revision_comments_to_post', 'rev_publication_delete_ed_comments', 'revision_statuses_noun_labels', 'revision_queue_capability', 'manage_unsubmitted_capability', 'revisor_lock_others_revisions', 'revisor_hide_others_revisions', 'admin_menu_pending_count_icon', 'front_end_indicator', 'admin_revisions_to_own_posts', 'view_filters_include_unsubmitted_revisions', 'deletion_queue', 'compare_revisions_direct_approval', 'use_publishpress_notifications', 'planner_notifications_access_limited', 'legacy_notifications', 'pending_rev_notify_admin', 'pending_rev_notify_author', 'revision_update_notifications', 'rev_approval_notify_admin', 'rev_approval_notify_author', 'rev_approval_notify_revisor', 'publish_scheduled_notify_admin', 'publish_scheduled_notify_author', 'publish_scheduled_notify_revisor', 'use_notification_buffer'],
'notifications' => [true],
'integrations' => [true],
'revisions' => ['visual_compare', 'visual_compare_javascript', 'rvy_compare_other_internal_fields', 'revision_preview_links', 'preview_link_type', 'preview_link_alternate_preview_arg', 'home_preview_set_home_flag', 'require_edit_others_drafts', 'apply_post_exceptions', 'enable_postmeta_revision', 'diff_display_strip_tags', 'compare_revisions_hide_copy_buttons', 'revision_edit_disable_rank_math', 'add_revisions_index', 'enable_classic_metaboxes', 'display_hints', 'delete_settings_on_uninstall'],
@@ -307,6 +316,129 @@
]
]);
+
+ return ['captions' => $this->option_captions, 'sections' => $this->form_options];
+ }
+
+ function option_checkbox( $option_name, $tab_name, $section_name, $hint_text, $unused_arg = '', $args = '') {
+ $return = array( 'in_scope' => false, 'val' => '', 'subcaption' => '', 'style' => '', 'hide' => false, 'no_escape' => false, 'disabled' => false );
+
+ if ( ! is_array($args) )
+ $args = array();
+
+ if (!empty($this->form_options[$tab_name][$section_name]) && in_array($option_name, $this->form_options[$tab_name][$section_name], true)) {
+ $this->all_options []= $option_name;
+
+
+ $return['val'] = (isset($args['val'])) ? $args['val'] : rvy_get_option($option_name, $this->sitewide, $this->customize_defaults, ['bypass_condition_check' => true]);
+
+
+ echo "<div class='agp-vspaced_input'";
+
+ if (!empty($args['style'])) {
+ echo " style='" . esc_attr($args['style']) . "'";
+ } elseif (!empty($args['hide'])) {
+ echo " style='display:none'";
+ }
+
+ echo ">";
+
+ echo "<label for='" . esc_attr($option_name) . "'><input name='" . esc_attr($option_name) . "' type='checkbox' id='" . esc_attr($option_name) . "' value='1' " . checked('1', $return['val'], false) . disabled('1', !empty($args['disabled']), false) . " autocomplete='off' " . " /> ";
+
+ if (!empty($args['no_escape'])) {
+ echo $this->option_captions[$option_name]; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
+ } else {
+ echo esc_html($this->option_captions[$option_name]);
+ }
+
+ echo "</label>";
+
+ if ( ! empty( $args['after_label'] ) ) {
+ echo wp_kses_post( $args['after_label'] );
+ }
+
+ if ( $hint_text && $this->display_hints ) {
+ echo "<div class='rvy-subtext'>";
+
+ if (!empty($args['no_escape'])) {
+ echo $hint_text; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
+ } else {
+ echo esc_html($hint_text);
+ }
+
+ echo "</div>";
+ }
+
+ if ( ! empty($args['subcaption']) )
+ echo $args['subcaption']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
+
+ echo "</div>";
+
+ $return['in_scope'] = true;
+ $this->section_options = true;
+ $this->subsection_options = true;
+ }
+
+ return $return;
+ }
+
+ function closeSubsection() {
+ if (!$this->subsection_options) :?>
+ <h4>
+ <?php esc_html_e('All settings on this tab are assigned network-wide.', 'revisionary'); ?>
+ </h4>
+ <?php endif;
+ }
+
+ function register_option($option_name) {
+ if (!in_array($option_name, $this->all_options, true)) {
+ $this->all_options []= $option_name;
+ }
+ }
+
+function options_ui( $sitewide = false, $customize_defaults = false ) {
+
+global $revisionary, $wpdb, $wp_version;
+global $rvy_options_sitewide, $rvy_default_options;
+
+if ( ! current_user_can( 'manage_options' ) || ( $sitewide && ! is_super_admin() ) )
+ wp_die('');
+
+?>
+<div class="wrap pressshack-admin-wrapper">
+<?php
+
+if ( $sitewide )
+ $customize_defaults = false; // this is intended only for storing custom default values for site-specific options
+
+rvy_refresh_default_options();
+
+$this->all_options = array();
+
+$this->tab_captions = array( 'features' => esc_html__( 'Settings', 'revisionary' ), 'optscope' => esc_html__( 'Setting Scope', 'revisionary' ) );
+
+$this->section_captions = array(
+ 'features' => array(
+ 'post_types' => esc_html__('Features', 'revisionary'),
+ 'archive' => esc_html__('Past Revisions', 'revisionary'),
+ 'working_copy' => esc_html__('New Revisions', 'revisionary'),
+ 'revisions' => esc_html__('Options', 'revisionary'),
+ 'integrations' => esc_html__('Integrations', 'revisionary'),
+ 'statuses' => esc_html__('Statuses', 'revisionary'),
+ 'notifications' => esc_html__('Notifications', 'revisionary'),
+ )
+);
+
+// TODO: replace individual _e calls with these (and section, tab captions)
+$pending_revision_singular = pp_revisions_status_label('pending-revision', 'name');
+$pending_revision_plural = rvy_get_option('revision_statuses_noun_labels') ? pp_revisions_status_label('pending-revision', 'plural') : esc_html__('Revision Submission', 'revisionary');
+$pending_revision_basic = pp_revisions_status_label('pending-revision', 'basic');
+$future_revision_singular = pp_revisions_status_label('future-revision', 'name');
+
+$pp_notif_url = admin_url('edit.php?post_type=psppnotif_workflow');
+
+$this->getNativeSettingsDefinition();
+
if (defined('PUBLISHPRESS_STATUSES_PRO_VERSION') || $sitewide || $customize_defaults) {
unset($this->section_captions['features']['statuses']);
unset($this->form_options['features']['statuses']);
@@ -790,21 +922,7 @@
</h2>
<?php
- $available_fields = [
- 'post_content' => __('Content', 'revisionary'),
- 'post_title' => __('Title', 'revisionary'),
- 'post_date' => __('Date', 'revisionary'),
- 'post_status' => __('Status', 'revisionary'),
- 'post_parent' => __('Parent', 'revisionary'),
- 'post_name' => __('Slug', 'revisionary'),
- 'post_excerpt' => __('Excerpt', 'revisionary'),
- 'post_author' => __('Author', 'revisionary'),
- '_thumbnail_id' => __('Thumbnail', 'revisionary'),
- '_wp_page_template' => __('Template', 'revisionary'),
- 'category' => __('Categories', 'revisionary'),
- 'post_tag' => __('Tags', 'revisionary'),
- 'taxonomies' => __('Taxonomies', 'revisionary')
- ];
+ $available_fields = $this->getNativeFieldChoices(false);
$hidden_fields = [];
$locked_fields = [];
@@ -953,21 +1071,7 @@
</h2>
<?php
- $available_fields = [
- 'post_content' => __('Content', 'revisionary'),
- 'post_title' => __('Title', 'revisionary'),
- 'post_date' => __('Date', 'revisionary'),
- 'post_status' => __('Status', 'revisionary'),
- 'post_parent' => __('Parent', 'revisionary'),
- 'post_name' => __('Slug', 'revisionary'),
- 'post_excerpt' => __('Excerpt', 'revisionary'),
- 'post_author' => __('Author', 'revisionary'),
- 'post_thumbnail' => __('Thumnbnail', 'revisionary'),
- 'post_template' => __('Template', 'revisionary'),
- 'category' => __('Categories', 'revisionary'),
- 'post_tag' => __('Tags', 'revisionary'),
- 'taxonomies' => __('Taxonomies', 'revisionary')
- ];
+ $available_fields = $this->getNativeFieldChoices(true);
$hidden_fields = [];
$locked_fields = [];
@@ -1208,7 +1312,7 @@
echo '<label class="screen-reader-text" for="' . esc_attr($id) . '">' . esc_html($this->option_captions[$id]) . '</label>';
echo " <select name='" . esc_attr($id) . "' id='" . esc_attr($id) . "' autocomplete='off' style='vertical-align: baseline'>";
- $captions = ['' => esc_html__('Post Date', 'revisionary'), 'modified' => esc_html__('Modification Date', 'revisionary')];
+ $captions = $this->nativeSettingChoices()['past_revisions_order_by'];
foreach ( $captions as $key => $value) {
$selected = ( $current_setting == $key ) ? 'selected' : '';
echo "nt<option value='" . esc_attr($key) . "' " . esc_attr($selected) . ">" . esc_html($captions[$key]) . "</option>";
@@ -1231,9 +1335,9 @@
<table class="form-table rs-form-table" role="presentation" id="<?php echo esc_attr("ppr-tab-$section");?>"<?php echo ($setActiveTab != $section) ? ' style="display:none;"' : '' ?>><tr><td><div class="rvy-opt-wrap">
<?php
- $pending_revisions_available = rvy_get_option( 'pending_revisions' );
-
- $scheduled_revisions_available = rvy_get_option( 'scheduled_revisions' );
+ $native_availability = $this->nativeSettingAvailability();
+ $pending_revisions_available = $native_availability['pending_revision_update_post_date'];
+ $scheduled_revisions_available = $native_availability['scheduled_revision_update_post_date'];
$_sections = [
'revision-creation' => esc_html__('Revision Creation', 'revisionary'),
@@ -1438,11 +1542,7 @@
echo '<label class="screen-reader-text" for="' . esc_attr($id) . '">' . esc_html($this->option_captions[$id]) . '</label>';
echo " <select name='" . esc_attr($id) . "' id='" . esc_attr($id) . "' autocomplete='off' style='max-width:inherit'>";
- $captions = [
- 0 => esc_html__('Allow any number of Revisions per post.', 'revisionary'),
- 1 => esc_html__('Prevent Revision creation if another was already created.', 'revisionary'),
- 'submitted' => esc_html__('Prevent Revision creation if another was already submitted.', 'revisionary'),
- ];
+ $captions = $this->nativeSettingChoices()['revision_limit_per_post'];
foreach ( $captions as $key => $value) {
$selected = ( $current_setting == $key ) ? 'selected' : '';
@@ -1473,7 +1573,6 @@
$this->option_checkbox( 'create_revision_direct_link', $tab, $section, $hint, '');
$hint = '';
- echo '<p>' . esc_html__('Query Loop previews use your existing post permissions. The legacy capability allowance has been retired.', 'revisionary') . '</p>';
?>
<?php
@@ -1536,6 +1635,7 @@
$this->option_checkbox( 'revise_posts_capability', $tab, $section, $hint, '', $checkbox_args );
+ if (in_array('revision_editor_bg_color', $this->form_options[$tab][$section], true)) {
$option = 'revision_editor_bg_color';
$this->all_options []= $option;
$color = rvy_get_option($option);
@@ -1591,6 +1691,7 @@
</style>
<?php
+ }
$hint = sprintf(esc_html__( 'When a %s is published, update post publish date to current time.', 'revisionary' ), pp_revisions_status_label('pending-revision', 'name'));
$this->option_checkbox( 'pending_revision_update_post_date', $tab, $section, $hint, '' );
@@ -1691,7 +1792,7 @@
$hint = esc_html__('Caption the button as either "Approve and Publish" or "Approve and Schedule."', 'revisionary');
$this->option_checkbox( 'approve_button_verbose', $tab, $section, $hint, '' );
- if (defined('PUBLISHPRESS_VERSION')) {
+ if ($native_availability['rev_publication_delete_ed_comments']) {
$this->option_checkbox( 'rev_publication_delete_ed_comments', $tab, $section, '', '' );
}
@@ -1785,7 +1886,7 @@
if (defined('PUBLISHPRESS_REVISIONS_PRO_VERSION') && !defined('PUBLISHPRESS_VERSION')) :
if (!$customize_defaults):?>
- <div id="rvy-planner-notice" class="activating rvy-plugin-notice" style="margin-bottom: 20px">
+ <div id="rvy-planner-notice" class="activating rvy-plugin-notice" style="margin-bottom: 15px">
<?php
$plugin_slug = 'publishpress';
$info_url = self_admin_url("plugin-install.php?tab=plugin-information&plugin=$plugin_slug&TB_iframe=true&width=640&height=678");
@@ -1797,11 +1898,10 @@
);
?>
</div>
- <br />
<?php endif;?>
<?php elseif (defined('PUBLISHPRESS_REVISIONS_PRO_VERSION') && !version_compare(PUBLISHPRESS_VERSION, '4.6-beta', '>=')) :
?>
- <div id="rvy-planner-notice" class="activating rvy-plugin-notice" style="margin-bottom: 20px">
+ <div id="rvy-planner-notice" class="activating rvy-plugin-notice" style="margin-bottom: 15px">
<?php
printf(
esc_html__('For enhanced notifications, update %sPublishPress Planner%s.', 'revisionary'),
@@ -1810,7 +1910,6 @@
);
?>
</div>
- <br />
<?php endif;
if ((defined('PUBLISHPRESS_VERSION') && version_compare(PUBLISHPRESS_VERSION, '4.6-beta', '>=')) || !defined('PUBLISHPRESS_REVISIONS_PRO_VERSION') || !defined('PUBLISHPRESS_VERSION')
@@ -1839,7 +1938,7 @@
$this->option_checkbox( 'use_publishpress_notifications', $tab, $section, $hint, '', $chk_args);
}
- if ($pp_notifications && defined('PRESSPERMIT_VERSION') && defined('RVY_CONTENT_ROLES') && defined('PUBLISHPRESS_REVISIONS_PRO_VERSION')) {
+ if ($native_availability['planner_notifications_access_limited']) {
echo '<br />';
$hint = esc_html__('Users matching Planner > Notifications configuration get revision notifications only if they can edit the published post.', 'revisionary');
$this->option_checkbox( 'planner_notifications_access_limited', $tab, $section, $hint, '', ['no_escape' => true] );
@@ -1884,7 +1983,7 @@
echo '<label class="screen-reader-text" for="' . esc_attr($id) . '">' . esc_html($this->option_captions[$id]) . '</label>';
echo "<select name='" . esc_attr($id) . "' id='" . esc_attr($id) . "' autocomplete='off'>";
- $captions = array( 0 => esc_html__('Never', 'revisionary'), 1 => esc_html__('By default', 'revisionary'), 'always' => esc_html__('Always', 'revisionary') );
+ $captions = $this->nativeSettingChoices()[$id];
foreach ( $captions as $key => $value) {
$selected = ( $current_setting == $key ) ? 'selected' : '';
echo "nt<option value='" . esc_attr($key) . "' " . esc_attr($selected) . ">" . esc_html($captions[$key]) . "</option>";
@@ -1907,7 +2006,7 @@
echo '<label class="screen-reader-text" for="' . esc_attr($id) . '">' . esc_html($this->option_captions[$id]) . '</label>';
echo "<select name='" . esc_attr($id) . "' id='" . esc_attr($id) . "' autocomplete='off'>";
- $captions = array( 0 => esc_html__('Never', 'revisionary'), 1 => esc_html__('By default', 'revisionary'), 'always' => esc_html__('Always', 'revisionary') );
+ $captions = $this->nativeSettingChoices()[$id];
foreach ( $captions as $key => $value) {
$selected = ( $current_setting == $key ) ? 'selected' : '';
echo "nt<option value='" . esc_attr($key) . "' " . esc_attr($selected) . ">" . esc_html($captions[$key]) . "</option>";
@@ -2220,6 +2319,9 @@
<?php
}
+ ?>
+ <br />
+ <?php
$hint = esc_html__('Some themes may block revision preview.', 'revisionary');
$this->option_checkbox( 'revision_preview_links', $tab, $section, $hint, '' );
@@ -2236,11 +2338,7 @@
<select name="<?php echo esc_attr($id);?>" id="<?php echo esc_attr($id);?>" autocomplete="off">
<?php
- $captions = [
- '' => esc_html__('Published Post Slug', 'revisionary'),
- 'revision_slug' => esc_html__('Revision Slug', 'revisionary'),
- 'id_only' => esc_html__('Revision ID only', 'revisionary')
- ];
+ $captions = $this->nativeSettingChoices()['preview_link_type'];
foreach ( $captions as $key => $value) {
$selected = ( $current_setting == $key ) ? 'selected' : '';
--- a/revisionary/admin/revision-action_rvy.php
+++ b/revisionary/admin/revision-action_rvy.php
@@ -451,7 +451,7 @@
}
}
- if (!rvy_revision_metadata_is_safe($revision_id, $post->ID, ['skip_meta_keys' => rvy_disabled_revision_meta_keys()])) {
+ if (!rvy_revision_metadata_is_safe($revision_id, $post->ID, ['skip_meta_keys' => revisionary_disabled_meta_keys()])) {
$error = new WP_Error('revisionary_unsafe_metadata', __('Revision metadata contains unsupported objects.', 'revisionary'));
if (!$batch_process) { wp_die(esc_html($error->get_error_message())); }
return $error;
@@ -777,29 +777,7 @@
$published_url = get_permalink($post->ID);
- global $wpdb;
-
- $data = array( 'post_status' => 'inherit', 'post_date' => $revision->post_modified, 'post_date_gmt' => $revision->post_modified );
-
- if ( class_exists('WPCom_Markdown') && ! defined( 'RVY_DISABLE_MARKDOWN_WORKAROUND' ) )
- $data['post_content_filtered'] = $revision->post_content;
-
- // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
- $wpdb->update($wpdb->posts, $data, array('ID' => $revision->ID));
-
- wp_restore_post_revision( $revision->ID, array( 'post_content', 'post_title', 'post_date', 'post_date_gmt', 'post_modified', 'post_modified_gmt' ) );
-
- // restore previous meta fields
- revisionary_copy_postmeta($revision, $post->ID);
-
- revisionary_copy_terms($revision, $post->ID);
-
- clean_post_cache($revision->ID);
- clean_post_cache($post->ID);
-
- delete_metadata('post', $post->ID, '_elementor_element_cache');
-
- rvy_format_content( $revision->post_content, $revision->post_content_filtered, $post->ID );
+ if (!rvy_restore_archived_revision($revision->ID)) { return false; }
if ( 'inherit' == $revision->post_status ) {
$last_arg = array( 'revision_action' => 1, 'restored_post' => $post->ID );
@@ -827,6 +805,40 @@
exit;
}
+
+/** Restore archived content, metadata and terms through the native lifecycle. */
+function rvy_restore_archived_revision($revision_id) {
+ $revision = wp_get_post_revision($revision_id);
+ $post = $revision ? get_post($revision->post_parent) : null;
+ if (!$post || !current_user_can('edit_post', $post->ID)) { return false; }
+ global $wpdb;
+
+ $data = array( 'post_status' => 'inherit', 'post_date' => $revision->post_modified, 'post_date_gmt' => $revision->post_modified );
+
+ if ( class_exists('WPCom_Markdown') && ! defined( 'RVY_DISABLE_MARKDOWN_WORKAROUND' ) )
+ $data['post_content_filtered'] = $revision->post_content;
+
+ // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
+ if (false === $wpdb->update($wpdb->posts, $data, array('ID' => $revision->ID))) { return false; }
+
+ if (!wp_restore_post_revision( $revision->ID, array( 'post_content', 'post_title', 'post_date', 'post_date_gmt', 'post_modified', 'post_modified_gmt' ) )) { return false; }
+
+ // restore previous meta fields
+ revisionary_copy_postmeta($revision, $post->ID);
+
+ revisionary_copy_terms($revision, $post->ID);
+
+ clean_post_cache($revision->ID);
+ clean_post_cache($post->ID);
+
+ delete_metadata('post', $post->ID, '_elementor_element_cache');
+
+ rvy_format_content( $revision->post_content, $revision->post_content_filtered, $post->ID );
+
+
+ return $post->ID;
+}
+
function rvy_apply_revision( $revision_id, $actual_revision_status = '' ) {
global $wpdb, $revisionary;
@@ -900,7 +912,7 @@
$existing_parent = 0;
}
- $skip_post_meta = rvy_is_revision_status($original_revision_status) ? rvy_disabled_revision_meta_keys() : [];
+ $skip_post_meta = rvy_is_revision_status($original_revision_status) ? revisionary_disabled_meta_keys() : [];
if (!rvy_revision_metadata_is_safe($revision_id, $published_id, ['skip_meta_keys' => $skip_post_meta])) {
return new WP_Error('revisionary_unsafe_metadata', __('Revision metadata contains unsupported objects.', 'revisionary'));
}
@@ -1113,8 +1125,14 @@
}
}
- $meta_result = revisionary_copy_postmeta($revision, $published->ID, ['skip_meta_keys' => $skip_post_meta, 'apply_empty' => !$is_imported]);
- if (is_wp_error($meta_result)) { return $meta_result; }
+ if (is_array($enabled_fields)) {
+ $skip_post_meta = revisionary_disabled_meta_keys($enabled_fields);
+ } else {
+ $skip_post_meta = [];
+ }
+
+ $meta_result = revisionary_copy_postmeta($revision, $published->ID, ['skip_meta_keys' => $skip_post_meta, 'apply_empty' => !$is_imported]);
+ if (is_wp_error($meta_result)) { return $meta_result; }
$_args = ['apply_empty' => !$is_imported, 'applying_revision' => true, 'skip_taxonomies' => []];
--- a/revisionary/functions.php
+++ b/revisionary/functions.php
@@ -76,15 +76,23 @@
return;
}
+ $taxonomy_type = $from_post->post_type;
+ if ($taxonomy_type === 'revision') {
+ // Core archives do not record taxonomy snapshots. Workflow archives retain their source marker.
+ $source = get_post($from_post->post_parent);
+ if (!$source || !get_post_meta($from_post->ID, '_rvy_base_post_id', true)) { return; }
+ $taxonomy_type = $source->post_type;
+ }
+
// Clear default category (added by wp_insert_post).
if (!$empty_target_only || !wp_get_object_terms($target_id, 'category', ['fields' => 'ids'])) {
wp_set_object_terms( $target_id, null, 'category' );
}
- $post_taxonomies = get_object_taxonomies( $from_post->post_type );
+ $post_taxonomies = get_object_taxonomies( $taxonomy_type );
// Several plugins just add support to post-formats but don't register post_format taxonomy.
- if (!in_array('post_format', $post_taxonomies, true) && post_type_supports($from_post->post_type, 'post-formats')) {
+ if (!in_array('post_format', $post_taxonomies, true) && post_type_supports($taxonomy_type, 'post-formats')) {
$post_taxonomies[] = 'post_format';
}
@@ -267,7 +275,12 @@
$delete_meta_keys = [];
if (!$empty_target_only && !empty($target_meta_keys) && is_array($target_meta_keys)) {
if ($delete_meta_keys = array_diff($target_meta_keys, $meta_keys, $skip_meta_keys, revisionary_unrevisioned_postmeta())) {
- $deletable_keys = apply_filters('revisionary_deletable_postmeta_keys', ['_links_to', '_links_to_target']);
+ $deletable_keys = ['_links_to', '_links_to_target'];
+ if ($from_post->post_type !== 'revision' && rvy_in_revision_workflow($from_post)) {
+ // A working copy contains the image snapshot; its native editor clears images by deleting this key.
+ $deletable_keys[] = '_thumbnail_id';
+ }
+ $deletable_keys = apply_filters('revisionary_deletable_postmeta_keys', $deletable_keys);
}
foreach($delete_meta_keys as $meta_key) {
@@ -1119,6 +1132,38 @@
require_once __DIR__ . '/permissions-read_rvy.php';
+/** Match workflow MIME statuses without a MIME subtype, as used by the native queue. */
+function rvy_revision_mime_where($where) {
+ $where = str_replace("-revision/%'", "-revision'", $where);
+ return preg_replace("#post_mime_type LIKE '([a-z0-9_\-]*)/%'#", "post_mime_type LIKE '$1'", $where);
+}
+
+/** Save the post-author choice independently of the working copy's revision owner. */
+function rvy_set_revision_author($revision_id, $author_id) {
+ $revision = get_post($revision_id);
+ $type = $revision ? get_post_type_object($revision->post_type) : null;
+ if (!$revision || !rvy_in_revision_workflow($revision) || !rvy_get_option('allow_post_author_revision') || !$type
+ || !current_user_can('edit_post', $revision_id) || !is_user_member_of_blog($author_id)
+ || !user_can($author_id, $type->cap->edit_posts)) { return false; }
+ update_post_meta($revision_id, '_rvy_author_selection', (int) $author_id);
+ return (int) get_post_meta($revision_id, '_rvy_author_selection', true) === (int) $author_id;
+}
+
+/** Convert disabled native field switches into metadata keys; default to revision fields. */
+function revisionary_disabled_meta_keys($fields = null) {
+ if (null === $fields) {
+ global $revisionary;
+ $fields = $revisionary->enabled_fields ?? null;
+ }
+ if (!is_array($fields)) { return []; }
+ $keys = array_keys(array_filter($fields, static fn($enabled) => !$enabled));
+ return array_values(array_unique(array_map(static fn($key) => match ($key) {
+ 'post_thumbnail' => '_thumbnail_id',
+ 'post_template' => '_wp_page_template',
+ default => $key,
+ }, $keys)));
+}
+
/** Visibility policy shared by preview, history and comparison. */
function rvy_can_view_workflow_revision($revision) {
$revision = get_post($revision);
@@ -1216,12 +1261,6 @@
return !is_wp_error(revisionary_copy_postmeta($post_id, $target_id, array_merge($args, ['validate_only' => true])));
}
-function rvy_disabled_revision_meta_keys() {
- global $revisionary;
- return is_array($revisionary->enabled_fields)
- ? array_keys(array_filter($revisionary->enabled_fields, static function ($value) { return !$value; })) : [];
-}
-
/**
* Authority to propose ownership changes is separate from target-user eligibility.
* Keep revision access checks and also honor object-specific live-post edit denials.
--- a/revisionary/includes/Mcp/Registry.php
+++ b/revisionary/includes/Mcp/Registry.php
@@ -0,0 +1,171 @@
+<?php
+
+/**
+ * Private Revisions abilities and strict, shared input contracts.
+ *
+ * @package PublishPress
+ */
+
+namespace PublishPressRevisionsMcp;
+
+defined('ABSPATH') || exit;
+class Registry
+{
+ public static function object(array $properties = [], array $required = []): array
+ {
+ $schema = ['type' => 'object', 'required' => $required, 'additionalProperties' => false];
+ if ($properties) {
+ $schema['properties'] = $properties;
+ }
+ return $schema;
+ }
+
+ public static function id(): array
+ {
+ return ['type' => 'integer', 'minimum' => 1];
+ }
+ public static function text(int $max = 1000): array
+ {
+ return ['type' => 'string', 'maxLength' => $max];
+ }
+ public static function revision(): array
+ {
+ return ['type' => 'string', 'pattern' => '^[a-f0-9]{64}$'];
+ }
+ public static function page(): array
+ {
+ return ['page' => ['type' => 'integer', 'minimum' => 1, 'maximum' => 10000],
+ 'per_page' => ['type' => 'integer', 'minimum' => 1, 'maximum' => 100]];
+ }
+ public static function listOf(array $items, int $max = 100): array
+ {
+ return ['type' => 'array', 'items' => $items, 'maxItems' => $max, 'uniqueItems' => true];
+ }
+
+ public static function error(string $message = '', int $status = 400): WP_Error
+ {
+ return new WP_Error('publishpress_revisions_mcp', $message ?: __('Use the exact fields, types and choices returned by discovery.', 'revisionary'), ['status' => $status]);
+ }
+
+ public static function denied(): WP_Error
+ {
+ return self::error(__('You do not have permission to use this Revisions operation.', 'revisionary'), 403);
+ }
+
+ public static function hash($value): string
+ {
+ return hash_hmac('sha256', wp_json_encode($value), wp_salt('nonce'));
+ }
+
+ public static function validate($value, array $schema, string $path = 'input')
+ {
+ $type = $schema['type'] ?? null;
+ $types = (array) $type;
+ $matches = false;
+ foreach ($types as $candidate) {
+ $matches = $matches || ($candidate === 'object' && (is_object($value) || (is_array($value) && (!$value || !array_is_list($value)))))
+ || ($candidate === 'array' && is_array($value) && array_is_list($value))
+ || ($candidate === 'string' && is_string($value))
+ || ($candidate === 'integer' && is_int($value))
+ || ($candidate === 'boolean' && is_bool($value))
+ || ($candidate === 'null' && $value === null)
+ || ($candidate === 'number' && (is_int($value) || is_float($value)));
+ }
+ if (!$matches) {
+ return self::error(sprintf(__('Invalid JSON type at %s.', 'revisionary'), $path));
+ }
+ if (in_array('object', $types, true) && (is_array($value) || is_object($value))) {
+ $value = (array) $value;
+ foreach ($schema['required'] ?? [] as $key) {
+ if (!array_key_exists($key, $value)) {
+ return self::error();
+ }
+ }
+ if (($schema['additionalProperties'] ?? true) === false && array_diff(array_keys($value), array_keys($schema['properties'] ?? []))) {
+ return self::error();
+ }
+ foreach ($value as $key => &$child) {
+ if (isset($schema['properties'][$key]) || is_array($schema['additionalProperties'] ?? null)) {
+ $child = self::validate($child, $schema['properties'][$key] ?? $schema['additionalProperties'], $path . '.' . $key);
+ if (is_wp_error($child)) {
+ return $child;
+ }
+ }
+ }
+ unset($child);
+ } elseif (in_array('array', $types, true) && is_array($value)) {
+ foreach ($value as $key => &$child) {
+ $child = self::validate($child, $schema['items'], $path . '[' . $key . ']');
+ if (is_wp_error($child)) {
+ return $child;
+ }
+ }
+ unset($child);
+ }
+ $check = rest_validate_value_from_schema($value, $schema, $path);
+ return is_wp_error($check) ? $check : $value;
+ }
+
+ public static function add(string $name, string $label, string $description, array $schema, callable $callback, callable $permission, bool $write = false, bool $destructive = false, array $output = []): void
+ {
+ wp_register_ability('publishpress-revisions/' . $name, [
+ 'label' => $label, 'description' => $description, 'category' => 'publishpress',
+ 'input_schema' => $schema, 'output_schema' => $output ?: self::object(['items' => ['type' => 'array', 'items' => ['type' => 'object']], 'has_more' => ['type' => 'boolean']]),
+ 'permission_callback' => static function ($input) use ($permission, $schema) {
+
+ $input = self::validate($input, $schema);
+ return is_wp_error($input) ? $input : ($permission($input) ? true : self::denied());
+ },
+ 'execute_callback' => static function ($input) use ($callback, $permission, $schema) {
+
+ $input = self::validate($input, $schema);
+ if (is_wp_error($input)) {
+ return $input;
+ }
+ if (!$permission($input)) {
+ return self::denied();
+ }
+ return self::executeNative($callback, $input);
+ },
+ 'meta' => ['public' => false, 'show_in_rest' => false, 'mcp' => ['public' => false],
+ 'annotations' => ['readonly' => !$write, 'destructive' => $destructive, 'idempotent' => !$write]],
+ ]);
+ }
+
+ private static function executeNative(callable $callback, array $input)
+ {
+ $saved = [];
+ foreach (['post', 'id', 'authordata', 'currentday', 'currentmonth', 'pages', 'page', 'multipage', 'more', 'numpages'] as $key) {
+ $saved[$key] = [array_key_exists($key, $GLOBALS), $GLOBALS[$key] ?? null];
+ }
+ try {
+ return $callback($input);
+ } catch (Throwable $error) {
+ return self::error(__('Revisions could not complete this operation. Inspect the current state before retrying; some changes may have been saved.', 'revisionary'), 500);
+ } finally {
+ foreach ($saved as $key => $value) {
+ if ($value[0]) {
+ $GLOBALS[$key] = $value[1];
+ } else {
+ unset($GLOBALS[$key]);
+ }
+ }
+ }
+ }
+
+ public static function pro(): bool
+ {
+ return defined('PUBLISHPRESS_REVISIONS_PRO_VERSION') && function_exists('revisionary');
+ }
+
+ public static function stale(array $input, $state)
+ {
+ return isset($input['expected_hash']) && hash_equals(self::hash($state), $input['expected_hash'])
+ ? true : self::error(__('This object changed. Read it again before saving.', 'revisionary'), 409);
+ }
+
+ public static function unconfirmed(): WP_Error
+ {
+ return self::error(__('The operation could not be fully confirmed. Read the object before retrying; some changes may have been saved.', 'revisionary'), 500);
+ }
+}
--- a/revisionary/includes/Mcp/Revisions.php
+++ b/revisionary/includes/Mcp/Revisions.php
@@ -0,0 +1,656 @@
+<?php
+
+/** Revision queue, editable copies, native transitions and archive operations. */
+
+namespace PublishPressRevisionsMcp;
+
+defined('ABSPATH') || exit;
+class Revisions
+{
+ public static function register(): void
+ {
+ $access = static fn() => is_user_logged_in();
+ $fields = ['id' => Registry::id(), 'post_id' => Registry::id(), 'title' => Registry::text(), 'content' => Registry::text(1000000), 'excerpt' => Registry::text(100000), 'status' => Registry::text(), 'slug' => Registry::text(200), 'parent' => ['type' => 'integer', 'minimum' => 0], 'post_type' => Registry::text(), 'date' => Registry::text(), 'date_gmt' => Registry::text(), 'author' => ['type' => 'integer'], 'revision_author' => ['type' => 'integer'], 'terms' => ['type' => 'object'], 'thumbnail_id' => ['type' => 'integer', 'minimum' => 0], 'template' => Registry::text(200), 'expected_hash' => Registry::revision(), 'parent_hash' => Registry::revision(), 'dry_run' => ['type' => 'boolean'], 'operation' => Registry::text(), 'complete' => ['type' => 'boolean'], 'applied_ids' => Registry::listOf(Registry::id()), 'failed_id' => Registry::id(), 'changes' => ['type' => 'object'], 'items' => ['type' => 'array', 'items' => ['type' => 'object']], 'has_more' => ['type' => 'boolean'], 'choices' => ['type' => 'object']];
+ $output = Registry::object($fields);
+ Registry::add('get-content-choices', __('Discover Revisions features and choices', 'revisionary'), __('Discover separate native revision, archive and duplication post types and fields, revision statuses and active Pro/integration state. Supply post_id for source permissions, available templates and taxonomy assignment choices. Revisions are separate from the published source post. Native capabilities and source read access are enforced.', 'revisionary'), Registry::object(['post_id' => Registry::id()]), [self::class, 'choices'], $access, false, false, Registry::object(['choices' => ['type' => 'object']]));
+ Registry::add('list-revisions', __('Find revisions and past revisions', 'revisionary'), __('Browse a bounded native revision queue or WordPress archive. Filter by source post, status, author or title. Every returned revision and source requires native read access. Other users’ restricted revisions are excluded.', 'revisionary'), Registry::object(Registry::page() + ['post_id' => Registry::id(), 'status' => ['type' => 'string', 'enum' => array_merge(['archive', 'trash'], rvy_revision_statuses())], 'author' => Registry::id(), 'search' => Registry::text(200)]), [self::class, 'listing'], $access);
+ Registry::add('get-source-post', __('Read a revision source post', 'revisionary'), __('Read one supported revision, archive or duplication source and its revision token before creating a new copy. Requires source read access and native copy_post or edit_post. Does not expose passwords, authentication metadata or signed preview links.', 'revisionary'), Registry::object(['id' => Registry::id()], ['id']), [self::class, 'readSource'], $access, false, false, $output);
+ Registry::add('get-revision', __('Read a revision', 'revisionary'), __('Read revision content, its native scheduling dates and terms, plus revisions for both the copy and source. Authentication metadata, passwords and signed preview links are excluded.', 'revisionary'), Registry::object(['id' => Registry::id()], ['id']), [self::class, 'read'], $access, false, false, $output);
+ $changes = Registry::object(['title' => Registry::text(1000), 'content' => Registry::text(1000000), 'excerpt' => Registry::text(100000), 'slug' => Registry::text(200), 'author' => Registry::id(), 'parent' => ['type' => 'integer', 'minimum' => 0], 'date' => ['type' => 'string', 'format' => 'date-time'], 'thumbnail_id' => ['type' => 'integer', 'minimum' => 0], 'template' => Registry::text(200), 'terms' => ['type' => 'object', 'maxProperties' => 30]]);
+ Registry::add('create-revision', __('Create a new revision', 'revisionary'), __('Create a native unsubmitted revision of one supported readable source using copy_post permission and the source expected_hash. Native metadata/taxonomy cloning, revision limits, builder gates and hooks apply. Omit changes to copy content unchanged. dry_run never creates a copy.', 'revisionary'), Registry::object(['post_id' => Registry::id(), 'expected_hash' => Registry::revision(), 'changes' => $changes, 'dry_run' => ['type' => 'boolean']], ['post_id', 'expected_hash']), [self::class, 'create'], $access, true, false, $output);
+ Registry::add('duplicate-post', __('Duplicate a source post', 'revisionary'), __('Create a native draft duplicate of an enabled readable source post. Requires duplicate_post permission, the source expected_hash and native duplication settings. Copies the native configured fields, taxonomy and metadata through RevisionCreation. dry_run creates nothing.', 'revisionary'), Registry::object(['post_id' => Registry::id(), 'expected_hash' => Registry::revision(), 'dry_run' => ['type' => 'boolean']], ['post_id', 'expected_hash']), [self::class, 'duplicate'], $access, true, false, $output);
+ Registry::add('update-revision', __('Update revision content', 'revisionary'), __('Patch only supplied editable revision fields using expected_hash. Native allowed fields, locks, term/author permissions and sanitizers apply. The published source is unchanged. Submitted or scheduled copies require their native edit permission; all edits to scheduled revisions require approval permission. dry_run validates without saving.', 'revisionary'), Registry::object(['id' => Registry::id(), 'expected_hash' => Registry::revision(), 'changes' => $changes, 'dry_run' => ['type' => 'boolean']], ['id', 'expected_hash', 'changes']), [self::class, 'update'], $access, true, false, $output);
+ $item = Registry::object(['id' => Registry::id(), 'expected_hash' => Registry::revision(), 'parent_hash' => Registry::revision()], ['id', 'expected_hash']);
+ Registry::add('transition-revisions', __('Submit, approve or manage revisions', 'revisionary'), __('Apply one native action to up to 50 explicit revision IDs: submit, decline, approve, publish a scheduled revision now, unschedule, trash, restore archive or delete an archived revision. Publishing/restoring requires parent_hash and native source edit and approval permissions. All targets are validated before writes; partial failures report confirmed IDs. Approval honors the saved date, scheduling future changes. dry_run never publishes or sends notifications.', 'revisionary'), Registry::object(['operation' => ['type' => 'string', 'enum' => ['submit', 'decline', 'approve', 'publish', 'unschedule', 'trash', 'untrash', 'restore', 'delete']], 'items' => ['type' => 'array', 'minItems' => 1, 'maxItems' => 50, 'items' => $item], 'dry_run' => ['type' => 'boolean']], ['operation', 'items']), [self::class, 'transition'], $access, true, true, $output);
+ Registry::add('compare-revision', __('Compare revision content', 'revisionary'), __('Compare standard fields and taxonomy assignments with the readable source, or supply compare_to to compare two authorized revisions of the same source. Missing historical fields are omitted, not treated as cleared. Returns plain source/revision values, not executable previews or signed URLs. Pro metadata providers are discovered separately; credentials are never exported.', 'revisionary'), Registry::object(['id' => Registry::id(), 'compare_to' => Registry::id()], ['id']), [self::class, 'compare'], $access, false, false, Registry::object(['id' => Registry::id(), 'post_id' => Registry::id(), 'changes' => ['type' => 'object'], 'expected_hash' => Registry::revision(), 'parent_hash' => Registry::revision(), 'comparison_id' => Registry::id(), 'comparison_hash' => Registry::revision()]));
+ }
+ public static function choices(array $input = [])
+ {
+ $engine = $GLOBALS['revisionary'];
+ $choices = ['post_types' => self::typeChoices($engine->enabled_post_types),
+ 'archive_post_types' => self::typeChoices($engine->enabled_post_types_archive),
+ 'duplicate_post_types' => self::typeChoices($engine->enabled_post_types_copy),
+ 'statuses' => rvy_revision_statuses(), 'pro_active' => Registry::pro(),
+ 'enabled_fields' => $engine->enabled_fields, 'duplicate_fields' => $engine->enabled_fields_copy,
+ 'integrations' => self::integrations()];
+ if (isset($input['post_id'])) {
+ $source = self::readSource(['id' => $input['post_id']]);
+ if (is_wp_error($source)) {
+ return $source;
+ }
+ $post = get_post($input['post_id']);
+ $taxonomies = [];
+ foreach (get_object_taxonomies($post->post_type, 'objects') as $taxonomy) {
+ if (!$taxonomy->show_ui || str_starts_with($taxonomy->name, 'pp_notify_')) {
+ continue;
+ }
+ $field = in_array($taxonomy->name, ['category', 'post_tag'], true) ? $taxonomy->name : 'taxonomies';
+ $taxonomies[$taxonomy->name] = ['label' => $taxonomy->label,
+ 'can_assign' => current_user_can($taxonomy->cap->assign_terms) && ($engine->enabled_fields === true || !empty($engine->enabled_fields[$field]))];
+ }
+ $choices['source'] = ['id' => $post->ID, 'expected_hash' => $source['expected_hash'],
+ 'can_create_revision' => self::canReviseStatus($post) && !empty($engine->enabled_post_types[$post->post_type]) && current_user_can('copy_post', $post->ID) && rvy_post_revision_supported($post),
+ 'can_duplicate' => !empty($engine->enabled_post_types_copy[$post->post_type]) && current_user_can('duplicate_post', $post->ID),
+ 'templates' => (object) (['default' => __('Default template', 'revisionary')] + wp_get_theme()->get_page_templates($post, $post->post_type)),
+ 'taxonomies' => (object) $taxonomies];
+ }
+ return ['choices' => (object) $choices];
+ }
+ private static function typeChoices(array $enabled): object
+ {
+ $types = [];
+ foreach ($enabled as $type => $active) {
+ if ($active && ($object = get_post_type_object($type))) {
+ $types[$type] = ['label' => $object->label, 'capabilities' => (object) $object->cap];
+ }
+ }
+ return (object) $types;
+ }
+ private static function integrations(): array
+ {
+ $items = [];
+ foreach (PublishPressRevisions::getDefinedIntegrations() as $integration) {
+ $items[] = ['id' => $integration['id'], 'label' => wp_strip_all_tags($integration['title']), 'available' => !empty(