• so I’m reading that action hooks pass arguments to the function that you hook to the action, but how does it happen? I mean how do I access the argument in my function?

    this code doesn’t get it

    function remove_post_dir($post_ID) {
      if(file_exists(ABSPATH. '/wp-content/uploads/'. $post_ID)) {
        rmdir(ABSPATH. '/wp-content/uploads/'. $post_ID);
      }
    }
    
    add_action( 'delete_post', remove_post_dir($post_ID));
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter ekitel

    (@ekitel)

    I used a bad example for add_action, it should be like this:

    add_action( 'delete_post', 'remove_post_dir');

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    There’s nothing wrong with your code there, as such. Try this for example:

    function remove_post_dir($post_ID) {
    echo "I JUST GOT $post_ID";
    }
    add_action('delete_post','remove_post_dir');

    That will work fine. The default setting is to receive 1 argument.

    If you wanted to be explicit, you could use:
    add_action('delete_post','remove_post_dir',10,1);
    which tells it that you have priority 10 and want to receive 1 argument.

    Thread Starter ekitel

    (@ekitel)

    problem was my function wasn’t in quotes, and had the parentheses like a regular function call, I copied that style out of an older plugin

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘how to get arguments from action hooks’ is closed to new replies.