wordpress实时站点:将他们纳入班级工作 [英] wordpress live site : include them class in a cron job
问题描述
从wordpress之外的主题目录导入一个类。
import a class from theme directory outside of wordpress.
CRON
我正在通过Cpanel进行日常工作,我的网站将提供统计信息表。我在根目录Home / myDirectory中创建了一个文件(与public_html相同级别),但代码是
The CRON I am cronning a daily job via Cpanel for my site that will feed a stats table. I created a file in the root Home/myDirectory (same level as public_html ) beloo is the code
<?php
include dirname(__FILE__) . '/public_html/wp-load.php'; // Load WP Functions
include dirname(__FILE__) . '/public_html/wp-content/themes/cooking/config/Data/ViewsData.php'; // require a class
function test(){
if(class_exists('ViewsData')){
$viewsData = new ViewsData;
$views= $viewsData::getViews(394);
update_post_meta(394 , 'views_test', $views);
}
die();
}
test();
班级
如代码中所示,我试图从主题文件夹中添加一个类。此类包含用于设置,获取和更新视图数据的不同函数>下面是对类结构的构想;
as shown in the code I am trying to include a class from the theme folder. this class include different functionaries to set , get and update the views data> bellow is an idea of how the class is structured ;
namespace GS\Data;
use GS\DisplayFunc;
class ViewsData {
static function getViews(){}
}
但是 class_exists('ViewsData')
始终返回false。
however class_exists('ViewsData')
always return false.
关于错误的任何建议。甚至是如何重组整个cron解决方案。最重要的是,我需要使用主题文件夹中的许多类。
any suggestions on what is wrong. or even on how to reorganize the whole cron solution. the most important is that I need to use many classes from my theme folder.
推荐答案
我能够找到问题所在。它与命名空间有关,下面是这样的代码:
I was able to find the problem. it has to do with namespaces the code that works bellow :
<?php
include dirname(__FILE__) . '/public_html/wp-load.php'; // Load WP Functions
include dirname(__FILE__) . '/public_html/wp-content/themes/cooking/config/Data/ViewsData.php'; // require a class
function test(){
if(class_exists('GS\Data\ViewsData')){
$viewsData = new ViewsData;
$views= $viewsData::getViews(394);
update_post_meta(394 , 'views_test', $views);
}
die();
}
test();
这篇关于wordpress实时站点:将他们纳入班级工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!