我有一个正在开发的插件。它在WordPress的单站点版本上运行良好。它安装在多站点版本的WordPress上,似乎可以在管理页面上工作,但当插件尝试添加javascript和css时,它不会被添加。
代码的显示部分如下所示。。。
add_action(\'init\', array(&$this, \'init\'));
function init() {
// Gather gallery and template variables
$url = explode(\'?\', \'http://\' . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
$ID = url_to_postid($url[0]);
load_plugin_textdomain(\'ngTemplateCreator\', ngTemplateCreator_DIR . \'/lang\', basename(dirname(__FILE__)) . \'/lang\');
$t = get_post($ID);
$c = 0;
$regex_pattern = get_shortcode_regex();
preg_match_all(\'/\' . $regex_pattern . \'/s\', $t->post_content, $regex_matches);
// loop thru shortcode
foreach ($regex_matches[3] as $key => $value) {
if ($regex_matches[2][$key] == \'nggtc\') {
$c = $c + 1;
// Found a NextGEN gallery find out what ID
// Turn the attributes into a URL parm string
$attribureStr = str_replace(" ", "&", trim($value));
$attribureStr = str_replace(\'"\', \'\', $attribureStr);
// Parse the attributes
$defaults = array(
\'id\' => 0,
\'template\' => \'\'
);
$attributes = wp_parse_args($attribureStr, $defaults);
if (isset($attributes["id"])) {
$this->gid = $attributes["id"];
}
if (isset($attributes["template"])) {
$this->tcname = $attributes["template"];
}
$wrapper = "nggtc_gallery_" . $this->gid . "_" . $c;
if (!empty($this->gid) && !empty($this->tcname)) {
$images = get_ngg_gallery($this->gid);
$templates = get_custom_template($this->tcname);
if ($templates && $images) {
foreach ($templates as $template) {
if ($template->bottom_javascript) {
$this->bottom_javascript = $this->bottom_javascript . process_script_shortcode($template->bottom_javascript, $wrapper, $panelid, $panelcss, $filmstripid, $filmstripcss) . "\\r\\n\\r\\n";
}
}
}
}
}
}
$this->count = $c;
if ($this->bottom_javascript) {
add_action(\'wp_footer\', array(&$this, \'footerScripts\'), 200);
}
wp_reset_query();
}
function process_script_shortcode($script, $wrapper, $panelid, $panelcss, $filmstripid, $filmstripcss) {
$out = remove_php($script);
// Swap shortcode
if($out) {
// strip html from filmstrip variables
$filmstripi = str_replace(" id=\\"", "", $filmstripid);
$filmstrip = str_replace("\\"", "", $filmstripi);
$filmstripcs = str_replace(" class=\\"", "", $filmstripcss);
$filmstripc = str_replace("\\"", "", $filmstripcs);
$out = str_replace("[wrapper]", $wrapper, $out);
$out = str_replace("[panel_id]", $panelid, $out);
$out = str_replace("[panel_css]", $panelcss, $out);
$out = str_replace("[filmstrip_id]", $filmstrip, $out);
$out = str_replace("[filmstrip_css]", $filmstripc, $out);
}
return $out;
}
function footerScripts() {
if (wp_script_is(\'jquery\', \'done\')) {
echo "<script type=\\"text/javascript\\" defer=\\"defer\\">" . $this->bottom_javascript . "</script>";
}
}
我只显示了页脚脚本的函数,但没有显示任何脚本和css,因此我很确定错误的来源是相同的。
有人能告诉我哪里出了问题吗?