Skip to content

Commit e3bfbbc

Browse files
committed
Update delete method to user callback function
1 parent 5aee1c4 commit e3bfbbc

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

src/Signup_Command.php

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,12 @@ public function activate( $args, $assoc_args ) {
228228
}
229229

230230
/**
231-
* Deletes a signup.
231+
* Deletes one or more signups.
232232
*
233233
* ## OPTIONS
234234
*
235-
* <signup>
236-
* : Signup ID, user login, user email, or activation key.
235+
* <signup>...
236+
* : Signup ID, user login, user email, or activation key of the signup(s) to delete.
237237
*
238238
* ## EXAMPLES
239239
*
@@ -244,16 +244,29 @@ public function activate( $args, $assoc_args ) {
244244
* @package wp-cli
245245
*/
246246
public function delete( $args, $assoc_args ) {
247+
$signups = $this->fetcher->get_many( $args );
248+
249+
parent::_delete( $signups, $assoc_args, [ $this, 'delete_callback' ] );
250+
}
251+
252+
/**
253+
* Callback used to delete a signup.
254+
*
255+
* @param $signup
256+
* @param $assoc_args
257+
* @return array
258+
*/
259+
protected function delete_callback( $signup, $assoc_args ) {
247260
global $wpdb;
248261

249-
$signup = $this->fetcher->get_check( $args[0] );
262+
$signup_id = $signup->signup_id;
250263

251-
$result = $wpdb->delete( $wpdb->signups, array( 'signup_id' => $signup->signup_id ), array( '%d' ) );
264+
$result = $wpdb->delete( $wpdb->signups, array( 'signup_id' => $signup_id ), array( '%d' ) );
252265

253266
if ( $result ) {
254-
WP_CLI::success( "Signup {$signup->signup_id} deleted." );
267+
return [ 'success', "Signup {$signup_id} deleted." ];
255268
} else {
256-
WP_CLI::error( "Failed deleting signup {$signup->signup_id}." );
269+
return [ 'error', "Failed deleting signup {$signup_id}." ];
257270
}
258271
}
259272
}

0 commit comments

Comments
 (0)