• Resolved loopforever

    (@loopforever)


    Hello,
    In a plugin file there is an action defined as follows. It contains a parameter of type array as you can see:

    do_action('vse_da_update',$id,$data[$rkey],$status);

    I’m trying to handle this by reaching it in function.php. However, I cannot reach it. am i making a mistake? Is the parameter as an array being accessed in a different way?

    add_action('vse_da_update', 'new_vse_da_update', 10, 2);
    function new_vse_da_update ($id, $data){
    $new_value[$id] = $data[$rkey];
    }
    • This topic was modified 3 years, 5 months ago by loopforever.
Viewing 2 replies - 1 through 2 (of 2 total)
  • This just means that the action is passing whatever value is inside $data[$rkey] as a variable. It will be a normal single variable in the callback function that you can access, with whatever name you choose:

    add_action('vse_da_update', 'new_vse_da_update', 10, 2);
    function new_vse_da_update ($id, $data){
    	$new_value[$id] = $data;
    }

    This is the same as if you pass a value to a function:

    funtion do_something( $value ) {
    	echo $value;
    }
    
    $data = [
    	'key' => 'value',
    ];
    
    do_something( $data['key'] ); // 'value'
    Thread Starter loopforever

    (@loopforever)

    Thank you very much for your reply. Problem is solved.

    • This reply was modified 3 years, 5 months ago by loopforever.
    • This reply was modified 3 years, 5 months ago by loopforever.
    • This reply was modified 3 years, 5 months ago by loopforever.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Accessing array-defined action’ is closed to new replies.