Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 ?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
that is ! work now , thanks so much –  l2aelba Mar 13 '13 at 11:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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