<?php require_once __DIR__ . '/lib/load-quiz.php'; require_once __DIR__ . '/views/quiz-editor.php'; add_action('add_meta_boxes', function () { $render = function () { global $post; renderQuizEditor(loadQuiz($post)); }; add_meta_box('quizMeta', __('Quiz'), $render, 'post'); });
* requested quiz. * * PARAMETERS passed in GET: * _GET['quizFile'] xml file to open * _GET['quizIndex'] index of requested quiz in xml file * _GET['questNo'] question to return (first is 0) * _GET['score'] score the player currently has (needed for serving last page) * */ $quizFile = $cwd . '/' . $quizFolder . '/' . $_GET['quizFile']; $quizIndex = intval($_GET['quizIndex']); $questNo = intval($_GET['questNo']); $score = intval($_GET['score']); //load up the quiz include 'quizzyXML.php'; $quiz = loadQuiz($quizFile, $quizIndex); //represents where this quiz's pictures should be found $picDir = 'quizzy/' . $quizFolder . '/' . $picFolder . '/'; //see if the requested question doesn't exist if ($questNo >= count($quiz->question)) { //see what the max possible score for the quiz was $maxPossible = 0; foreach ($quiz->question as $quest) { $thisBest = 0; foreach ($quest->option as $opt) { if (intval($opt->score) > $thisBest) { $thisBest = $opt->score; } } $maxPossible += intval($thisBest); }
<?php require_once __DIR__ . '/lib/load-quiz.php'; // If this post has a quiz, then append a div to the post. The quiz will be mounted within it. add_filter('the_content', function ($content) { global $post; if (!is_singular('post')) { return $content; } $quiz = loadQuiz($post); // If we don't have a quiz, or we only have a draft quiz, then don't try to load a quiz if ($quiz === null || !isset($quiz->published) && isset($quiz->draft)) { return $content; } wp_localize_script('quiz-frontend', 'quizContent', isset($quiz->published) ? $quiz->published : $quiz); wp_localize_script('quiz-frontend', 'quizTitle', $post->post_title); wp_localize_script('quiz-frontend', 'shortUrl', wp_get_shortlink($post->ID)); wp_localize_script('quiz-frontend', 'siteUrl', site_url()); return $content . '<div id="quiz-mount-point"></div>'; }); add_action('wp_enqueue_scripts', function () { // TODO: check if post is a quiz post before enqueueing quiz scripts $staticRoute = plugin_dir_url(__DIR__) . plugin_basename(__DIR__); wp_enqueue_script('quiz-frontend', $staticRoute . '/static/quiz-app.min.js', array(), null, true); wp_enqueue_style('quiz-frontend', $staticRoute . '/static/quiz-app.min.css'); });