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
78130edb
Commit
78130edb
authored
May 26, 2019
by
Erick Hitter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Admin notices for bulk actions
parent
6060b5e5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
87 additions
and
4 deletions
+87
-4
inc/class-wp-revisions-control-bulk-actions.php
inc/class-wp-revisions-control-bulk-actions.php
+87
-4
No files found.
inc/class-wp-revisions-control-bulk-actions.php
View file @
78130edb
...
...
@@ -44,6 +44,7 @@ class WP_Revisions_Control_Bulk_Actions {
$this
->
register_actions
();
add_action
(
'load-edit.php'
,
array
(
$this
,
'setup'
)
);
add_filter
(
'removable_query_args'
,
array
(
$this
,
'remove_message_query_args'
)
);
}
/**
...
...
@@ -80,7 +81,29 @@ 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.
add_action
(
'admin_notices'
,
array
(
$this
,
'admin_notices'
)
);
}
/**
* Remove message query arguments to prevent re-display.
*
* @param array $args Array of query variables to remove from URL.
* @return array
*/
public
function
remove_message_query_args
(
$args
)
{
return
array_merge
(
$args
,
$this
->
get_message_query_args
()
);
}
/**
* Return array of supported query args that trigger admin notices.
*
* @return array
*/
protected
function
get_message_query_args
()
{
$args
=
array_keys
(
$this
->
actions
);
$args
[]
=
$this
->
action_base
.
'missing'
;
return
$args
;
}
/**
...
...
@@ -106,9 +129,11 @@ class WP_Revisions_Control_Bulk_Actions {
return
$redirect_to
;
}
$action
=
str_replace
(
$this
->
action_base
,
''
,
$action
);
$response
=
array
(
$action
=>
1
,
);
switch
(
$action
)
{
switch
(
str_replace
(
$this
->
action_base
,
''
,
$action
)
)
{
case
'purge_all'
:
$this
->
purge_all
(
$ids
);
break
;
...
...
@@ -118,10 +143,16 @@ class WP_Revisions_Control_Bulk_Actions {
break
;
default
:
$response
=
array
(
$this
->
action_base
.
'missing'
=>
1
,
);
break
;
}
// TODO: implement and add a query string to trigger a message.
if
(
is_array
(
$response
)
)
{
$redirect_to
=
add_query_arg
(
$response
,
$redirect_to
);
}
return
$redirect_to
;
}
...
...
@@ -146,4 +177,56 @@ class WP_Revisions_Control_Bulk_Actions {
WP_Revisions_Control
::
get_instance
()
->
do_purge_excess
(
$id
);
}
}
/**
* Render admin notices.
*/
public
function
admin_notices
()
{
$message
=
null
;
foreach
(
$this
->
get_message_query_args
()
as
$arg
)
{
// phpcs:ignore WordPress.Security.NonceVerification.NoNonceVerification
if
(
isset
(
$_GET
[
$arg
]
)
)
{
$message
=
$arg
;
break
;
}
}
if
(
null
===
$message
)
{
return
;
}
$type
=
'updated'
;
switch
(
str_replace
(
$this
->
action_base
,
''
,
$message
)
)
{
case
'purge_all'
:
$message
=
__
(
'Purged all revisions.'
,
'wp_revisions_control'
);
break
;
case
'purge_excess'
:
$message
=
__
(
'Purged excess revisions.'
,
'wp_revisions_control'
);
break
;
default
:
case
'missing'
:
$message
=
__
(
'WP Revisions Control encountered an unspecified error.'
,
'wp_revisions_control'
);
$type
=
'error'
;
break
;
}
?>
<div
class=
"notice is-dismissible
<?php
echo
esc_attr
(
$type
);
?>
"
>
<p>
<?php
echo
esc_html
(
$message
);
?>
</p>
</div>
<?php
}
}
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