Skip to content
Open
Changes from all commits
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
22 changes: 22 additions & 0 deletions php/class-wp-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class CoAuthorsPlus_Command extends WP_CLI_Command {
public function create_guest_authors( $args, $assoc_args ): void {
global $coauthors_plus;

$this->verify_guest_authors_or_die();

$defaults = array(
// There are no arguments at this time
);
Expand Down Expand Up @@ -576,6 +578,8 @@ public function reassign_terms( $args, $assoc_args ): void {
public function rename_coauthor( $args, $assoc_args ): void {
global $coauthors_plus, $wpdb;

$this->verify_guest_authors_or_die();

$defaults = array(
'from' => null,
'to' => null,
Expand Down Expand Up @@ -830,6 +834,9 @@ public function migrate_author_terms( $args, $assoc_args ): void {
*/
public function update_author_terms(): void {
global $coauthors_plus;

$this->verify_guest_authors_or_die();

$author_terms = get_terms( $coauthors_plus->coauthor_taxonomy, array( 'hide_empty' => false ) );
WP_CLI::log( 'Now updating ' . count( $author_terms ) . ' terms' );
foreach ( $author_terms as $author_term ) {
Expand Down Expand Up @@ -1082,6 +1089,9 @@ public function create_guest_authors_from_csv( $args, $assoc_args ): void {
*/
private function create_guest_author( $author ): void {
global $coauthors_plus;

$this->verify_guest_authors_or_die();

$guest_author = $coauthors_plus->guest_authors->get_guest_author_by( 'user_email', $author['user_email'], true );

if ( ! $guest_author ) {
Expand Down Expand Up @@ -1316,4 +1326,16 @@ private function skip_backfill_for_post( $post_id, $reason ) {
private function get_formatted_complete_percentage( $completed, $total ) {
return number_format( ( $completed / $total ) * 100, 2 ) . '%';
}

/**
* Verify Guest Authors is enabled and instantiated, otherwise print error and die.
*
* @return void
*/
private function verify_guest_authors_or_die(): void {
global $coauthors_plus;
if ( ! $coauthors_plus->is_guest_authors_enabled() || ! $coauthors_plus->guest_authors instanceof CoAuthors_Guest_Authors ) {
WP_CLI::error( __( 'Guest Authors needs to be enabled and instantiated to run this command.', 'co-authors-plus' ) );
}
}
}