Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm working on a plugin that I have to release in parts.

The problem is, if there is a menu in the page then add the new plugin to the 2nd or next submenu else add a new menu and then add the plugin to 1st submenu.

My questions:

  1. How to check that there exists a menu?
  2. If I'm coding a reusable function , that will go with every plugin then that causes conflict option.
  3. I don't know the order of the plugin release.
add_menu_page(
    'Page Title',
    'Top Menu Title',
    'manage_options',
    'my_unique_slug',
    'my_magic_function'
);
add_submenu_page(
    'my_unique_slug',
    'page title',
    'submenu title',
    'manage_options',
    'my_submenu_slug',
    'my_magic_function_of_submenu'
);
share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

You can use the fourth parameter of add_menu_page(), the my_unique_slug, to check if the page exists:

if ( empty ( $GLOBALS['admin_page_hooks']['my_unique_slug'] ) )
    add_menu_page(
        'Page Title',
        'Top Menu Title',
        'manage_options',
        'my_unique_slug',
        'my_magic_function'
    );

$GLOBALS['admin_page_hooks'] is the list of registered pages.

share|improve this answer
1  
Thank you so much man. The content you've provided to me , is awesome, thank you so much. I was looking for this from last two days. echo "Thank You toscho"; –  Kaushik Kishore Oct 18 '13 at 8:32
    
@Kaushik Is there a problem with my suggestion? Doesn’t it work anymore? –  toscho Oct 21 '13 at 7:25
    
Not at all, By mistake I did that –  Kaushik Kishore Oct 21 '13 at 8:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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