Skip to main content
removed incorrect solution
Source Link
hwl
  • 2.1k
  • 10
  • 15

UPDATE for Sample Plugin:

The following edit to your registering/enqueuing method removed the JS console exception on my end:

 public function enqueue_scripts() {    
    $handle = "ies-rest-api";
    $jsfileurl = plugin_dir_url( __FILE__ ) . '/ies.js';
    //wp_register_script($handle, $jsfileurl, array("wp-api"));    
    //wp_enqueue_script($handle);
    wp_register_script($handle, $jsfileurl); 
    wp_enqueue_script( $handle, $jsfileurl, array( 'wp-api' ) ); 
    
    }  
}

So, just enqueuing it as a dependency rather than registering it as one. While the docs are explicit to this, I would have to dig further into wp_register_script and wp_enqueue_script to figure out how that affects dependencies being loaded. Of course, assuming this actually solves it for you, too.

The docs:

Activate the WP-API plugin. Enqueue the script directly: wp_enqueue_script( 'wp-api' ); or as a dependency for your script: wp_enqueue_script( 'my_script', 'path/to/my/script', array( 'wp-api' ) );

previous answer:

It appears your JS isn't loaded. You have registered the script, but haven't enqueued it. Add wp_enqueue_script after you register it. You can also use wp_localize_script to pass dependencies to your script and make variables from your php available to it.

Both above linked to codex on those functions.

UPDATE for Sample Plugin:

The following edit to your registering/enqueuing method removed the JS console exception on my end:

 public function enqueue_scripts() {    
    $handle = "ies-rest-api";
    $jsfileurl = plugin_dir_url( __FILE__ ) . '/ies.js';
    //wp_register_script($handle, $jsfileurl, array("wp-api"));    
    //wp_enqueue_script($handle);
    wp_register_script($handle, $jsfileurl); 
    wp_enqueue_script( $handle, $jsfileurl, array( 'wp-api' ) ); 
    
    }  
}

So, just enqueuing it as a dependency rather than registering it as one. While the docs are explicit to this, I would have to dig further into wp_register_script and wp_enqueue_script to figure out how that affects dependencies being loaded. Of course, assuming this actually solves it for you, too.

The docs:

Activate the WP-API plugin. Enqueue the script directly: wp_enqueue_script( 'wp-api' ); or as a dependency for your script: wp_enqueue_script( 'my_script', 'path/to/my/script', array( 'wp-api' ) );

previous answer:

It appears your JS isn't loaded. You have registered the script, but haven't enqueued it. Add wp_enqueue_script after you register it. You can also use wp_localize_script to pass dependencies to your script and make variables from your php available to it.

Both above linked to codex on those functions.

previous answer:

It appears your JS isn't loaded. You have registered the script, but haven't enqueued it. Add wp_enqueue_script after you register it. You can also use wp_localize_script to pass dependencies to your script and make variables from your php available to it.

Both above linked to codex on those functions.

new info from user, new details for answer
Source Link
hwl
  • 2.1k
  • 10
  • 15

UPDATE for Sample Plugin:

The following edit to your registering/enqueuing method removed the JS console exception on my end:

 public function enqueue_scripts() {    
    $handle = "ies-rest-api";
    $jsfileurl = plugin_dir_url( __FILE__ ) . '/ies.js';
    //wp_register_script($handle, $jsfileurl, array("wp-api"));    
    //wp_enqueue_script($handle);
    wp_register_script($handle, $jsfileurl); 
    wp_enqueue_script( $handle, $jsfileurl, array( 'wp-api' ) ); 
    
    }  
}

So, just enqueuing it as a dependency rather than registering it as one. While the docs are explicit to this, I would have to dig further into wp_register_script and wp_enqueue_script to figure out how that affects dependencies being loaded. Of course, assuming this actually solves it for you, too.

The docs:

Activate the WP-API plugin. Enqueue the script directly: wp_enqueue_script( 'wp-api' ); or as a dependency for your script: wp_enqueue_script( 'my_script', 'path/to/my/script', array( 'wp-api' ) );

previous answer:

It appears your JS isn't loaded. You have registered the script, but haven't enqueued it. Add wp_enqueue_script after you register it. You can also use wp_localize_script to pass dependencies to your script and make variables from your php available to it.

Both above linked to codex on those functions.

It appears your JS isn't loaded. You have registered the script, but haven't enqueued it. Add wp_enqueue_script after you register it. You can also use wp_localize_script to pass dependencies to your script and make variables from your php available to it.

Both above linked to codex on those functions.

UPDATE for Sample Plugin:

The following edit to your registering/enqueuing method removed the JS console exception on my end:

 public function enqueue_scripts() {    
    $handle = "ies-rest-api";
    $jsfileurl = plugin_dir_url( __FILE__ ) . '/ies.js';
    //wp_register_script($handle, $jsfileurl, array("wp-api"));    
    //wp_enqueue_script($handle);
    wp_register_script($handle, $jsfileurl); 
    wp_enqueue_script( $handle, $jsfileurl, array( 'wp-api' ) ); 
    
    }  
}

So, just enqueuing it as a dependency rather than registering it as one. While the docs are explicit to this, I would have to dig further into wp_register_script and wp_enqueue_script to figure out how that affects dependencies being loaded. Of course, assuming this actually solves it for you, too.

The docs:

Activate the WP-API plugin. Enqueue the script directly: wp_enqueue_script( 'wp-api' ); or as a dependency for your script: wp_enqueue_script( 'my_script', 'path/to/my/script', array( 'wp-api' ) );

previous answer:

It appears your JS isn't loaded. You have registered the script, but haven't enqueued it. Add wp_enqueue_script after you register it. You can also use wp_localize_script to pass dependencies to your script and make variables from your php available to it.

Both above linked to codex on those functions.

Source Link
hwl
  • 2.1k
  • 10
  • 15

It appears your JS isn't loaded. You have registered the script, but haven't enqueued it. Add wp_enqueue_script after you register it. You can also use wp_localize_script to pass dependencies to your script and make variables from your php available to it.

Both above linked to codex on those functions.