2013-05-07 147 views
3

這個問題發生在我不知道WordPress的解剖結構(這是我第一次使用WP),而且任務應該緊急解決。我開發了一個不受歡迎的openID提供者的openID授權插件。我開發了插件,就好像它在'init'鉤子上調用main函數一樣。因此,沒有任何非授權用戶可以訪問任何網站頁面。但任務是我必須在我的索引頁面上有「授權」鏈接,授權必須在點擊此鏈接後立即執行。我嘗試用自定義鉤子來解決問題。WordPress的自定義鉤子

我添加以下到我的插件主文件(它是一個類函數)

public function m_authenticate(){ 
    do_action('m_authenticate'); 
} 

比增加像

add_action('m_authenticate', array(&$this, 'mAuthenticate'), 7); 

這裏mAuthenticate的動作會被重定向到OpenID提供商的功能AUTH。 之後,我創建了一個PHP腳本與此掛鉤

<?php 
m_authenticate(); 

但在調用由瀏覽器這個腳本,它發生該腳本不能找到一個功能m_authenticate()錯誤。如果我需要腳本,其中定義了m_authenticate(),那麼對於此腳本的其他行會發生錯誤,例如, cannot find function on line

register_activation_hook(__FILE__, array('some_func', 'addNewWordPressAdmin')); 

請幫助建議如何使用此openID功能製作單獨的頁面。任何幫助將不勝感激。

回答

0

以下是解決此問題的一種方法。在這裏,您有與類插件:

class MyAuthHookClass {

public function __construct() { 
    add_action('m_authenticate', array($this, 'mAuthenticate')); 
} 

public function mAuthenticate() { 
    echo "<h1>My Auth</h1>"; 
} 

public static function m_authenticate(){ 
    do_action('m_authenticate'); 
} } 

new MyAuthHookClass();

而在主題結構我把header.php鉤:

<?php if(class_exists('MyAuthHookClass')) MyAuthHookClass::m_authenticate(); ?>