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
eb221dd6
Commit
eb221dd6
authored
5 years ago
by
Erick Hitter
Browse files
Options
Downloads
Patches
Plain Diff
Begin adding bulk actions
parent
c4502d89
No related branches found
No related tags found
1 merge request
!4
Add bulk actions
Pipeline
#1058
passed
5 years ago
Stage: test
Stage: deploy
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
inc/class-wp-revisions-control-bulk-actions.php
+105
-0
105 additions, 0 deletions
inc/class-wp-revisions-control-bulk-actions.php
inc/class-wp-revisions-control.php
+6
-1
6 additions, 1 deletion
inc/class-wp-revisions-control.php
wp-revisions-control.php
+1
-0
1 addition, 0 deletions
wp-revisions-control.php
with
112 additions
and
1 deletion
inc/class-wp-revisions-control-bulk-actions.php
0 → 100644
+
105
−
0
View file @
eb221dd6
<?php
/**
* Bulk actions.
*
* @package WP_Revisions_Control
*/
/**
* Class WP_Revisions_Control_Bulk_Actions.
*/
class
WP_Revisions_Control_Bulk_Actions
{
/**
* Supported post types.
*
* @var array
*/
protected
$post_types
;
/**
* Custom bulk actions.
*
* @var array
*/
protected
$actions
;
/**
* Constructor.
*
* @param array $post_types Supported post types.
*/
public
function
__construct
(
$post_types
)
{
if
(
empty
(
$post_types
)
||
!
is_array
(
$post_types
)
)
{
return
;
}
$this
->
post_types
=
$post_types
;
$this
->
register_actions
();
add_action
(
'load-edit.php'
,
array
(
$this
,
'setup'
)
);
}
/**
* Register custom 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'
);
$this
->
actions
=
$actions
;
}
/**
* Register various hooks.
*/
public
function
setup
()
{
$screen
=
get_current_screen
();
if
(
null
===
$screen
)
{
return
;
}
$post_types
=
array_keys
(
$this
->
post_types
);
if
(
!
in_array
(
$screen
->
post_type
,
$post_types
,
true
)
)
{
return
;
}
if
(
'edit'
!==
$screen
->
base
)
{
return
;
}
add_filter
(
'bulk_actions-'
.
$screen
->
id
,
array
(
$this
,
'add_actions'
)
);
add_filter
(
'handle_bulk_actions-'
.
$screen
->
id
,
array
(
$this
,
'handle_action'
),
10
,
3
);
}
/**
* Add our actions.
*
* @param string[] $actions Array of available actions.
* @return array
*/
public
function
add_actions
(
$actions
)
{
return
array_merge
(
$actions
,
$this
->
actions
);
}
/**
* Handle our bulk actions.
*
* @param string $redirect_to Redirect URL.
* @param string $action Bulk action being taken.
* @param array $ids Object IDs to manipulate.
* @return string
*/
public
function
handle_action
(
$redirect_to
,
$action
,
$ids
)
{
if
(
!
array_key_exists
(
$action
,
$this
->
actions
)
)
{
return
$redirect_to
;
}
// TODO: implement and add a query string to trigger a message.
return
$redirect_to
;
}
}
This diff is collapsed.
Click to expand it.
inc/class-wp-revisions-control.php
+
6
−
1
View file @
eb221dd6
...
...
@@ -125,12 +125,14 @@ class WP_Revisions_Control {
* Plugin title is intentionally not translatable.
*/
public
function
action_admin_init
()
{
$post_types
=
$this
->
get_post_types
();
// Plugin setting section.
register_setting
(
$this
->
settings_page
,
$this
->
settings_section
,
array
(
$this
,
'sanitize_options'
)
);
add_settings_section
(
$this
->
settings_section
,
'WP Revisions Control'
,
array
(
$this
,
'settings_section_intro'
),
$this
->
settings_page
);
foreach
(
$
this
->
get_
post_types
()
as
$post_type
=>
$name
)
{
foreach
(
$post_types
as
$post_type
=>
$name
)
{
add_settings_field
(
$this
->
settings_section
.
'-'
.
$post_type
,
$name
,
array
(
$this
,
'field_post_type'
),
$this
->
settings_page
,
$this
->
settings_section
,
array
(
'post_type'
=>
$post_type
)
);
}
...
...
@@ -138,6 +140,9 @@ class WP_Revisions_Control {
add_action
(
'add_meta_boxes'
,
array
(
$this
,
'action_add_meta_boxes'
),
10
,
2
);
add_action
(
'wp_ajax_'
.
$this
->
settings_section
.
'_purge'
,
array
(
$this
,
'ajax_purge'
)
);
add_action
(
'save_post'
,
array
(
$this
,
'action_save_post'
)
);
// Bulk actions.
new
WP_Revisions_Control_Bulk_Actions
(
$post_types
);
}
/**
...
...
This diff is collapsed.
Click to expand it.
wp-revisions-control.php
+
1
−
0
View file @
eb221dd6
...
...
@@ -30,4 +30,5 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
require_once
__DIR__
.
'/inc/class-wp-revisions-control-bulk-actions.php'
;
require_once
__DIR__
.
'/inc/class-wp-revisions-control.php'
;
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