include function xy() of a wordpress plugin
I want to build a WordPress a开发者_C百科dmin dashboard widget which should return some information from another plugin.
This dashboard widget should read the functions of this plugin here: http://plugins.svn.wordpress.org/wp-document-revisions/trunk/wp-document-revisions.php
So my code is:
include (WP_PLUGIN_URL.'/wp-document-revisions/wp-document-revisions.php');
$file_type = get_file_type('3');
But this doesn't work. These are the errors:
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
Can anyone tell me how I have to do this, that I can read the function get_file_type('3')?
I'm assuming you are navigating straight to your PHP file in the wp-content/plugins/ folder rather than using a stub to create a URL. If this is the case, then you probably forgot to include wp-load.php
You should not include the plugin file (since the plugin may not be installed or activated). Instead of this you should check if the function exists:
if (function_exists('get_file_type')) {
$file_type = get_file_type('3');
// rest of the code of the widget
}
It sounds like you are trying to access the PHP file directly, rather than going through WordPress proper. You should create a plugin, and hook into the Dashboard Widgets API.
As for implementation with WP Document Revisions, you've got two options. As of version 1.2, get_documents()
and get_document_revisions()
are two global functions that will be accessible anytime after the plugins_loaded
hook. The FAQ has a bit more info, but they basically function like the native get_posts()
function.
Alternatively, the class should be available globally as $wpdr
. So if you wanted, for example, to call get_latest_version( 1 )
it'd be $wpdb->get_latest_version( 1 )
.
Both assume the plugin's already activated. If you simply include the file, you're going to get an error that you're trying to redeclare the WP_Document_Revisions
class.
If you do create a dashboard, I'd love to include it in future releases of the plugin!
精彩评论