WordPress.org

Ready to get started?Download WordPress

Forums

Post UI Tabs
[resolved] support for nested shortcodes? (2 posts)

  1. duncan
    Member
    Posted 2 years ago #

    Hi Mark,

    This is a great plugin - thank you.

    I had to pull in some tabs via a shortcode recently, and found that the only way to make sure the plugin tabified them as normal was to force the has_tabs property to true (thanks for making that public), because the first shortcode needed to be parsed before the page contained '[end_tabset]' (if that makes sense), and 'on_the_posts' only checks the plain $content of the $posts.

    Might you consider adding a filter inside 'on_the_posts' to assign has_tabs, passing in $content so developers could do any shortcode parsing etc they wanted, to decide whether there are tabs or not?

    Something like

    $this->has_tabs = apply_filters( 'put_decide_has_tabs', $this->has_tabs, $content );

    towards the end?

    I would send this in Trac but I'm no good with it and can't find this plugin in the dropdown.

    Best Regards,
    Duncan

    http://wordpress.org/extend/plugins/put/

  2. Mark / t31os
    Moderator
    Plugin Author

    Posted 1 year ago #

    Whilst that's certainly an option, you should note that the data a filter passes to functions hooking on can only be passed back the data from the first argument, so using your above example, regardless of what you may change in $content, that data would not be getting passed back to the plugin.

    An option would be would be pass an array of the data into the hook, eg.

    $this->has_tabs = apply_filters( 'put_decide_has_tabs', array( $this->has_tabs, $content ) );

    Though i'm inclined to say that if you want to hook the post content and determine whether to enable/disable tabs, you should do so with your own filter on the_content and i'd be happy to add a filter to set the has_tabs variable, so you can more easily set that via a filter instead of bringing the $Post_UI_Tabs object into scope and explicitly setting the has_tabs property.

    $this->has_tabs = (bool) apply_filters( 'put_decide_has_tabs', $this->has_tabs );

    If you wanted to run some conditional logic over the post content before setting that hook you could run two filters, something along the lines of..

    // Hook at priority 6, plugin runs filter at priority 7
    add_filter( 'the_content', 'my_filter_on_the_content', 6 );
    
    // Assuming you want tabs disabled unless logic in filter is true
    $set_tabs = false;
    
    function my_filter_on_the_content( $content ) {
    
    	global $set_tabs;
    	// Do condition logic to determine whether to enable has_tabs
    	$set_tabs = true;
    
    	return $content;
    }
    if( $set_tabs )
    	add_filter( 'put_decide_has_tabs', '__return_true' );

    The logic can be inversed if you want to have tabs on, but conditionally turn them off.

    I'll add the filter to the next update anyway, it definitely makes sense to have users set that variable via a filter instead of messing around with the class object.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.