| 1 |
<?php |
| 2 |
|
| 3 |
namespace FilterEverything\Filter; |
| 4 |
|
| 5 |
if ( ! defined('ABSPATH') ) { |
| 6 |
exit; |
| 7 |
} |
| 8 |
|
| 9 |
class SettingsTab extends BaseSettings |
| 10 |
{ |
| 11 |
protected $page = 'wpc-filter-admin-settings'; |
| 12 |
|
| 13 |
protected $group = 'wpc_filter'; |
| 14 |
|
| 15 |
protected $optionName = 'wpc_filter_settings'; |
| 16 |
|
| 17 |
public function init() |
| 18 |
{ |
| 19 |
add_action('admin_init', array($this, 'initSettings')); |
| 20 |
} |
| 21 |
|
| 22 |
public function initSettings() |
| 23 |
{ |
| 24 |
register_setting($this->group, $this->optionName); |
| 25 |
/** |
| 26 |
* @see https://developer.wordpress.org/reference/functions/add_settings_field/ |
| 27 |
*/ |
| 28 |
$defaultPostsContainer = flrt_default_posts_container(); |
| 29 |
$defaultPrimaryColor = flrt_default_theme_color(); |
| 30 |
|
| 31 |
$settings = array( |
| 32 |
'mobile_devices' => array( |
| 33 |
'label' => esc_html__('Mobile devices', 'filter-everything'), |
| 34 |
'fields' => array( |
| 35 |
'mobile_filter_settings' => array( |
| 36 |
'type' => 'select', |
| 37 |
'title' => esc_html__('Filters widget on mobile should be', 'filter-everything'), |
| 38 |
'options' => array( |
| 39 |
'nothing' => esc_html__('The same as on a desktop', 'filter-everything'), |
| 40 |
'show_open_close_button' => esc_html__('Collapsed and expanded', 'filter-everything'), |
| 41 |
), |
| 42 |
'default' => 'no', |
| 43 |
'id' => 'mobile_filter_settings', |
| 44 |
), |
| 45 |
/*'show_open_close_button' => array( |
| 46 |
'type' => 'checkbox', |
| 47 |
'title' => esc_html__('Collapse Filters Widget on Mobile devices', 'filter-everything'), |
| 48 |
'id' => 'show_open_close_button', |
| 49 |
'label' => esc_html__('Collapse the widget and show the Filters opening button', 'filter-everything'), |
| 50 |
),*/ |
| 51 |
'try_move_to_top_sidebar' => array( |
| 52 |
'type' => 'checkbox', |
| 53 |
'title' => esc_html__('Sidebar on top', 'filter-everything'), |
| 54 |
'id' => 'try_move_to_top_sidebar', |
| 55 |
'label' => esc_html__('Try to move the sidebar to the top on mobile devices', 'filter-everything'), |
| 56 |
) |
| 57 |
), |
| 58 |
), |
| 59 |
'ajax' => array( |
| 60 |
'label' => esc_html__('AJAX', 'filter-everything'), |
| 61 |
'fields' => array( |
| 62 |
'enable_ajax' => array( |
| 63 |
'type' => 'checkbox', |
| 64 |
'title' => esc_html__('AJAX for Filters', 'filter-everything'), |
| 65 |
'id' => 'enable_ajax', |
| 66 |
'label' => esc_html__('Try to use AJAX', 'filter-everything'), |
| 67 |
'description' => esc_html__( 'Please enable this option only after you have ensured that the filtering is working correctly', 'filter-everything' ), |
| 68 |
), |
| 69 |
'posts_container' => array( |
| 70 |
'type' => 'text', |
| 71 |
'title' => esc_html__('Results container', 'filter-everything'), |
| 72 |
'id' => 'posts_container', |
| 73 |
'default' => $defaultPostsContainer, |
| 74 |
'description' => esc_html__( 'e.g. #primary or .main-content', 'filter-everything' ), |
| 75 |
'label' => '', |
| 76 |
'tooltip' => wp_kses( |
| 77 |
__( 'The part of the page where your posts or products are listed. When AJAX is enabled, the plugin refreshes only this area after each filter click, without reloading the whole page.<br /><br />Click «Select visually» and simply click the area with your posts, or enter its CSS id or class if you know it.', 'filter-everything' ), |
| 78 |
array( 'br' => array() ) |
| 79 |
), |
| 80 |
'additional_link' => [ |
| 81 |
'label' => esc_html__( 'Select visually', 'filter-everything' ), |
| 82 |
'url' => add_query_arg( |
| 83 |
[ |
| 84 |
'flrt_get_html_selector' => 1, |
| 85 |
'flrt_set_id' => 'global_posts_container', |
| 86 |
], |
| 87 |
flrt_default_selector_page_link() |
| 88 |
), |
| 89 |
], |
| 90 |
), |
| 91 |
'apply_button_instant_recount' => array( |
| 92 |
'type' => (defined('FLRT_FILTERS_PRO') && FLRT_FILTERS_PRO) ? 'checkbox' : 'inProButton', |
| 93 |
'pro_label' => (defined('FLRT_FILTERS_PRO') && FLRT_FILTERS_PRO) ? '' : flrt_pro_promo_label(), |
| 94 |
'title' => esc_html__('Instant recount for the «Apply Button» mode', 'filter-everything'), |
| 95 |
'id' => 'apply_button_instant_recount', |
| 96 |
'label' => esc_html__('Instantly recalculate filter counters in the browser', 'filter-everything'), |
| 97 |
'description' => (defined('FLRT_FILTERS_PRO') && FLRT_FILTERS_PRO) |
| 98 |
? esc_html__( 'When disabled, Filter Sets in the «Apply Button» mode recalculate counters on the server with an AJAX request on every filter click.', 'filter-everything' ) |
| 99 |
// Free: promo wording — sells what the PRO option does |
| 100 |
: esc_html__( 'When enabled, Filter Sets in the «Apply Button» mode recalculate counters instantly in the browser, without an AJAX request on every filter click.', 'filter-everything' ), |
| 101 |
'tooltip' => wp_kses( |
| 102 |
__( 'This option greatly speeds up filtering, but the recount runs in the visitor\'s browser and may be heavy on sites with a large amount of content. If you filter more than 30,000 posts, make sure filtering does not freeze — especially on mobile devices.', 'filter-everything' ), |
| 103 |
array( 'br' => array() ) |
| 104 |
), |
| 105 |
) |
| 106 |
) |
| 107 |
), |
| 108 |
'common_settings' => array( |
| 109 |
'label' => esc_html__('Other', 'filter-everything'), |
| 110 |
'fields' => array( |
| 111 |
'primary_color' => array( |
| 112 |
'type' => 'text', |
| 113 |
'title' => esc_html__('Widget Primary Color', 'filter-everything'), |
| 114 |
'id' => 'wpc_primary_color', |
| 115 |
'default' => $defaultPrimaryColor, |
| 116 |
'label' => '', |
| 117 |
), |
| 118 |
'disable_filter_links_for_bots' => array( |
| 119 |
'type' => (defined('FLRT_FILTERS_PRO') && FLRT_FILTERS_PRO) ? 'checkbox' : 'inProButton', |
| 120 |
'pro_label' => (defined('FLRT_FILTERS_PRO') && FLRT_FILTERS_PRO) ? '' : flrt_pro_promo_label(), |
| 121 |
'title' => esc_html__('Disable filter links for crawlers', 'filter-everything'), |
| 122 |
'id' => 'disable_filter_links_for_bots', |
| 123 |
'description' => esc_html__( 'Replaces <a> tags with <span> in filters to prevent crawlers from following filter links and overloading your site.', 'filter-everything' ), |
| 124 |
// The detailed how-it-works lives in the tooltip; in free the |
| 125 |
// short promo description is enough |
| 126 |
'tooltip' => (defined('FLRT_FILTERS_PRO') && FLRT_FILTERS_PRO) |
| 127 |
? wp_kses( |
| 128 |
__( 'Filter combinations produce thousands of URLs, and crawlers may waste your crawl budget and server resources trying to follow them all. This option renders filter links as <span> tags — they keep working for visitors, but crawlers no longer see them as links.<br /><br />Links to pages that your SEO Rules define as indexed always keep the real <a> tag, so search engines can still discover and rank those pages.<br /><br />You can also block unwanted pages and specific bots in the robots.txt file.', 'filter-everything' ), |
| 129 |
array( 'br' => array() ) |
| 130 |
) |
| 131 |
: '' |
| 132 |
), |
| 133 |
'container_height' => array( |
| 134 |
'type' => 'text', |
| 135 |
'title' => esc_html__('Filter Container max height, px', 'filter-everything'), |
| 136 |
'id' => 'container_height', |
| 137 |
'label' => '', |
| 138 |
), |
| 139 |
'show_terms_in_content' => array( |
| 140 |
'type' => 'select', |
| 141 |
'title' => esc_html__('Selected Filters (Chips) integration', 'filter-everything'), |
| 142 |
'id' => 'show_terms_in_content', |
| 143 |
'label' => esc_html__('Try to show selected terms above the Results container', 'filter-everything'), |
| 144 |
'options' => array(), |
| 145 |
'multiple' => true, |
| 146 |
'description' => esc_html__( 'Select where to show Chips on your site. Or enter your theme\'s hooks. For example: before_main_content', 'filter-everything' ) |
| 147 |
), |
| 148 |
'widget_debug_messages' => array( |
| 149 |
'type' => 'checkbox', |
| 150 |
'title' => esc_html__('Debug mode', 'filter-everything'), |
| 151 |
'id' => 'widget_debug_messages', |
| 152 |
'label' => esc_html__('Enable debugging messages to help to configure filters', 'filter-everything'), |
| 153 |
) |
| 154 |
) |
| 155 |
) |
| 156 |
); |
| 157 |
|
| 158 |
if (!defined('FLRT_FILTERS_PRO')) { |
| 159 |
$settings['mobile_devices']['fields']['mobile_filter_settings']['options'][''] = esc_html__('Appear as a Pop-up', 'filter-everything') . ' — ' . esc_html__('Available in PRO', 'filter-everything'); |
| 160 |
$settings['mobile_devices']['fields']['mobile_filter_settings']['disabled'][] = ''; |
| 161 |
} |
| 162 |
|
| 163 |
$settings = apply_filters('wpc_general_filters_settings', $settings); |
| 164 |
|
| 165 |
$this->registerSettings($settings, $this->page, $this->optionName); |
| 166 |
} |
| 167 |
|
| 168 |
public function getLabel() |
| 169 |
{ |
| 170 |
return esc_html__('General', 'filter-everything'); |
| 171 |
} |
| 172 |
|
| 173 |
public function getName() |
| 174 |
{ |
| 175 |
return 'settings'; |
| 176 |
} |
| 177 |
|
| 178 |
public function valid() |
| 179 |
{ |
| 180 |
return true; |
| 181 |
} |
| 182 |
} |
| 183 |
|
| 184 |
|