Open TheCrowned opened 6 years ago
Right now I am using this WP_CLI command to clear the database from all non-necessary CAP entries. Useful for testing, it basically reverts wp co-authors-plus create-guest-authors
and wp co-authors-plus create-terms-for-posts
. Nor sure we want it in the repo code though.
/**
* Subcommand to delete guest authors based on users.
*
* @subcommand delete-linked-guest-authors
*/
public function delete_linked_guest_authors( $args, $assoc_args ) {
global $coauthors_plus;
WP_CLI::confirm( 'Are you sure you want to delete author terms for all users having a linked account? This includes posts and author terms.' );
$defaults = array(
// There are no arguments at this time
);
$this->args = wp_parse_args( $assoc_args, $defaults );
$users = get_users();
$created = 0;
$skipped = 0;
$progress = \WP_CLI\Utils\make_progress_bar( 'Processing guest authors...', count ( $users ) );
foreach ( $users as $user ) {
$guest_author = $coauthors_plus->guest_authors->get_guest_author_by( 'linked_account', $user->data->user_login );
if ( ! empty( $guest_author ) ) {
$coauthors_plus->guest_authors->delete( $guest_author->ID );
}
$progress->tick();
}
$progress->finish();
WP_CLI::success( sprintf( 'All done! Processed %d users.', count( $users ) ) );
}
Right now, the plugin does not uninstall itself at all. We may want to create a
uninstall.php
file that removes all plugin records from database to avoid leaving it cluttered with potentially unwanted data.