Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Oop 如何从基于类的wordpress插件访问方法?_Oop_Wordpress - Fatal编程技术网

Oop 如何从基于类的wordpress插件访问方法?

Oop 如何从基于类的wordpress插件访问方法?,oop,wordpress,Oop,Wordpress,我有一个插件,可以注册帖子类型、分类法和处理一些业务逻辑 我继续前进,并使我的完美工作插件面向对象的基础上,现在它只工作了一些时间 其设置如下所示: class Fruit { public function __construct() { add_action('init', array(&$this, 'init')); } public function init() {

我有一个插件,可以注册帖子类型、分类法和处理一些业务逻辑

我继续前进,并使我的完美工作插件面向对象的基础上,现在它只工作了一些时间

其设置如下所示:

    class Fruit {
       public function __construct() {
           add_action('init', array(&$this, 'init'));       
       }

       public function init() { 
           $this->the_apple();
       }


       public function the_apple() {
           return print $apple = 'my apple';
       }
    }

    $fruit = new Fruit();
然后在taxonomy.php中,通过循环执行以下操作:

$fruit->the_apple();
但是,一旦我将get_template_part与loop.php一起使用,它就不再有效了

$fruit->the_apple();
我收到以下通知:

Notice: Undefined variable the_apple();
我的解决方案是使用:

global $fruit;
现在它一直在工作,仅供参考globals他们的名声不好。还有名称空间问题,以及将所有内容转储到globals和使用注册表

在生产过程中,我从不使用$FROUT这个名字,而是称之为

global $skylar_fruit;