Cannot connect to a function within an add_submenu_page() using OOP

27 Views Asked by At

This is my first transition to OOP in a WordPress plugin.

I am trying to create a submenu in Settings and the associated function to drive an admin screen.

The code below creates the menu item successfully but when I select the menu item, I receive the following error:

call_user_func_array(): Argument #1 ($callback) must be a valid callback, function "aa_admin_nsp_signoff_nav" not found or invalid function name.

Any insight to what I'm doing wrong is greatly appreciated!

    class AaSignTheForm {
    
        public function __construct() {  
    
            add_action( 'admin_menu', array( $this, 'aa_nsp_signoff_submenu' ) );
        }
    
    
        public function aa_nsp_signoff_submenu() {
        
            add_submenu_page(
                'options-general.php',
                'Nominal Sale Price Signoff',
                'NSP Signoff',
                'administrator',
                'aa-signoff',
                'aa_admin_nsp_signoff_nav' );
        }
    
    }
    new AaSignTheForm();
1

There are 1 best solutions below

0
Randy32 On

I just added $this in an array for the callable function:

add_submenu_page(
    'options-general.php',
    'Nominal Sale Price Plugin Signoff',
    'NSP Signoff',
    'administrator',
    'aa-signoff',
    array( $this, 'aa_admin_nsp_signoff_nav' ));
}