Docs

Hooks reference

All PHP hooks are available after RD Quiz is loaded. JavaScript filters use @wordpress/hooks; register them before the corresponding screen first renders. In examples, return the incoming value unchanged when your extension does not handle the current record.

PHP filters

HookArgumentsReturn valuePurpose
rd_quiz_question_types$typesstring[]Add question type slugs that the REST API accepts. Supply matching editor, sanitization, and scoring behavior.
rd_quiz_quiz_types$typesstring[]Add accepted quiz type slugs.
rd_quiz_validate_question$valid, $type, $choices, $datatrue or WP_ErrorValidate a question after core validation. Return WP_Error to reject the save.
rd_quiz_sanitize_question_settings$clean, $type, $rawarraySanitize type-specific question settings before storage.
rd_quiz_sanitize_answer$default, $raw, $question, $quizmixed JSON-encodable valueConvert a visitor answer to its stored form. Core choice types use sorted choice indexes.
rd_quiz_score_answer$result, $question, $weight, $quizarrayChange scoring for one answer. points_awarded is clamped to 0..$weight.
rd_quiz_pass_mark$mark, $quizint|nullSet the percentage required to pass. null means no pass/fail result.
rd_quiz_allow_retake$allowed, $quizboolPermit repeat attempts. Defaults to false.
rd_quiz_style$style, $quizstyle arraySet style values for a quiz. Returned values are sanitized by RD Quiz.
rd_quiz_action_events$eventsevent registryAdd an event only when your code actually runs that event.
rd_quiz_actions$actionsaction registryAdd an action type. Its definition includes label, description, events, defaults_to, repeatable, blocking, icon, and fields.
rd_quiz_action_should_run$run, $action, $context, $quizboolDecide whether a non-blocking action runs.
rd_quiz_run_action$context, $action, $quiz, $event, $attempt_idarrayPerform an action and optionally add values for later actions.
rd_quiz_action_satisfied$satisfied, $action, $event, $quiz, $attempt_idboolDetermine whether a blocking action has been cleared. $attempt_id is null before submission.
rd_quiz_action_shortcodes$itemsshortcode catalogueAdd picker entries for shortcodes your action makes available while rendering its own messages.
rd_quiz_rest_attempt$attemptattempt arrayAdd data to an attempt REST response, such as a manual-marking state.
rd_quiz_settings_tabs$tabstab mapAdd a tab to the RD Quiz settings page.
rd_quiz_report_quiz_row$rowarrayOne quiz’s row in the RD Quiz → Reports table. Add a value here and its column through rdQuiz.reports.fields.
rd_quiz_load_styles$loadboolWhether the front-end stylesheet loads. The Styles screen’s Load RD Quiz styles setting; custom CSS from a style still prints when it is off.
rd_quiz_take_question$item, $question, $quizarrayOne question as the visitor receives it before answering: id, question, type, choices. For a type whose visitor needs something other than its stored choices, such as shuffled tiles. Everything returned is visible in the browser, so never include the answer key.
rd_quiz_csv_answer_cells$cells, $questionarray of { text, correct } or nullWhat a question writes in its CSV answer columns, for a type that keeps its answer in settings. Positions marked correct are listed in the correct column, in order. null keeps the built-in handling.
rd_quiz_csv_correct_cell$cell, $questionstringThe correct cell a question writes in a CSV. By default the positions its answer cells mark correct. A type whose answer is an order, or several, writes its own and reads it back from raw in rd_quiz_csv_question_row.
rd_quiz_csv_question_row$parsed, $type, $rowarray( 'choices', 'settings' ), WP_Error or nullThe import side: turn a CSV row into a question of your type. $row holds answers (the non-empty answer cells), correct (the listed positions, in order) and raw.
rd_quiz_result_payload$payload, $quiz, $attemptarrayThe result a visitor is shown. Applied on every path to it: on submission, when a held result is released, and in a preview, which action output does not reach. Add data here for rdQuiz.take.results.summary and rdQuiz.take.review.extra to render. Everything added is sent to that visitor.
rd_quiz_pro_url$urlstringWhere the switched-off Pro features link to: on the Reports and Styles screens, the question editor’s types and Level, the quiz Settings and the Actions tab. Empty by default, which shows no link.
rd_quiz_pro_active$activeboolWhether RD Quiz Pro is active. false by default; Pro returns true. RD Quiz uses it to leave out its switched-off copies of Pro’s quiz settings and Level field, which it cannot detect otherwise. Pro’s question types and actions are detected by being registered.

Action registry shape

rd_quiz_actions receives a map keyed by action type. A minimal non-blocking definition looks like this:

$actions['my_action'] = array(
	'label'       => __( 'My action', 'my-quiz-addon' ),
	'description' => __( 'Does work after submission.', 'my-quiz-addon' ),
	'events'      => array( 'attempt_submitted' ),
	'defaults_to' => array( 'attempt_submitted' ),
	'repeatable'  => true,
	'blocking'    => false,
	'icon'        => 'dashicons-admin-generic',
	'fields'      => array(),
);

For a blocking action, provide a waiting message when visitors may need to wait without interacting. Otherwise, implement both the PHP satisfaction check and a visitor UI through rdQuiz.take.gate.

PHP actions

HookArgumentsFires when
rd_quiz_question_saved$question_id, $is_newA question is saved.
rd_quiz_question_deleted$question_idA question and its assignments have been removed.
rd_quiz_quiz_saved$quiz_idA quiz is saved.
rd_quiz_quiz_deleted$quiz_idA quiz and its question assignments have been removed.
rd_quiz_topic_saved$topic_idA topic is saved.
rd_quiz_topic_deleted$topic_idA topic is deleted and removed from questions.
rd_quiz_attempt_completed$attempt_id, $quiz_idA visitor’s attempt has been stored after submission. Not fired for previews.
rd_quiz_lead_captured$lead_id, $leadAn email lead has been recorded. $lead contains email, name, source_type, and source_id. Not fired for an address entered while previewing, or for leads brought in by Import leads.
rd_quiz_action_failed$action, $exception, $quiz, $attempt_idA non-blocking action throws an exception.
rd_quiz_styles_screennoneThe Styles admin page is rendered and an extension registered a listener. The listener renders the page body.

JavaScript filters

Use namespaced IDs when registering filters, for example:

import { addFilter } from '@wordpress/hooks';

addFilter( 'rdQuiz.quizSettings.fields', 'my-quiz-addon/setting', callback );
FilterArgumentsExpected valuePurpose
rdQuiz.questionTypes$typesarray of { value, label }Add a type to the question editor selector. Pair it with rd_quiz_question_types.
rdQuiz.answerSummary$summary, questionstringDescribe a non-choice question’s answer key in the question lists, instead of a dash.
rdQuiz.questionForm.validate$error, values, choicesstring or nullReject a question before its REST request. PHP validation is still required.
rdQuiz.questionForm.answerKey$element, values, setReact element or nullReplace the default choice/answer-key editor for a custom type.
rdQuiz.questionForm.fields$fields, values, setReact element arrayAdd fields to the main question-editor column.
rdQuiz.questionForm.sidebar$fields, values, setReact element arrayAdd fields to the question-editor sidebar.
rdQuiz.quizSettings.fields$fields, values, onChangeReact element arrayAdd fields at the top of the quiz Settings tab.
rdQuiz.quizSettings.flags$flagsflag definition arrayAdd or modify checkbox flags in the quiz Settings tab.
rdQuiz.quizQuestion.fields$fields, question, indexReact element arrayAdd controls beside a question assigned to a quiz.
rdQuiz.actionConditions$element, action, earlier, onChangeReact element or nullRender configuration for action conditions.
rdQuiz.quizReports.sections$sections, dataarray of { id, render( data ) }Sections on a quiz’s Reports tab. RD Quiz seeds pass-rate and by-question as switched-off Pro features; replace one by id to provide it. data holds summary, per_day and quizId.
rdQuiz.reports.sections$sections, dataarray of { id, render( data ) }Sections below the table on RD Quiz → Reports. RD Quiz seeds a pro-reports advertisement.
rdQuiz.reports.fields$fieldsDataViews field arrayAdd columns to the Reports table. Add the value with rd_quiz_report_quiz_row.
rdQuiz.reports.actions$actions, dataarray of elementsButtons beside the Reports table’s view options, such as an export.
rdQuiz.quizAttempts.fields$fieldsDataViews field arrayAdd columns to the quiz Attempts tab. Add corresponding data with rd_quiz_rest_attempt.
rdQuiz.quizAttempts.review$element, itemReact element or nullRender a custom answer-review item in the admin’s attempt view. Same item shape as rdQuiz.take.review, which only runs on the front end.
rdQuiz.take.gate$element, action, quiz, phaseReact element or nullRender a visitor control for a blocking action.
rdQuiz.take.question$element, question, answer, select, stateReact element or nullRender an answer control for a custom question type. state includes feedback and disabled.
rdQuiz.take.review$element, itemReact element or nullRender a custom answer-review item after submission.
rdQuiz.take.results.summary$element, resultReact element or nullShow something about the result as a whole, under the score. result includes anything added through rd_quiz_result_payload.
rdQuiz.take.review.extra$element, item, resultReact element or nullShow something more under one review item’s answers, above its explanation, for any question type.

Shortcodes available to email actions

These are intentionally available only while RD Quiz renders a Send email action. They are not public WordPress shortcodes.

ShortcodeResult
[rd_quiz_attempt]All answers for the current attempt.
[rd_quiz_attempt question_id="12"]One answer from the current attempt.
[rd_quiz_result field="quiz|score|total|percent|passed"]One result value.
[rd_quiz_lead field="name|email"]A collected lead value for the current attempt.