Skip to content
Merged
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
36 changes: 21 additions & 15 deletions includes/cli/class-co-authors-plus.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,26 @@ function( $value ) {
get_post_meta( $guest_author->ID )
);
if ( self::$verbose ) {
WP_CLI::line( sprintf( 'Creating user %s from Guest Author #%d.', $post_meta['cap-display_name'], $guest_author->ID ) );
if ( self::$live ) {
WP_CLI::line( sprintf( 'Creating user %s from Guest Author #%d.', $post_meta['cap-display_name'], $guest_author->ID ) );
} else {
WP_CLI::line( sprintf( 'Would create user %s from Guest Author #%d.', $post_meta['cap-display_name'], $guest_author->ID ) );
}
}

$user_login = $post_meta['cap-user_login'];

$user_data = [
'user_login' => $user_login,
'user_nicename' => $post_meta['cap-user_login'],
'user_url' => $post_meta['cap-website'],
'user_nicename' => isset( $post_meta['cap-user_login'] ) ? $post_meta['cap-user_login'] : '',
'user_url' => isset( $post_meta['cap-website'] ) ? $post_meta['cap-website'] : '',
'user_pass' => wp_generate_password(),
'role' => \Newspack\Co_Authors_Plus::CONTRIBUTOR_NO_EDIT_ROLE_NAME,
'user_email' => $post_meta['cap-user_email'],
'display_name' => $post_meta['cap-display_name'],
'first_name' => $post_meta['cap-first_name'],
'last_name' => $post_meta['cap-last_name'],
'description' => $post_meta['cap-description'],
'user_email' => isset( $post_meta['cap-user_email'] ) ? $post_meta['cap-user_email'] : '',
'display_name' => isset( $post_meta['cap-display_name'] ) ? $post_meta['cap-display_name'] : '',
'first_name' => isset( $post_meta['cap-first_name'] ) ? $post_meta['cap-first_name'] : '',
'last_name' => isset( $post_meta['cap-last_name'] ) ? $post_meta['cap-last_name'] : '',
'description' => isset( $post_meta['cap-description'] ) ? $post_meta['cap-description'] : '',
'user_registered' => $guest_author->post_date,
'meta_input' => [
'_np_migrated_cap_guest_author' => $guest_author->ID,
Expand All @@ -124,7 +128,9 @@ function( $value ) {
}

foreach ( array_values( \Newspack\Authors_Custom_Fields::USER_META_NAMES ) as $meta_key ) {
$user_data['meta_input'][ $meta_key ] = $post_meta[ 'cap-' . $meta_key ];
if ( isset( $post_meta[ 'cap-' . $meta_key ] ) ) {
$user_data['meta_input'][ $meta_key ] = $post_meta[ 'cap-' . $meta_key ];
}
}
if ( self::$live ) {
$user_id = \wp_insert_user( $user_data );
Expand Down Expand Up @@ -161,7 +167,7 @@ private static function migrate_linked_guest_authors() {
],
]
);
WP_CLI::line( sprintf( 'Found %d guest author(s) linked to a WP User.', count( $linked_guest_authors ) ) );
WP_CLI::line( sprintf( 'Found %d guest author(s) linked to WP Users.', count( $linked_guest_authors ) ) );
foreach ( $linked_guest_authors as $guest_author ) {
WP_CLI::line( '' );
$linked_user_slug = get_post_meta( $guest_author->ID, 'cap-linked_account', true );
Expand Down Expand Up @@ -201,7 +207,7 @@ private static function migrate_linked_guest_authors() {
if ( $result === true ) {
WP_CLI::success( 'Deleted the guest author and reassigned the posts.' );
} else {
WP_CLI::warning( 'Could not delete the guest author and reassign the posts: ' . $result->get_error_message() );
WP_CLI::warning( sprintf( 'Could not delete the guest author and reassign the posts: %s', $result->get_error_message() ) );
}
} else {
// Otherwise, only delete the Guest Author post and cache, leaving the term intact.
Expand All @@ -219,9 +225,9 @@ private static function migrate_linked_guest_authors() {
]
);
if ( is_wp_error( $result ) ) {
WP_CLI::warning( 'Could not update the WP User CAP term: ' . $result->get_error_message() );
WP_CLI::warning( sprintf( 'Could not update the WP User CAP term: %s', $result->get_error_message() ) );
} else {
WP_CLI::success( sprintf( 'Updated the WP User CAP term %d.', $result['term_id'] ) );
WP_CLI::success( sprintf( 'Updated the WP User CAP term: %d.', $result['term_id'] ) );
}
}
}
Expand All @@ -242,7 +248,7 @@ private static function delete_guest_author_post( $guest_author_id ) {
$result = wp_delete_post( $guest_author_id, true );
$coauthors_plus->guest_authors->delete_guest_author_cache( $guest_author_object );
if ( ! $result ) {
WP_CLI::warning( 'Could not delete the guest author post: ' . $result->get_error_message() );
WP_CLI::warning( sprintf( 'Could not delete the guest author post: %s', $result->get_error_message() ) );
} else {
WP_CLI::success( sprintf( 'Deleted the guest author post (#%d).', $guest_author_id ) );
}
Expand Down Expand Up @@ -371,7 +377,7 @@ private static function assign_user_avatar( $guest_author, $user_id ) {
$avatar_id = media_sideload_image( $guest_author_featured_image_url, 0, null, 'id' );

if ( is_wp_error( $avatar_id ) ) {
WP_CLI::warning( 'Error sideloading avatar: ' . $avatar_id->get_error_message() );
WP_CLI::warning( sprintf( 'Error sideloading avatar: %s', $avatar_id->get_error_message() ) );
return false;
}
if ( is_int( $avatar_id ) ) {
Expand Down