【发布时间】:2020-02-19 18:00:12
【问题描述】:
我基本上是 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 数据库中。
【问题讨论】:
标签: php wordpress wordpress-theming custom-wordpress-pages wordpress-rest-api