You can use Magic Login with REST API for programmatic access to login links or sending login emails directly to the users.
Enable API Access on the Settings Page #
Once you enable REST API, it will register the necessary endpoints.
Authorization #
You will need to use “Basic Auth” as the authorization method, which you can easily set up by creating an application token within your WordPress. The endpoint checks the “edit_user” capability. For example, an admin user can request a login link for any user, while a user with a subscriber role can only request their own login link.
Endpoint #
Example request with cURL:
curl -L 'https://plugindevel.test/wp-json/magic-login/v1/token' \
-H 'Content-Type: application/json' \
-H 'Authorization: Basic YWRtaW46S080SyBxUG4yIFkzdHUgY2NwbSB5MzFkIEVZblY=' \
-d '{
"user": "[email protected]",
"send": true,
"redirect_to": "https://plugindevel.test/my-account/"
}'
Response:
{
"link": "https://plugindevel.test/wp-login.php?user_id=12&token=09544282e92ed3b31980336938e3dc1f61a28f7e&magic-login=1&redirect_to=https%3A%2F%2Fplugindevel.test%2Fmy-account%2F",
"mail_sent": true
}
or error with 422 status code:
{
"code": "missing_user",
"message": "No account matches the given user."
}
Endpoint: https://example.com/wp-json/magic-login/v1/token
Request method: POST
Supported Parameters
user: ID or username or email (Required)
send: boolean (Optional) If set to true, the login email will be sent.
redirect_to: string (Optional) Target URL for the redirection.