First time working with WordPress
and looking to build a plugin.
In the plugin I create a user to which I want to create a named application password.
Is there a way to programmatically create this password? I cannot find an example of this.
I create my user like this within the WordPress plugin:
// create the user
$user_id = wp_create_user(
$this->plugin_wp_user_name,
$this->plugin_wp_password_transient,
$this->plugin_wp_user_email
);
$user = get_user_by('id', $user_id);
$user_id = wp_update_user( array(
'ID' => $user_id,
'first_name' => 'API',
'last_name' => 'User',
'display_name' => 'API User',
'description' => 'This user belongs to the App API. Please do not delete.',
'user_url' => $this->plugin_owner_url,
) );
2
Answers
I found it is the WordPress docs.
The password is then retrieved from
$app_password[0]
You can use the
[WP_Application_Passwords::create_new_application_password( int $user_id, array $args = array() )][1]
.Example code:
Return
(array|WP_Error) The first key in the array is the new password, the second is its detailed information. A WP_Error instance is returned on error.