Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
W
WP Revisions Control
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Code Review
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
WP Plugins
WP Revisions Control
Commits
6060b5e5
Commit
6060b5e5
authored
May 26, 2019
by
Erick Hitter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce method to purge excess revisions
parent
8d885579
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
92 additions
and
4 deletions
+92
-4
inc/class-wp-revisions-control-bulk-actions.php
inc/class-wp-revisions-control-bulk-actions.php
+48
-4
inc/class-wp-revisions-control.php
inc/class-wp-revisions-control.php
+44
-0
No files found.
inc/class-wp-revisions-control-bulk-actions.php
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.
*
...
...
@@ -44,10 +51,9 @@ class WP_Revisions_Control_Bulk_Actions {
*/
protected
function
register_actions
()
{
$actions
=
array
();
$action_base
=
'wp_rev_ctl_bulk_'
;
$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
);
}
}
}
inc/class-wp-revisions-control.php
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.
*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment