如何为Android应用程序创建WordPress REST API

我基本上是android开发人员, 我也使用PHP来为移动应用创建REST API。我正在开发一个Android应用程序, 我想为我的Android应用程序创建WordPress-REST-API, 以通过Android应用程序将用户添加到WordPress wp_user的表中。

为此, 我用PHP创建了REST API, 并使用wp_create_user()方法将用户添加到WordPress数据库中。我将API放置在” wp-content / themes / mytheme”目录中, 但它始终向我显示此错误”调用未定义函数wp_create_user()”, 我认为wp_create_user()函数在我的API中不可用。

我问我的WordPress朋友, 他说, 你必须创建一个自定义页面模板, 并且必须从android应用程序调用该页面, 但这对我来说是不合逻辑的。我该如何解决这个问题?

<?php
if (!isset($_POST['ins_name'])) {
    die("ins_name  is not set");
}

$ins_name = $_POST['ins_name'];

if (!isset($_POST['ins_email'])) {
    die("ins_email is not set");
}

$ins_email = $_POST['ins_email'];

if (!isset($_POST['ins_password'])) {
    die("ins_password  is not set");
}

$ins_password = $_POST['ins_password'];


function addUserIntoWordpressTable($email, $password) {
      $user_id = wp_create_user( $username, $password, $email );
      echo $user_id;
}
addUserIntoWordpressTable($ins_name, $ins_password, $ins_email);

?>

我想通过REST API将用户的数据添加到WordPress数据库中。


#1


WordPress具有自己内置的REST API框架, 你可以在其中使用所有现有功能, 并以干净的方式扩展它, 而不必担心REST样板或做诸如制作REST页面模板之类的丑陋事情。

你可以在这里了解更多信息:https://developer.wordpress.org/rest-api/

来源:

https://www.srcmini02.com/63206.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_37667.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?