jewlofthelotus / SlickQuiz-WordPress

SlickQuiz is a plugin for displaying and managing pretty, dynamic quizzes. It uses the SlickQuiz jQuery plugin.
http://wordpress.org/extend/plugins/slickquiz
Other
18 stars 19 forks source link

New WP action 'slickquiz_save_quiz' and optional callback in 'admin.js' - see patch #58

Closed nfreear closed 10 years ago

nfreear commented 10 years ago

Hi, I'd like to propose a way for third-party WP plugins to save extra meta-data at the same time that a SlickQuiz is saved/ updated.

The attached patch contains PHP and Javascript proposals:

Note, the Javascript needs tidying up - see comments in the patch. Please can you advise on the neatest way for me to hook into plugin.config?

I attach a patch for SlickQuiz-WordPress, and a patch showing how I intend using the mods. in IET-OU/ ..wp-juxtalearn-quiz.

I welcome your feedback. Thanks,

Nick

nfreear commented 10 years ago

By "patch" I mean commit, of course!

Example of Javascript usage -- juxtalearn-quiz-scaffold.js

// SlickQuiz-WP/admin.js: callback.
$.fn.setPreSaveQuiz(function () {
    var trickytopic = $('#jlq-trickytopic option:selected', qEdit)

    // Append some "extra" data to the SlickQuiz POST.
    return { tricky_topic_id: trickytopic.val(), TODO: 123 };
});

Example of PHP usage -- juxtalearn_quiz_scaffold.php

<?php
// Simplified (actually a PHP class)

add_action('slickquiz_save_quiz', 'slickquiz_save_quiz');

function slickquiz_save_quiz( $quiz, $mode = 'create_draft' ) {

    $data = json_decode( $_POST['json'] );

    $extra = $data->extra;

    // Save $extra data in model for my third-party plugin.
    //...
}

Background: JuxtaLearn is an educational technology project. We're looking at ways to "scaffold" a quiz, to help teachers write more effective quizzes about "tricky topics" in STEM (science, tech., engineering and math) learning. The extra data mentioned above relates to the scaffolding.