Hooking new functions to actions + passing parameters

For this example lets say we have the following

do_action('bt_custom_action', get_the_ID(), get_the_title(), get_the_content());

The arguments that will be passed to add_action would be in this order

  1. the post id
  2. the post title
  3. the post content

By default if we hook into our do_action without any arguments, like this

add_action('bt_custom_action', 'bt_callback_func');

Our call back function “gets” one argument, in this case the ID

function bt_callback_func ($id) {
    echo $id;
}

In order to get the post content we would need to do something like this

add_action('bt_custom_action', 'bt_callback_func', 10, 3);

This will pass three arguments to our callback function and to use them we would do something like this

function bt_callback_func ($id, $title, $content) {
    echo $id . '<br>' . $title . '<br>' . $content;
}

Now to finally answer your question about getting a specific argument.

If we go by this example

add_action('bt_custom_action', 'bt_callback_func', 10, 3);

we know that our callback function will get three arguments, but we only need the content. We don’t have to set parameters for each and every expected argument. We can use PHPs ..., see Variable-length argument lists.

So now our callback function will look like this

function bt_callback_func (...$args) {
    echo args[2];
}

Because in our add action we told that our callback will expect three arguments and we know that the third argument is what we need (the content), using ... we now created a variable that will contain all passed argumnets.

In this case it will contain an array with three elements in order. ID, title and then content.

We know that content is last, third, in our array. We can target it directly like this $args[2].

Hope this helps =]