Skip to content

wp user create with no --user_registered arg creates users with invalid registration date #377

Closed
@jorgeatorres

Description

Bug Report

Describe the current, buggy behavior

(Discovered in woocommerce/woocommerce#34894).

When creating users via wp user create and not specifying a value for the optional field --user_registered, the user ends up with "0000-00-00 00:00:00" as the value of the user_registered column in the database (i.e. the default value for this column in the wp_users table).

According to the docs, this field should default to the current date/time:

* [--user_registered=<yyyy-mm-dd-hh-ii-ss>]
* : The date the user registered. Default: current date.

This relates to commit a6acb64, in which the default value for user_registered was set to the result of a date_format() call instead of the previous strftime() call, without changing the placeholders in the format string ('%F %T'):

  • In strftime() %F %T produced the correct result because %F is the same as %Y-%m-%d and %T is a shorthand for %H:%M:%S.
  • In date_format() not only the % symbol is not used, but F is the full textual representation of a month and T the timezone abbreviation. This means users are being created with user_registered set to something like "%September %UTC", which is incorrect.

Describe how other contributors can replicate this bug

  • Run wp user create testuser testuser@example.com.
  • Check that wp user get testuser shows 0000-00-00 00:00:00 as the value for the user_registered field.

Describe what you would expect as the correct outcome

Per the docs, the user should've been created with the current date/time as user_registered.

Let us know what environment you are running this on

OS:	Darwin 21.6.0 Darwin Kernel Version 21.6.0: Mon Aug 22 20:19:52 PDT 2022; root:xnu-8020.140.49~2/RELEASE_ARM64_T6000 arm64
Shell:	/bin/zsh
PHP binary:	/opt/homebrew/bin/php
PHP version:	8.1.11
php.ini used:	/opt/homebrew/etc/php/8.1/php.ini
MySQL binary:	/opt/homebrew/bin/mysql
MySQL version:	mysql  Ver 14.14 Distrib 5.7.39, for osx10.17 (x86_64) using  EditLine wrapper
SQL modes:	
WP-CLI root dir:	/Users/jorge/src/wpcli-entity-command/vendor/wp-cli/wp-cli
WP-CLI vendor dir:	/Users/jorge/src/wpcli-entity-command/vendor
WP_CLI phar path:	
WP-CLI packages dir:	
WP-CLI global config:	
WP-CLI project config:	/Users/jorge/src/wpcli-entity-command/wp-cli.yml
WP-CLI version:	2.6.0

Provide a possible solution

Use the proper placeholders in the date $format string in date_format() or rely on current_time( 'mysql', true ) which already produces a string in the desired format.

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions