wordpress plugin - instantiate the plugin after ajax call

Forums: 

Hi,

I've installed the h5p plugin in wordpress and i'm calling the shortcode as usual. This doesn't work on posts that are loaded via ajax, it returns an empty iframe. 

I could instantiate the plugin via H5P.init(); on javascript, but H5P doesn't exist. Which script should I enqueue for it to work?

The js AJAX event:

jQuery.post(ajax_object.ajax_url, data, function(response) {

$('.course-content').html(response);

});

where "response" comes from this php function

 

function loadh5pQuiz ($postID, $section, $chapterNr, $subchapterNr) {

$class = $postID . "-". $section;

$h5p = '<div id="h5p-' . $class . '" class="container h5p h5p-' . $class . '">';

$h5p .= '<div class="quiz-' .$class.'">' . do_shortcode( '[h5p id="1"]') . '</div>';

$plugin = \H5P_Plugin::get_instance();

$plugin->add_settings();

$h5p .= "</div>";

echo $h5p;

}			

 

any hints?

icc's picture

There is a small guide available here:
https://github.com/h5p/h5p-wordpress-plugin/issues/8