开发者

Import users into WordPress remotely and securely

开发者 https://www.devze.com 2023-02-03 11:58 出处:网络
I am in a process of doing a single sign-on in Wordpress, but in the meantime I need to be able to import users in Wordpress by using some sort of REST API. It looks like there isn\'t anything like th

I am in a process of doing a single sign-on in Wordpress, but in the meantime I need to be able to import users in Wordpress by using some sort of REST API. It looks like there isn't anything like this at this time, so I 开发者_JAVA技巧was wondering what is my best approach to do this?

I need to be able to send some info trough JSON, GET or POST, so the new account will be created with some of the user info pre-filled (mostly meta data).

This is what I have so far:

<?php

require_once('./wp-load.php');
require_once('./wp-includes/registration.php');

if($_REQUEST['user'] && $_REQUEST['email'])
{
    $user_data['user_login'] = $_REQUEST['user'];
    $user_data['user_pass'] = $random_password;
    $user_data['user_email'] = $_REQUEST['email'];

    $new_user = wp_insert_user($user_data);
    if(is_int($new_user))
    {
         update_user_meta( $new_user, 'first_name',strtolower($_REQUEST['first_name']));
         update_user_meta( $new_user, 'last_name',strtolower($_REQUEST['last_name']));
    }
}

?>

Thanks.


Take a look at wp_create_user you could write your own script to accept input and call this function (making sure you don't compromise your own blogs security).

0

精彩评论

暂无评论...
验证码 换一张
取 消