Home > OS >  Right callback with do_action for add_menu_page and add_submenu_page
Right callback with do_action for add_menu_page and add_submenu_page

Time:08-03

I'm trying to add my custom admin menu and I don't understand, how I should make a callback for the function skillupCustomMenuMain() and skillupCustomMenuMainArchive () in __construct()

Could you help me, please

class AdminMenuFormSubmission
{
    public function __construct()
    {
        add_action('admin_menu', array($this, 'addCustomMenu'));
    }

    public function addCustomMenu()
    {
        add_menu_page(
            'Forms',
            'Form items',
            'manage_options',
            'skillup-custom-menu',
            'skillupCustomMenuMain',
            'dashicons-cart',
            4
        );

        add_submenu_page(
            'skillup-custom-menu',
            'Archived submissions',
            'Archive',
            'manage_options',
            'skillup-custom-menu-main-archive',
            'skillupCustomMenuMainArchive'
        );
    }

    public function skillupCustomMenuMain()
    {
        echo '<h2>Form submission</h2><div >Welcome to the form submission</div>';
    }

    public function skillupCustomMenuMainArchive()
    {
    }

}

CodePudding user response:

Change from

  public function addCustomMenu()
{
    add_menu_page(
        'Forms',
        'Form items',
        'manage_options',
        'skillup-custom-menu',
        'skillupCustomMenuMain',
        'dashicons-cart',
        4
    );

To

  public function addCustomMenu()
{
    add_menu_page(
        'Forms',
        'Form items',
        'manage_options',
        'skillup-custom-menu',
        array( $this, 'skillupCustomMenuMain' ),
        'dashicons-cart',
        4
    );
  • Related