[英]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.