diff --git a/assets/build/gutenberg.asset.php b/assets/build/gutenberg.asset.php index 024960ba7a9dd6963bddbddd1e92f2772c270678..951faa5405590216510a600a1cceb928261bdf44 100644 --- a/assets/build/gutenberg.asset.php +++ b/assets/build/gutenberg.asset.php @@ -1 +1 @@ -<?php return array('dependencies' => array('wp-api-fetch', 'wp-components', 'wp-compose', 'wp-data', 'wp-edit-post', 'wp-element', 'wp-i18n', 'wp-plugins'), 'version' => 'caf115ed5017b4ad3c90'); +<?php return array('dependencies' => array('wp-api-fetch', 'wp-components', 'wp-compose', 'wp-data', 'wp-edit-post', 'wp-element', 'wp-i18n', 'wp-plugins'), 'version' => '7f1755eabefc886809fd'); diff --git a/assets/build/gutenberg.js b/assets/build/gutenberg.js index ef44797dd1f679b344d9ebc067481ff6724aa5af..c904ff14ac42899b20e22ca4c063ae74c0372d9d 100644 --- a/assets/build/gutenberg.js +++ b/assets/build/gutenberg.js @@ -1,3 +1,3 @@ -!function(){"use strict";var e={989:function(e){e.exports=window.wp.apiFetch},609:function(e){e.exports=window.wp.components},333:function(e){e.exports=window.wp.compose},818:function(e){e.exports=window.wp.data},67:function(e){e.exports=window.wp.editPost},307:function(e){e.exports=window.wp.element},736:function(e){e.exports=window.wp.i18n},817:function(e){e.exports=window.wp.plugins}},t={};function o(n){var r=t[n];if(void 0!==r)return r.exports;var i=t[n]={exports:{}};return e[n](i,i.exports,o),i.exports}o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,{a:t}),t},o.d=function(e,t){for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e=o(307);const t=o(989),{Button:n,Modal:r,TextControl:i}=o(609),{compose:s}=o(333),{withSelect:l,withDispatch:c}=o(818),{PluginDocumentSettingPanel:a}=o(67),{useState:u}=o(307),{__:__,_n:_n,sprintf:p}=o(736),{registerPlugin:w}=o(817),d=window.wpRevisionsControlBlockEditorSettings.metaKey,v="wp-revisions-control",m=s([l((e=>{const{getCurrentPostRevisionsCount:t,getEditedPostAttribute:o}=e("core/editor"),n=t(),r=o("meta")[d];return{limit:r,showPurgeButton:Boolean(r)&&n>parseInt(r)}})),c(((e,o,n)=>{let{}=o,{select:r}=n;return{manualPurge:()=>{const o=r("core/editor").getCurrentPostId();t({path:`/wp-revisions-control/v1/schedule/${o}`,method:"PUT"}).then((t=>{let o,n;t?(o="success",n=__("Excess revisions scheduled for removal.","wp_revisions_control")):(o="error",n=__("Failed to schedule excess revisions for removal.","wp_revisions_control")),e("core/notices").createNotice(o,n,{id:"wp-revisions-control-scheduled-purge",isDismissible:!0,type:"snackbar"})}))},updateMeta:t=>{e("core/editor").editPost({meta:{[d]:t}})}}}))])((t=>{let{limit:o,manualPurge:s,showPurgeButton:l,updateMeta:c}=t;return(0,e.createElement)(a,{name:v,title:__("WP Revisions Control","wp_revisions_control"),className:v},(0,e.createElement)(i,{label:__("Number of revisions to retain:","wp_revisions_control"),help:__("Leave blank to keep all revisions.","wp_revisions_control"),value:o,onChange:c}),l&&((t,o)=>{const[i,s]=u(!1),l=()=>s(!1),c=parseInt(t,10),a=0===c?__("This will remove all revisions.","wp_revisions_control"):p( +!function(){"use strict";var e={989:function(e){e.exports=window.wp.apiFetch},609:function(e){e.exports=window.wp.components},333:function(e){e.exports=window.wp.compose},818:function(e){e.exports=window.wp.data},67:function(e){e.exports=window.wp.editPost},307:function(e){e.exports=window.wp.element},736:function(e){e.exports=window.wp.i18n},817:function(e){e.exports=window.wp.plugins}},t={};function o(n){var r=t[n];if(void 0!==r)return r.exports;var i=t[n]={exports:{}};return e[n](i,i.exports,o),i.exports}o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,{a:t}),t},o.d=function(e,t){for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){var e=o(307);const t=o(989),{Button:n,Modal:r,TextControl:i}=o(609),{compose:s}=o(333),{withSelect:l,withDispatch:c}=o(818),{PluginDocumentSettingPanel:a}=o(67),{useState:u}=o(307),{__:__,_n:_n,sprintf:p}=o(736),{registerPlugin:w}=o(817),d=window.wpRevisionsControlBlockEditorSettings.metaKey,v="wp-revisions-control",m=s([l((e=>{const{getCurrentPostRevisionsCount:t,getEditedPostAttribute:o}=e("core/editor"),n=t(),r=o("meta")[d];return{limit:r,showPurgeButton:Boolean(r)&&n>parseInt(r)}})),c(((e,o,n)=>{let{limit:r}=o,{select:i}=n;return{manualPurge:()=>{const o=i("core/editor").getCurrentPostId();t({path:`/wp-revisions-control/v1/schedule/${o}/${parseInt(r,10)}`,method:"PUT"}).then((t=>{let o,n;t?(o="success",n=__("Excess revisions scheduled for removal.","wp_revisions_control")):(o="error",n=__("Failed to schedule excess revisions for removal.","wp_revisions_control")),e("core/notices").createNotice(o,n,{id:"wp-revisions-control-scheduled-purge",isDismissible:!0,type:"snackbar"})}))},updateMeta:t=>{e("core/editor").editPost({meta:{[d]:t}})}}}))])((t=>{let{limit:o,manualPurge:s,showPurgeButton:l,updateMeta:c}=t;return(0,e.createElement)(a,{name:v,title:__("WP Revisions Control","wp_revisions_control"),className:v},(0,e.createElement)(i,{label:__("Number of revisions to retain:","wp_revisions_control"),help:__("Leave blank to keep all revisions.","wp_revisions_control"),value:o,onChange:c}),l&&((t,o)=>{const[i,s]=u(!1),l=()=>s(!1),c=parseInt(t,10),a=0===c?__("This will remove all revisions.","wp_revisions_control"):p( /* translators: 1. Number of revisions to keep. */ _n("This will remove all but the most-recent revision.","This will remove all but the %1$d most-recent revisions.",c,"wp_revisions_control"),t);return(0,e.createElement)(e.Fragment,null,(0,e.createElement)(n,{isSecondary:!0,onClick:()=>s(!0)},__("Purge excess revisions","wp_revisions_control")),i&&(0,e.createElement)(r,{title:__("Purge excess revisions","wp_revisions_control"),contentLabel:a,onRequestClose:l},(0,e.createElement)("p",null,a),(0,e.createElement)(n,{isPrimary:!0,onClick:()=>{l(),o()}},__("Purge","wp_revisions_control"))," ",(0,e.createElement)(n,{isSecondary:!0,onClick:l},__("Cancel","wp_revisions_control"))))})(o,s))}));w(v,{render:m,icon:"backup"})}()}(); \ No newline at end of file diff --git a/assets/src/gutenberg.js b/assets/src/gutenberg.js index ac847f9f9a674afb9861c0d95b82402b2c9a7e4b..097eb7b97c687d105c3b3c3645df2961b44139ef 100644 --- a/assets/src/gutenberg.js +++ b/assets/src/gutenberg.js @@ -125,12 +125,15 @@ const RevisionsControl = compose( [ showPurgeButton, }; } ), - withDispatch( ( dispatch, {}, { select } ) => { + withDispatch( ( dispatch, { limit }, { select } ) => { const manualPurge = () => { const postId = select( 'core/editor' ).getCurrentPostId(); apiFetch( { - path: `/wp-revisions-control/v1/schedule/${ postId }`, + path: `/wp-revisions-control/v1/schedule/${ postId }/${ parseInt( + limit, + 10 + ) }`, method: 'PUT', } ).then( ( result ) => { let noticeType; diff --git a/inc/class-block-editor.php b/inc/class-block-editor.php index d9c428e565122cb3a4f37017d3e2d4b18dc71c5b..c13061f9bf54e18296f5f1a536ca92f5e408dd1b 100644 --- a/inc/class-block-editor.php +++ b/inc/class-block-editor.php @@ -33,7 +33,7 @@ class Block_Editor { private function setup() { add_action( 'rest_api_init', array( $this, 'action_rest_api_init' ) ); add_filter( 'is_protected_meta', array( $this, 'filter_is_protected_meta' ), 10, 2 ); - add_action( $this->cron_action, array( WP_Revisions_Control::get_instance(), 'do_purge_excess' ) ); + add_action( $this->cron_action, array( WP_Revisions_Control::get_instance(), 'do_purge_excess' ), 10, 2 ); add_action( 'admin_init', array( $this, 'action_admin_init' ) ); } @@ -78,17 +78,23 @@ class Block_Editor { register_rest_route( 'wp-revisions-control/v1', - 'schedule/(?P<id>[\d]+)', + 'schedule/(?P<id>[\d]+)/(?P<limit_override>[\d]+)', array( 'methods' => 'PUT', 'callback' => array( $this, 'rest_api_schedule_purge' ), 'permission_callback' => array( $this, 'rest_api_permission_callback' ), 'args' => array( - 'id' => array( + 'id' => array( 'required' => true, 'type' => 'integer', 'validate_callback' => array( $this, 'rest_api_validate_id' ), ), + 'limit_override' => array( + 'required' => false, + 'type' => 'integer', + 'default' => null, + 'validate_callback' => array( $this, 'rest_api_validate_id' ), + ), ), 'show_in_index' => false, ) @@ -130,6 +136,7 @@ class Block_Editor { $this->cron_action, array( $request->get_param( 'id' ), + $request->get_param( 'limit_override' ), ) ); diff --git a/inc/class-wp-revisions-control.php b/inc/class-wp-revisions-control.php index ea89a07bf5594f42f3203b4db9ced7ffb38470cc..75d4c04e61eea093b5a80e12f6d792c378968daa 100644 --- a/inc/class-wp-revisions-control.php +++ b/inc/class-wp-revisions-control.php @@ -413,15 +413,19 @@ class WP_Revisions_Control { /** * Remove any revisions in excess of a post's limit. * - * @param int $post_id Post ID to purge of excess revisions. + * @param int $post_id Post ID to purge of excess revisions. + * @param int|null $limit_override Optional. Override post's revisions + * limit. * @return array */ - public function do_purge_excess( $post_id ) { + public function do_purge_excess( $post_id, $limit_override = null ) { $response = array( 'count' => 0, ); - $to_keep = wp_revisions_to_keep( get_post( $post_id ) ); + $to_keep = null !== $limit_override + ? $limit_override + : wp_revisions_to_keep( get_post( $post_id ) ); if ( $to_keep < 0 ) { $response['success'] = __(