Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
WP Revisions Control
Manage
Activity
Members
Labels
Plan
Issues
3
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
0
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
6060b5e5
Commit
6060b5e5
authored
5 years ago
by
Erick Hitter
Browse files
Options
Downloads
Patches
Plain Diff
Introduce method to purge excess revisions
parent
8d885579
No related branches found
No related tags found
1 merge request
!4
Add bulk actions
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
inc/class-wp-revisions-control-bulk-actions.php
+48
-4
48 additions, 4 deletions
inc/class-wp-revisions-control-bulk-actions.php
inc/class-wp-revisions-control.php
+44
-0
44 additions, 0 deletions
inc/class-wp-revisions-control.php
with
92 additions
and
4 deletions
inc/class-wp-revisions-control-bulk-actions.php
+
48
−
4
View file @
6060b5e5
...
...
@@ -16,6 +16,13 @@ class WP_Revisions_Control_Bulk_Actions {
*/
protected
$post_types
;
/**
* Base for bulk action names.
*
* @var string
*/
protected
$action_base
=
'wp_rev_ctl_bulk_'
;
/**
* Custom bulk actions.
*
...
...
@@ -43,11 +50,10 @@ class WP_Revisions_Control_Bulk_Actions {
* Register custom actions.
*/
protected
function
register_actions
()
{
$actions
=
array
();
$action_base
=
'wp_rev_ctl_bulk_'
;
$actions
=
array
();
$actions
[
$action_base
.
'purge_excess'
]
=
__
(
'Purge excess revisions'
,
'wp_revisions_control'
);
$actions
[
$action_base
.
'purge_all'
]
=
__
(
'Purge ALL revisions'
,
'wp_revisions_control'
);
$actions
[
$
this
->
action_base
.
'purge_excess'
]
=
__
(
'Purge excess revisions'
,
'wp_revisions_control'
);
$actions
[
$
this
->
action_base
.
'purge_all'
]
=
__
(
'Purge ALL revisions'
,
'wp_revisions_control'
);
$this
->
actions
=
$actions
;
}
...
...
@@ -74,6 +80,7 @@ class WP_Revisions_Control_Bulk_Actions {
add_filter
(
'bulk_actions-'
.
$screen
->
id
,
array
(
$this
,
'add_actions'
)
);
add_filter
(
'handle_bulk_actions-'
.
$screen
->
id
,
array
(
$this
,
'handle_action'
),
10
,
3
);
// TODO: messages.
}
/**
...
...
@@ -99,7 +106,44 @@ class WP_Revisions_Control_Bulk_Actions {
return
$redirect_to
;
}
$action
=
str_replace
(
$this
->
action_base
,
''
,
$action
);
switch
(
$action
)
{
case
'purge_all'
:
$this
->
purge_all
(
$ids
);
break
;
case
'purge_excess'
:
$this
->
purge_excess
(
$ids
);
break
;
default
:
break
;
}
// TODO: implement and add a query string to trigger a message.
return
$redirect_to
;
}
/**
* Remove all revisions from the given IDs.
*
* @param array $ids Object IDs.
*/
protected
function
purge_all
(
$ids
)
{
foreach
(
$ids
as
$id
)
{
WP_Revisions_Control
::
get_instance
()
->
do_purge_all
(
$id
);
}
}
/**
* Remove excess revisions from the given IDs.
*
* @param array $ids Object IDs.
*/
protected
function
purge_excess
(
$ids
)
{
foreach
(
$ids
as
$id
)
{
WP_Revisions_Control
::
get_instance
()
->
do_purge_excess
(
$id
);
}
}
}
This diff is collapsed.
Click to expand it.
inc/class-wp-revisions-control.php
+
44
−
0
View file @
6060b5e5
...
...
@@ -410,6 +410,50 @@ class WP_Revisions_Control {
return
$response
;
}
/**
* Remove any revisions in excess of a post's limit.
*
* @param int $post_id Post ID to purge of excess revisions.
* @return array
*/
public
function
do_purge_excess
(
$post_id
)
{
$response
=
array
(
'count'
=>
0
,
);
$to_keep
=
wp_revisions_to_keep
(
get_post
(
$post_id
)
);
if
(
$to_keep
<
0
)
{
$response
[
'success'
]
=
__
(
'No revisions to remove.'
,
'wp_revisions_control'
);
return
$response
;
}
$revisions
=
wp_get_post_revisions
(
$post_id
);
$starting_count
=
count
(
$revisions
);
if
(
$starting_count
<=
$to_keep
)
{
$response
[
'success'
]
=
__
(
'No revisions to remove.'
,
'wp_revisions_control'
);
return
$response
;
}
$to_remove
=
array_slice
(
$revisions
,
$to_keep
,
null
,
true
);
$response
[
'count'
]
=
count
(
$to_remove
);
foreach
(
$to_remove
as
$revision
)
{
wp_delete_post_revision
(
$revision
->
ID
);
}
return
$response
;
}
/**
* Sanitize and store post-specifiy revisions quantity.
*
...
...
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