Skip to content

Commit c484b34

Browse files
Merge pull request #97 from buddypress/feature/messages
Messages: improvements to the `generate` command
2 parents 4effecc + 8c691c6 commit c484b34

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/messages.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function create( $args, $assoc_args ) {
102102
}
103103

104104
// Existing thread recipients will be assumed.
105-
$recipient = ( ! empty( $r['thread-id'] ) ) ? array() : array( $recipient->ID );
105+
$recipient = ! empty( $r['thread-id'] ) ? array() : array( $recipient->ID );
106106

107107
$thread_id = messages_new_message(
108108
array(
@@ -312,6 +312,13 @@ public function list_( $args, $assoc_args ) { // phpcs:ignore PSR2.Methods.Metho
312312
*
313313
* ## OPTIONS
314314
*
315+
* [--from=<user>]
316+
* : Identifier for the user. Accepts either a user_login or a numeric ID.
317+
*
318+
* [--to=<user>]
319+
* : Identifier for the recipient. To is not required when thread id is set.
320+
* Accepts either a user_login or a numeric ID.
321+
*
315322
* [--thread-id=<thread-id>]
316323
* : Thread ID to generate messages against.
317324
* ---
@@ -326,6 +333,7 @@ public function list_( $args, $assoc_args ) { // phpcs:ignore PSR2.Methods.Metho
326333
*
327334
* ## EXAMPLES
328335
*
336+
* $ wp bp message generate --from=1 --to=2 --thread-id=6465 --count=30
329337
* $ wp bp message generate --thread-id=6465 --count=10
330338
* $ wp bp message generate --count=100
331339
*/
@@ -336,10 +344,11 @@ public function generate( $args, $assoc_args ) {
336344
$this->create(
337345
array(),
338346
array(
339-
'from' => $this->get_random_user_id(),
340-
'to' => $this->get_random_user_id(),
347+
'from' => empty( $assoc_args['from'] ) ? $this->get_random_user_id() : $assoc_args['from'],
348+
'to' => empty( $assoc_args['to'] ) ? $this->get_random_user_id() : $assoc_args['to'],
341349
'subject' => sprintf( 'Message Subject - #%d', $i ),
342-
'thread-id' => $assoc_args['thread-id'],
350+
'content' => $this->generate_random_text(),
351+
'thread-id' => empty( $assoc_args['thread-id'] ) ? false : $assoc_args['thread-id'],
343352
'silent',
344353
)
345354
);

0 commit comments

Comments
 (0)