0

Here is my current code,

aio_menu.php

<?php
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
add_action( 'admin_menu', 'AIO_menu_creator' );
function AIO_menu_creator() {

    add_menu_page( 'AIO WooCommerce Plugin', 'AIO', 'manage_options', 'aio-dashboard', plugins_url('AIO-WooCommerce-Plugin/menu/aio_dashboard.php'), plugins_url('AIO-WooCommerce-Plugin/ico.png') , '81.912514514511451' ); 
}
require_once 'aio_dashboard.php';

?>

aio_dashboard.php

<?php

function my_plugin_options() {
    if ( !current_user_can( 'manage_options' ) )  {
        wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
    }
    echo '<div class="wrap">';
    echo '<p>Here is where the form would go if I actually had options.</p>';
    echo '</div>';
}

add_action( 'current_screen', 'my_plugin_options' );

?>

the image of the page

in my main plugin file,

require_once 'menu/aio_menu.php';

I want to add sub menu items like, dashboard, shipping editor, price specifier and etc.

So, aio_menu will have all my menu's specified and I will have aio_dashboard and so on for the page content.

Now I want to align the content I get in the middle of the page and make sure the notifications which are shown are properly shown. I know I am doing something wrong in aio_dashboard file.

Can anyone just suggest me how to get the content I want in the page correctly?Just this,

a h3 title DASHBOARD

and below it

'content goes here'

It should be in the admin page.

Here is an example of where I want my content, enter image description here

I have edited it with inspect element. You can compare the first image and second so any ideas how to get it in the correct place ?

2
  • 1
    Welcome to WPSE. Unfortunately your question is way too broad. What you are asking is for someone to code the entire project for you, and that will in all probability not happen. Please break your question up into a couple smaller ones, and most importantly, post your code, working or not and explain where you are stuck and the exact problem you are experiencing. Thank you :-) – Pieter Goosen Mar 1 '15 at 14:24
  • @PieterGoosen :) I did it. Just want the content in middle. Found out how to add submenu to custom top level menus :D – kks21199 Mar 1 '15 at 14:27
2

The $function argument of add_menu_page should be a function that produces your page output, or if omitted, then the $menu_slug argument can be a file that when included will output the menu page.

But your output right now has nothing to do with the add_menu_page call, the problem is that you're requiring aio_dashboard.php, which has a function hooked to current_screen. The current_screen action should not generate output, that's not what it's for, it fires too early in the load process. Its purpose is for adding filters and actions based on the current admin page being viewed.

Change the add_menu_page $function argument to contain the function that outputs the page content, remove the add_action call hooking that function to current_screen.

2
  • So i wouldn't be needing aio_menu.php ? and is adding this in aio_dashboard.php enough ? add_menu_page( 'AIO WooCommerce Plugin', 'AIO', 'manage_options', 'aio-dashboard', 'my_function'), plugins_url('AIO-WooCommerce-Plugin/ico.png') , '81.912514514511451' ); and add_submenu_page( 'aio-dashboard', 'AIO WooCommerce Plugin', 'Dashboard', 'manage_options', 'my_function'); I will add this in aio_dashboard.php and for the next submenu defining the add_submenu_page is enough in the next .php file I hope. anyway to manage all menu creation in aio_menu.php and only functions in other files ? – kks21199 Mar 2 '15 at 5:17
  • Sorry stupid of me asking the question :P I just needed to add the function name instead of the file location and make sure its required once and it works :D gyazo.com/2a200d9a756689f2e119617db9e60744 – kks21199 Mar 2 '15 at 5:24
0

For anyone who wants to add their own admin menu ;) The format is,

<?php add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position ); ?>

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

(from wordpress codex)

<?php
    defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
    add_action( 'admin_menu', 'mgg_aio_menu_creator' );
    function mgg_aio_menu_creator() {

        add_menu_page( 'AIO WooCommerce Plugin', 'AIO', 'manage_options', 'aio-dashboard', 'mgg_aio_dashboard', plugins_url('AIO-WooCommerce-Plugin/ico.png') , '81.912514514511451' ); 
        add_submenu_page( 'aio-dashboard', 'AIO WooCommerce Plugin', 'Dashboard', 'manage_options', 'aio-dashboard', 'mgg_aio_dashboard');
        add_submenu_page( 'aio-dashboard', 'Shipping Options | AIO WooCommerce Plugin', 'Shipping Options', 'manage_options', 'aio-shipping-options', 'mgg_aio_shipping_options');
    }
    require_once 'aio_dashboard.php';
    require_once 'aio_shipping_options.php';
    ?>

You will have a menu like this, enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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