Skip to main content
variable naming
Source Link

I think you are headed down the right path, but I think that func_get_args() is goingonly going to give you the arguments passed to that function. That is how I have always used it in the past.

I took a different approach that I think might work. I found debug_backtrace() to be helpful in debugging Actions and Filters before. And the 4th element in that array it returns you is the do_action call with all the arguments that live inside of the call you are looking to make.

Here is a snippet I put together with a few actions I tested:

<?php

// Here are the Actions I tested against.
$events = array(
    'profile_personal_options',
    'profile_update',
    'show_user_profile',
    'show_user_profile'
);

foreach ($events as $event) {
  add_action($event, function($args = null) {

    $backtrace = debug_backtrace();
            
    // This element is going to be the do_action call
    echo '<pre>';
    print_r($backtrace[3]['function']);
    echo '</pre>';
        
    $action_arguments = $backtrace[3]['args'];
    // The first element of the argsthis is going to be the $event
    array_shift($backtrace[3]['args']$action_arguments);
        
    // Leaving you with the rest of the parameters available to that action
    echo '<pre>';
    print_r($backtrace[3]['args']$action_arguments);
    echo '</pre>';

  }, 100);
}

If this is not what you are looking for, or I am off...let me know and I'd be happy to take my answer down!!

I think you are headed down the right path, but I think that func_get_args() is going going to give you the arguments passed to that function.

I took a different approach that I think might work. I found debug_backtrace() to be helpful in debugging Actions and Filters before. And the 4th element in that array it returns you is the do_action call with all the arguments that live inside of the call you are looking to make.

Here is a snippet I put together with a few actions I tested:

<?php

// Here are the Actions I tested against.
$events = array(
    'profile_personal_options',
    'profile_update',
    'show_user_profile',
    'show_user_profile'
);

foreach ($events as $event) {
  add_action($event, function($args = null) {

    $backtrace = debug_backtrace();
            
    // This element is going to be the do_action call
    echo '<pre>';
    print_r($backtrace[3]['function']);
    echo '</pre>';
        
    // The first element of the args is going to be the $event
    array_shift($backtrace[3]['args']);
        
    // Leaving you with the rest of the parameters available to that action
    echo '<pre>';
    print_r($backtrace[3]['args']);
    echo '</pre>';

  }, 100);
}

If this is not what you are looking for, or I am off...let me know and I'd be happy to take my answer down!!

I think you are headed down the right path, but I think that func_get_args() is only going to give you the arguments passed to that function. That is how I have always used it in the past.

I took a different approach that I think might work. I found debug_backtrace() to be helpful in debugging Actions and Filters before. And the 4th element in that array it returns you is the do_action call with all the arguments that live inside of the call you are looking to make.

Here is a snippet I put together with a few actions I tested:

<?php

// Here are the Actions I tested against.
$events = array(
    'profile_personal_options',
    'profile_update',
    'show_user_profile',
    'show_user_profile'
);

foreach ($events as $event) {
  add_action($event, function($args = null) {

    $backtrace = debug_backtrace();
            
    // This element is going to be the do_action call
    echo '<pre>';
    print_r($backtrace[3]['function']);
    echo '</pre>';
        
    $action_arguments = $backtrace[3]['args'];
    // The first element of this is going to be the $event
    array_shift($action_arguments);
        
    // Leaving you with the rest of the parameters available to that action
    echo '<pre>';
    print_r($action_arguments);
    echo '</pre>';

  }, 100);
}

If this is not what you are looking for, or I am off...let me know and I'd be happy to take my answer down!!

Source Link

I think you are headed down the right path, but I think that func_get_args() is going going to give you the arguments passed to that function.

I took a different approach that I think might work. I found debug_backtrace() to be helpful in debugging Actions and Filters before. And the 4th element in that array it returns you is the do_action call with all the arguments that live inside of the call you are looking to make.

Here is a snippet I put together with a few actions I tested:

<?php

// Here are the Actions I tested against.
$events = array(
    'profile_personal_options',
    'profile_update',
    'show_user_profile',
    'show_user_profile'
);

foreach ($events as $event) {
  add_action($event, function($args = null) {

    $backtrace = debug_backtrace();
            
    // This element is going to be the do_action call
    echo '<pre>';
    print_r($backtrace[3]['function']);
    echo '</pre>';
        
    // The first element of the args is going to be the $event
    array_shift($backtrace[3]['args']);
        
    // Leaving you with the rest of the parameters available to that action
    echo '<pre>';
    print_r($backtrace[3]['args']);
    echo '</pre>';

  }, 100);
}

If this is not what you are looking for, or I am off...let me know and I'd be happy to take my answer down!!