Skip to content
Open
Changes from 2 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
18 changes: 12 additions & 6 deletions php/class-wp-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,30 +210,36 @@ public function assign_coauthors( $args, $assoc_args ) {
* @since 3.0
*
* @subcommand assign-user-to-coauthor
* @synopsis --user_login=<user-login> --coauthor=<coauthor>
* @synopsis --user_login=<user-login> --user_id=<user-id> --coauthor=<coauthor>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not at all sure how to specify that one of user_login or user_id is required. Anyone else?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In git's man pages, parentheses and pipes are used to indicate that a subcommand accepts one and only one of a selection of flags (see the last line):

SYNOPSIS
       git rebase [-i | --interactive] [<options>] [--exec <cmd>] [--onto <newbase>]
               [<upstream> [<branch>]]
       git rebase [-i | --interactive] [<options>] [--exec <cmd>] [--onto <newbase>]
               --root [<branch>]
       git rebase (--continue | --skip | --abort | --quit | --edit-todo | --show-current-patch)

So this line could be rewritten as:

	 * @synopsis ( --user_login=<user-login> | --user_id=<user-id> ) --coauthor=<coauthor>

*/
public function assign_user_to_coauthor( $args, $assoc_args ) {
global $coauthors_plus, $wpdb;

$defaults = array(
'user_login' => '',
'user_login' => NULL,
'user_id' => NULL,
'coauthor' => '',
);
$assoc_args = wp_parse_args( $assoc_args, $defaults );

$user = get_user_by( 'login', $assoc_args['user_login'] );
$user_id = $assoc_args['user_id'];
if ( $assoc_args['user_login'] ) {
$user = get_user_by( 'login', $assoc_args['user_login'] );
$user_id = $user->ID;
}

$coauthor = $coauthors_plus->get_coauthor_by( 'login', $assoc_args['coauthor'] );

if ( ! $user ) {
WP_CLI::error( __( 'Please specify a valid user_login', 'co-authors-plus' ) );
if ( ! $user_id ) {
WP_CLI::error( __( 'Please specify a valid user_login or user_id', 'co-authors-plus' ) );
}

if ( ! $coauthor ) {
WP_CLI::error( __( 'Please specify a valid co-author login', 'co-authors-plus' ) );
}

$post_types = implode( "','", $coauthors_plus->supported_post_types );
$posts = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author=%d AND post_type IN ('$post_types')", $user->ID ) );
$posts = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author=%d AND post_type IN ('$post_types')", $user_id ) );
$affected = 0;
foreach ( $posts as $post_id ) {
$coauthors = cap_get_coauthor_terms_for_post( $post_id );
Expand Down