How to add a new plugin page under desired Options page?

Using WordPress Settings API tutorial I created a new custom menu and corresponding sub menus. Each of my menus have a page of its own. I used add_menu_page() and add_submenu_page() for that. (Here is the Complete Code)

Admin——–
» Special Admin
» Price Quotation

Read More

Now I’m trying to make a Plugin for some additional purposes. I want to integrate my plugin with the custom menu, I created earlier.

I placed a checkbox saying “Activate Price Quotation” in the “Special Admin” page. When the user Activates the Price Quotation the plugin will come into action. Then plugin will be available in the “Price Quotation” submenu_page.

There I’ll make some tabbed pages under the Price Quotation page with some certain functionalities.

I tried with a basic plugin with add_plugins_page():

<?php
/*
 * Plugin Name: Price Quotation
 * Plugin URI: http://www.example.com
 * Author: Mayeenul Islam
 * Author URI: http://www.example.com
 * Version: 1.0.0
 */
?>

<?php

function add_a_menu(){
    add_plugins_page(
        'Price Factor',
        'Price Factor',
        'edit_posts',
        'edit_private_posts',
        'price_factor_callback'
    );
}
add_action('admin_menu', 'add_a_menu');

function price_factor_callback(){
    echo "This is Price Quotation Page";
}

?>

But this admin_menu filter added the menu under the default “Plugins” menu by default. How can I manage to call the menu or menus where I decided them to?

Related posts

1 comment

  1. Use add_submenu_page instead.

     <?php add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function ); ?> 
    

    $parent_slug should be one of the following

    For Dashboard: add_submenu_page( 'index.php', ... ); Also see add_dashboard_page()
    For Posts: add_submenu_page( 'edit.php', ... ); Also see Also see add_posts_page()
    For Media: add_submenu_page( 'upload.php', ... ); Also see add_media_page()
    For Links: add_submenu_page( 'link-manager.php', ... ); Also see add_links_page()
    For Pages: add_submenu_page( 'edit.php?post_type=page', ... ); Also see add_pages_page()
    For Comments: add_submenu_page( 'edit-comments.php', ... ); Also see add_comments_page()
    For Custom Post Types: add_submenu_page( 'edit.php?post_type=your_post_type', ... );
    For Appearance: add_submenu_page( 'themes.php', ... ); Also see add_theme_page()
    For Plugins: add_submenu_page( 'plugins.php', ... ); Also see add_plugins_page()
    For Users: add_submenu_page( 'users.php', ... ); Also see add_users_page()
    For Tools: add_submenu_page( 'tools.php', ... ); Also see add_management_page()
    For Settings: add_submenu_page( 'options-general.php', ... ); Also see add_options_page()
    

    Example:

    add_submenu_page( 'tools.php', 'My Custom Submenu Page', 'My Custom Submenu Page', 'manage_options', 'my-custom-submenu-page', 'my_custom_submenu_page_callback' ); 
    

Comments are closed.