Pasar argumentos con add_action y do_action arrojando el error 'Se espera que el primer argumento sea una devolución de llamada válida'

I have a form on my WordPress page that sends submission data to a third party service upon form submit. The form uses the Gravity Forms post-submit API hook (, though thats not the cause for the error.

I have the following error appearing upon loading my site due to my JavaScript argument-passing having a problem:

Warning: call_user_func_array() []: First argument is expected to be a valid callback, 'aoExtPost' was given in /home2/jcollins/public_html/wp-includes/plugin.php on line 429

I have the following in my WordPress theme functions.php file:

if (function_exists('load_aoExtPost')) {
    function load_aoExtPost() {
        if (!is_admin()) {
        wp_register_script('ExtPost', get_template_directory_uri() . '/teravoxel/js/ExtPost.js', array(), '0.1', true );

//extPostUrl is the argument to pass
$extPostUrl = 'http://www.---webservice---/eform/3122/0027/d-ext-0002';
add_action('gform_after_submission_1', 'ExtPost', 10, 2);
do_action('gform_after_submission_1', $extPostUrl, $entry);

This is the content of the JavaScript being referenced:

function aoExtPost(extPostUrl) {
//generate iframe via some echoed out javascript
var aoUrl = extPostUrl;
var aoUrlStr = aoUrlA.toString();
var aoIfrm = document.createElement('iframe');
aoIfrm.setAttribute('id', 'ifrm');'none';'0px';'0px';
aoIfrm.src = aoUrlStr;

If I replace the above JS file reference with a simple PHP function just to test the argument-pass in functions.php, it works. Can someone tell me where I'm going wrong in the handoff to the script please?

The purpose is to take the contents of $extPostUrl and move them into the JS-generated iframe's source's query-string (which is how I'm passing data to this third-party service)

preguntado el 27 de noviembre de 13 a las 01:11

1 Respuestas

Como indica la advertencia, add_action expects a valid callback function. If you pass two arguments to the hook:

do_action( 'gform_after_submission_1', $extPostUrl, $entry );

You can do stuff with (one or both of) them in a callback function:

add_action( 'gform_after_submission_1', 'so20231440_extpost', 10, 2 );
function so20231440_extpost( $extPostUrl, $entry )
    // do stuff with $extPostUrl and/or $entry

    // for example:
    wp_enqueue_script( 'extpost' );
    wp_localize_script( 'extpost', 'extpost', array( 'url' => $extPostUrl ) );

    // var usage in JS: extpost.url

respondido 27 nov., 13:02

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.