如何调用基本的WordPress头文件? [英] How do I call the basic WordPress header files?

查看:62
本文介绍了如何调用基本的WordPress头文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个自定义表单action.php,目前看起来像这样:

I'm making a custom form action.php and currently it looks like this:

<?php
// Collect Data
$first      = $_POST["first_name"];
$last       = $_POST["last_name"];
$email      = $_POST["email"];
$pass       = $_POST["password"];
$pass2      = $_POST["confirm_password"];
$cat        = $_POST["category"];
$tAndC      = $_POST["terms_and_conditions"];
$privacy    = $_POST["privacy_policy"];
$newsletter = $_POST["newsletter"];
die();
?>

基本上什么也没发生-问题是当我想调用WordPress钩子之类的东西时:

Essentially nothing going on - the problem though is when I want to call a WordPress hook such as something like this:

$user_name = $email;
$user_id = username_exists( $user_name );

它返回错误:

严重错误:调用未定义函数username_exists()...

Fatal error: Call to undefined function username_exists()...

我知道可能有些头文件不是我要调用的'undefined function'才能真正运行.

I'm aware that there are probably header files I am not calling for the 'undefined function' to actually run.

我尝试在页面顶部添加: wp_head(); -但出现以下错误:

I have tried adding at the top of the page: wp_head(); - but I get the following error:

致命错误:调用未定义函数wp_head()

Fatal error: Call to undefined function wp_head()

推荐答案

像这样,在您的php脚本文件中包含wp-load.php文件(在wordpress安装的根目录中),

Include wp-load.php file (in the root of your wordpress installation) in your php script file like so,

require_once("/path/to/wordpress/wp-load.php");

您将必须提供wp-load文件的绝对路径,现在您可以在php脚本中使用wordpress的所有功能.

you will have to provide the abspath of the wp-load file, now you can use all the functions of wordpress in your php script.

这篇关于如何调用基本的WordPress头文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆