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
| Hook | Arguments | Return value | Purpose |
|---|---|---|---|
rd_quiz_question_types | $types | string[] | Add question type slugs that the REST API accepts. Supply matching editor, sanitization, and scoring behavior. |
rd_quiz_quiz_types | $types | string[] | Add accepted quiz type slugs. |
rd_quiz_validate_question | $valid, $type, $choices, $data | true or WP_Error | Validate a question after core validation. Return WP_Error to reject the save. |
rd_quiz_sanitize_question_settings | $clean, $type, $raw | array | Sanitize type-specific question settings before storage. |
rd_quiz_sanitize_answer | $default, $raw, $question, $quiz | mixed JSON-encodable value | Convert a visitor answer to its stored form. Core choice types use sorted choice indexes. |
rd_quiz_score_answer | $result, $question, $weight, $quiz | array | Change scoring for one answer. points_awarded is clamped to 0..$weight. |
rd_quiz_pass_mark | $mark, $quiz | int|null | Set the percentage required to pass. null means no pass/fail result. |
rd_quiz_allow_retake | $allowed, $quiz | bool | Permit repeat attempts. Defaults to false. |
rd_quiz_style | $style, $quiz | style array | Set style values for a quiz. Returned values are sanitized by RD Quiz. |
rd_quiz_action_events | $events | event registry | Add an event only when your code actually runs that event. |
rd_quiz_actions | $actions | action registry | Add an action type. Its definition includes label, description, events, defaults_to, repeatable, blocking, icon, and fields. |
rd_quiz_action_should_run | $run, $action, $context, $quiz | bool | Decide whether a non-blocking action runs. |
rd_quiz_run_action | $context, $action, $quiz, $event, $attempt_id | array | Perform an action and optionally add values for later actions. |
rd_quiz_action_satisfied | $satisfied, $action, $event, $quiz, $attempt_id | bool | Determine whether a blocking action has been cleared. $attempt_id is null before submission. |
rd_quiz_action_shortcodes | $items | shortcode catalogue | Add picker entries for shortcodes your action makes available while rendering its own messages. |
rd_quiz_rest_attempt | $attempt | attempt array | Add data to an attempt REST response, such as a manual-marking state. |
rd_quiz_settings_tabs | $tabs | tab map | Add a tab to the RD Quiz settings page. |
rd_quiz_report_quiz_row | $row | array | One quiz’s row in the RD Quiz → Reports table. Add a value here and its column through rdQuiz.reports.fields. |
rd_quiz_load_styles | $load | bool | Whether 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, $quiz | array | One 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, $question | array of { text, correct } or null | What 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, $question | string | The 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, $row | array( 'choices', 'settings' ), WP_Error or null | The 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, $attempt | array | The 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 | $url | string | Where 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 | $active | bool | Whether 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
| Hook | Arguments | Fires when |
|---|---|---|
rd_quiz_question_saved | $question_id, $is_new | A question is saved. |
rd_quiz_question_deleted | $question_id | A question and its assignments have been removed. |
rd_quiz_quiz_saved | $quiz_id | A quiz is saved. |
rd_quiz_quiz_deleted | $quiz_id | A quiz and its question assignments have been removed. |
rd_quiz_topic_saved | $topic_id | A topic is saved. |
rd_quiz_topic_deleted | $topic_id | A topic is deleted and removed from questions. |
rd_quiz_attempt_completed | $attempt_id, $quiz_id | A visitor’s attempt has been stored after submission. Not fired for previews. |
rd_quiz_lead_captured | $lead_id, $lead | An 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_id | A non-blocking action throws an exception. |
rd_quiz_styles_screen | none | The 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 );
| Filter | Arguments | Expected value | Purpose |
|---|---|---|---|
rdQuiz.questionTypes | $types | array of { value, label } | Add a type to the question editor selector. Pair it with rd_quiz_question_types. |
rdQuiz.answerSummary | $summary, question | string | Describe a non-choice question’s answer key in the question lists, instead of a dash. |
rdQuiz.questionForm.validate | $error, values, choices | string or null | Reject a question before its REST request. PHP validation is still required. |
rdQuiz.questionForm.answerKey | $element, values, set | React element or null | Replace the default choice/answer-key editor for a custom type. |
rdQuiz.questionForm.fields | $fields, values, set | React element array | Add fields to the main question-editor column. |
rdQuiz.questionForm.sidebar | $fields, values, set | React element array | Add fields to the question-editor sidebar. |
rdQuiz.quizSettings.fields | $fields, values, onChange | React element array | Add fields at the top of the quiz Settings tab. |
rdQuiz.quizSettings.flags | $flags | flag definition array | Add or modify checkbox flags in the quiz Settings tab. |
rdQuiz.quizQuestion.fields | $fields, question, index | React element array | Add controls beside a question assigned to a quiz. |
rdQuiz.actionConditions | $element, action, earlier, onChange | React element or null | Render configuration for action conditions. |
rdQuiz.quizReports.sections | $sections, data | array 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, data | array of { id, render( data ) } | Sections below the table on RD Quiz → Reports. RD Quiz seeds a pro-reports advertisement. |
rdQuiz.reports.fields | $fields | DataViews field array | Add columns to the Reports table. Add the value with rd_quiz_report_quiz_row. |
rdQuiz.reports.actions | $actions, data | array of elements | Buttons beside the Reports table’s view options, such as an export. |
rdQuiz.quizAttempts.fields | $fields | DataViews field array | Add columns to the quiz Attempts tab. Add corresponding data with rd_quiz_rest_attempt. |
rdQuiz.quizAttempts.review | $element, item | React element or null | Render 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, phase | React element or null | Render a visitor control for a blocking action. |
rdQuiz.take.question | $element, question, answer, select, state | React element or null | Render an answer control for a custom question type. state includes feedback and disabled. |
rdQuiz.take.review | $element, item | React element or null | Render a custom answer-review item after submission. |
rdQuiz.take.results.summary | $element, result | React element or null | Show 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, result | React element or null | Show 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.
| Shortcode | Result |
|---|---|
[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. |