php类作为wordpress中的插件 [英] php class as a plugin in wordpress

查看:69
本文介绍了php类作为wordpress中的插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该如何编写一个仅旨在提供要由其他插件调用的类的插件. 例如,如果我有这样的课程:

How can I write a plugin that only intents to provide the class to be called by other plugins. for example, if I have a class like this:

class Test{
     public static function testMethod(){}
}

然后在wordpress环境中,我们将可以调用Test::testMethod();

then within wordpress envrionement, we will be able to call Test::testMethod();

以下作品有用吗?

<?php
/*
 Plugin Name: My Plugin
 ...other WP plugin headers
*/
add_action('init', 'test_init', 0);
function test_init(){
    $test=new Test();
}

class Test{
   public static function testMethod(){}  
}
?>

我认为这不是正确的方法.任何输入表示赞赏.

I don't think this is a right way to do it. any input is appreciated.

推荐答案

您不需要add_action-仅激活插件将使WP包含该类,然后将这样的静态函数包括在内可用.

You wouldn't need the add_action - just activating the plug-in would cause WP to include the class, and a static function like that would then be available.

这篇关于php类作为wordpress中的插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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