简体   繁体   中英

Wordpress: Use do_shortcode in plugin not working

I have this plugin installed on my wordpress: http://wordpress.org/plugins/put/

Im trying to make plugin that uses UI Tabs plugin inside my own plugin.

My plugin code so far:

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');

Now if I use [print_tabs] shortcode in new page, it should look like this: http://img835.imageshack.us/img835/4905/workingp.png

But its not working, it looks like this: http://imageshack.us/a/img62/9772/notworkingm.png

What could be the problem here?

The problem, from what I can see in put.php in the Post UI Tabs plugin is that the shortcodes are only added during the "the_content" filter in a function called "on_the_content".

add_filter( 'the_content',        array( $this, 'on_the_content' ), 7 ); // Priority 7 - before wpautop

(line 96 of put.php)

And that function looks like:

    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;
}

(starting at line 118 of put.php)

So, given how this plugin is written by modifying the content with a filter which in turn adds the shortcodes when that filter is run, what you're seeing is probably happening because when you call "do_shortcode" those shortcodes don't actually exist.

What echoing do_shortcode is doing then, is just coughing up the text.

Unfortunately, because of the way the Post UI Tabs plugin is written, you may not be able to do what you're trying to do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM