Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
WP Revisions Control
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
WP Plugins
WP Revisions Control
Commits
78396183
Commit
78396183
authored
4 years ago
by
Erick Hitter
Browse files
Options
Downloads
Patches
Plain Diff
REST endpoint for purging excess revisions
parent
bd86687e
No related branches found
No related tags found
1 merge request
!12
Introduce native Gutenberg controls
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
inc/class-wp-revisions-control.php
+69
-3
69 additions, 3 deletions
inc/class-wp-revisions-control.php
with
69 additions
and
3 deletions
inc/class-wp-revisions-control.php
+
69
−
3
View file @
78396183
...
...
@@ -71,6 +71,13 @@ class WP_Revisions_Control {
*/
private
$meta_key_limit
=
'_wp_rev_ctl_limit'
;
/**
* Name of action used to clean up post's revisions via cron.
*
* @var string
*/
private
$cron_action
=
'wp_revisions_control_cron_purge'
;
/**
* Silence is golden!
*/
...
...
@@ -121,6 +128,7 @@ class WP_Revisions_Control {
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
(
'enqueue_block_editor_assets'
,
array
(
$this
,
'action_enqueue_block_editor_assets'
)
);
add_action
(
$this
->
cron_action
,
array
(
$this
,
'do_purge_excess'
)
);
}
/**
...
...
@@ -279,8 +287,8 @@ class WP_Revisions_Control {
/**
* Override Core's revisions metabox.
*
* @param string
$post_type Post type.
* @param
\
WP_Post $post Post object.
* @param string $post_type Post type.
* @param WP_Post $post Post object.
*/
public
function
action_add_meta_boxes
(
$post_type
,
$post
)
{
if
(
...
...
@@ -522,7 +530,7 @@ class WP_Revisions_Control {
*/
/**
* Register
meta
for Gutenberg UI.
* Register
REST API components
for Gutenberg UI.
*/
public
function
action_rest_api_init
()
{
foreach
(
array_keys
(
$this
->
get_post_types
()
)
as
$post_type
)
{
...
...
@@ -542,6 +550,64 @@ class WP_Revisions_Control {
)
);
}
register_rest_route
(
'wp-revisions-control/v1'
,
'schedule/(?P<id>[\d]+)'
,
array
(
'methods'
=>
'PUT'
,
'callback'
=>
array
(
$this
,
'rest_api_schedule_purge'
),
'permission_callback'
=>
array
(
$this
,
'rest_api_permission_callback'
),
'args'
=>
array
(
'id'
=>
array
(
'required'
=>
true
,
'type'
=>
'integer'
,
'validate_callback'
=>
array
(
$this
,
'rest_api_validate_id'
),
),
),
)
);
}
/**
* Permissions callback for REST endpoint.
*
* @param WP_REST_Request $request Request object.
* @return bool
*/
public
function
rest_api_permission_callback
(
$request
)
{
return
current_user_can
(
'edit_post'
,
$request
->
get_param
(
'id'
)
);
}
/**
* Validate post ID.
*
* @param int $input Post ID.
* @return bool
*/
public
function
rest_api_validate_id
(
$input
)
{
return
is_numeric
(
$input
);
}
/**
* Schedule cleanup of post's excess revisions.
*
* @param WP_REST_Request $request Request object.
* @return WP_REST_Response
*/
public
function
rest_api_schedule_purge
(
$request
)
{
$result
=
wp_schedule_single_event
(
time
()
+
3
,
$this
->
cron_action
,
[
$request
->
get_param
(
'id'
),
]
);
return
rest_ensure_response
(
$result
);
}
/**
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment