2011-12-29 36 views
0

我該如何編寫一個只意圖提供被其他插件調用的類的插件。 舉例來說,如果我有這樣一個類:php類作爲wordpress中的插件

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

然後WordPress的envrionement內,我們將能夠調用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(){} 
} 
?> 

我不認爲這是正確的做法。任何輸入讚賞。

回答

2

你不需要add_action - 只要激活插件將導致WP包含類,然後可以使用類似這樣的靜態函數。

+0

它就是這麼簡單....欣賞。 :) – bingjie2680 2011-12-29 14:00:01