Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(h5p-content-hooks) : Add the ability to extend h5p plugin upon content crud #115

Open
HaidarZ opened this issue Sep 25, 2020 · 1 comment

Comments

@HaidarZ
Copy link

HaidarZ commented Sep 25, 2020

Hello guys,

Is it possible to add hooks for h5p content create/update/delete , just like what you've done with h5p_mods.
In that way we can easily integrate the h5p content within wordpress. For example we can create a custom post upon content creation that includes the h5p_content shortcode in it's body.
All of this process is now done manually and not easy for non-technical content editors.

Psuedo code

function handle_h5p_content_creation($content){
   wp_insert_post( array(
	'post_type' => 'lesson' ,
	'post_status' => 'publish',
	'post_title' => $content->title,
	'post_content' => '[h5p id="'. $content->id . '"]' ,
    ));
}

add_action('h5p_content_created', 'handle_h5p_content_creation' );

Just add the do_action hooks after the creation/update/deletion of the content.

Regards,

@kraftner
Copy link

Although hacky and messy I needed to get this to work and did it like this:

  1. Create a new WordPress plugin
  2. Copy public/class-h5p-event.php into that plugin.
  3. Add an autoloader to this plugin that loads this class. Make sure that this autoloader runs before the one from H5P. The easiest way to do this setting prepend to true on spl_autoload_register or make it a mu-plugin.
  4. Edit the Constructor of the copied H5P_Event and add do_action() calls for the intended event. Something like if($type === 'content'){ do_action('my_h5p_hooks_plugin . '_' . $sub_type); }

I have intentionally only added instructions here and no final code since this is hacky and you need to fully understand what you are doing here including being aware that you'll need to repeat this on every H5P update to handle the case of H5P_Event being changed upstream.

If you do not understand what you are doing here and/or forget to keep this in sync with H5P updates this will probably end in a fatal error taking down your entire site at some point.

You have been warned. 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants