Skip to content

Commit aca6758

Browse files
committed
Make string generation for consistent
1 parent 8409289 commit aca6758

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

src/Capabilities_Command.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function list_( $args, $assoc_args ) {
8686
$output_cap = new stdClass();
8787

8888
$output_cap->name = $cap;
89-
$output_cap->grant = ( $grant ) ? 'true' : 'false';
89+
$output_cap->grant = $grant ? 'true' : 'false';
9090

9191
$output_caps[] = $output_cap;
9292
}
@@ -156,12 +156,10 @@ public function add( $args, $assoc_args ) {
156156
$count++;
157157
}
158158

159-
if ( $grant ) {
160-
$message = ( 1 === $count ) ? "Added %d capability to '%s' role." : "Added %d capabilities to '%s' role.";
161-
} else {
162-
$message = ( 1 === $count ) ? "Added %d capability to '%s' role as false." : "Added %d capabilities to '%s' role as false.";
163-
}
164-
WP_CLI::success( sprintf( $message, $count, $role ) );
159+
$capability = WP_CLI\Utils\pluralize( 'capability', $count );
160+
$grant_qualification = $grant ? '' : ' as false';
161+
162+
WP_CLI::success( "Added {$count} {$capability} to '{$role}' role{$grant_qualification}." );
165163
}
166164

167165
/**
@@ -200,8 +198,9 @@ public function remove( $args ) {
200198
$count++;
201199
}
202200

203-
$message = ( 1 === $count ) ? "Removed %d capability from '%s' role." : "Removed %d capabilities from '%s' role.";
204-
WP_CLI::success( sprintf( $message, $count, $role ) );
201+
$capability = WP_CLI\Utils\pluralize( 'capability', $count );
202+
203+
WP_CLI::success( "Removed {$count} {$capability} from '{$role}' role." );
205204
}
206205

207206
/**

src/Role_Command.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,9 @@ public function create( $args, $assoc_args ) {
192192
foreach ( $capabilities as $cap ) {
193193
$role_obj->add_cap( $cap );
194194
}
195-
WP_CLI::success( sprintf( "Role with key '%s' created. Cloned capabilities from '%s'.", $role_key, $assoc_args['clone'] ) );
195+
WP_CLI::success( "Role with key '{$role_key}' created. Cloned capabilities from '{$assoc_args['clone']}'." );
196196
} else {
197-
WP_CLI::success( sprintf( "Role with key '%s' created.", $role_key ) );
197+
WP_CLI::success( "Role with key '{$role_key}' created." );
198198
}
199199
} else {
200200
WP_CLI::error( "Role couldn't be created." );
@@ -235,9 +235,9 @@ public function delete( $args ) {
235235
// Note: remove_role() doesn't indicate success or otherwise, so we have to
236236
// check ourselves
237237
if ( ! isset( $wp_roles->roles[ $role_key ] ) ) {
238-
WP_CLI::success( sprintf( "Role with key '%s' deleted.", $role_key ) );
238+
WP_CLI::success( "Role with key '{$role_key}' deleted." );
239239
} else {
240-
WP_CLI::error( sprintf( "Role with key '%s' could not be deleted.", $role_key ) );
240+
WP_CLI::error( "Role with key '{$role_key}' could not be deleted." );
241241
}
242242

243243
}

0 commit comments

Comments
 (0)