0
class mafongroup_admin {

    public function __construct() {
        add_action( 'admin_menu', array( $this, 'mafongroup_admin_menu' ) );
        add_action( 'admin_init', array( $this, 'mafongroup_admin_menu_function' ));
    }

    public function mafongroup_admin_menu(){
        if ( current_user_can( 'edit_theme_options' ) ){
            $page_title="MAFON GROUP";
            $menu_title="MAFON GROUP";
            $capability="administrator";
            $menu_slug="mafongroup_admin_settings";
            $function="mafongroup_admin_menu_function";

            $mafongroup_menu_page_creation_method    = 'add_menu_page';
            $mafongroup_submenu_page_creation_method = 'add_submenu_page';

            $theme_options = $mafongroup_menu_page_creation_method( $page_title, $menu_title, $capability, $menu_slug, $function,'dashicons-image-filter', '2.111111');
        }
    }

    public function mafongroup_admin_menu_function(){
        echo 'do something';
    }
}

new mafongroup_admin();

Why is calling this method gives me error-'call_user_func_array() expects parameter 1 to be a valid callback, function 'mafongroup_admin_menu_function' not found or invalid function name'

Could someone assist ?

Thanks

Jeff

1 Answer 1

1

Like your previous questions answer if you have called any class method you need to reference the class. So you need to replace this line

$theme_options = $mafongroup_menu_page_creation_method( $page_title, $menu_title, $capability, $menu_slug, $function,'dashicons-image-filter', '2.111111');

With this one-

$theme_options = $mafongroup_menu_page_creation_method( $page_title, $menu_title, $capability, $menu_slug, array( $this, $function ),'dashicons-image-filter', '2.111111');

So your above code will be like below-

class mafongroup_admin {

    public function __construct() {
        add_action( 'admin_menu', array( $this, 'mafongroup_admin_menu' ) );
        add_action( 'admin_init', array( $this, 'mafongroup_admin_menu_function' ));
    }

    public function mafongroup_admin_menu(){
        if ( current_user_can( 'edit_theme_options' ) ){
            $page_title="MAFON GROUP";
            $menu_title="MAFON GROUP";
            $capability="administrator";
            $menu_slug="mafongroup_admin_settings";
            $function="mafongroup_admin_menu_function";

            $mafongroup_menu_page_creation_method    = 'add_menu_page';
            $mafongroup_submenu_page_creation_method = 'add_submenu_page';

            $theme_options = $mafongroup_menu_page_creation_method( $page_title, $menu_title, $capability, $menu_slug, array( $this, $function ),'dashicons-image-filter', '2.111111');
        }
    }

    public function mafongroup_admin_menu_function(){
        echo 'do something';
    }
}

new mafongroup_admin();

Hope that helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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