Skip to content

Commit b83abb9

Browse files
committed
Set comment_post_ID to 0 if not set; revert message check change in import-csv.
1 parent 3caa401 commit b83abb9

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

features/user-import-csv.feature

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ Feature: Import users from CSV
5252
"""
5353

5454
When I try `wp user import-csv user-invalid.csv`
55-
Then STDERR should be:
55+
# Message changed from "Only lowercase..." to "Usernames can contain only lowercase..." in `wpmu_validate_user_signup()` WP 4.4 https://core.trac.wordpress.org/ticket/33336
56+
Then STDERR should contain:
5657
"""
57-
Warning: Usernames can only contain lowercase letters (a-z) and numbers.
58+
lowercase letters (a-z) and numbers
5859
"""
5960
And the return code should be 0
6061

src/Comment_Command.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ public function create( $args, $assoc_args ) {
6969
if ( !$post ) {
7070
return new WP_Error( 'no_post', "Can't find post $post_id." );
7171
}
72+
} else {
73+
// Make sure it's set for older WP versions else get undefined PHP notice.
74+
$params['comment_post_ID'] = 0;
7275
}
7376

7477
// We use wp_insert_comment() instead of wp_new_comment() to stay at a low level and
@@ -163,7 +166,9 @@ public function generate( $args, $assoc_args ) {
163166
$notify = \WP_CLI\Utils\make_progress_bar( 'Generating comments', $assoc_args['count'] );
164167
}
165168

166-
$comment_post_ID = empty( $assoc_args['post_id'] ) ? 1 : $assoc_args['post_id'];
169+
// Make sure comment_post_ID set for older WP versions else get undefined PHP notice.
170+
$comment_post_ID = isset( $assoc_args['post_id'] ) ? $assoc_args['post_id'] : 0;
171+
167172
$comment_count = wp_count_comments();
168173
$total = (int )$comment_count->total_comments;
169174
$limit = $total + $assoc_args['count'];

0 commit comments

Comments
 (0)