mirror of
https://gh.llkk.cc/https://github.com/Tetrakern/fictioneer-email-notifications.git
synced 2025-10-03 18:11:01 +08:00
Add table action to remove all sent notifications
This commit is contained in:
parent
a7029de79d
commit
c28cbae00f
2 changed files with 38 additions and 0 deletions
|
@ -626,6 +626,14 @@ function fcnen_admin_notices() {
|
|||
$notice = sprintf( __( 'Error. Could not mark notification for "%s" (#%s) as unsent.', 'fcnen' ), $post_title, $maybe_id );
|
||||
$type = 'error';
|
||||
break;
|
||||
case 'remove-sent-notification-success':
|
||||
$notice = __( 'Deleted sent notifications.', 'fcnen' );
|
||||
$type = 'success';
|
||||
break;
|
||||
case 'remove-sent-notification-failure':
|
||||
$notice = __( 'Error. Could not delete sent notifications.', 'fcnen' );
|
||||
$type = 'error';
|
||||
break;
|
||||
case 'bulk-delete-notifications-success':
|
||||
$notice = sprintf( __( 'Deleted %s notifications.', 'fcnen' ), $message ?: '0' );
|
||||
$type = 'success';
|
||||
|
|
|
@ -596,6 +596,26 @@ class FCNEN_Notifications_Table extends WP_List_Table {
|
|||
*/
|
||||
|
||||
function extra_tablenav( $which ) {
|
||||
if ( $this->total_items > 0 ) {
|
||||
// Start HTML ---> ?>
|
||||
<div class="alignleft actions">
|
||||
<?php
|
||||
printf(
|
||||
'<a href="%s" class="button action">%s</a>',
|
||||
wp_nonce_url(
|
||||
add_query_arg(
|
||||
array( 'action' => 'remove_sent' ),
|
||||
remove_query_arg( ['paged'], $this->uri )
|
||||
),
|
||||
'fcnen-table-action',
|
||||
'fcnen-nonce'
|
||||
),
|
||||
__( 'Remove Sent', 'fcnen' )
|
||||
);
|
||||
?>
|
||||
</div>
|
||||
<?php // <--- End HTML
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -698,6 +718,16 @@ class FCNEN_Notifications_Table extends WP_List_Table {
|
|||
$post = get_post( $post_id );
|
||||
$title = empty( $post ) ? __( 'UNAVAILABLE', 'fcnen' ) : $post->post_title;
|
||||
|
||||
// Remove sent notifications
|
||||
if ( $_GET['action'] === 'remove_sent' ) {
|
||||
if ( $wpdb->query( $wpdb->prepare( "DELETE FROM $table_name WHERE last_sent IS NOT NULL" ) ) ) {
|
||||
$query_args['fcnen-notice'] = 'remove-sent-notification-success';
|
||||
fcnen_log( 'Removed sent notification.' );
|
||||
} else {
|
||||
$query_args['fcnen-notice'] = 'remove-sent-notification-failure';
|
||||
}
|
||||
}
|
||||
|
||||
// Abort if...
|
||||
if ( empty( $post_id ) ) {
|
||||
wp_safe_redirect( add_query_arg( $query_args, $this->uri ) );
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue