Viewing 15 replies - 1 through 15 (of 50 total)
  • Plugin Author icc0rz

    (@icc0rz)

    Hi, this sounds quite interesting!

    Unfortunately, there’s currently no action triggered when results are logged. However, adding one shouldn’t be an issue if you could be so kind and test it, and check that it meets all your requirements. To do so you have to add the following code to the H5P plugin:

    
        /**
         * Allows you to alter a user's submitted result for a given H5P content
         * This action is fired before the result is saved.
         *
         * @since 1.7.8
         *
         * @param object &$data Has the following properties score,max_score,opened,finished,time
         * @param int $result_id Only set if updating result
         * @param int $content_id Identifier of the H5P Content
         * @param int $user_id Identfieri of the User
         */
        do_action_ref_array('h5p_alter_user_result', array(&$data, $result_id, $content_id, $user_id));
    

    This has to be placed inside the public function ajax_results() found in wp-content/plugins/h5p/admin/class-h5p-plugin-admin.php right before the following code:

    
    
        if (!$result_id) {
          // Insert new results
    

    After this, you should be able to use the action in your myCRED_Hook class:

    
      public function run() {
        add_action( 'h5p_alter_user_result',  array( $this, 'h5p_result' ) );
      }
    
      public function h5p_result( $data, $result_id, $content_id, $user_id ) {
        // Check if full score
        if ( $data['score'] !== $data['max_score'] ) return;
    
        // Make sure this is the first result for this content
        if ( $result_id ) return; // (result_id is only used when updating an old score)
    
        // Make sure this is a unique event
        if ( $this->has_entry( 'completing_h5p', '', $user_id ) ) return;
    
        // Execute
        $this->core->add_creds(
          'completing_h5p',
          $user_id,
          $this->prefs['creds'],
          $this->prefs['log'],
          0,
          '',
          $m
        );
      }
    

    I’m not 100 % sure about the myCREED parts, but this should at least give you the action/score you need.

    • This reply was modified 7 years, 10 months ago by icc0rz.

    Hi, I have the same question as rpetitto. Thank you for providing the code!
    Where exactly am I supposed to paste in the last chunk of code (the part that begins with “public function run()….” ?

    Plugin Author icc0rz

    (@icc0rz)

    I just took a code part from the class described at myCRED Hooks 101 and modified it a bit. I believe you will have to add the whole class to your theme’s functions.php file or you can create a small custom plugin for your site where you keep custom stuff.

    Thanks! I’m not so familiar with php so don’t really understand how to edit the code myself. Can you send me the entire code that I should paste into my themes.php file?

    @icc0rz thanks, for the code, however, I tried your snippet in my myCRED hook but it doesn’t work.

    The hook is working properly because I tried it with a different trigger and it worked fine. So I’m assuming it’s the H5P part of the myCRED code or the code added to the H5P plugin to create and action trigger.

    Any suggestions you have for a fix would be much appreciated.

    It would be great if H5P could be connected to MyCred. I am sure there are other scoring plugins but MyCred has worked really well for us and if we were easily able to link it to H5P content, the combination would make a great interactive quiz package.

    Plugin Author icc0rz

    (@icc0rz)

    I agree that it would be great to be able to give myCred points for H5P results. I’ve added triggering of the action required to the H5P plugin: 04c60c8 and also an example on how to use it: 2a03e17. What’s left now is to create an adapter plugin that registers a myCred hook and listens for the H5P plugin to trigger the new action. I’m not that familiar with the myCred plugin, I’ve only tested it once. I will try to have a go at this when I get some spare time. Others are welcome to try.

    Thread Starter rpetitto

    (@rpetitto)

    Thanks for your diligence! I just saw this updated thread. I’ll attempt to install and see if I can get it working!

    Thread Starter rpetitto

    (@rpetitto)

    No dice. I managed to get the H5P Hook visible within myCred, but it doesn’t awards any points. Please take a look at this custom myCRED hook as it would mimic what h5P hopes to accomplish:
    https://mycred.me/code-snippets/custom-hook-wp-pro-quiz-plugin/

    @icc0rz I can confirm @rpetitto findings. I used your updated code in my myCRED hook about two weeks ago and got the same results. The myCRED hook is working but the H5P code doesn’t trigger the myCRED hook to give points.

    • This reply was modified 7 years, 8 months ago by mobetman2.
    Plugin Author icc0rz

    (@icc0rz)

    I copied the example and replaced some code as a small proof of concept: https://github.com/icc/mycred-h5p

    You should be able to see H5P log entries once you enable the plugin and the hook. Though, I’m not sure how you really want it to behave. Feel free to push back any changes you make so everyone can enjoy them ??

    Thread Starter rpetitto

    (@rpetitto)

    Hi @icc0rz,

    I was able to successfully download and install the plugin. However, I still do not see log entries after activating the hook. Did I miss a step? Does the h5P Mod plugin need to be installed/configured somehow?

    Plugin Author icc0rz

    (@icc0rz)

    @rpetitto, make sure you apply the patch I linked to in my previous post: 04c60c8. It’s still in a testing state so it hasn’t been released yet. Hopefully, it will be part of the upcoming version of the plugin.

    Thread Starter rpetitto

    (@rpetitto)

    I applied the patch. Will test in just a moment. Do I need h5P Mod installed?

    Thread Starter rpetitto

    (@rpetitto)

    Wait…Got it to work!!! Gonna tweak the preferences a bit to see if I can customize the values! I’ll keep you posted.

Viewing 15 replies - 1 through 15 (of 50 total)
  • The topic ‘H5P myCRED Hook’ is closed to new replies.