array($this, 'checkboxCallback'), 'text' => array($this, 'inputCallback'), 'license' => array($this, 'licenseCallback'), 'textarea' => array($this, 'textareaCallback'), 'editor' => array($this, 'textEditorCallback'), 'select' => array($this, 'selectCallback'), 'hidden' => array($this, 'hiddenCallback'), 'file' => array($this, 'fileCallback'), 'number' => array($this, 'numberCallback'), 'inProButton' => array($this, 'inProButtonCallback'), 'html' => array($this, 'htmlCallback'), ); foreach ($settings as $sectionId => $section) { $callback = isset($section['callback']) ? $section['callback'] : null; $args = isset($section['args']) ? $section['args'] : array(); add_settings_section($sectionId, $section['label'], $callback, $page, $args ); if( isset( $section['fields'] ) ){ foreach ( $section['fields'] as $fieldId => $field) { $title = isset($field['title']) ? $field['title'] : ''; $field['label_for'] = $fieldId; $field['option_name'] = $optionName; $field['placeholder'] = isset($field['placeholder']) ? $field['placeholder'] : ''; $field['id'] = isset($field['id']) ? $field['id'] : $fieldId; add_settings_field($fieldId, $title, $callbacks[$field['type']], $page, $sectionId, $field); } } } } public function checkBoxCallback($args) { $args = wp_parse_args( $args, array( 'checked' => false, 'disabled' => false, 'label' => '', ) ); $checkbox = ''; $checkbox = apply_filters( 'wpc_settings_field_checkbox', $checkbox, $args ); $checked = $this->getOption($args['label_for']); if ( $checked == '1' || $args['checked'] === true ) { $checked = 'on'; } $disabled = ( $args['disabled'] === true ) ? 'disabled' : ''; printf( $checkbox, esc_attr($args['option_name']), esc_attr($args['label_for']), checked('on', $checked, false), esc_attr($args['id']), esc_attr($disabled), esc_html($args['label']) ); if( isset( $args['description'] ) ){ printf( '

%s

', esc_html( $args['description'] ) ); } } public function inputCallback($args) { $input = ''; $class = isset( $args['class'] ) ? $args['class'] : 'regular-text'; if( isset( $args['default'] ) ){ $value = $this->getOption($args['label_for']) ? $this->getOption($args['label_for']) : $args['default']; }else{ $value = $this->getOption($args['label_for']); } if (!is_null($value)) { $value = trim($value); } printf( $input, esc_attr($class), esc_attr($this->optionName), esc_attr($args['label_for']), esc_attr($value), esc_attr($args['placeholder']), esc_attr($args['id']) ); if(!empty($args['additional_link'])){ echo '' . esc_html($args['additional_link']['label']) . ''; } if( isset($args['id']) && $args['id'] === 'posts_container' ){ if( flrt_get_option('enable_ajax') === 'on' && ! $value ){ printf( '

%s

', esc_html__( 'You must specify the Results container, otherwise AJAX will not work properly', 'filter-everything' ) ); } } if( isset( $args['description'] ) ){ printf( '

%s

', esc_html( $args['description'] ) ); } } public function numberCallback($args) { $input = ''; $class = isset( $args['class'] ) ? $args['class'] : 'regular-text'; if( isset( $args['default'] ) ){ $value = $this->getOption($args['label_for']) ? $this->getOption($args['label_for']) : $args['default']; }else{ $value = $this->getOption($args['label_for']); } if (!is_null($value)) { $value = trim($value); } printf( $input, esc_attr($class), esc_attr($this->optionName), esc_attr($args['label_for']), esc_attr($value), esc_attr($args['placeholder']), esc_attr($args['id']) ); if( isset($args['id']) && $args['id'] === 'posts_container' ){ if( flrt_get_option('enable_ajax') === 'on' && ! $value ){ printf( '

%s

', esc_html__( 'You must specify the Results container, otherwise AJAX will not work properly', 'filter-everything' ) ); } } if( isset( $args['description'] ) ){ printf( '

%s

', esc_html( $args['description'] ) ); } } public function licenseCallback( $args ) { $input = ''; $class = isset( $args['class'] ) ? $args['class'] : 'regular-text'; $value = str_repeat( '*', 80 ); $value = trim($value); printf( $input, esc_attr($class), esc_attr($this->optionName), esc_attr($args['label_for']), esc_attr($value), esc_attr($args['placeholder']), esc_attr($args['id']) ); if( isset( $args['description'] ) ){ printf( '

%s

', esc_html( $args['description'] ) ); } } public function hiddenCallback( $args ) { $input = ''; $class = isset( $args['class'] ) ? $args['class'] : 'regular-text'; printf( $input, esc_attr($class), esc_attr($this->optionName), esc_attr($args['label_for']), esc_attr($this->getOption($args['label_for'])), esc_attr($args['placeholder']), esc_attr($args['id']) ); } public function fileCallback( $args ) { $input = ''; $class = isset( $args['class'] ) ? $args['class'] : 'regular-text'; printf( $input, esc_attr($args['id']), esc_attr($class), esc_attr($this->optionName), esc_attr($args['label_for']), esc_attr($this->getOption($args['label_for'])), esc_attr($args['placeholder']), esc_attr($args['id']), esc_attr($args['required']) ); } public function selectCallback( $args ) { $options = isset($args['options']) ? $args['options'] : []; $disabled = isset($args['disabled']) ? $args['disabled'] : []; $class = isset( $args['class'] ) ? $args['class'] : 'filter-settings-select'; $value = $this->getOption($args['label_for']); $multiple = ! empty($args['multiple']) ? 'multiple' : null; $select = ''); if (isset($args['help'])) { printf('

%s

', esc_html($args['help'])); } if( isset( $args['description'] ) ){ printf( '

%s

', esc_html( $args['description'] ) ); } } public function textareaCallback($args) { $textarea = ''; $textarea_text = $this->getOption($args['label_for']); if(empty($textarea_text)){ $textarea_text = ''; } printf( $textarea, esc_attr($this->optionName), esc_attr($args['label_for']), esc_attr($args['placeholder']), esc_attr($args['id']), esc_textarea( $textarea_text ) ); } public function textEditorCallback($args) { wp_editor( $this->getOption( $args['label_for'] ), esc_attr( $args['id'] ), array( 'textarea_name' => esc_attr( $this->optionName . '[' . $args['label_for'] . ']' ) ) ); } public function render() { print('
'); settings_errors(); settings_fields($this->group); do_action('wpc_before_sections_settings_fields', $this->page ); $this->doSettingsSections($this->page); do_action('wpc_after_sections_settings_fields', $this->page ); if( apply_filters('wpc_settings_submit_button', true ) ){ submit_button(); } print('
'); } public function doSettingsSections( $page ) { global $wp_settings_sections, $wp_settings_fields; if ( ! isset( $wp_settings_sections[ $page ] ) ) { return; } foreach ( (array) $wp_settings_sections[ $page ] as $section ) { do_action('wpc_before_settings_fields_title', $page ); if ( $section['title'] ) { echo "

". wp_kses( $section['title'], array( 'span' => array( 'class' => true ) )) ."

\n"; } do_action('wpc_after_settings_fields_title', $page ); if ( $section['callback'] ) { call_user_func( $section['callback'], $section ); } if ( ! isset( $wp_settings_fields ) || ! isset( $wp_settings_fields[ $page ] ) || ! isset( $wp_settings_fields[ $page ][ $section['id'] ] ) ) { continue; } $sortable = ( $section['id'] === 'wpc_slugs' ) ? ' wpc-sortable-table' : ''; echo ''; $this->doSettingsFields( $page, $section['id'] ); echo ''; } do_action('wpc_after_settings_fields', $page ); } public function doSettingsFields( $page, $section ) { global $wp_settings_fields; if ( ! isset( $wp_settings_fields[ $page ][ $section ] ) ) { return; } $i = 1; foreach ( (array) $wp_settings_fields[ $page ][ $section ] as $field ) { $class = ''; if( $field['id'] === 'bottom_widget_compatibility' ){ if( flrt_get_option('mobile_filter_settings') === 'show_bottom_widget' ){ $field['args']['class'] .= ' wpc-opened'; } } if( $field['id'] === 'color_swatches_taxonomies' || $field['id'] === 'rounded_swatches' ) { if( flrt_get_experimental_option('use_color_swatches') === 'on' ) { $field['args']['class'] .= ' wpc-opened'; } } if ( ! empty( $field['args']['class'] ) ) { $class = ' class="' . esc_attr( $field['args']['class'] ) . '"'; } do_action('wpc_before_settings_field', $field ); echo ""; $sortable = isset( $field['args']['sortable'] ) ? $i : ''; if( $sortable ){ echo ''.esc_html($sortable).''; } $tooltip = isset( $field['args']['tooltip'] ) ? flrt_tooltip( array( 'tooltip' => $field['args']['tooltip'] ) ) : ''; $tooltip = wp_kses( $tooltip, array( 'strong' => array(), 'br' => array(), 'a' => array( 'href'=>true, 'title'=>true, 'class'=>true ), 'span' => array( 'class'=>true, 'data-tip'=>true) ) ); $enabled_in_pro_string = ''; $enabled_in_pro_class = ''; if( !empty($field['args']['pro_label']) ){ $enabled_in_pro_string = $field['args']['pro_label']; $enabled_in_pro_class = 'class="wpc-row-pro-only wpc-pro-badge-text"'; } if ( ! empty( $field['args']['label_for'] ) ) { echo ' ' .$tooltip. $enabled_in_pro_string . ''; // $tooltip already escaped } else { echo ''. esc_html($field['title'] ) . ' ' .$tooltip. ''; // $tooltip already escaped } echo ''; call_user_func( $field['callback'], $field['args'] ); echo ''; if( $sortable ){ $title = ( ! defined( 'FLRT_FILTERS_PRO' ) ) ? __( 'Editing the order of URL prefixes is available in the PRO version', 'filter-everything' ) : ''; echo ' '; } echo ''; do_action('wpc_after_settings_field', $field ); $i++; } } public function getOption($key, $default = null) { if (is_null($this->options)) { $this->options = get_option($this->optionName); } return isset($this->options[$key]) ? $this->options[$key] : $default; } public function inProButtonCallback($args) { echo flrt_unlock_in_pro(); if( isset( $args['description'] ) ){ printf( '

%s

', esc_html( $args['description'] ) ); } } /** * Read-only field: delegates the cell markup to $args['render'] (callable * receiving $args) or echoes pre-escaped $args['html']. Nothing is saved — * for generated previews, hints and code blocks inside a settings table. */ public function htmlCallback($args) { if ( isset( $args['render'] ) && is_callable( $args['render'] ) ) { call_user_func( $args['render'], $args ); return; } if ( isset( $args['html'] ) ) { echo wp_kses_post( $args['html'] ); } } }