在functions.php中加载插件类
我正在使用在functions.php中加载插件类,php,wordpress,Php,Wordpress,我正在使用WordPress4.9.8和PHP7.1.8我想从我的类中加载一个函数 插件类位于以下目录下: C:\Users\admin\Desktop\wordpress\wp content\plugins\content creator\includes\SinglePostContent.php 我的function.php文件包含以下文件夹: C:\Users\admin\Desktop\wordpress\wp content\themes\rehub blankchild\func
WordPress4.9.8
和PHP7.1.8
我想从我的类中加载一个函数
插件类位于以下目录下:
C:\Users\admin\Desktop\wordpress\wp content\plugins\content creator\includes\SinglePostContent.php
我的function.php
文件包含以下文件夹:
C:\Users\admin\Desktop\wordpress\wp content\themes\rehub blankchild\functions.php
我要加载的函数如下所示:
class SinglePostContent
{
public function __construct()
{
//...
}
public function main($postID)
{
//...
}
我试着使用
add_action('wp_ajax_updateContent', 'updateContent');
function updateContent()
{
$post_id = intval($_POST['post_id']);
try {
SinglePostContent::main($post_id); // HERE I get the error!
} catch (Exception $e) {
echo $e;
}
wp_die();
}
任何关于如何在my
function.php中加载类SinglePostContent
的建议,您都是以静态方式访问该方法,而不是以静态方式访问。您需要实例化该类,然后按如下方式调用该方法:
add_action('wp_ajax_updateContent', 'updateContent');
function updateContent(){
$post_id = 1;
$single_post_content = new SinglePostContent;
try {
$single_post_content->main( $post_id );
} catch ( Exception $e ) {
echo $e;
}
wp_die();
}
SinglePostContent
是否存在于您未引用的特定命名空间中?