【发布时间】:2009-10-23 18:19:03
【问题描述】:
我正在尝试从我制作的插件中添加一些功能到 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';
}
?>
目前我所看到的只是“否”和“未找到功能”。感谢您的任何意见。
李,
【问题讨论】:
-
附带说明,这应该对所有 wordpress 主题设计师都有帮助:devideas.blogetery.com/testing-wordpress-themes-easily