[英]Wordpress: Use do_shortcode in plugin not working
我在我的wordpress上安装了此插件: http : //wordpress.org/plugins/put/
我正在尝试制作在我自己的插件中使用UI Tabs插件的插件。
到目前为止,我的插件代码:
function load_jquery(){
echo '<link rel=\'stylesheet\' id=\'jquery-ui-tabs-css\' href=\'http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/themes/smoothness/jquery-ui.css?ver=1.9.2\' type=\'text/css\' media=\'all\' />';
}
add_action('wp_head','load_jquery');
function print_tabs(){
echo do_shortcode('[tab name="Tab"]-[/tab]');
echo do_shortcode('[end_tabset]');
}
add_shortcode('print_tabs', 'print_tabs');
现在,如果我在新页面中使用[print_tabs]简码,它应该看起来像这样: http : //img835.imageshack.us/img835/4905/workingp.png
但是它不起作用,看起来像这样: http : //imageshack.us/a/img62/9772/notworkingm.png
这可能是什么问题?
从我在Post UI Tabs插件的put.php中看到的问题是,仅在“ the_content”过滤器中的“ on_the_content”函数中添加了短代码。
add_filter( 'the_content', array( $this, 'on_the_content' ), 7 ); // Priority 7 - before wpautop
(put.php的第96行)
该函数如下所示:
public function on_the_content( $content ) {
$this->has_tabs = (bool) apply_filters( 'put_decide_has_tabs', $this->has_tabs );
if( !$this->has_tabs )
return $content;
global $shortcode_tags;
// Backup current registered shortcodes and clear them all out
$orig_shortcode_tags = $shortcode_tags;
$shortcode_tags = array();
add_shortcode( 'tab', array( $this, 'on_tab_shortcode' ) );
add_shortcode( 'end_tabset', array( $this, 'on_tab_end_shortcode' ) );
// Do the shortcode(only the tab shortcode is registered at this point)
$content = do_shortcode( $content );
// Put the original shortcodes back
$shortcode_tags = $orig_shortcode_tags;
return $content;
}
(从put.php的第118行开始)
因此,考虑到通过使用过滤器修改内容来编写此插件的方式,该过滤器又在运行该过滤器时添加了短代码,因此您看到的可能正在发生,因为当您调用“ do_shortcode”时,这些短代码实际上并不存在。
然后,回声do_shortcode所做的只是咳嗽文本。
不幸的是,由于Post UI Tabs插件的编写方式,您可能无法执行您想做的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.