<?php
if (!defined('FW'))
die('Forbidden');
class FW_Settings_Form_Test extends FW_Settings_Form
{
public function get_values()
{
return get_option('test_fw_settings_form', array());
}
public function set_values($values)
{
update_option('test_fw_settings_form', $values, false);
}
public function get_options()
{
$options_radio = array();
$terms = get_terms(array(
'hide_empty' => 0,
'orderby' => 'name',
'order' => 'ASC',
'taxonomy' => 'courses',
'pad_counts' => 1
));
$terms = wp_list_filter($terms, array(
'parent' => 0
));
foreach ($terms as $term) {
$options_radio[$term->term_id] = __($term->name, '{domain}');
}
return array(
'tab1' => array(
'type' => 'tab',
'title' => 'Система экзаменов',
'options' => array(
'examinations' => array(
'type' => 'addable-popup',
'label' => __('Добавить экзамен', '{domain}'),
'desc' => __('Нажмите чтобы добавить экзамен.', '{domain}'),
'template' => '{{- name_exam }}',
'popup-title' => null,
'size' => 'large', // small, medium, large
'limit' => 0, // limit the number of popup`s that can be added
'add-button-text' => __('Добавить', '{domain}'),
'sortable' => true,
'popup-options' => array(
'name_exam' => array(
'label' => __('Наименование', '{domain}'),
'type' => 'text',
'value' => '',
'desc' => __('Введите наименование экзамена.', '{domain}')
),
'tickets' => array(
'type' => 'addable-popup',
'label' => __('Добавить билет', '{domain}'),
'desc' => __('Нажмите чтобы добавить билет для данного экзамена.', '{domain}'),
'template' => '{{- name_ticket }}',
'popup-title' => null,
'size' => 'large', // small, medium, large
'limit' => 0, // limit the number of popup`s that can be added
'add-button-text' => __('Добавить', '{domain}'),
'sortable' => true,
'popup-options' => array(
'name_ticket' => array(
'label' => __('Название билета', '{domain}'),
'type' => 'text',
'value' => ''
),
'issues' => array(
'type' => 'addable-popup',
'label' => __('Вопросы билета', '{domain}'),
'desc' => __('Нажмите чтобы добавить вопрос для текущего билета.', '{domain}'),
'template' => '{{- name_issue }}',
'popup-title' => null,
'size' => 'large', // small, medium, large
'limit' => 0, // limit the number of popup`s that can be added
'add-button-text' => __('Добавить', '{domain}'),
'sortable' => true,
'popup-options' => array(
'name_issue' => array(
'label' => __('Текст вопроса', '{domain}'),
'type' => 'text',
'value' => '',
'desc' => __('Введите описание вопроса.', '{domain}')
),
'option_2' => array(
'type' => 'addable-box',
'label' => __('Вариант ответа', '{domain}'),
'desc' => __('Добавте вариант ответа', '{domain}'),
'box-options' => array(
'option_1' => array(
'label' => __('Текст', '{domain}'),
'type' => 'textarea',
'value' => '',
'desc' => __('Введите описание варианта ответа.', '{domain}')
),
'option_2' => array(
'type' => 'checkbox',
'value' => false, // checked/unchecked
'label' => __('Правильный', '{domain}'),
'desc' => __('Нажмите если ответ является верным', '{domain}'),
'text' => __('Да', '{domain}')
)
),
'template' => 'Вариант {{- option_1 }}', // box title
'box-controls' => array( // buttons next to (x) remove box button
'control-id' => '<small class="dashicons dashicons-smiley"></small>'
),
'limit' => 0, // limit the number of boxes that can be added
'add-button-text' => __('Добавить', '{domain}'),
'sortable' => true
)
)
)
)
),
'cours' => array(
'type' => 'radio',
'attr' => array(
'class' => 'custom-class',
'data-foo' => 'bar'
),
'label' => __('Экзамен для курса:', '{domain}'),
'desc' => __('Выберите к какому курсу относится данный экзамен', '{domain}'),
'choices' => $options_radio,
// Display choices inline instead of list
'inline' => false
)
)
)
)
)
/*'tab2' => array(
'type' => 'tab',
'title' => 'Tab #2',
'options' => array(
'tab2_1' => array(
'type' => 'tab',
'title' => 'Sub Tab #1',
'options' => array(
'opt2_1' => array(
'type' => 'text',
'label' => 'Sub Option #1'
),
),
),
'tab2_2' => array(
'type' => 'tab',
'title' => 'Sub Tab #2',
'options' => array(
'opt2_2' => array(
'type' => 'textarea',
'label' => 'Sub Option #2'
),
),
),
),
),*/
);
}
protected function _init()
{
add_action('admin_menu', array(
$this,
'_action_admin_menu'
));
add_action('admin_enqueue_scripts', array(
$this,
'_action_admin_enqueue_scripts'
));
$this->set_is_side_tabs(true);
$this->set_is_ajax_submit(true);
# This returns the whole taxonomy...
//var_dump($options_radio);
}
/**
* @internal
*/
public function _action_admin_menu()
{
add_menu_page('Экзамены', 'Экзамены', 'manage_options', /** used in @see _action_admin_enqueue_scripts() */ 'test-fw-settings-form', array(
$this,
'render'
), '', 6);
}
/**
* @internal
*/
public function _action_admin_enqueue_scripts()
{
$current_screen = get_current_screen(); // fw_print($current_screen);
// enqueue only on settings page
if ('toplevel_page_' . 'test-fw-settings-form' === $current_screen->base) {
$this->enqueue_static();
}
}
}
add_action('fw_init', '_action_theme_test_fw_settings_form');
function _action_theme_test_fw_settings_form() {
if (class_exists('FW_Settings_Form'))
{
require_once get_template_directory() . '/class-fw-settings-form-test.php';
new FW_Settings_Form_Test('test');
}
}
Hello!







I created the settings page by following the instructions:
http://manual.unyson.io/en/latest/helpers/settings-form.html
Everything worked well! But soon the work of the data ajax stopped working. Most likely this problem is due to the fact that ajax sends a lot of data (see screenshots). How to solve the problem I do not understand.
class-fw-settings-form-test.php:
functions.php: