2011-09-27 120 views
0

我想要構建一個WordPress管理儀表板小部件,它應該從另一個插件返回一些信息。包含wordpress插件的函數xy()

本面板控件應該閱讀這個插件在這裏的功能: http://plugins.svn.wordpress.org/wp-document-revisions/trunk/wp-document-revisions.php

所以我的代碼是:

include (WP_PLUGIN_URL.'/wp-document-revisions/wp-document-revisions.php'); 
$file_type = get_file_type('3'); 

但是,這是行不通的。這些都是錯誤的:

Fatal error: Call to undefined function add_action() in /.../wp-content/plugins/wp-document-revisions/wp-document-revisions.php on line 26

Fatal error: Call to undefined function get_file_type() in /.../wp-content/plugins/dashboard-widget/dashboard-widget.php

誰能告訴我,我怎麼也得做到這一點,我可以讀取功能get_file_type(「3」)?

回答

0

我假設你直接瀏覽wp-content/plugins /文件夾中的PHP文件,而不是使用存根創建URL。如果是這種情況,那麼你可能忘記了包含wp-load.php

+0

add_action()是一個WordPress的核心功能,所以如果該功能不存在,這意味着你還沒有實際加載WordPress。你可以做'include('../../../ wp-load.php');'(或者指向你的wp-load.php文件的任何點),然後你就可以使用任何活動插件。 – jprofitt

0

你不應該包含插件文件(因爲插件可能沒有安裝或激活)。 取而代之的是,你應該檢查是否函數存在:

if (function_exists('get_file_type')) { 
$file_type = get_file_type('3'); 
// rest of the code of the widget 
} 
0

這聽起來像你試圖直接訪問PHP文件,而不是通過WordPress的正確去。你應該創建一個插件,並鉤入Dashboard Widgets API

至於使用WP Document Revisions的實現,您有兩種選擇。從版本1.2開始,get_documents()get_document_revisions()是兩個全局函數,它們將在plugins_loaded鉤子後隨時訪問。 FAQ有更多的信息,但它們基本上像本地功能get_posts()一樣運作。

或者,該類應該在全球範圍內可用,如$wpdr。所以,如果你想要,例如,撥打get_latest_version(1)它會是$wpdb->get_latest_version(1)

兩者都假定插件已被激活。如果你只是簡單地包含這個文件,你會得到一個錯誤,你試圖重新聲明WP_Document_Revisions類。

如果您確實創建了儀表板,我很樂意將它包含在插件的未來版本中!