Support Forum
Support › Meta Box Conditional Logic › Show A Specific Tab When A Feature Image is AddedResolved
HI there,
I am using meta-box-tab
as well as meta-box-conditional-logic
extensions. In my theme the user can select where the Featured Image
of a post or page is displayed. Here is the code I am added to the theme:
https://ghostbin.com/paste/daepa
As you can see the user has two options: they can show the featured image below the title or display it above the title.
My question is how can I hide the Featured Image Options
tab if there is no featured image and show the Featured Image Options
tab if a featured image is used?
Thanks for any help you can provide.
Hi Thomas,
Let me see if I can find a workaround for this.
Awesome sir thank you. I appreciate any help.
Hi Thomas, I've just updated the plugin, adding support for Featured Image. Please see the documentation for usage.
Cheers
Oh wow, unexpected. Thank you sir. I will take a look at it later today and let you know what I think.
Again, thank you for the update.
So if I am trying to HIDE the Featured Image Options
TAB, where would I add the code from https://docs.metabox.io/extensions/meta-box-conditional-logic/#featured-image in the following:
https://ghostbin.com/paste/pss7p
I have tried adding it to Featured Image Options
tab but it still shows.
What am I doing wrong?
P.S. yes i updated the conditional extension.
Hi Thomas,
Your case is a combination of the featured image rule with this tutorial.
I added the solution to the library. Please take a look.
(Note: I removed all textdomain and prefix to help others see the code clear).
Hi there,
Ah OK I see it now...lol! Thank you very much, greatly appreciated my friend.
OK just wanted to stop in and say THANK YOU, THANK YOU, THANK YOU!!! This works beautimously...lol!
Great job guys, you killed it. Seriously, this is AWESOME!!! Thanks again.
Like I said before it works perfect, but I do have a question and I am hoping you can provide me with an answer as I am sure someone else will probably ask this.
OK so before I add my featured image, this is what the metabox looks like:
https://imgur.com/OR5CWv9 (screenshot 1)
and when I add my featured image it looks like this:
https://imgur.com/gNK9URW (screenshot 2)
This is pretty cool, however, I am wondering, how can I make the "Hide Post/Page Elements" tab be the "active" tab and show the contents of that tab if there is NO featured image.
In other words: If there is NO featured Image, how can I make it look like this:
https://imgur.com/f0Ny2ur (screenshot 3)
when there is no featured image I would like the next tab to be the active tab and show the tab content. Is this possible?
I hope there is a way to do it. Thanks again guys.
I got it. The first tab is always the active one when page loads. It's styled by a CSS class. I think the best solution for this issue is reorder the tabs, e.g. move another tab to the top, so when Featured Image tab is hidden, the first tab is still the active one.
Hey there,
Yes I thought about that before asking the question and I even tried it to see what happens.
This is what happens:
1. I move the featured image tab to the last position. I remove the featured image and now the featured image tab is hidden because there is no featured image:
https://i.imgur.com/N28Q70X.png
2. So I add a featured image and the Featured Image Options tab appears:
https://i.imgur.com/Rzlfx0z.png
As you can see this is not the desired effect. Which is why I asked the question in the first place amigo. Trust me I never ask a question on how to do something if I haven't already tried doing everything possible to make it work 😉
So, is there a way to maybe set a tab to be the active tab, maybe like this:
'active' => true,
Thanks again.
Hi Thomas,
I've been thinking about this, too. It seems that I have to add some more code to target this situation. Let me try to do that.
Awesome amigo I look forward to seeing what you come up with.
I know you'll knock it out of the ballpark
OK so my theme <b>TotalPress</b> was reviewed yesterday. I was excited. However they are using a new plugin for review. You can find it here: https://github.com/WPTRT/theme-sniffer
You can run checks against different version of PHP, from 5.2 all the way to 7.
So they ran the theme through this new plugin and it ran into a few errors running it against php 5.2. One of the errors was generated from the code for Meta Box Conditional Logic plugin.
It's this code from the library, at the very bottom: https://github.com/wpmetabox/library/blob/master/extensions/conditional-logic/featured-image-with-tabs.php
Specifically:
// hide our featured image options tab if there is no featured image being used.
add_filter( 'rwmb_outside_conditions', function ( $conditions ) {
$conditions['.rwmb-tab-totalpress_featured_image_options'] = array(
'visible' => array('_thumbnail_id', '!=', '-1'),
);
$conditions['.rwmb-tab-panel-totalpress_featured_image_options'] = array(
'visible' => array('_thumbnail_id', '!=', '-1'),
);
return $conditions;
} );
This is what the error states:
Closures / anonymous functions are not available in PHP 5.2 or earlier
So I had to remove this from the theme as well as the plugin meta box conditional logic. I really would like to include this in the theme but for now to get the theme approved, I have removed it.
Any idea what it means...lol - know how I can correct it?
Any help you can provide is greatly appreciated.