Hide admin menu items if it is empty

I have a plugin ( adds a new menu to the admin top bar ) and it works.. There is an option page where the user inputs th

I have a plugin ( adds a new menu to the admin top bar ) and it works.. There is an option page where the user inputs the menu title into that field (shows as menu item) - then adds the url address in the second field (this is what the menu item is linked to).

Both these input data fields are saved in the options.php as separate options with thier own names - this data is removed if the plugin is deactivated (testing), or is deleted - keeps the DB clean.

This works and I have hardcoded three menus to accept the data from the options tables:

adm_topmenu_one_link
adm_topmenu_one_title

adm_topmenu_two_link
adm_topmenu_two_title

adm_topmenu_three_link
adm_topmenu_three_title

Not super imaginative, but it suffices to make it easier to find and work with.

The problem is that if the menu is empty it still shows (and before you'all say it; I know its hardcoded)

I wish I could make it dynamic, so on the option page you click on a "Add Menu" - something and a new set of fields appear to enter the details *then you could populate it with as many as you like Alas, I'm not that good, so I'm stuck with what I have.

Seeing that the fields are named as above and use an echo in the value that looks at the title option. Can they be hidden if the value is null? and if not, then show?

I have a separate function for each menu item (options page) which is:

function adm_topmenu_callback_function() {
    echo "<fieldset style='border-top:1px solid #d2d2d2; width:100%; display:inline;'>";
    echo "<br>";
    echo '<input name="adm_topmenu_one_title" id="adm_topmenu_insert" type="text" class="code" value="'.get_option('adm_topmenu_one_title').'" placeholder="Add > Title"/>';
    echo " &nbsp; ";
    echo '<input name="adm_topmenu_one_link" id="adm_topmenu_insert" type="text" class="code" value="'.get_option('adm_topmenu_one_link').'" placeholder="Add > URL"/>';
    echo "<br>";
    echo "<br>";
    echo "</fieldset>";

Which in turn echos out to the menu tool bar items array:

$admin_bar->add_menu( array(
    'id'    => 'my-sub-item',
    'parent' => 'wp-101',
    'title' => '<span style="color:'.$GLOBALS["subVC"].'">★</span> '.get_option('adm_topmenu_one_title').' ',
    'href'  => ''.get_option('adm_topmenu_one_link').'',
    'meta'  => array(
        'title' => __(''.get_option('adm_topmenu_one_link').''),
        'target' => '_blank',
        'class' => 'my_menu_item_class'
    ),
));

The three ids for the menus are:

my-sub-item
my-second-sub-item
my-third-sub-item

I added a class "my_menu_item_class" in hopes that this could be the way. Maybe set it to

if null - display:none;
and if (not) null - display:block;

But... again it needs to be checked, somehow... or as I said earlier, setup as a dynamic "add menu item" feature.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745282629a4620367.html

相关推荐

  • Hide admin menu items if it is empty

    I have a plugin ( adds a new menu to the admin top bar ) and it works.. There is an option page where the user inputs th

    6小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信