0

How can I use add_menu_page() functions some variable function ?

add_menu_page('My page','My page','manage_options','my_page', 'func' );

$func = function() {
        echo "Done !";
};

I know I can use like

function func() {
            echo "Done !";
};

But how can I use like

$func = function() {
            echo "Done !";
};

to call it ?

1 Answer 1

1

You have to declare the closure before you call add_menu_page():

$func = function() {
            echo "Done !";
};

add_menu_page('My page','My page','manage_options','my_page', $func );

Note you need PHP 5.3 to do that.

0

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.