Changeset 1936148
- Timestamp:
- 09/05/2018 11:36:43 AM (8 years ago)
- Location:
- qnotsquiz
- Files:
-
- 12 edited
-
assets/screenshot-1.png (modified) (previous)
-
assets/screenshot-2.png (modified) (previous)
-
assets/screenshot-3.png (modified) (previous)
-
assets/screenshot-4.png (modified) (previous)
-
assets/screenshot-5.png (modified) (previous)
-
assets/screenshot-6.png (modified) (previous)
-
assets/screenshot-7.png (modified) (previous)
-
trunk/README.txt (modified) (4 diffs)
-
trunk/css/style.css (modified) (12 diffs)
-
trunk/js/script.js (modified) (8 diffs)
-
trunk/qnotsquiz.php (modified) (11 diffs)
-
trunk/uninstall.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
qnotsquiz/trunk/README.txt
r1926810 r1936148 6 6 Requires at least: 4.9.8 7 7 Tested up to: 4.9.8 8 Stable tag: 1. 0.08 Stable tag: 1.1.0 9 9 License: GPLv2 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html 11 11 12 Create quizzes with eazy navigations.12 Create quizzes and show results and answers in awesome way. 13 13 14 14 == Description == 15 create quizzes with easy navigations. 15 create quizzes with easy navigations. view result in a pie chart. 16 view solutions and leaderboard. 16 17 17 18 == Installation == … … 19 20 This section describes how to install the plugin and get it working. 20 21 21 1. Upload qnotsquiz.zip file in plugins 22 2. This plugin requires ACF- Advanced custom fields plugin to run properly. Please make sure it is installed before activating qnotsquiz plugin. 23 2. Activate and start make quizzes 22 1. Upload qnotsquiz.zip file in plugins folder. 23 2. Activate and create questions. Add questions to quizzes. 24 24 3. Find the shortcode for each quiz at quiz dashboard 25 25 4. Paste the shortcode anywhere in yours posts or pages … … 36 36 == Screenshots == 37 37 38 1.starting point of the quiz 39 2.question with navigation 40 3.result screen 41 4.show solutions 42 5.add new question 43 6.creating a new quiz. find and copy the shortcode to be pasted 44 7.paste the shortcode in posts or pages 38 1.QnotQuiz menu shows general screen with option to customise quiz starting text 39 2.Question dashboard 40 3.Add new question 41 4.Add new quiz 42 5.Quiz dashboard with shortcode to be copied and pasted at pages or posts 43 6.Paste the shortcode on pages or posts with quiz instructions 44 7.Click on the start button to start the quiz 45 8.Quiz starting page shows quiz numbers and option to toggle(view) navigator 46 9.Navigator visible 47 10.Result screen 48 11.View solutions screen 49 12.Leaderboard 45 50 46 51 == Changelog == 52 53 = 1.1.0 = 54 * Structured admin menu. 55 * Show result in a pie chart 56 * Packaged ACF plugin. So no need to install it separately. 57 * Shows view solutions in a separate link 58 * View leaderboard 47 59 48 60 = 1.0.0 = … … 52 64 == Upgrade Notice == 53 65 66 =1.0.0= 67 Improved QnotsQuiz with result chart and leaderboard sections. 68 54 69 = 1.0.0 = 55 70 Initial version -
qnotsquiz/trunk/css/style.css
r1926809 r1936148 16 16 border-style: solid; 17 17 overflow: auto; 18 18 box-sizing: border-box; 19 padding: 20px; 20 } 21 .chart-container{ 22 position: relative; 23 height:20vh; 24 width:40vw; 25 min-height: 320px; 26 min-width: 320px; 27 margin-left: auto; 28 margin-right: auto 29 } 30 31 32 .solutionInstruction{ 33 34 text-align: center; 35 } 36 37 .lbdisplayheader{ 38 list-style-type: none; 39 background-color: lightblue; 40 width:320px; 41 padding: 10px; 42 margin: 1px auto auto; 43 text-align: left 44 } 45 46 .lbdisplayheader li{ 47 48 display: inline-flex; 49 padding: 5px; 50 color:white; 51 width: 33%; 52 53 } 54 .lbdisplay{ 55 list-style-type: none; 56 57 width:320px; 58 padding: 10px; 59 margin: auto; 60 text-align: left; 61 62 border-width:0px; 63 border-bottom: 1px; 64 border-style: solid; 65 border-color: lightblue; 66 } 67 68 69 .lbdisplay li{ 70 71 display: inline-flex; 72 padding: 5px; 73 color:lightblue; 74 width: 33% 75 76 77 } 78 79 .final ul{ 80 list-style-type: none; 81 } 82 .final li{ 83 display: inline-flex; 84 background-color:white ; 85 padding: 10px; 86 margin: 3px; 87 color: lightblue; 88 font-weight: 300px; 89 90 } 91 92 .final .active{ 93 background-color: lightblue; 94 color: white; 19 95 } 20 96 .hiddenID{ … … 22 98 } 23 99 #result li{ 24 background-color: lightblue; 100 25 101 color: white; 26 width:60%; 27 margin: auto; 28 102 103 margin: 1px; 104 margin-left: auto; 105 margin-right: auto; 106 display: inline-grid; 107 108 } 109 110 .resultSections_score{ 111 background-color: lightblue; 112 width: 100px; 113 height: 100px; 114 } 115 .resultSections_correct{ 116 width: 100px; 117 height: 100px; 118 background-color: lightgreen; 119 } 120 .resultSections_incorrect{ 121 width: 100px; 122 height: 100px; 123 background-color: red; 124 } 125 .resultSections_notattempted{ 126 width: 100px; 127 height: 100px; 128 background-color: grey; 129 } 130 131 .scoreDisplay{ 132 font-size: 40px; 29 133 } 30 134 #result{ … … 36 140 } 37 141 .questnav{ 38 margin -top: 3%;142 margin: 0px; 39 143 list-style-type: none; 40 padding-right: 24px; 144 padding: 0px; 145 margin-top:10px; 41 146 display: inline-flex; 42 147 width: 100%; … … 48 153 position: relative; 49 154 top: 10%; 50 51 52 53 text-align: center; 54 155 text-align: center; 55 156 background-color:white; 56 157 } … … 72 173 } 73 174 175 .option:hover{ 176 background-color: lightblue; 177 } 178 179 .insideQuest{ 180 margin: 5px; 181 } 182 74 183 .attempted{ 75 184 background-color: lightblue; … … 78 187 79 188 .question{ 80 padding: 20px;189 padding: 20px; 81 190 margin-top: 10px; 82 191 margin-bottom: 10px; 83 192 text-align: center; 193 max-width: 80%; 194 min-width: 60%; 195 margin-left: auto; 196 margin-right: auto; 197 font-size: 1.5rem; 198 font-weight: 100px; 84 199 85 200 } 86 201 #startQuizBtn{ 87 202 background-color: lightblue; 88 203 width: fit-content; 204 padding: 10px; 205 color: white; 206 font-weight: bold; 89 207 } 90 208 #next{ … … 108 226 109 227 } 110 228 .showprogress{ 229 font-size: 1rem; 230 color: lightblue; 231 } 232 .hideprogress{ 233 font-size: 1rem; 234 color: lightgrey; 235 } 236 237 button{ 238 padding:10px 24px; 239 border: none; 240 border-radius: 0px; 241 } 111 242 112 243 .progress{ 113 display: flex; 244 114 245 padding:10px; 115 width: 100%; 246 116 247 border: 1px; 117 248 border-style: solid; … … 122 253 margin-bottom:15%; 123 254 } 255 256 .progressBtn{ 257 border-radius: 100%; 258 border-style:solid; 259 padding: 8px 15px; 260 261 262 263 264 } 265 124 266 .holder{ 125 width: 30px; 267 126 268 margin: 5px; 127 269 text-align: center; … … 130 272 } 131 273 .holderUnattempted{ 132 width: 30px; 274 133 275 margin: 5px; 134 276 text-align: center; … … 137 279 } 138 280 .holderupdated{ 139 width: 30px; 281 140 282 margin: 5px; 141 283 text-align: center; … … 153 295 154 296 .correctflag{ 155 width: 30px; 297 156 298 margin: 5px; 157 299 text-align: center; … … 161 303 } 162 304 .wrongflag{ 163 width: 30px; 305 164 306 margin: 5px; 165 307 text-align: center; -
qnotsquiz/trunk/js/script.js
r1926809 r1936148 6 6 var quizposts = new Object(); 7 7 var post1 = new Object(); 8 var url=jQuery("#url"). text();8 var url=jQuery("#url").data('url'); 9 9 var notattempted=0; 10 10 var totQuestions=0; 11 11 var resp=new Array(); 12 var quizid=jQuery("#quizid"). text();12 var quizid=jQuery("#quizid").data('quizid'); 13 13 jQuery.getJSON(url+'/wp-json/wp/v2/quiz/'+quizid,function(post){ 14 14 quizposts=post; … … 30 30 }); 31 31 32 32 //jQuery("#close").confirm(); 33 33 34 34 jQuery("#close").click(function() { 35 if(confirm("Are you sure you want to exit this quiz?")){ 35 36 document.getElementById("quiz").style.display = "none"; 36 37 jQuery("#startQuizBtn").removeClass("nav"); 37 } );38 } }); 38 39 39 40 jQuery("#startQuizBtn").click(function() { 40 41 document.getElementById("quiz").style.display = "block"; 41 jQuery(".progress").removeClass("hide");42 //jQuery(".progress").removeClass("hide"); 42 43 jQuery(".totalQuestions").addClass("nav"); 43 44 jQuery(".quizTitle").addClass("nav"); … … 52 53 53 54 function afterQuizOver(){ 54 jQuery(".insideQuest").html(` 55 <ul id="result"> 56 <li class="resultSections">Your score ${correct}/${totQuestions}</li> 57 <li class="resultSections">Correct : ${correct}</li> 58 <li class="resultSections">InCorrect : ${wrong}</li> 59 <li class="resultSections">Unattempted : ${notattempted}<br></li> 60 </ul> 61 <div id="afterquiz"> 62 <div class="question"></div> 63 <div class="option1 option"></div> 64 <div class="option2 option"></div> 65 <div class="option3 option"></div> 66 <div class="option4 option"></div> 67 </div> 68 69 `); 55 jQuery(".insideQuest").removeClass("hide"); 56 jQuery(".option1").removeClass("correct incorrect"); 57 jQuery(".option2").removeClass("correct incorrect"); 58 jQuery(".option3").removeClass("correct incorrect"); 59 jQuery(".option4").removeClass("correct incorrect"); 60 // jQuery(".insideQuest").html(` 61 // <ul id="result"> 62 // <li class="resultSections">Your score ${correct}/${totQuestions}</li> 63 // <li class="resultSections">Correct : ${correct}</li> 64 // <li class="resultSections">InCorrect : ${wrong}</li> 65 // <li class="resultSections">Unattempted : ${notattempted}<br></li> 66 // </ul> 67 // <div id="afterquiz"> 68 // <div class="question"></div> 69 // <div class="option1 option"></div> 70 // <div class="option2 option"></div> 71 // <div class="option3 option"></div> 72 // <div class="option4 option"></div> 73 // </div> 74 75 // `); 70 76 71 77 } … … 108 114 }); 109 115 116 117 118 119 120 110 121 jQuery(document).on('click', '.holder', function (e) { 111 122 … … 120 131 jQuery(document).on('click', '.holderupdated', function (e) { 121 132 122 var viewAnsID=(this.innerHTML)-1; 123 getQuestion(quizid,viewAnsID); 124 125 126 127 e.preventDefault(); 133 var viewAnsID=(this.innerHTML)-1; 134 getQuestion(quizid,viewAnsID); 135 e.preventDefault(); 128 136 }); 129 137 … … 212 220 213 221 }); 222 //show hide navigator 223 224 jQuery(document).on('click', '.showprogress', function (e) { 225 jQuery(".progress").removeClass("hide"); 226 jQuery(".navigator").addClass("hideprogress"); 227 jQuery(".navigator").removeClass("showprogress") 228 229 e.preventDefault(); 230 }); 231 232 233 234 jQuery(document).on('click', '.hideprogress', function (e) { 235 236 jQuery(".progress").addClass("hide"); 237 jQuery(".navigator").addClass("showprogress"); 238 jQuery(".navigator").removeClass("hideprogress"); 239 e.preventDefault(); 240 }); 241 242 // jQuery(".hideprogress").click(function() { 243 244 // jQuery(".progress").addClass("hide"); 245 // jQuery(".navigator").addClass("showprogress"); 246 // jQuery(".navigator").removeClass("hideprogress"); 247 248 249 // }); 214 250 215 251 //after finishing the quiz result and solution navigation should be present … … 247 283 jQuery(".insideQuest").html(` 248 284 249 285 <h1>Your have scored ${correct} out of ${totQuestions}</h1> 250 286 <ul id="result"> 251 <li class="resultSections">Your score ${correct}/${totQuestions}</li> 252 <li class="resultSections">Correct : ${correct}</li> 253 <li class="resultSections">InCorrect : ${wrong}</li> 254 <li class="resultSections">Unattempted : ${notattempted}<br></li> 287 <li class="resultSections resultSections_correct">Correct<span class="scoreDisplay">${correct}</span></li> 288 <li class="resultSections resultSections_incorrect">InCorrect<span class="scoreDisplay">${wrong}</span></li> 289 <li class="resultSections resultSections_notattempted">Skipped<span class="scoreDisplay">${notattempted}</span><br></li> 255 290 </ul> 291 <div class="chart-container"> 292 <canvas id="myChart" ></canvas> 293 </div> 256 294 257 295 `); 258 jQuery("#qno").text("RESULTS"); 296 var ctx = document.getElementById("myChart"); 297 var myChart = new Chart(ctx, { 298 type: 'pie', 299 data: { 300 labels: ['correct','incorrect','skipped'], 301 302 datasets: [ 303 { 304 data: [correct,wrong,notattempted], 305 backgroundColor: [ 306 "green", 307 "red", 308 "grey" 309 ] 310 } 311 ] 312 } 313 }); 314 jQuery("#qno").text(""); 315 jQuery(".progress").addClass("hide"); 316 jQuery(".navigator").addClass("hide"); 317 jQuery(".final").removeClass("hide"); 259 318 document.getElementById("next").style.display = "none"; 260 319 document.getElementById("prev").style.display = "none"; 261 320 document.getElementById("finish").style.display = "none"; 262 263 264 }); 321 //creating new attempt post via json 322 i=0; 323 var attemptLog=''; 324 while(i<totQuestions){ 325 attemptLog+=resp[i][0]+'|'+resp[i][1]+','; 326 i++; 327 } 328 329 jQuery.ajax({ 330 method: "POST", 331 url: POST_SUBMITTER.root + 'qnotsAttempts/v1/qnots_attempts', 332 data : { 333 'quiz_id':quizid, 334 'attempts_log':attemptLog, 335 'score':correct}, 336 beforeSend: function ( xhr ) { 337 xhr.setRequestHeader( 'X-WP-Nonce', POST_SUBMITTER.nonce ); 338 }, 339 success : function( response ) { 340 //console.log( response ); 341 alert( POST_SUBMITTER.success ); 342 }, 343 fail : function( response ) { 344 //console.log( response ); 345 alert( POST_SUBMITTER.failure ); 346 } 347 348 }); 349 350 }); 351 352 jQuery("#finalSectionSolutions").click(function() { 353 jQuery("#qno").html('<div class="solutionInstruction">Click on a question to view solution.</div>'); 354 jQuery("#finalSectionResult").removeClass("active"); 355 jQuery("#finalSectionLeaderBoard").removeClass("active"); 356 jQuery("#finalSectionSolutions").addClass("active"); 357 jQuery(".progress").removeClass("hide"); 358 359 360 jQuery(".insideQuest").html(` 361 362 363 <div id="afterquiz"> 364 <div class="question"></div> 365 <div class="option1 option"></div> 366 <div class="option2 option"></div> 367 <div class="option3 option"></div> 368 <div class="option4 option"></div> 369 </div> 370 371 `); 372 jQuery(".insideQuest").addClass("hide"); 373 374 }); 375 jQuery("#finalSectionResult").click(function() { 376 jQuery("#qno").text(""); 377 jQuery(".progress").addClass("hide"); 378 jQuery("#finalSectionSolutions").removeClass("active"); 379 jQuery("#finalSectionLeaderBoard").removeClass("active"); 380 jQuery("#finalSectionResult").addClass("active"); 381 jQuery(".insideQuest").removeClass("hide"); 382 jQuery(".insideQuest").html(` 383 384 <h1>Your have scored ${correct} out of ${totQuestions}</h1> 385 <ul id="result"> 386 <li class="resultSections resultSections_correct">Correct<span class="scoreDisplay">${correct}</span></li> 387 <li class="resultSections resultSections_incorrect">InCorrect<span class="scoreDisplay">${wrong}</span></li> 388 <li class="resultSections resultSections_notattempted">Skipped<span class="scoreDisplay">${notattempted}</span><br></li> 389 </ul> 390 <div class="chart-container"> 391 <canvas id="myChart" ></canvas> 392 </div> 393 394 `); 395 var ctx = document.getElementById("myChart"); 396 var myChart = new Chart(ctx, { 397 type: 'pie', 398 data: { 399 labels: ['correct','incorrect','skipped'], 400 401 datasets: [ 402 { 403 data: [correct,wrong,notattempted], 404 backgroundColor: [ 405 "green", 406 "red", 407 "grey" 408 ] 409 } 410 ] 411 } 412 }); 413 414 415 }); 416 417 418 //Leaderboard section 419 jQuery("#finalSectionLeaderBoard").click(function() { 420 jQuery("#qno").text(""); 421 jQuery(".progress").addClass("hide"); 422 jQuery("#finalSectionResult").removeClass("active"); 423 jQuery("#finalSectionSolutions").removeClass("active"); 424 jQuery("#finalSectionLeaderBoard").addClass("active"); 425 jQuery(".insideQuest").removeClass("hide"); 426 //jQuery.getJSON(url+'/wp-json/wp/v2/qnots_attempts/?filter[orderby]=meta_value_num&filter[meta_key]=score&filter[order]=desc&filter[meta_key]=quiz_id&filter[meta_value]='+quizid,function(attempts){ 427 //for(i = 0; i < Object.keys(attempts).length; i++) { 428 // attempts.sort(function(a, b){ 429 // return b.score - a.score; 430 // }); 431 jQuery.getJSON(url+'/wp-json/qnotsAttempts/v1/qnots_attempts/?quiz_id='+quizid,function(attempts){ 432 var attemptsData='<div>Top 10 scorers</div><br><div><ul class="lbdisplayheader"><li>Rank</li><li>Name</li><li>Score</li></ul></div>'; 433 for(i = 0; i < Object.keys(attempts).length&&i<10; i++) { 434 435 attemptsData+='<div><ul class="lbdisplay"><li>'+(i+1)+'</li><li>'+attempts[i].user_name+'</li><li>'+attempts[i].score+'</li></ul></div>'; 436 } 437 438 jQuery(".insideQuest").html(` 439 ${attemptsData} 440 441 `); 442 443 }); 444 }); 445 446 265 447 //sets the attempt flag 266 448 function setAttemptFlag(flag){ … … 313 495 314 496 while(i<qcount) 315 { questHolder+='<button class=" holder" id="q'+i+'">'+(i+1)+'</button>';497 { questHolder+='<button class="progressBtn holder" id="q'+i+'">'+(i+1)+'</button>'; 316 498 i++; } 317 499 jQuery(".progress").html(questHolder); -
qnotsquiz/trunk/qnotsquiz.php
r1926809 r1936148 11 11 //if this file accessed directly then exit 12 12 13 14 13 15 if( !defined('ABSPATH')){ 14 16 die; … … 16 18 17 19 //check for ACF installed or not 18 if( !function_exists( 'the_field' ) ) {20 /*if( !function_exists( 'the_field' ) ) { 19 21 add_action( 'admin_notices', 'qnotsquiz_my_acf_notice' ); 20 22 } … … 28 30 </div> 29 31 <?php 30 } 32 }*/ 33 34 //packaging acf 35 // 1. customize ACF path 36 add_filter('acf/settings/path', 'my_acf_settings_path'); 37 38 function my_acf_settings_path( $path ) { 39 40 // update path 41 $path = plugin_dir_path( __FILE__ ) .('/acf/'); 42 43 // return 44 return $path; 45 46 } 47 48 49 // 2. customize ACF dir 50 add_filter('acf/settings/dir', 'my_acf_settings_dir'); 51 52 function my_acf_settings_dir( $dir ) { 53 54 // update path 55 $dir = plugins_url('/acf/'); 56 57 // return 58 return $dir; 59 60 } 61 62 63 // 3. Hide ACF field group menu item 64 add_filter('/acf/settings/show_admin', '__return_false'); 65 66 67 // 4. Include ACF 68 include_once( plugin_dir_path( __FILE__ ) .('/acf/acf.php') ); 31 69 32 70 … … 35 73 wp_register_style( 'qnotsquiz_style',plugins_url('/css/style.css', __FILE__), array(), '1.1', 'all'); 36 74 wp_register_script( 'qnotsquiz_script',plugins_url('/js/script.js', __FILE__), array ( 'jquery' ), 1.1, true); 75 wp_register_script( 'qnotsquiz_chart_script','https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.min.js', array ( 'jquery' ), 1.1, true); 37 76 wp_enqueue_style('qnotsquiz_style'); 38 77 wp_enqueue_script('qnotsquiz_script'); 78 wp_enqueue_script('qnotsquiz_chart_script'); 79 //localize data for script 80 wp_localize_script( 'qnotsquiz_script', 'POST_SUBMITTER', array( 81 'root' => esc_url_raw( rest_url() ), 82 'nonce' => wp_create_nonce( 'wp_rest' ), 83 'success' => __( 'Thanks for your submission!', 'your-text-domain' ), 84 'failure' => __( 'Your submission could not be processed.', 'your-text-domain' ), 85 'current_user_id' => get_current_user_id() 86 ) 87 ); 39 88 } 40 89 add_action( 'wp_enqueue_scripts', 'qnotsquiz_add_scripts' ); … … 64 113 'get_callback' => function(){return get_field('correctanswer');} 65 114 )); 66 } 115 register_rest_field('qnots_attempts','user_id',array( 116 'get_callback' => function(){return get_field('user_id');} 117 )); 118 register_rest_field('qnots_attempts','user_name',array( 119 'get_callback' => function(){return get_field('user_name');} 120 )); 121 register_rest_field('qnots_attempts','quiz_id',array( 122 'get_callback' => function(){return get_field('quiz_id');} 123 )); 124 register_rest_field('qnots_attempts','attempts_log',array( 125 'get_callback' => function(){return get_field('attempts_log');} 126 )); 127 register_rest_field('qnots_attempts','score',array( 128 'get_callback' => function(){return get_field('score');} 129 )); 130 register_rest_route( 'qnotsAttempts/v1/','/qnots_attempts',array( 131 'methods'=>'POST', 132 'callback'=>'updateQnotsAttempts' 133 )); 134 register_rest_route( 'qnotsAttempts/v1/','/qnots_attempts',array( 135 'methods' => WP_REST_SERVER::READABLE, 136 'callback' => 'getQnotsAttempts', 137 138 )); 139 } 140 141 function getQnotsAttempts($data){ 142 $qnotsAmps=new WP_Query(array( 143 'post_type'=>'qnots_attempts', 144 'posts_per_page' => -1, 145 'nopaging' => true, 146 'orderby'=>'meta_value_num', 147 'meta_key'=>'score', 148 'order'=>'desc' 149 )); 150 $attempsList=array(); 151 while($qnotsAmps->have_posts()){ 152 $qnotsAmps->the_post(); 153 if($data['quiz_id']==get_field('quiz_id')){ 154 array_push($attempsList,array( 155 'user_name'=>get_field('user_name'), 156 'score'=>get_field('score') 157 )); 158 } 159 } 160 return $attempsList; 161 } 162 163 // flush_rewrite_rules(true); // FIXME: <------- DONT LEAVE ME HERE 164 // } 165 166 67 167 add_action('rest_api_init','qnotsquiz_qnotsquiz_rest'); 168 169 add_action( 'rest_api_init', 'wp_rest_filter_add_filters' ); 170 /** 171 * Add the necessary filter to each post type 172 **/ 173 function wp_rest_filter_add_filters() { 174 foreach ( get_post_types( array( 'show_in_rest' => true ), 'objects' ) as $post_type ) { 175 add_filter( 'rest_' . $post_type->name . '_query', 'wp_rest_filter_add_filter_param', 10, 2 ); 176 } 177 } 178 /** 179 * Add the filter parameter 180 * 181 * @param array $args The query arguments. 182 * @param WP_REST_Request $request Full details about the request. 183 * @return array $args. 184 **/ 185 function wp_rest_filter_add_filter_param( $args, $request ) { 186 // Bail out if no filter parameter is set. 187 if ( empty( $request['filter'] ) || ! is_array( $request['filter'] ) ) { 188 return $args; 189 } 190 $filter = $request['filter']; 191 if ( isset( $filter['posts_per_page'] ) && ( (int) $filter['posts_per_page'] >= 1 && (int) $filter['posts_per_page'] <= 100 ) ) { 192 $args['posts_per_page'] = $filter['posts_per_page']; 193 } 194 global $wp; 195 $vars = apply_filters( 'rest_query_vars', $wp->public_query_vars ); 196 function allow_meta_query( $valid_vars ) 197 { 198 $valid_vars = array_merge( $valid_vars, array( 'meta_query', 'meta_key', 'meta_value', 'meta_compare' ) ); 199 return $valid_vars; 200 } 201 $vars = allow_meta_query( $vars ); 202 203 foreach ( $vars as $var ) { 204 if ( isset( $filter[ $var ] ) ) { 205 $args[ $var ] = $filter[ $var ]; 206 } 207 } 208 return $args; 209 } 210 211 //save quiz attempts 212 function updateQnotsAttempts($data){ 213 $current_user = wp_get_current_user(); 214 if ( 0 == $current_user->ID ) { 215 $user_name='Guest'; 216 } else { 217 $user_name=$current_user->display_name; 218 219 } 220 wp_insert_post(array( 221 222 'post_title'=>'new quizAttempt', 223 'post_type'=>'qnots_attempts', 224 225 226 'post_status' => 'publish', 227 228 meta_input=>array( 229 'user_id'=> get_current_user_id(), 230 'user_name'=> $user_name, 231 'quiz_id'=> $data['quiz_id'], 232 'attempts_log'=> $data['attempts_log'], 233 'score'=>$data['score'] 234 ) 235 )); 236 } 68 237 69 238 70 239 // overall template of the qnotsquiz 71 240 function qnotsquiz_shortcode ($qnotsquizID) { 241 ob_start(); 242 243 if(!get_option( 'qnotsquiz_start_text' )) 244 $qnotsquiz_custom_start_text="START"; 245 else 246 $qnotsquiz_custom_start_text=get_option( 'qnotsquiz_start_text' ); 247 248 249 72 250 ?> 73 251 <div class="quiz" id="quiz"> 74 <label id="qno">Question 1 of totalQuestions</label> 252 <!-- <div class="quizTitle hide"><?php echo get_the_title();?></div> 253 <div class="quizLink hide"><?php echo the_permalink();?></div> --> 75 254 <button id="close">close</button> 255 <div class="final hide"> 256 <ul> 257 <li id="finalSectionResult" class=" active">Results</li> 258 <li id="finalSectionSolutions"class="">View Solutions</li> 259 <li id="finalSectionLeaderBoard"class="">LeaderBoard</li> 260 261 </ul> 262 </div> 263 264 <label id="qno">Question 1 of totalQuestions</label> 265 76 266 <div class="questcontent"> 77 <div class="hide" id="url"><?php echo get_site_url();?></div>78 <div class="hiddenID" id="quizid"><?php echo $qnotsquizID[0]; ?></div>267 <div class="hide" data-url="<?php echo get_site_url();?>" id="url"></div> 268 <div class="hiddenID" data-quizid="<?php echo $qnotsquizID[0]; ?>" id="quizid"></div> 79 269 <div class="hiddenID" id="questionid">0</div> 80 270 … … 95 285 <li class="next"><button class="nav" id="next">Next</button></li> 96 286 </ul> 97 98 <div class="progress"> 287 <div class="navigator showprogress"> 288 Toggle Navigator 289 </div> 290 <div class="progress hide"> 99 291 </div> 292 100 293 </div> 101 294 102 295 </div> 103 < button id="startQuizBtn">START</button>296 <div id="startQuizBtn"><?php echo $qnotsquiz_custom_start_text; ?></div> 104 297 105 298 <?php 299 300 $ReturnString = ob_get_contents(); 301 ob_end_clean(); 302 return $ReturnString; 106 303 } 107 304 add_shortcode('qnotsquiz', 'qnotsquiz_shortcode'); … … 128 325 register_post_type('quiz',array( 129 326 'show_in_rest' => true, 130 327 'show_in_menu' => false, 131 328 'supports'=>array('title','editor'), 132 329 'rewrite' => array('slug'=>'quiz'), … … 141 338 register_post_type('questions',array( 142 339 'show_in_rest' => true, 340 'show_in_menu' => false, 143 341 'supports'=>array('title'), 144 342 'rewrite' => array('slug'=>'questions'), … … 147 345 'labels' => array( 148 346 'name' => 'questions' 347 ), 348 349 )); 350 351 register_post_type('qnots_attempts',array( 352 'show_in_rest' => true, 353 354 'rest_controller_class' => 'WP_REST_Posts_Controller', 355 'show_in_menu' => false, 356 'supports'=>array('title'), 357 'rewrite' => array('slug'=>'qnots_attempts'), 358 'has_archive' => true, 359 'public' => true, 360 'labels' => array( 361 'name' => 'qnots_attempts' 149 362 ), 150 363 … … 305 518 'menu_order' => 0, 306 519 )); 520 register_field_group(array ( 521 'id' => 'acf_qnots_attempts', 522 'title' => 'qnots_attempts', 523 'fields' => array ( 524 array ( 525 'key' => 'field_5b7f9e3407c34', 526 'label' => 'user_id', 527 'name' => 'user_id', 528 'type' => 'text', 529 'default_value' => '', 530 'placeholder' => '', 531 'prepend' => '', 532 'append' => '', 533 'formatting' => 'html', 534 'maxlength' => '', 535 ), 536 array ( 537 'key' => 'field_5b838ec788f58', 538 'label' => 'user_name', 539 'name' => 'user_name', 540 'type' => 'text', 541 'default_value' => '', 542 'placeholder' => '', 543 'prepend' => '', 544 'append' => '', 545 'formatting' => 'html', 546 'maxlength' => '', 547 ), 548 array ( 549 'key' => 'field_5b7f9ea607c35', 550 'label' => 'quiz_id', 551 'name' => 'quiz_id', 552 'type' => 'text', 553 'default_value' => '', 554 'placeholder' => '', 555 'prepend' => '', 556 'append' => '', 557 'formatting' => 'html', 558 'maxlength' => '', 559 ), 560 array ( 561 'key' => 'field_5b7f9f5107c36', 562 'label' => 'attempts_log', 563 'name' => 'attempts_log', 564 'type' => 'text', 565 'default_value' => '', 566 'placeholder' => '', 567 'prepend' => '', 568 'append' => '', 569 'formatting' => 'html', 570 'maxlength' => '', 571 ), 572 array ( 573 'key' => 'field_5b7fa03107c37', 574 'label' => 'score', 575 'name' => 'score', 576 'type' => 'number', 577 'default_value' => '', 578 'placeholder' => '', 579 'prepend' => '', 580 'append' => '', 581 'min' => '', 582 'max' => '', 583 'step' => '', 584 ), 585 ), 586 'location' => array ( 587 array ( 588 array ( 589 'param' => 'post_type', 590 'operator' => '==', 591 'value' => 'qnots_attempts', 592 'order_no' => 0, 593 'group_no' => 0, 594 ), 595 ), 596 ), 597 'options' => array ( 598 'position' => 'normal', 599 'layout' => 'no_box', 600 'hide_on_screen' => array ( 601 ), 602 ), 603 'menu_order' => 0, 604 )); 307 605 } 308 606 … … 312 610 //while initialisation show custom post types 313 611 add_action('init','qnotsquiz_postTypes'); 612 613 //Add admin menu 614 add_action( 'admin_menu', 'qnotsquiz_admin_menu' ); 615 616 function qnotsquiz_admin_menu(){ 617 618 $page_title = 'QnotsQuiz'; 619 $menu_title = 'QnotsQuiz'; 620 $capability = 'manage_options'; 621 $menu_slug = 'qnotsquiz'; 622 $function = 'qnotsquiz_settings_page'; 623 $icon_url = 'dashicons-editor-help'; 624 $position = 99; 625 626 add_menu_page( $page_title, 627 $menu_title, 628 $capability, 629 $menu_slug, 630 $function, 631 $icon_url, 632 $position ); 633 634 add_submenu_page('qnotsquiz', 'General', 'General', 'manage_options', 'qnotsquiz'); 635 add_submenu_page('qnotsquiz', 'Quizzes', 'Quizzes', 'manage_options', 'edit.php?post_type=quiz'); 636 add_submenu_page('qnotsquiz', 'Questions', 'Questions', 'manage_options', 'edit.php?post_type=questions'); 637 638 } 639 640 if( !function_exists("qnotsquiz_settings_page") ) 641 { 642 function qnotsquiz_settings_page(){ 643 if(!get_option( 'qnotsquiz_start_text' )) 644 $qnotsquiz_custom_start_text="START"; 645 else 646 $qnotsquiz_custom_start_text=get_option( 'qnotsquiz_start_text' ); 647 ?> 648 649 <h1>QnotsQuiz Settings</h1> 650 <form method="post" action="options.php"> 651 <?php settings_fields( 'qnotsquiz-settings' ); ?> 652 <?php do_settings_sections( 'qnotsquiz-settings' ); ?> 653 <table class="form-table"> 654 <tr valign="top"> 655 <th scope="row">Text to appear on start button:</th> 656 <td><input type="text" name="qnotsquiz_start_text" value="<?php echo $qnotsquiz_custom_start_text; ?>"/></td> 657 </tr> 658 </table> 659 <?php submit_button(); ?> 660 </form> 661 662 663 <?php 664 } 665 } 666 register_setting('qnotsquiz-settings','qnotsquiz_start_text'); 667 668 669 670 671 672 ?> -
qnotsquiz/trunk/uninstall.php
r1926809 r1936148 6 6 exit; 7 7 } 8 9 8 //delete options 9 delete_option( 'qnotsquiz_start_text' ); 10 10 //delete posts with types questions and quiz upon uninstallation of qnotsquiz 11 11 $args = array ( 12 'post_type' => array('questions','quiz' ),12 'post_type' => array('questions','quiz','qnots_attempts'), 13 13 'nopaging' => true 14 14 );
Note: See TracChangeset
for help on using the changeset viewer.