我想为一个wordpress网站创建移动应用程序。我已经集成了wordpress json plugin。我不知道在哪里可以找到用户注册和登录的服务。敬请指教。
发布于 2017-08-06 20:08:22
1.将以下代码粘贴到主题function.php文件中。
2.确保在wordpress站点上安装了WP-REST-API插件
add_action( 'rest_api_init', 'register_api_hooks' );
function register_api_hooks() {
register_rest_route(
'custom-plugin', '/login/',
array(
'methods' => 'POST',
'callback' => 'login',
)
);
}
function login($request){
$creds = array();
$creds['user_login'] = $request["username"];
$creds['user_password'] = $request["password"];
$creds['remember'] = true;
$user = wp_signon( $creds, false );
if ( is_wp_error($user) )
echo $user->get_error_message();
return $user;
}
add_action( 'after_setup_theme', 'custom_login' );然后,您的API将创建为
http://www.url.com/wp-json/custom-plugin/login尝试使用Postman,您将得到200作为响应和user info
https://stackoverflow.com/questions/13679001
复制相似问题