Хуки

В плагине Quizle добавлены фильтры (filter). С их помощью Вы можете изменять вывод или даже убирать какие-то блоки. Ниже идет описание фильтров и примеры их использования.

Лучше всего для этого использовать плагин ProFunctions, установите и добавьте в него нужный код.

Filters

quizle/answer/description

Filter that allows you to modify the content of the answer description.

Фильтр, позволяющий модифицировать контент описания ответа.

/**
 * Modify content of answer description
 */
add_filter( 'quizle/answer/description', function ( $description ) {
    return str_replace( '{{more_link}}', '<a href="#">get more...</a>', $description );
} );

quizle/contacts/description

Filter that allows you to modify the content of the description on the contact screen.

Фильтр, позволяющий модифицировать контент описания на экране контактов.

/**
 * Modify content of description of contacts screen
 */
add_filter( 'quizle/contacts/description', function ( $description ) {
    return str_replace( '{{more_link}}', '<a href="#">get more...</a>', $description );
} );

quizle/contacts/message

Filter that allows you to modify the content of a message on the contact screen.

Фильтр, позволяющий модифицировать контент сообщения на экране контактов.

/**
 * Modify content of message of contacts screen
 */
add_filter( 'quizle/contacts/message', function ( $message ) {
    return str_replace( '{{more_link}}', '<a href="#">get more...</a>', $message );
} );

quizle/contacts/user_name 1.1.0

Filter to change the username substituted automatically if the user is logged in.

Фильтр, позволяющий поменять имя пользователя, подставляемое автоматически, если пользователь залогинен

/**
 * Use first name if set instead of display name
 */
add_filter( 'quizle/contacts/user_name', function ( $display_name, $user ) {
    /** @var WP_User $user */
    if ( $user->first_name ) {
        return $user->first_name;
    }

    return $display_name
}, 10, 2 );

quizle/element_colors/brightness_adjustment_threshold

Filter that allows you to change the brightness adjustment threshold according to
the YIQ algorithm. This algorithm is used when generating additional background
colors.

Фильтр, позволяющий поменять порог регулирования яркости согласно алгоритму YIQ. Этот алгоритм используется при
генерации дополнительных фоновых цветов.

/**
 * Change brightness adjustment threshold. Default value is 128
 */
add_filter( 'quizle/element_colors/brightness_adjustment_threshold', function () {
    return 120
} );

quizle/functions/generate_name

Filter that allows you to change the algorithm for generating the name of a quizle.

Фильтр, позволяющий поменять алгоритм генерации названия квиза.

/**
 * Change quizle name generation function
 */
add_filter( 'quizle/functions/generate_name', function () {
    return uniqid( date('Ymd-') );
} );

quizle/locate_template/located

A filter that allows you to replace the path to the file. Useful when you need to make changes to the layout of the
template without editing the files in the plugin.

Фильтр, позволяющий подменить путь к файлу. Удобно при необходимости внести правки в верстку шаблона при этом не
редактируя файлы в плагине.

/**
 * Replace plugin template
 */
add_filter( 'quizle/locate_template/located', function ( $located, $template_name ) {
    if ( 'quizle-result.php' == $template_name ) {
        $located = 'your-theme/path/template.php';
    }
    
    return $located;
}, 10, 2 );

quizle/progress/is_text_shown

A filter that allows you to hide progress text.

Фильтр, позволяющий скрыть текст прогресса.

/**
 * Hide progress text
 */
add_filter( 'quizle/progress/is_text_shown', '__return_false' );

quizle/question/description

Filter that allows you to modify the content of the question description.

Фильтр, позволяющий модифицировать контент описания вопроса.

/**
 * Modify content of question description
 */
add_filter( 'quizle/question/description', function ( $description ) {
    return str_replace( '{{more_link}}', '<a href="#">get more...</a>', $description );
} );

quizle/question/right_answer_description

Filter that allows you to modify the content of the right answer description.

Фильтр, позволяющий модифицировать контент описания правильного ответа.

/**
 * Modify content of right answer description
 */
add_filter( 'quizle/question/right_answer_description', function ( $description ) {
    return str_replace( '{{more_link}}', '<a href="#">get more...</a>', $description );
} );

quizle/question/title

Filter that allows you to modify the question title.

Фильтр, позволяющий модифицировать заголовок вопроса.

/**
 * Modify content of question title
 */
add_filter( 'quizle/question/title', function ( $title ) {
    return mb_strtoupper( $title, 'UTF-8' );
} );

quizle/question/media_html 1.1.0

Filter that allows you to modify the question media html.

Фильтр, позволяющий модифицировать в вопросе html медиа контент.

/**
 * Add support of shortcode

 */
add_filter( 'quizle/question/media_html', function ( $content, $media ) {
    return $GLOBALS['wp_embed']->run_shortcode( $media['url'] );
} );

quizle/result/count_tests_text_inputs

A filter that allows you to eliminate the counting of textual answers in the total scores.

Фильтр, позволяющий убрать подсчет текстовых ответов в общие баллы.

/**
 * Eliminate the counting of text responses in the total scores
 */
add_filter( 'quizle/result/count_tests_text_inputs', '__return_false' );

quizle/result/default_btn_text

A filter that allows you to replace the default text of the result button.

Фильтр, позволяющий заменить текст по умолчанию кнопки результатов.

/**
 * Change default text of result btn
 */
add_filter( 'quizle/result/default_btn_text', function () {
    return 'Excellent!'
} );

quizle/result/table_per_page

A filter that allows you to change count of row in admin results grid.

Фильтр, позволяющий изменять количество строк в списке результатов в админке.

/**
 * Change count of row in admin results grid
 */
add_filter( 'quizle/result_table/per_page', function () {
    return 50;
} );

quizle/result/title 1.1.0

A filter that allows you to change output of result title.

Фильтр, позволяющий изменить вывод заголовка результата.

/**
 * Forbid all html in the title
 */
remove_filter( 'quizle/result/title', 'wp_kses_post' );
add_filter( 'quizle/result/title', 'esc_html' );

quizle/result/description 1.1.0

A filter that allows you to change output of result description.

Фильтр, позволяющий изменить вывод описания результата.

/**
 * Forbid all html in the description
 */
remove_filter( 'quizle/result/description', 'wp_kses_post' );
add_filter( 'quizle/result/description', 'esc_html' );

quizle/shortcode/do_output

A filter that allows you to disable shortcode output according to conditions.

Фильтр, позволяющий отключить вывод шорткода в зависимости от условий.

/**
 * Prevent shortcode output on product page
 */
add_filter( 'quizle/shortcode/do_output', function ( $result ) {
    if ( function_exists('is_product' ) && is_product() ) {
        return false;
    }

    return $result;
} );

quizle/social/share_providers

A filter that allows you to add or remove social providers.

Фильтр, позволяющий добавить или удалить социальные провайдеры.

/**
 * Add additional social provider
 */
add_filter( 'quizle/social/share_providers', function ( $providers ) {
    $providers['telegram'] = [
        'width'  => '32',
        'height' => '32',
        'path'   => '...', // value of property for svg path element
        'color'  => '#64a9dc',
    ];

    return $providers;
} );

quizle/social/messengers 1.1.0

A filter that allows you to add or remove messengers.

Фильтр, позволяющий добавить или удалить мессенджеры.

/**
 * Add additional social provider
 */
add_filter( 'quizle/social/messengers', function ( $providers ) {
    $providers['telegram'] = [
        'width'  => '32',
        'height' => '32',
        'path'   => '...', // value of property for svg path element
        'color'  => '#64a9dc',
    ];

    return $providers;
} );

quizle/steps/finish_btn_text

A filter that allows you to change the text of the ” finish ” button.

Фильтр, позволяющий поменять текст кнопки “завершить”.

/**
 * Change finish btn text
 */
add_filter( 'quizle/steps/finish_btn_text', function () {
    return 'Got it!';
} );

quizle/steps/next_btn_text

Filter that allows you to change the text of the “next” button.

Фильтр, позволяющий поменять текст кнопки “дальше”.

/**
 * Next btn text
 */
add_filter( 'quizle/steps/next_btn_text', function () {
    return '>>';
} );

quizle/steps/prev_btn_text

Filter that allows you to change the text of the “previous” button.

Фильтр, позволяющий поменять текст кнопки “назад”.

/**
 * Prev btn text
 */
add_filter( 'quizle/steps/prev_btn_text', function () {
    return '<<';
} );

quizle/welcome/description

Filter that allows you to change the description of the welcome screen.

Фильтр, позволяющий поменять описание стартового экрана.

/**
 * Modify content of welcome description
 */
add_filter( 'quizle/welcome/description', function ( $description ) {
    return str_replace( '{{more_link}}', '<a href="#">get more...</a>', $description );
} );

quizle/progress_bar/text 1.1.0

Filter that allows you to change the text of the progress bar while calculating results.

Фильтр, позволяющий поменять текст прогресс бара, пока идет подсчет результатов.

/**
 * Modify text of progress bar
 */
add_filter( 'quizle/progress_bar/text', function ( $text ) {
    return 'New progress bar text';
} );

Actions

quizle/mail/send

Action that allows you to add handlers of result sending

/**
 * Example of custom additional notifications
 */
add_action( 'quizle/mail/send', function ( \Wpshop\Quizle\QuizleResult $result ) {
    $context = $result->get_context();
    $url = '';
    if ( $context && ! is_wp_error( $context ) ) {
        $url = $context->get_relative_url();
    }
    // let pretend that there is function like this
    notify_on_telegram( "New results of quizle: {$result->quiz_id}, name: {$result->name}, email: {$result->email}, url: {$url}" );
} );

/**
 * Remove default mail send  
 */
if ( class_exists( \Wpshop\Quizle\PluginContainer::class ) ) {
    remove_action( 'quizle/mail/send', [ \Wpshop\Quizle\PluginContainer::get( \Wpshop\Quizle\MailService::class ), '_send_to_admin' ] );
}

JavaScript Events

  • quizle:start {detail:{quizle, $quizle}}
  • quizle:next {detail:{quizle, $quizle, $question}}
  • quizle:prev {detail:{quizle, $quizle, $question}}
  • quizle:confirm {detail:{quizle, $quizle, $question}}
  • quizle:progress {detail:{quizle, $quizle, percent}}
  • quizle:show_contacts {detail:{quizle, $quizle}}
  • quizle:show_results {detail:{quizle, $quizle}}
  • quizle:finish {detail:{quizle, $quizle}}

Example of google analytics event

document.addEventListener('quizle:confirm', function (ev) {
    var $question = ev.detail.$question;
    var title = $question.find('.quizle-question__title').text();

    window.dataLayer = window.dataLayer || [];

    dataLayer.push({'event': 'quizle_confirm_answer'}, {
        quizle: ev.detail.quizle,
        question: title,
        answer: ev.detail.answers.join(', ')
    });
});

Add a script for yandex.metrika via php plugin:

add_action( 'init', function () {
    add_action( 'wp_enqueue_scripts', function () {
        $js = <<<'JS'
    jQuery(function($) {
        document.addEventListener('quizle:finish', function (e) {
            if (typeof ym !== 'undefined') {
                ym(XXXXXX, 'reachGoal', 'finish_quizle', {quizle:e.detail.quizle});
            }
        });
    });
JS;
        wp_add_inline_script( 'quizle-scripts', $js );
    } );
} );