• How do I send a argument(s) to my function when calling it from add_action? I have tried many, many ways and can not get it to work.

    add_action('admin_menu', 'mt_add_pages');
    
    function mt_add_pages($name) {
    
        add_menu_page($name, $name, 0, __FILE__, 'mt_toplevel_page');
    
    }
    
    function mt_toplevel_page() {
        echo "<h2>Edit Listing</h2>";
    }

Viewing 4 replies - 1 through 4 (of 4 total)
  • function myfunky_function() {
    	echo "hello";
    }
    function user_menu () {
    	add_users_page('menu', 'menu', 1, basename(__FILE__), 'myfunky_function');
    }

    add_action('admin_menu', 'user_menu');

    works for me.

    Thread Starter pwdrskier4

    (@pwdrskier4)

    Okay, I think you may have missed what I am getting at. From your example, I would be trying to pass a variable to myfunky_function when I called it. So that it is something like this:

    function myfunky_function($text) {
    	echo $text;
    }
    
    function user_menu () {
    	add_users_page('menu', 'menu', 1, basename(__FILE__), 'myfunky_function($text-to-pass)');
    }
    
    add_action('admin_menu', 'user_menu');

    Basically I am trying to make myfunky_function($text-to-pass) work.

    Does that make sense? Any suggestions?

    I might still be misunderstanding, but if you are trying to pass a variable to your function, you need to make it a global.

    any update on this? can no one answer this supposedly easy thing if it were straight php?

    wordpress is making it hard .

    can I use

    add_action('action_here', 'function_name($variable)');

    to work?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘adding function arguments to add_action’ is closed to new replies.