Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update delete method to user callback function
  • Loading branch information
ernilambar committed Apr 26, 2024
commit e3bfbbc79346028633b5ff160382636a384b416c
27 changes: 20 additions & 7 deletions src/Signup_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,12 @@ public function activate( $args, $assoc_args ) {
}

/**
* Deletes a signup.
* Deletes one or more signups.
*
* ## OPTIONS
*
* <signup>
* : Signup ID, user login, user email, or activation key.
* <signup>...
* : Signup ID, user login, user email, or activation key of the signup(s) to delete.
Comment thread
ernilambar marked this conversation as resolved.
Outdated
*
* ## EXAMPLES
*
Expand All @@ -244,16 +244,29 @@ public function activate( $args, $assoc_args ) {
* @package wp-cli
*/
public function delete( $args, $assoc_args ) {
Comment thread
ernilambar marked this conversation as resolved.
$signups = $this->fetcher->get_many( $args );

parent::_delete( $signups, $assoc_args, [ $this, 'delete_callback' ] );
}

/**
* Callback used to delete a signup.
*
* @param $signup
* @param $assoc_args
* @return array
*/
protected function delete_callback( $signup, $assoc_args ) {
global $wpdb;

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

$result = $wpdb->delete( $wpdb->signups, array( 'signup_id' => $signup->signup_id ), array( '%d' ) );
$result = $wpdb->delete( $wpdb->signups, array( 'signup_id' => $signup_id ), array( '%d' ) );
Comment thread
danielbachhuber marked this conversation as resolved.

if ( $result ) {
WP_CLI::success( "Signup {$signup->signup_id} deleted." );
return [ 'success', "Signup {$signup_id} deleted." ];
} else {
WP_CLI::error( "Failed deleting signup {$signup->signup_id}." );
return [ 'error', "Failed deleting signup {$signup_id}." ];
}
}
}