Skip to content

Commit

Permalink
Notification: wp bp notification delete command
Browse files Browse the repository at this point in the history
  • Loading branch information
renatonascalves committed Aug 2, 2018
1 parent bda2842 commit 3cf3973
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
45 changes: 44 additions & 1 deletion components/notification.php
Expand Up @@ -111,8 +111,11 @@ public function create( $args, $assoc_args ) {
* default: table
* options:
* - table
* - csv
* - ids
* - json
* - haml
* - count
* - yaml
* ---
*
* ## EXAMPLES
Expand Down Expand Up @@ -142,4 +145,44 @@ public function get( $args, $assoc_args ) {
$formatter = $this->get_formatter( $assoc_args );
$formatter->display_item( $notification_arr );
}

/**
* Delete a notification.
*
* ## OPTIONS
*
* <notification-id>...
* : ID or IDs of notification.
*
* [--yes]
* : Answer yes to the confirmation message.
*
* ## EXAMPLES
*
* $ wp bp notification delete 520
* Success: Notification deleted.
*
* $ wp bp notification delete 55654 54564 --yes
* Success: Notification deleted.
*/
public function delete( $args, $assoc_args ) {
$notification_id = $args[0];

WP_CLI::confirm( 'Are you sure you want to delete this notification?', $assoc_args );

parent::_delete( array( $notification_id ), $assoc_args, function( $notification_id ) {

$notification = bp_notifications_get_notification( $notification_id );

if ( empty( $notification->id ) ) {
WP_CLI::error( 'No notification found by that ID.' );
}

if ( BP_Notifications_Notification::delete( array( 'id' => $notification_id ) ) ) {
return array( 'success', 'Notification deleted.' );
} else {
return array( 'error', 'Could not delete notification.' );
}
} );
}
}
6 changes: 6 additions & 0 deletions features/notification.feature
Expand Up @@ -10,3 +10,9 @@ Feature: Manage BuddyPress Notifications
When I run `wp bp notification create --component=groups --user-id={MEMBER_ID} --porcelain`
Then STDOUT should be a number
And save STDOUT as {NOTIFICATION_ID}

When I run `wp bp notification delete {NOTIFICATION_ID} --yes`
Then STDOUT should contain:
"""
Success: Notification deleted.
"""

0 comments on commit 3cf3973

Please sign in to comment.