0

I use this in my Functions.php file to format short codes for some jQuery UI tabs, however I also use a short tag to reference my video embeds, which breaks when they're inside the UI tabs.

My question is, how would I just pass my video short code through this function unaltered:

// jQuery UI Tabs
add_shortcode( 'tabgroup', 'etdc_tab_group' );
function etdc_tab_group( $atts, $content ){
$GLOBALS['tab_count'] = 0;

do_shortcode( $content );

if( is_array( $GLOBALS['tabs'] ) ){
foreach( $GLOBALS['tabs'] as $tab ){
$tabs[] = '<li><a class="" href="#'.$tab['title'].'">'.$tab['title'].'</a></li>';
$panes[] = '<div id="'.$tab['title'].'"><h3>'.$tab['title'].'</h3>'.$tab['content'].'</div>';
}
$return = "\n".'<!-- the tabs --><div id="tabs"><ul>'.implode( "\n", $tabs ).'</ul>'."\n".'<!-- tab "panes" -->'.implode( "\n", $panes ).'</div>'."\n";
}
return $return;
}

add_shortcode( 'tab', 'etdc_tab' );
function etdc_tab( $atts, $content ){
extract(shortcode_atts(array(
'title' => 'Tab %d'
), $atts));

$x = $GLOBALS['tab_count'];
$GLOBALS['tabs'][$x] = array( 'title' => sprintf( $title,   $GLOBALS['tab_count'] ), 'content' =>  $content );
$GLOBALS['tab_count']++;
}

My video short code looks like this [video src="http://site.com/uploads/example.mp4"]. I imagine I just have to set something in $GLOBALS, but I don't know how I would just pass it through unaltered.

(My 'video' short code is being translated by another plugin)

Update: This was the solution to my problem. Adding do_shortcode to $panes:

$panes[] = '<div id="'.$tab['title'].'"><h3>'.$tab['title'].'</h3>'.do_shortcode($tab['content']).'</div>';
2
  • 1
    try adding do_shortcode( $content ); to etdc_tab function
    – Bainternet
    Commented Feb 28, 2011 at 15:55
  • @Bainternet Moving the do_shortcode($content); to the etdc_tab function, doesn't solve it.
    – PHearst
    Commented Mar 1, 2011 at 12:57

1 Answer 1

1

Here's a trick that wp-includes/media.php uses for the embed shortcode: first remove all shortcodes, then add a specific shortcode back to the system, filter your content for it, then re-register the original shortcodes.

Try this:

function etdc_tab_group( $atts, $content ){
  global $shortcode_tags;
  $GLOBALS['tab_count'] = 0;

  // save the shortcode registrations
  $orig_shortcode_tags = $shortcode_tags;
  // remove them all
  remove_all_shortcodes();
  // add ours back in
  add_shortcode( 'tab', 'etdc_tab' );
  $content = do_shortcode( $content );
  // restore original shortcodes
  $shortcode_tags = $orig_shortcode_tags;

  //...rest of the function...
}

Actually, now that I'm looking at that etdc_tab_group() function more closely, I'm suprised it's not breaking something... Did you copy and paste it directly, or did you edit anything out? Because it's never passing $content back out again.

So first thing I'd try is just commenting out the do_shortcode() call and see how that works. If that breaks something else, then try the method above?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.