• I’m developing extended quiz functions and would appreciate to use Learnpress as the LMS frame (using e.g. a plugin as “Add On” for lp). My problem: Is seems to me that the predefined questiontypes are hard coded in js, means no new question type can be easily added. Example: “single_compare”: One question with one correct answer to be provided as string. Choice of “single_compare”-type should be possible in admin-area (question post-type) and integration of specific view in front-end with input field. Is there any hint you can give (e.g. using hooks)? Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support brianvu-tp

    (@briantp)

    Hi,

    First, you should create a class extend LP_Question then set protected $_question_type = ‘name_uinque’; // should start with prefix by name of your plugin

    Add hooks:

    
    add_filter(
    	'learn-press/question-types',
    	function( $types ) {
    		$types['name_uinque'] = esc_html__( 'Sorting Choice', 'learnpress-sorting-choice' );
    
    					return $types;
    				}
    			);
    
    			add_filter(
    				'learn-press/default-question-types-support-answer-options',
    				function( $data ) {
    					$data[] = 'name_uinque';
    
    					return $data;
    				}
    			);

    Then you can write code in backend and frontend

    Thread Starter rookiewp

    (@rookiewp)

    Thanks for the helpful hint: Using the filters the new question-type appeared in the backend question-type choice list.

    However I didn’t succeed in extending properly the LP_Question class. What I did first was to copy “class-lp-question-single-choice.php” as an example for the extension and then to change filename, classname and question-type name to the new one. But when I choose in backend the new type the typical “single-choice” view (with radio buttons) doesn’t appear. Is there any other datastructure to double from “single-choice”?
    Question for me is also how the extended LP_Question-class will be called. I included the file with the new class within my AddOn by “required_once” after lp has been loaded, but how does lp calls the extended class and uses it for front and backend when the new question type has been chosen?

    For eventual further questions: Is there any tutorial for AddOn development in LP (e.g. explaining the datastructure and extendable classes)? I could only find the “Rest API” and a list of actions and filters, but to find the right interfaces I’m doing deep-dives in lp-code and I’m greatful for getting your good hints.
    Thanks a lot!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Create custom question type’ is closed to new replies.