我试图从一个插件添加一些功能,我已经成为一个WordPress主题,但我有点小喜悦。这些文档并不能真正帮助我解决问题,所以也许这里有人可以提供帮助。WordPress的:从主题访问插件的功能
我有一个插件在WordPress的激活和工作正常。这个插件的类有一个名为generateHtml的函数,我想从一个WordPress主题访问。但无论我尝试,我似乎无法访问我的插件的代码。
能要么给我什么,我需要做的,从插件获取主题访问代码和/或指出有我错在我的代码摘要:
插件:
<?php
/** Usual comments here **/
if (!class_exists("ImageRotator")) {
class ImageRotator {
private $uploadPath = '';
private $pluginPath = '';
private $options;
function __construct() {
$this->uploadPath = dirname(__file__).'\\uploads\\';
// add_shortcode('imagerotator', array(&$this, 'generateHtml'));
}
// Various functions for plugin
function generateHtml() {
echo '<p>Hello World</p>';
}
}
}
/**
* Create instance of image rotator
*/
$imageRotator = new ImageRotator();
/**
* Create actions & filters for Wordpress
*/
if (isset($imageRotator)) {
// Actions
add_action('admin_menu', array(&$imageRotator, 'createMenu'));
add_action('admin_init', array(&$imageRotator, 'registerSettings'));
add_action('imagerotator_show', array(&$imageRotator, 'generateHtml'));
}
从主题标题页
部分:
<?php if (isset($imageRotator)) {
$imageRotator->generateHtml();
} else if (isset($ImageRotator)) {
print_r($ImageRotator);
} else {
echo '<p>Nope!</p>';
}
if (function_exists("imagerotator_show")) {
echo 'Function found';
} else {
echo 'Function NOT found';
}
?>
目前,所有我曾经看到的是“没有”,“不发现功能”。感谢您的任何意见。
Lee,
请注意,这应该对所有WordPress主题设计师有所帮助:http://devideas.blogetery.com/testing-wordpress-themes-easily/ – Sarfraz 2010-04-07 13:51:15