PluginProbe
WebberZone Top 10 — Popular Posts / 4.3.1
WebberZone Top 10 — Popular Posts v4.3.1
4.5.1 4.5.0 4.4.3 4.4.2 4.4.1 4.4.0 4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 trunk 1.0 1.0.1 1.1 1.2 1.3 1.4 1.4.1 1.5 1.5.1 1.5.2 1.5.3 1.6 1.6.1 All 117 releases
top-10 / includes / admin / class-settings.php

class-settings.php in WebberZone Top 10 — Popular Posts 4.3.1, at includes/admin/class-settings.php

1,774 lines 65.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Settings class.
4 *
5 * @package WebberZone\Top_Ten\Admin
6 */
7
8 namespace WebberZone\Top_Ten\Admin;
9
10 use WebberZone\Top_Ten\Admin\Settings\Settings_API;
11 use WebberZone\Top_Ten\Admin\Settings\Settings_Sanitize;
12 use WebberZone\Top_Ten\Frontend\Display;
13 use WebberZone\Top_Ten\Frontend\Media_Handler;
14 use WebberZone\Top_Ten\Util\Hook_Registry;
15
16 // If this file is called directly, abort.
17 if ( ! defined( 'WPINC' ) ) {
18 die;
19 }
20
21 /**
22 * Class to register the settings.
23 *
24 * @since 3.3.0
25 */
26 class Settings {
27
28 /**
29 * Settings API.
30 *
31 * @since 3.3.0
32 *
33 * @var Settings_API Settings API.
34 */
35 public $settings_api;
36
37 /**
38 * Statistics table.
39 *
40 * @since 3.3.0
41 *
42 * @var object Statistics table.
43 */
44 public $statistics;
45
46 /**
47 * Prefix which is used for creating the unique filters and actions.
48 *
49 * @since 3.3.0
50 *
51 * @var string Prefix.
52 */
53 public static $prefix = 'tptn';
54
55 /**
56 * Settings Key.
57 *
58 * @since 3.3.0
59 *
60 * @var string Settings Key.
61 */
62 public $settings_key = 'tptn_settings';
63
64 /**
65 * The slug name to refer to this menu by (should be unique for this menu).
66 *
67 * @since 3.3.0
68 *
69 * @var string Menu slug.
70 */
71 public $menu_slug = 'tptn_options_page';
72
73 /**
74 * Main constructor class.
75 *
76 * @since 3.3.0
77 */
78 public function __construct() {
79 Hook_Registry::add_action( 'admin_menu', array( $this, 'initialise_settings' ) );
80 Hook_Registry::add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 11, 2 );
81 Hook_Registry::add_filter( 'plugin_action_links_' . plugin_basename( TOP_TEN_PLUGIN_FILE ), array( $this, 'plugin_actions_links' ) );
82 Hook_Registry::add_filter( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ), 99 );
83 Hook_Registry::add_filter( self::$prefix . '_settings_sanitize', array( $this, 'change_settings_on_save' ), 99 );
84 Hook_Registry::add_filter( self::$prefix . '_after_setting_output', array( $this, 'display_admin_thumbnail' ), 10, 2 );
85 Hook_Registry::add_filter( self::$prefix . '_setting_field_description', array( $this, 'reset_default_thumb_setting' ), 10, 2 );
86 Hook_Registry::add_filter( self::$prefix . '_settings_page_header', array( $this, 'settings_page_header' ) );
87 Hook_Registry::add_filter( self::$prefix . '_after_setting_output', array( $this, 'after_setting_output' ), 10, 2 );
88 Hook_Registry::add_action( self::$prefix . '_settings_form_buttons', array( $this, 'add_wizard_button' ) );
89
90 Hook_Registry::add_action( 'wp_ajax_nopriv_' . self::$prefix . '_taxonomy_search_tom_select', array( __CLASS__, 'taxonomy_search_tom_select' ) );
91 Hook_Registry::add_action( 'wp_ajax_' . self::$prefix . '_taxonomy_search_tom_select', array( __CLASS__, 'taxonomy_search_tom_select' ) );
92 }
93
94 /**
95 * Initialise the settings API.
96 *
97 * @since 3.3.0
98 */
99 public function initialise_settings() {
100 $props = array(
101 'default_tab' => 'general',
102 'help_sidebar' => $this->get_help_sidebar(),
103 'help_tabs' => $this->get_help_tabs(),
104 'admin_footer_text' => $this->get_admin_footer_text(),
105 'menus' => $this->get_menus(),
106 );
107
108 $args = array(
109 'props' => $props,
110 'translation_strings' => $this->get_translation_strings(),
111 'settings_sections' => $this->get_settings_sections(),
112 'registered_settings' => $this->get_registered_settings(),
113 'upgraded_settings' => array(),
114 );
115
116 $this->settings_api = new Settings_API( $this->settings_key, self::$prefix, $args );
117 }
118
119 /**
120 * Array containing the settings' sections.
121 *
122 * @since 1.8.0
123 *
124 * @return array Settings array
125 */
126 public function get_translation_strings() {
127 $strings = array(
128 'page_header' => esc_html__( 'Top 10 Settings', 'top-10' ),
129 'reset_message' => esc_html__( 'Settings have been reset to their default values. Reload this page to view the updated settings.', 'top-10' ),
130 'success_message' => esc_html__( 'Settings updated.', 'top-10' ),
131 'save_changes' => esc_html__( 'Save Changes', 'top-10' ),
132 'reset_settings' => esc_html__( 'Reset all settings', 'top-10' ),
133 'reset_button_confirm' => esc_html__( 'Do you really want to reset all these settings to their default values?', 'top-10' ),
134 'checkbox_modified' => esc_html__( 'Modified from default setting', 'top-10' ),
135 );
136
137 /**
138 * Filter the array containing the settings' sections.
139 *
140 * @since 1.8.0
141 *
142 * @param array $strings Translation strings.
143 */
144 return apply_filters( self::$prefix . '_translation_strings', $strings );
145 }
146
147 /**
148 * Get the admin menus.
149 *
150 * @return array Admin menus.
151 */
152 public function get_menus() {
153 $menus = array();
154
155 // Settings menu.
156 $menus[] = array(
157 'settings_page' => true,
158 'type' => 'submenu',
159 'parent_slug' => 'tptn_dashboard',
160 'page_title' => esc_html__( 'Top 10 Settings', 'top-10' ),
161 'menu_title' => esc_html__( 'Settings', 'top-10' ),
162 'menu_slug' => $this->menu_slug,
163 );
164
165 return $menus;
166 }
167
168 /**
169 * Array containing the settings' sections.
170 *
171 * @since 3.3.0
172 *
173 * @return array Settings array
174 */
175 public static function get_settings_sections() {
176 $settings_sections = array(
177 'general' => __( 'General', 'top-10' ),
178 'counter' => __( 'Counter/Tracker', 'top-10' ),
179 'list' => __( 'Posts list', 'top-10' ),
180 'thumbnail' => __( 'Thumbnail', 'top-10' ),
181 'styles' => __( 'Styles', 'top-10' ),
182 'maintenance' => __( 'Maintenance', 'top-10' ),
183 'feed' => __( 'Feed', 'top-10' ),
184 );
185
186 /**
187 * Filter the array containing the settings' sections.
188 *
189 * @since 1.2.0
190 *
191 * @param array $settings_sections Settings array
192 */
193 return apply_filters( self::$prefix . '_settings_sections', $settings_sections );
194 }
195
196
197 /**
198 * Retrieve the array of plugin settings
199 *
200 * @since 3.3.0
201 *
202 * @return array Settings array
203 */
204 public static function get_registered_settings() {
205 $settings = array();
206 $sections = self::get_settings_sections();
207
208 foreach ( $sections as $section => $value ) {
209 $method_name = 'settings_' . $section;
210 if ( method_exists( __CLASS__, $method_name ) ) {
211 $settings[ $section ] = self::$method_name();
212 }
213 }
214
215 /**
216 * Filters the settings array
217 *
218 * @since 1.2.0
219 *
220 * @param array $tptn_setings Settings array
221 */
222 return apply_filters( self::$prefix . '_registered_settings', $settings );
223 }
224
225 /**
226 * Retrieve the array of General settings
227 *
228 * @since 3.3.0
229 *
230 * @return array General settings array
231 */
232 public static function settings_general() {
233 $settings = array(
234 'cache' => array(
235 'id' => 'cache',
236 'name' => esc_html__( 'Enable cache', 'top-10' ),
237 'desc' => esc_html__( 'If activated, Top 10 will use the Transients API to cache the popular posts output for the time specified below.', 'top-10' ),
238 'type' => 'checkbox',
239 'default' => true,
240 ),
241 'cache_time' => array(
242 'id' => 'cache_time',
243 'name' => esc_html__( 'Time to cache', 'top-10' ),
244 'desc' => esc_html__( 'Enter the number of seconds to cache the output.', 'top-10' ),
245 'type' => 'text',
246 'default' => HOUR_IN_SECONDS,
247 ),
248 'uninstall_clean_options' => array(
249 'id' => 'uninstall_clean_options',
250 'name' => esc_html__( 'Delete options on uninstall', 'top-10' ),
251 'desc' => esc_html__( 'If this is checked, all settings related to Top 10 are removed from the database if you choose to uninstall/delete the plugin.', 'top-10' ),
252 'type' => 'checkbox',
253 'default' => true,
254 ),
255 'uninstall_clean_tables' => array(
256 'id' => 'uninstall_clean_tables',
257 'name' => esc_html__( 'Delete counter data on uninstall', 'top-10' ),
258 'desc' => esc_html__( 'If this is checked, the tables containing the counter statistics are removed from the database if you choose to uninstall/delete the plugin. Keep this unchecked if you choose to reinstall the plugin and do not want to lose your counter data.', 'top-10' ),
259 'type' => 'checkbox',
260 'default' => false,
261 ),
262 'show_credit' => array(
263 'id' => 'show_credit',
264 'name' => esc_html__( 'Link to Top 10 plugin page', 'top-10' ),
265 'desc' => esc_html__( 'A no-follow link to the plugin homepage will be added as the last item of the popular posts.', 'top-10' ),
266 'type' => 'checkbox',
267 'default' => false,
268 ),
269 'admin_header' => array(
270 'id' => 'admin_header',
271 'name' => '<h3>' . esc_html__( 'Admin settings', 'top-10' ) . '</h3>',
272 'desc' => '',
273 'type' => 'header',
274 ),
275 'show_metabox' => array(
276 'id' => 'show_metabox',
277 'name' => esc_html__( 'Show metabox', 'top-10' ),
278 'desc' => esc_html__( 'This will add the Top 10 metabox on Edit Posts or Add New Posts screens. Also applies to Pages and Custom Post Types.', 'top-10' ),
279 'type' => 'checkbox',
280 'default' => true,
281 ),
282 'show_metabox_admins' => array(
283 'id' => 'show_metabox_admins',
284 'name' => esc_html__( 'Limit meta box to Admins', 'top-10' ),
285 'desc' => esc_html__( 'If selected, the meta box will be hidden from anyone who is not an Admin. By default, Contributors and above will be able to see the meta box. Applies only if the above option is selected.', 'top-10' ),
286 'type' => 'checkbox',
287 'default' => false,
288 ),
289 'pv_in_admin' => array(
290 'id' => 'pv_in_admin',
291 'name' => esc_html__( 'Display admin columns', 'top-10' ),
292 'desc' => esc_html__( "Adds three columns called Total Views, Today's Views and Views. You can selectively disable these by pulling down the Screen Options from the top right of the respective screens.", 'top-10' ),
293 'type' => 'checkbox',
294 'default' => true,
295 ),
296 'admin_column_post_types' => array(
297 'id' => 'admin_column_post_types',
298 'name' => esc_html__( 'Display columns on post types', 'top-10' ),
299 'desc' => esc_html__( 'Select which post types to display the admin columns. Unselect the above option if you would like to disable the columns.', 'top-10' ),
300 'type' => 'posttypes',
301 'default' => 'post,page',
302 'pro' => true,
303 ),
304 'show_count_non_admins' => array(
305 'id' => 'show_count_non_admins',
306 'name' => esc_html__( 'Show views to non-admins', 'top-10' ),
307 'desc' => esc_html__( "If you disable this then non-admins won't see the above columns or view the independent pages with the top posts.", 'top-10' ),
308 'type' => 'checkbox',
309 'default' => true,
310 ),
311 'show_dashboard_to_roles' => array(
312 'id' => 'show_dashboard_to_roles',
313 'name' => esc_html__( 'Also show dashboard to', 'top-10' ),
314 'desc' => esc_html__( 'Choose the user roles that should have access to the Top 10 dashboard, which showcases popular posts over time. These roles are linked to specific capabilities, and selecting a lower role will automatically grant access to higher roles.', 'top-10' ),
315 'type' => 'multicheck',
316 'default' => 'administrator',
317 'options' => self::get_user_roles( array( 'administrator' ) ),
318 'pro' => true,
319 ),
320 'show_admin_bar' => array(
321 'id' => 'show_admin_bar',
322 'name' => esc_html__( 'Show Admin Bar menu', 'top-10' ),
323 'desc' => esc_html__( 'Display the Top 10 menu in the WordPress admin bar with quick access to popular posts stats and tools.', 'top-10' ),
324 'type' => 'checkbox',
325 'default' => true,
326 'pro' => true,
327 ),
328 'query_optimization' => array(
329 'id' => 'query_optimization',
330 'name' => '<h3>' . esc_html__( 'Query Optimization', 'top-10' ) . '</h3>',
331 'desc' => esc_html__( 'Settings for optimizing database queries', 'top-10' ),
332 'type' => 'header',
333 ),
334 'max_execution_time' => array(
335 'id' => 'max_execution_time',
336 'name' => esc_html__( 'Max Execution Time', 'top-10' ),
337 'desc' => esc_html__( 'Maximum execution time for MySQL queries in milliseconds. Set to 0 to disable. Default is 3000 (3 seconds).', 'top-10' ),
338 'type' => 'number',
339 'default' => 3000,
340 'min' => 0,
341 'step' => 100,
342 'pro' => true,
343 ),
344 );
345
346 /**
347 * Filters the General settings array
348 *
349 * @since 3.3.0
350 *
351 * @param array $settings General settings array
352 */
353 return apply_filters( self::$prefix . '_settings_general', $settings );
354 }
355
356
357 /**
358 * Retrieve the array of Counter settings
359 *
360 * @since 3.3.0
361 *
362 * @return array Counter settings array
363 */
364 public static function settings_counter() {
365 $settings = array(
366 'counter_header' => array(
367 'id' => 'counter_header',
368 'name' => '<h3>' . esc_html__( 'Counter settings', 'top-10' ) . '</h3>',
369 'desc' => '',
370 'type' => 'header',
371 ),
372 'add_to' => array(
373 'id' => 'add_to',
374 'name' => esc_html__( 'Display number of views on', 'top-10' ) . ':',
375 /* translators: 1: Code. */
376 'desc' => sprintf( esc_html__( 'If you choose to disable this, please add the following code to your template file where you want it displayed: %1$s', 'top-10' ), "<code>&lt;?php if ( function_exists( 'echo_tptn_post_count' ) ) { echo_tptn_post_count(); } ?&gt;</code>" ),
377 'type' => 'multicheck',
378 'default' => 'single,page',
379 'options' => array(
380 'single' => esc_html__( 'Posts', 'top-10' ),
381 'page' => esc_html__( 'Pages', 'top-10' ),
382 'home' => esc_html__( 'Home page', 'top-10' ),
383 'feed' => esc_html__( 'Feeds', 'top-10' ),
384 'category_archives' => esc_html__( 'Category archives', 'top-10' ),
385 'tag_archives' => esc_html__( 'Tag archives', 'top-10' ),
386 'other_archives' => esc_html__( 'Other archives', 'top-10' ),
387 ),
388 ),
389 'count_disp_form' => array(
390 'id' => 'count_disp_form',
391 'name' => esc_html__( 'Format to display the post views', 'top-10' ),
392 /* translators: 1: Opening a tag, 2: Closing a tag, 3: Opening code tage, 4. Closing code tag. */
393 'desc' => sprintf( esc_html__( 'Use %1$s to display the total count, %2$s for daily count and %3$s for overall counts across all posts. Default display is %4$s', 'top-10' ), '<code>%totalcount%</code>', '<code>%dailycount%</code>', '<code>%overallcount%</code>', '<code>Visited %totalcount% times, %dailycount% visit(s) today</code>' ),
394 'type' => 'textarea',
395 'default' => 'Visited %totalcount% times, %dailycount% visit(s) today',
396 ),
397 'count_disp_form_zero' => array(
398 'id' => 'count_disp_form_zero',
399 'name' => esc_html__( 'No visits text', 'top-10' ),
400 'desc' => esc_html__( "This text is displayed when there are no hits for the post and it isn't a single page. For example, if you display post views on the Homepage or Archives, this text will be used. To override this, simply enter the same text as the above option.", 'top-10' ),
401 'type' => 'textarea',
402 'default' => 'No visits yet',
403 ),
404 'number_format_count' => array(
405 'id' => 'number_format_count',
406 'name' => esc_html__( 'Number format post count', 'top-10' ),
407 'desc' => esc_html__( 'Activating this option will convert the post counts into a number format based on the locale', 'top-10' ),
408 'type' => 'checkbox',
409 'default' => true,
410 ),
411 'daily_midnight' => array(
412 'id' => 'daily_midnight',
413 'name' => esc_html__( 'Start daily counts at midnight', 'top-10' ),
414 'desc' => esc_html__( 'The daily counter displays visits starting at midnight. This option is enabled by default, similar to most standard counters. If you disable this option, you can use the hourly setting in the next option.', 'top-10' ),
415 'type' => 'checkbox',
416 'default' => true,
417 ),
418 'range_desc' => array(
419 'id' => 'range_desc',
420 'name' => esc_html__( 'Default custom period range', 'top-10' ),
421 'desc' => esc_html__( 'The following two options let you set the default range for the custom period. This can be overridden in the widget settings.', 'top-10' ),
422 'type' => 'descriptive_text',
423 ),
424 'daily_range' => array(
425 'id' => 'daily_range',
426 'name' => esc_html__( 'Day(s)', 'top-10' ),
427 'desc' => '',
428 'type' => 'number',
429 'default' => '1',
430 'min' => '0',
431 'size' => 'small',
432 ),
433 'hour_range' => array(
434 'id' => 'hour_range',
435 'name' => esc_html__( 'Hour(s)', 'top-10' ),
436 'desc' => '',
437 'type' => 'number',
438 'default' => '0',
439 'min' => '0',
440 'max' => '23',
441 'size' => 'small',
442 ),
443 'dynamic_post_count' => array(
444 'id' => 'dynamic_post_count',
445 'name' => esc_html__( 'Always display latest post count', 'top-10' ),
446 'desc' => esc_html__( 'This option uses JavaScript and will increase your page load time. Turn this off if you are not using caching plugins or are OK with displaying older cached counts.', 'top-10' ),
447 'type' => 'checkbox',
448 'default' => false,
449 ),
450 'exclude_on_post_ids' => array(
451 'id' => 'exclude_on_post_ids',
452 'name' => esc_html__( 'Exclude display on these post IDs', 'top-10' ),
453 'desc' => esc_html__( 'Comma-separated list of post or page IDs to exclude displaying the top posts on. e.g. 188,320,500', 'top-10' ),
454 'type' => 'numbercsv',
455 'default' => '',
456 ),
457 'tracker_header' => array(
458 'id' => 'tracker_header',
459 'name' => '<h3>' . esc_html__( 'Tracker settings', 'top-10' ) . '</h3>',
460 'desc' => '',
461 'type' => 'header',
462 ),
463 'trackers' => array(
464 'id' => 'trackers',
465 'name' => esc_html__( 'Enable trackers', 'top-10' ),
466 /* translators: 1: Code. */
467 'desc' => esc_html__( 'Top 10 tracks hits in two tables in the database. The overall table only tracks the total hits per post. The daily table tracks hits per post on an hourly basis.', 'top-10' ),
468 'type' => 'multicheck',
469 'default' => 'overall,daily',
470 'options' => array(
471 'overall' => esc_html__( 'Overall', 'top-10' ),
472 'daily' => esc_html__( 'Daily range', 'top-10' ),
473 ),
474 ),
475 'tracker_type' => array(
476 'id' => 'tracker_type',
477 'name' => esc_html__( 'Tracker type', 'top-10' ),
478 'desc' => '',
479 'type' => 'radiodesc',
480 'default' => 'query_based',
481 'options' => self::get_tracker_types(),
482 ),
483 'tracker_all_pages' => array(
484 'id' => 'tracker_all_pages',
485 'name' => esc_html__( 'Load tracker on all pages', 'top-10' ),
486 'desc' => esc_html__( 'This will load the tracker js on all pages. Helpful if you are running minification/concatenation plugins.', 'top-10' ),
487 'type' => 'checkbox',
488 'default' => false,
489 ),
490 'track_feed_views' => array(
491 'id' => 'track_feed_views',
492 'name' => esc_html__( 'Track feed views', 'top-10' ),
493 'desc' => esc_html__( 'Count post views from RSS/Atom feed readers via a tracking pixel. Views are added to the post\'s regular view count. Note: some feed readers block remote images by default; views are only counted when the reader loads images.', 'top-10' ),
494 'type' => 'checkbox',
495 'default' => false,
496 'pro' => true,
497 ),
498 'track_users' => array(
499 'id' => 'track_users',
500 'name' => esc_html__( 'Track user groups', 'top-10' ) . ':',
501 'desc' => esc_html__( 'Uncheck above to disable tracking if the current user falls into any one of these groups.', 'top-10' ),
502 'type' => 'multicheck',
503 'default' => 'authors,editors,admins',
504 'options' => array(
505 'authors' => esc_html__( 'Authors', 'top-10' ),
506 'editors' => esc_html__( 'Editors', 'top-10' ),
507 'admins' => esc_html__( 'Admins', 'top-10' ),
508 ),
509 ),
510 'logged_in' => array(
511 'id' => 'logged_in',
512 'name' => esc_html__( 'Track logged-in users', 'top-10' ),
513 'desc' => esc_html__( 'Uncheck to stop tracking logged in users. Only logged out visitors will be tracked if this is disabled. Unchecking this will override the above setting.', 'top-10' ),
514 'type' => 'checkbox',
515 'default' => true,
516 ),
517 'no_bots' => array(
518 'id' => 'no_bots',
519 'name' => esc_html__( 'Do not track bots', 'top-10' ),
520 'desc' => esc_html__( 'Enable this if you want Top 10 to attempt to stop tracking bots. The plugin includes a comprehensive set of known bot user agents but in some cases this might not be enough to stop tracking bots.', 'top-10' ),
521 'type' => 'checkbox',
522 'default' => false,
523 ),
524 'debug_mode' => array(
525 'id' => 'debug_mode',
526 'name' => esc_html__( 'Debug mode', 'top-10' ),
527 'desc' => esc_html__( 'Setting this to true will force the tracker to display an output in the browser. This is useful if you are having issues and are seeking support.', 'top-10' ),
528 'type' => 'checkbox',
529 'default' => false,
530 ),
531 );
532
533 /**
534 * Filters the Counter settings array
535 *
536 * @since 3.3.0
537 *
538 * @param array $settings Counter settings array
539 */
540 return apply_filters( self::$prefix . '_settings_counter', $settings );
541 }
542
543
544 /**
545 * Retrieve the array of List settings
546 *
547 * @since 3.3.0
548 *
549 * @return array List settings array
550 */
551 public static function settings_list() {
552 $settings = array(
553 'use_global_settings' => array(
554 'id' => 'use_global_settings',
555 'name' => esc_html__( 'Use global settings in block', 'top-10' ),
556 'desc' => esc_html__( 'If activated, the settings from this page are automatically inserted in the Popular Posts block. This also applies to existing blocks which do not have any attributes set if the post is edited.', 'top-10' ),
557 'type' => 'checkbox',
558 'default' => false,
559 'pro' => true,
560 ),
561 'limit' => array(
562 'id' => 'limit',
563 'name' => esc_html__( 'Number of posts to display', 'top-10' ),
564 'desc' => esc_html__( 'Maximum number of posts that will be displayed in the list. This option is used if you do not specify the number of posts in the widget or shortcodes', 'top-10' ),
565 'type' => 'number',
566 'default' => '10',
567 'size' => 'small',
568 ),
569 'how_old' => array(
570 'id' => 'how_old',
571 'name' => esc_html__( 'Published age of posts', 'top-10' ),
572 'desc' => esc_html__( 'This options allows you to only show posts that have been published within the above day range. Applies to both overall posts and daily posts lists. e.g. 365 days will only show posts published in the last year in the popular posts lists. Enter 0 for no restriction.', 'top-10' ),
573 'type' => 'number',
574 'default' => '0',
575 'size' => 'small',
576 ),
577 'post_types' => array(
578 'id' => 'post_types',
579 'name' => esc_html__( 'Post types to include', 'top-10' ),
580 'desc' => esc_html__( 'At least one option should be selected above. Select which post types you want to include in the list of posts. This field can be overridden using a comma separated list of post types when using the manual display.', 'top-10' ),
581 'type' => 'posttypes',
582 'default' => 'post',
583 ),
584 'exclusion_header' => array(
585 'id' => 'exclusion_header',
586 'name' => '<h3>' . esc_html__( 'Exclusion settings', 'top-10' ) . '</h3>',
587 'desc' => '',
588 'type' => 'header',
589 ),
590 'exclude_front' => array(
591 'id' => 'exclude_front',
592 'name' => esc_html__( 'Exclude Front page and Posts page', 'top-10' ),
593 'desc' => esc_html__( 'If you have designated specific pages for your Front page and Posts page via Settings > Reading, they will be tracked like any other page. Enable this option to exclude them from appearing in the popular posts lists. Note that tracking will still occur.', 'top-10' ),
594 'type' => 'checkbox',
595 'default' => false,
596 ),
597 'exclude_current_post' => array(
598 'id' => 'exclude_current_post',
599 'name' => esc_html__( 'Exclude current post', 'top-10' ),
600 'desc' => esc_html__( 'Enabling this will exclude the current post being browsed from being displayed in the popular posts list.', 'top-10' ),
601 'type' => 'checkbox',
602 'default' => false,
603 ),
604 'exclude_post_ids' => array(
605 'id' => 'exclude_post_ids',
606 'name' => esc_html__( 'Post/page IDs to exclude', 'top-10' ),
607 'desc' => esc_html__( 'Comma-separated list of post or page IDs to exclude from the list. e.g. 188,320,500', 'top-10' ),
608 'type' => 'numbercsv',
609 'default' => '',
610 'size' => 'large',
611 ),
612 'exclude_cat_slugs' => array(
613 'id' => 'exclude_cat_slugs',
614 'name' => esc_html__( 'Exclude Categories', 'top-10' ),
615 'desc' => esc_html__( 'Comma separated list of category slugs. The field above has an autocomplete so simply start typing in the starting letters and it will prompt you with options. Does not support custom taxonomies.', 'top-10' ),
616 'type' => 'csv',
617 'default' => '',
618 'size' => 'large',
619 'field_class' => 'ts_autocomplete',
620 'field_attributes' => self::get_taxonomy_search_field_attributes( 'category' ),
621 ),
622 'exclude_categories' => array(
623 'id' => 'exclude_categories',
624 'name' => esc_html__( 'Exclude category IDs', 'top-10' ),
625 'desc' => esc_html__( 'This is a readonly field that is automatically populated based on the above input when the settings are saved. These might differ from the IDs visible in the Categories page which use the term_id. Top 10 uses the term_taxonomy_id which is unique to this taxonomy.', 'top-10' ),
626 'type' => 'text',
627 'default' => '',
628 'size' => 'large',
629 'readonly' => true,
630 ),
631 'exclude_terms_include_parents' => array(
632 'id' => 'exclude_terms_include_parents',
633 'name' => esc_html__( 'Include parent categories', 'top-10' ),
634 'desc' => esc_html__( 'Exclude popular posts from parent categories or all ancestors for nested categories.', 'top-10' ),
635 'type' => 'radio',
636 'default' => 'none',
637 'options' => array(
638 'none' => esc_html__( 'None', 'top-10' ),
639 'parent' => esc_html__( 'Only parent categories', 'top-10' ),
640 'all' => esc_html__( 'All ancestors', 'top-10' ),
641 ),
642 'pro' => true,
643 ),
644 'exclude_on_cat_slugs' => array(
645 'id' => 'exclude_on_cat_slugs',
646 'name' => esc_html__( 'Exclude on Categories', 'top-10' ),
647 'desc' => esc_html__( 'Comma separated list of category slugs. The field above has an autocomplete so simply start typing in the starting letters and it will prompt you with options. Does not support custom taxonomies.', 'top-10' ),
648 'type' => 'csv',
649 'default' => '',
650 'size' => 'large',
651 'field_class' => 'ts_autocomplete',
652 'field_attributes' => self::get_taxonomy_search_field_attributes( 'category' ),
653 ),
654 'customize_output_header' => array(
655 'id' => 'customize_output_header',
656 'name' => '<h3>' . esc_html__( 'Customize the output', 'top-10' ) . '</h3>',
657 'desc' => '',
658 'type' => 'header',
659 ),
660 'title' => array(
661 'id' => 'title',
662 'name' => esc_html__( 'Heading of posts', 'top-10' ),
663 'desc' => esc_html__( 'Displayed before the list of the posts as a the master heading', 'top-10' ),
664 'type' => 'text',
665 'default' => '<h3>' . esc_html__( 'Popular posts:', 'top-10' ) . '</h3>',
666 'size' => 'large',
667 ),
668 'title_daily' => array(
669 'id' => 'title_daily',
670 'name' => esc_html__( 'Heading of posts for daily/custom period lists', 'top-10' ),
671 'desc' => esc_html__( 'Displayed before the list of the posts as a the master heading', 'top-10' ),
672 'type' => 'text',
673 'default' => '<h3>' . esc_html__( 'Currently trending:', 'top-10' ) . '</h3>',
674 'size' => 'large',
675 ),
676 'blank_output' => array(
677 'id' => 'blank_output',
678 'name' => esc_html__( 'Show when no posts are found', 'top-10' ),
679 /* translators: 1: Code. */
680 'desc' => '',
681 'type' => 'radio',
682 'default' => 'blank',
683 'options' => array(
684 'blank' => esc_html__( 'Blank output', 'top-10' ),
685 'custom_text' => esc_html__( 'Display custom text', 'top-10' ),
686 ),
687 ),
688 'blank_output_text' => array(
689 'id' => 'blank_output_text',
690 'name' => esc_html__( 'Custom text', 'top-10' ),
691 'desc' => esc_html__( 'Enter the custom text that will be displayed if the second option is selected above', 'top-10' ),
692 'type' => 'textarea',
693 'default' => esc_html__( 'No top posts yet', 'top-10' ),
694 ),
695 'show_excerpt' => array(
696 'id' => 'show_excerpt',
697 'name' => esc_html__( 'Show post excerpt', 'top-10' ),
698 'desc' => '',
699 'type' => 'checkbox',
700 'default' => false,
701 ),
702 'excerpt_length' => array(
703 'id' => 'excerpt_length',
704 'name' => esc_html__( 'Length of excerpt (in words)', 'top-10' ),
705 'desc' => '',
706 'type' => 'number',
707 'default' => '10',
708 'size' => 'small',
709 ),
710 'show_date' => array(
711 'id' => 'show_date',
712 'name' => esc_html__( 'Show date', 'top-10' ),
713 'desc' => '',
714 'type' => 'checkbox',
715 'default' => false,
716 ),
717 'show_author' => array(
718 'id' => 'show_author',
719 'name' => esc_html__( 'Show author', 'top-10' ),
720 'desc' => '',
721 'type' => 'checkbox',
722 'default' => false,
723 ),
724 'disp_list_count' => array(
725 'id' => 'disp_list_count',
726 'name' => esc_html__( 'Show number of views', 'top-10' ),
727 'desc' => '',
728 'type' => 'checkbox',
729 'default' => false,
730 ),
731 'title_length' => array(
732 'id' => 'title_length',
733 'name' => esc_html__( 'Limit post title length (in characters)', 'top-10' ),
734 'desc' => '',
735 'type' => 'number',
736 'default' => '60',
737 'size' => 'small',
738 ),
739 'link_new_window' => array(
740 'id' => 'link_new_window',
741 'name' => esc_html__( 'Open links in new window', 'top-10' ),
742 'desc' => '',
743 'type' => 'checkbox',
744 'default' => false,
745 ),
746 'link_nofollow' => array(
747 'id' => 'link_nofollow',
748 'name' => esc_html__( 'Add nofollow to links', 'top-10' ),
749 'desc' => '',
750 'type' => 'checkbox',
751 'default' => false,
752 ),
753 'html_wrapper_header' => array(
754 'id' => 'html_wrapper_header',
755 'name' => '<h3>' . esc_html__( 'HTML to display', 'top-10' ) . '</h3>',
756 'desc' => '',
757 'type' => 'header',
758 ),
759 'before_list' => array(
760 'id' => 'before_list',
761 'name' => esc_html__( 'Before the list of posts', 'top-10' ),
762 'desc' => '',
763 'type' => 'text',
764 'default' => '<ul>',
765 'size' => 'large',
766 ),
767 'after_list' => array(
768 'id' => 'after_list',
769 'name' => esc_html__( 'After the list of posts', 'top-10' ),
770 'desc' => '',
771 'type' => 'text',
772 'default' => '</ul>',
773 'size' => 'large',
774 ),
775 'before_list_item' => array(
776 'id' => 'before_list_item',
777 'name' => esc_html__( 'Before each list item', 'top-10' ),
778 'desc' => '',
779 'type' => 'text',
780 'default' => '<li>',
781 'size' => 'large',
782 ),
783 'after_list_item' => array(
784 'id' => 'after_list_item',
785 'name' => esc_html__( 'After each list item', 'top-10' ),
786 'desc' => '',
787 'type' => 'text',
788 'default' => '</li>',
789 'size' => 'large',
790 ),
791 );
792
793 /**
794 * Filters the List settings array
795 *
796 * @since 3.3.0
797 *
798 * @param array $settings List settings array
799 */
800 return apply_filters( self::$prefix . '_settings_list', $settings );
801 }
802
803
804 /**
805 * Retrieve the array of Thumbnail settings
806 *
807 * @since 3.3.0
808 *
809 * @return array Thumbnail settings array
810 */
811 public static function settings_thumbnail() {
812 $settings = array(
813 'post_thumb_op' => array(
814 'id' => 'post_thumb_op',
815 'name' => esc_html__( 'Location of the post thumbnail', 'top-10' ),
816 'desc' => '',
817 'type' => 'radio',
818 'default' => 'text_only',
819 'options' => array(
820 'inline' => esc_html__( 'Display thumbnails inline with posts, before title', 'top-10' ),
821 'after' => esc_html__( 'Display thumbnails inline with posts, after title', 'top-10' ),
822 'thumbs_only' => esc_html__( 'Display only thumbnails, no text', 'top-10' ),
823 'text_only' => esc_html__( 'Do not display thumbnails, only text', 'top-10' ),
824 ),
825 ),
826 'thumb_size' => array(
827 'id' => 'thumb_size',
828 'name' => esc_html__( 'Thumbnail size', 'top-10' ),
829 'desc' => esc_html__( 'You can choose from existing image sizes above or create a custom size (tptn_thumbnail). If you select a custom size, enter the width, height, and crop settings below. For best results, use a cropped image. Note that changing the width and/or height below will not automatically resize existing images. You will need to regenerate the images using a plugin or WP CLI: wp media regenerate.', 'top-10' ),
830 'type' => 'thumbsizes',
831 'default' => 'tptn_thumbnail',
832 'options' => Media_Handler::get_all_image_sizes(),
833 ),
834 'thumb_width' => array(
835 'id' => 'thumb_width',
836 'name' => esc_html__( 'Thumbnail width', 'top-10' ),
837 'desc' => '',
838 'type' => 'number',
839 'default' => '250',
840 'size' => 'small',
841 ),
842 'thumb_height' => array(
843 'id' => 'thumb_height',
844 'name' => esc_html__( 'Thumbnail height', 'top-10' ),
845 'desc' => '',
846 'type' => 'number',
847 'default' => '250',
848 'size' => 'small',
849 ),
850 'thumb_crop' => array(
851 'id' => 'thumb_crop',
852 'name' => esc_html__( 'Hard crop thumbnails', 'top-10' ),
853 'desc' => esc_html__( 'Check this box to hard crop the thumbnails. i.e. force the width and height above vs. maintaining proportions.', 'top-10' ),
854 'type' => 'checkbox',
855 'default' => true,
856 ),
857 'thumb_create_sizes' => array(
858 'id' => 'thumb_create_sizes',
859 'name' => esc_html__( 'Generate thumbnail sizes', 'top-10' ),
860 'desc' => esc_html__( 'If you select this option and tptn_thumbnail is chosen above, the plugin will register the image size with WordPress to create new thumbnails. Note that this does not update old images, as explained above.', 'top-10' ),
861 'type' => 'checkbox',
862 'default' => true,
863 ),
864 'thumb_html' => array(
865 'id' => 'thumb_html',
866 'name' => esc_html__( 'Thumbnail size attributes', 'top-10' ),
867 'desc' => '',
868 'type' => 'radio',
869 'default' => 'html',
870 'options' => array(
871 /* translators: %s: Code. */
872 'css' => sprintf( esc_html__( 'Use CSS to set the width and height: e.g. %s', 'top-10' ), '<code>style="max-width:250px;max-height:250px"</code>' ),
873 /* translators: %s: Code. */
874 'html' => sprintf( esc_html__( 'Use HTML attributes to set the width and height: e.g. %s', 'top-10' ), '<code>width="250" height="250"</code>' ),
875 'none' => esc_html__( 'No width or height set. You will need to use external styles to force any width or height of your choice.', 'top-10' ),
876 ),
877 ),
878 'thumb_meta' => array(
879 'id' => 'thumb_meta',
880 'name' => esc_html__( 'Thumbnail meta field name', 'top-10' ),
881 'desc' => esc_html__( 'The value of this field should contain the URL of the image and can be set in the metabox in the Edit Post screen', 'top-10' ),
882 'type' => 'text',
883 'default' => 'post-image',
884 ),
885 'scan_images' => array(
886 'id' => 'scan_images',
887 'name' => esc_html__( 'Get first image', 'top-10' ),
888 'desc' => esc_html__( 'If enabled, the plugin will fetch the first image in the post content. Note that this might slow down your page loading time if the first image in the posts is large in file size.', 'top-10' ),
889 'type' => 'checkbox',
890 'default' => true,
891 ),
892 'thumb_default_show' => array(
893 'id' => 'thumb_default_show',
894 'name' => esc_html__( 'Use default thumbnail', 'top-10' ),
895 'desc' => esc_html__( 'Check this box to show the default thumbnail from the next option if no thumbnail is found from the post.', 'top-10' ),
896 'type' => 'checkbox',
897 'default' => true,
898 ),
899 'thumb_default' => array(
900 'id' => 'thumb_default',
901 'name' => esc_html__( 'Default thumbnail', 'top-10' ),
902 'desc' => esc_html__( 'Enter the full URL of the image that you wish to display if no thumbnail is found. This image will be displayed below.', 'top-10' ),
903 'type' => 'file',
904 'default' => Display::get_default_thumbnail(),
905 'size' => 'large',
906 ),
907 );
908
909 /**
910 * Filters the Thumbnail settings array
911 *
912 * @since 3.3.0
913 *
914 * @param array $settings Thumbnail settings array
915 */
916 return apply_filters( self::$prefix . '_settings_thumbnail', $settings );
917 }
918
919
920 /**
921 * Retrieve the array of Styles settings
922 *
923 * @since 3.3.0
924 *
925 * @return array Styles settings array
926 */
927 public static function settings_styles() {
928 $settings = array(
929 'tptn_styles' => array(
930 'id' => 'tptn_styles',
931 'name' => esc_html__( 'Popular posts style', 'top-10' ),
932 'desc' => '',
933 'type' => 'select',
934 'default' => 'no_style',
935 'options' => wp_list_pluck( self::get_styles(), 'name', 'id' ),
936 ),
937 'custom_css' => array(
938 'id' => 'custom_css',
939 'name' => esc_html__( 'Custom CSS', 'top-10' ),
940 'desc' => sprintf(
941 /* translators: 1: Opening a tag, 2: Closing a tag, 3: Opening code tage, 4. Closing code tag. */
942 esc_html__( 'Do not include %3$sstyle%4$s tags. Check out %1$sthis article%2$s for available CSS classes to style.', 'top-10' ),
943 '<a href="' . esc_url( 'https://webberzone.com/support/knowledgebase/using-and-customising-top-10/' ) . '" target="_blank">',
944 '</a>',
945 '<code>',
946 '</code>'
947 ),
948 'type' => 'css',
949 'default' => '',
950 'field_class' => 'codemirror_css',
951 ),
952 );
953
954 /**
955 * Filters the Styles settings array
956 *
957 * @since 3.3.0
958 *
959 * @param array $settings Styles settings array
960 */
961 return apply_filters( self::$prefix . '_settings_styles', $settings );
962 }
963
964
965 /**
966 * Retrieve the array of Maintenance settings
967 *
968 * @since 3.3.0
969 *
970 * @return array Maintenance settings array
971 */
972 public static function settings_maintenance() {
973 $settings = array(
974 'cron_on' => array(
975 'id' => 'cron_on',
976 'name' => esc_html__( 'Enable scheduled maintenance', 'top-10' ),
977 'desc' => sprintf(
978 /* translators: 1: Constant holding number of days data is stored. */
979 esc_html__( 'Regularly cleaning the database can enhance performance, especially for high-traffic blogs. Enabling maintenance will automatically delete entries older than %s days from the daily tables.', 'top-10' ),
980 '<strong>' . (int) apply_filters( 'tptn_maintenance_days', TOP_TEN_STORE_DATA ) . '</strong>'
981 ),
982 'type' => 'checkbox',
983 'default' => false,
984 ),
985 'maintenance_days' => array(
986 'id' => 'maintenance_days',
987 'name' => esc_html__( 'Daily table retention period', 'top-10' ),
988 'desc' => sprintf(
989 /* translators: 1: Constant holding number of days data is stored. */
990 esc_html__( 'Enter the number of days to retain data in the daily tables before scheduled maintenance removes older entries. Enter 0 to use the default value of %s days.', 'top-10' ),
991 '<strong>' . TOP_TEN_STORE_DATA . '</strong>'
992 ),
993 'type' => 'number',
994 'default' => 0,
995 'min' => 0,
996 'size' => 'small',
997 'pro' => true,
998 ),
999 'log_retention_days' => array(
1000 'id' => 'log_retention_days',
1001 'name' => esc_html__( 'Visits log retention period', 'top-10' ),
1002 'desc' => sprintf(
1003 /* translators: 1: Default number of days for visits log retention. */
1004 esc_html__( 'Enter the number of days to retain raw visit rows in the visits log table. The log stores one row per visit and grows faster than the daily table, so a shorter window is recommended. Enter 0 to use the default value of %s days.', 'top-10' ),
1005 '<strong>' . TOP_TEN_LOG_STORE_DATA . '</strong>'
1006 ),
1007 'type' => 'number',
1008 'default' => 0,
1009 'min' => 0,
1010 'size' => 'small',
1011 'pro' => true,
1012 ),
1013 'cron_range_desc' => array(
1014 'id' => 'cron_range_desc',
1015 'name' => esc_html__( 'Time to run maintenance', 'top-10' ),
1016 'desc' => esc_html__( 'The next two options allow you to set the time to run the cron.', 'top-10' ),
1017 'type' => 'descriptive_text',
1018 ),
1019 'cron_hour' => array(
1020 'id' => 'cron_hour',
1021 'name' => esc_html__( 'Hour', 'top-10' ),
1022 'desc' => '',
1023 'type' => 'number',
1024 'default' => '0',
1025 'min' => '0',
1026 'max' => '23',
1027 'size' => 'small',
1028 ),
1029 'cron_min' => array(
1030 'id' => 'cron_min',
1031 'name' => esc_html__( 'Minute', 'top-10' ),
1032 'desc' => '',
1033 'type' => 'number',
1034 'default' => '0',
1035 'min' => '0',
1036 'max' => '59',
1037 'size' => 'small',
1038 ),
1039 'cron_recurrence' => array(
1040 'id' => 'cron_recurrence',
1041 'name' => esc_html__( 'Run maintenance', 'top-10' ),
1042 'desc' => '',
1043 'type' => 'radio',
1044 'default' => 'weekly',
1045 'options' => array(
1046 'daily' => esc_html__( 'Daily', 'top-10' ),
1047 'weekly' => esc_html__( 'Weekly', 'top-10' ),
1048 'fortnightly' => esc_html__( 'Fortnightly', 'top-10' ),
1049 'monthly' => esc_html__( 'Monthly', 'top-10' ),
1050 ),
1051 ),
1052 );
1053
1054 /**
1055 * Filters the Maintenance settings array
1056 *
1057 * @since 3.3.0
1058 *
1059 * @param array $settings Maintenance settings array
1060 */
1061 return apply_filters( self::$prefix . '_settings_maintenance', $settings );
1062 }
1063
1064
1065 /**
1066 * Retrieve the array of Feed settings
1067 *
1068 * @since 2.8.0
1069 *
1070 * @return array Feed settings array
1071 */
1072 public static function settings_feed() {
1073 $settings = array(
1074 'feed_permalink_overall' => array(
1075 'id' => 'feed_permalink_overall',
1076 'name' => esc_html__( 'Permalink - Overall', 'top-10' ),
1077 /* translators: 1: Opening link tag, 2: Closing link tag. */
1078 'desc' => sprintf( esc_html__( 'This will set the path of the custom feed generated by the plugin for overall popular posts. You might need to %1$srefresh your permalinks%2$s when changing this option.', 'top-10' ), '<a href="' . admin_url( 'options-permalink.php' ) . '" target="_blank">', '</a>' ),
1079 'type' => 'text',
1080 'default' => 'popular-posts',
1081 'size' => 'large',
1082 ),
1083 'feed_permalink_daily' => array(
1084 'id' => 'feed_permalink_daily',
1085 'name' => esc_html__( 'Permalink - Daily', 'top-10' ),
1086 /* translators: 1: Opening link tag, 2: Closing link tag. */
1087 'desc' => sprintf( esc_html__( 'This will set the path of the custom feed generated by the plugin for daily/custom period popular posts. You might need to %1$srefresh your permalinks%2$s when changing this option.', 'top-10' ), '<a href="' . admin_url( 'options-permalink.php' ) . '" target="_blank">', '</a>' ),
1088 'type' => 'text',
1089 'default' => 'popular-posts-daily',
1090 'size' => 'large',
1091 ),
1092 'feed_limit' => array(
1093 'id' => 'feed_limit',
1094 'name' => esc_html__( 'Number of posts to display', 'top-10' ),
1095 'desc' => esc_html__( 'Maximum number of posts that will be displayed in the custom feed.', 'top-10' ),
1096 'type' => 'number',
1097 'default' => '10',
1098 'size' => 'small',
1099 ),
1100 'feed_daily_range' => array(
1101 'id' => 'feed_daily_range',
1102 'name' => esc_html__( 'Custom period in day(s)', 'top-10' ),
1103 'desc' => '',
1104 'type' => 'number',
1105 'default' => '1',
1106 'min' => '0',
1107 'size' => 'small',
1108 ),
1109 'feed_category_slugs' => array(
1110 'id' => 'feed_category_slugs',
1111 'name' => esc_html__( 'Filter Categories', 'top-10' ),
1112 'desc' => esc_html__( 'Comma separated list of category slugs to include in the feed. The field has an autocomplete so simply start typing the starting letters and it will prompt you with options. Leave blank to include all categories.', 'top-10' ),
1113 'type' => 'csv',
1114 'default' => '',
1115 'size' => 'large',
1116 'field_class' => 'ts_autocomplete',
1117 'field_attributes' => self::get_taxonomy_search_field_attributes( 'category' ),
1118 'pro' => true,
1119 ),
1120 );
1121
1122 /**
1123 * Filters the Feed settings array
1124 *
1125 * @since 2.8.0
1126 *
1127 * @param array $settings Feed settings array
1128 */
1129 return apply_filters( self::$prefix . '_settings_feed', $settings );
1130 }
1131
1132 /**
1133 * Get the various styles.
1134 *
1135 * @since 2.5.0
1136 * @return array Style options.
1137 */
1138 public static function get_styles() {
1139 $styles = array(
1140 array(
1141 'id' => 'no_style',
1142 'name' => esc_html__( 'No styles', 'top-10' ),
1143 'description' => esc_html__( 'Select this option if you plan to add your own styles', 'top-10' ) . '<br />',
1144 ),
1145 array(
1146 'id' => 'text_only',
1147 'name' => esc_html__( 'Text only', 'top-10' ),
1148 'description' => esc_html__( 'Disable thumbnails and no longer include the default style sheet included in the plugin', 'top-10' ) . '<br />',
1149 ),
1150 array(
1151 'id' => 'left_thumbs',
1152 'name' => esc_html__( 'Left thumbnails', 'top-10' ),
1153 'description' => esc_html__( 'Enabling this option will set the post thumbnail to be before text. Disabling this option will not revert any settings.', 'top-10' ),
1154 ),
1155 );
1156
1157 /**
1158 * Filter the array containing the types of styles to add your own.
1159 *
1160 * @since 2.5.0
1161 *
1162 * @param array $styles Different styles.
1163 */
1164 return apply_filters( self::$prefix . '_get_styles', $styles );
1165 }
1166
1167 /**
1168 * Get User Roles.
1169 *
1170 * @since 4.0.0
1171 *
1172 * @param array $remove_roles Roles to remove.
1173 * @return array User roles in the format 'role' => 'name'.
1174 */
1175 public static function get_user_roles( $remove_roles = array() ) {
1176 // Get the global $wp_roles object using the wp_roles() function.
1177 $wp_roles = wp_roles();
1178
1179 // Initialize the array to store roles in the desired format.
1180 $roles_array = array();
1181
1182 if ( ! empty( $wp_roles->roles ) ) {
1183 // Loop through all roles and store them in 'role' => 'name' format.
1184 foreach ( $wp_roles->roles as $role_key => $role_details ) {
1185 if ( in_array( $role_key, $remove_roles, true ) ) {
1186 continue;
1187 }
1188 $roles_array[ $role_key ] = esc_html( $role_details['name'] );
1189 }
1190 } else {
1191 // Fallback to default WordPress roles.
1192 $default_roles = array(
1193 'administrator' => esc_html__( 'Administrator' ),
1194 'editor' => esc_html__( 'Editor' ),
1195 'author' => esc_html__( 'Author' ),
1196 'contributor' => esc_html__( 'Contributor' ),
1197 'subscriber' => esc_html__( 'Subscriber' ),
1198 );
1199
1200 foreach ( $default_roles as $role_key => $role_name ) {
1201 if ( ! in_array( $role_key, $remove_roles, true ) ) {
1202 $roles_array[ $role_key ] = $role_name;
1203 }
1204 }
1205 }
1206
1207 return $roles_array;
1208 }
1209
1210 /**
1211 * Adding WordPress plugin action links.
1212 *
1213 * @since 3.3.0
1214 *
1215 * @param array $links Array of links.
1216 * @return array
1217 */
1218 public function plugin_actions_links( $links ) {
1219
1220 return array_merge(
1221 array(
1222 'settings' => '<a href="' . admin_url( 'admin.php?page=' . $this->menu_slug ) . '">' . esc_html__( 'Settings', 'top-10' ) . '</a>',
1223 ),
1224 $links
1225 );
1226 }
1227
1228 /**
1229 * Add meta links on Plugins page.
1230 *
1231 * @since 3.3.0
1232 *
1233 * @param array $links Array of Links.
1234 * @param string $file Current file.
1235 * @return array
1236 */
1237 public function plugin_row_meta( $links, $file ) {
1238
1239 if ( false !== strpos( $file, 'top-10.php' ) ) {
1240 $new_links = array(
1241 'support' => '<a href = "https://wordpress.org/support/plugin/top-10">' . esc_html__( 'Support', 'top-10' ) . '</a>',
1242 'donate' => '<a href = "https://wzn.io/donate-wz">' . esc_html__( 'Donate', 'top-10' ) . '</a>',
1243 'contribute' => '<a href = "https://github.com/WebberZone/top-10">' . esc_html__( 'Contribute', 'top-10' ) . '</a>',
1244 );
1245
1246 $links = array_merge( $links, $new_links );
1247 }
1248 return $links;
1249 }
1250
1251 /**
1252 * Get the help sidebar content to display on the plugin settings page.
1253 *
1254 * @since 1.8.0
1255 */
1256 public function get_help_sidebar() {
1257 $help_sidebar =
1258 /* translators: 1: Plugin support site link. */
1259 '<p>' . sprintf( __( 'For more information or how to get support visit the <a href="%s">support site</a>.', 'top-10' ), esc_url( 'https://webberzone.com/support/' ) ) . '</p>' .
1260 /* translators: 1: WordPress.org support forums link. */
1261 '<p>' . sprintf( __( 'Support queries should be posted in the <a href="%s">WordPress.org support forums</a>.', 'top-10' ), esc_url( 'https://wordpress.org/support/plugin/top-10' ) ) . '</p>' .
1262 '<p>' . sprintf(
1263 /* translators: 1: Github issues link, 2: Github plugin page link. */
1264 __( '<a href="%1$s">Post an issue</a> on <a href="%2$s">GitHub</a> (bug reports only).', 'top-10' ),
1265 esc_url( 'https://github.com/ajaydsouza/top-10/issues' ),
1266 esc_url( 'https://github.com/ajaydsouza/top-10' )
1267 ) . '</p>';
1268
1269 /**
1270 * Filter to modify the help sidebar content.
1271 *
1272 * @since 1.8.0
1273 *
1274 * @param string $help_sidebar Help sidebar content.
1275 */
1276 return apply_filters( self::$prefix . '_settings_help', $help_sidebar );
1277 }
1278
1279 /**
1280 * Get the help tabs to display on the plugin settings page.
1281 *
1282 * @since 1.8.0
1283 */
1284 public function get_help_tabs() {
1285 $help_tabs = array(
1286 array(
1287 'id' => 'tptn-settings-general-help',
1288 'title' => esc_html__( 'General', 'top-10' ),
1289 'content' =>
1290 '<p><strong>' . esc_html__( 'This tab provides global settings for how Top 10 works across your site.', 'top-10' ) . '</strong></p>' .
1291 '<p>' . esc_html__( 'Configure caching, uninstall behaviour, admin columns, the dashboard, and other high-level options. You must click the Save Changes button at the bottom of the screen for new settings to take effect.', 'top-10' ) . '</p>',
1292 ),
1293 array(
1294 'id' => 'tptn-settings-counter-help',
1295 'title' => esc_html__( 'Counter / Tracker', 'top-10' ),
1296 'content' =>
1297 '<p><strong>' . esc_html__( 'This tab controls how Top 10 tracks and displays view counts.', 'top-10' ) . '</strong></p>' .
1298 '<p>' . esc_html__( 'Choose where to display view counts, how they are formatted, which visits are tracked, and how the tracker works (REST API, query variables, or Ajax).', 'top-10' ) . '</p>',
1299 ),
1300 array(
1301 'id' => 'tptn-settings-list-help',
1302 'title' => esc_html__( 'Posts list', 'top-10' ),
1303 'content' =>
1304 '<p><strong>' . esc_html__( 'This tab controls the popular posts list output.', 'top-10' ) . '</strong></p>' .
1305 '<p>' . esc_html__( 'Configure the number of posts, age of posts, post types, exclusions, and what information is shown (title, date, author, views, excerpts, and HTML wrappers).', 'top-10' ) . '</p>',
1306 ),
1307 array(
1308 'id' => 'tptn-settings-thumbnail-help',
1309 'title' => esc_html__( 'Thumbnail', 'top-10' ),
1310 'content' =>
1311 '<p><strong>' . esc_html__( 'This tab manages thumbnail settings for the popular posts list.', 'top-10' ) . '</strong></p>' .
1312 '<p>' . esc_html__( 'Choose whether thumbnails are displayed, select the image size, configure custom dimensions, cropping, the default thumbnail, and fallback behaviour when no thumbnail is found.', 'top-10' ) . '</p>',
1313 ),
1314 array(
1315 'id' => 'tptn-settings-styles-help',
1316 'title' => esc_html__( 'Styles', 'top-10' ),
1317 'content' =>
1318 '<p><strong>' . esc_html__( 'This tab controls how the popular posts list is styled.', 'top-10' ) . '</strong></p>' .
1319 '<p>' . esc_html__( 'Select a built-in style or disable styles if you want to fully control the look using your own CSS.', 'top-10' ) . '</p>',
1320 ),
1321 array(
1322 'id' => 'tptn-settings-maintenance-help',
1323 'title' => esc_html__( 'Maintenance', 'top-10' ),
1324 'content' =>
1325 '<p><strong>' . esc_html__( 'This tab handles tools and maintenance-related options.', 'top-10' ) . '</strong></p>' .
1326 '<p>' . esc_html__( 'Use this screen to reset settings, clear cached popular posts, and manage database-related options such as pruning or rebuilding counts.', 'top-10' ) . '</p>',
1327 ),
1328 array(
1329 'id' => 'tptn-settings-feed-help',
1330 'title' => esc_html__( 'Feed', 'top-10' ),
1331 'content' =>
1332 '<p><strong>' . esc_html__( 'This tab controls how Top 10 content appears in your site feed.', 'top-10' ) . '</strong></p>' .
1333 '<p>' . esc_html__( 'Configure copyright text and additional HTML that is added before or after the content in your feeds.', 'top-10' ) . '</p>',
1334 ),
1335 );
1336
1337 /**
1338 * Filter to add more help tabs.
1339 *
1340 * @since 1.8.0
1341 *
1342 * @param array $help_tabs Associative array of help tabs.
1343 */
1344 return apply_filters( self::$prefix . '_settings_help', $help_tabs );
1345 }
1346
1347 /**
1348 * Function returns the different types of trackers.
1349 *
1350 * @since 3.3.0
1351 * @return array Tracker types.
1352 */
1353 public static function get_tracker_types() {
1354
1355 $trackers = array(
1356 array(
1357 'id' => 'rest_based',
1358 'name' => __( 'REST API based', 'top-10' ),
1359 'description' => __( 'Uses the REST API to record visits', 'top-10' ),
1360 ),
1361 array(
1362 'id' => 'query_based',
1363 'name' => __( 'Query variable based', 'top-10' ),
1364 'description' => __( 'Uses query variables to record visits', 'top-10' ),
1365 ),
1366 array(
1367 'id' => 'ajaxurl',
1368 'name' => __( 'Ajaxurl based', 'top-10' ),
1369 'description' => __( 'Uses admin-ajax.php which is inbuilt within WordPress to process the tracker', 'top-10' ),
1370 ),
1371 );
1372
1373 /**
1374 * Filter the array containing the types of trackers to add your own.
1375 *
1376 * @since 2.4.0
1377 *
1378 * @param array $trackers Different trackers.
1379 */
1380 return apply_filters( self::$prefix . '_get_tracker_types', $trackers );
1381 }
1382
1383
1384
1385
1386 /**
1387 * Add footer text on the plugin page.
1388 *
1389 * @since 2.0.0
1390 */
1391 public static function get_admin_footer_text() {
1392 return sprintf(
1393 /* translators: 1: Opening achor tag with Plugin page link, 2: Closing anchor tag, 3: Opening anchor tag with review link. */
1394 __( 'Thank you for using %1$sWebberZone Top 10%2$s! Please %3$srate us%2$s on WordPress.org', 'top-10' ),
1395 '<a href="https://webberzone.com/plugins/top-10/" target="_blank">',
1396 '</a>',
1397 '<a href="https://wordpress.org/support/plugin/top-10/reviews/#new-post" target="_blank">'
1398 );
1399 }
1400
1401 /**
1402 * Enqueue scripts and styles.
1403 *
1404 * @since 3.3.0
1405 *
1406 * @param string $hook Current hook.
1407 */
1408 public function admin_enqueue_scripts( $hook ) {
1409
1410 if ( ! isset( $this->settings_api->settings_page ) || $this->settings_api->settings_page !== $hook ) {
1411 return;
1412 }
1413
1414 wp_enqueue_script( 'top-ten-admin-js' );
1415 wp_enqueue_style( 'top-ten-admin-css' );
1416 wp_enqueue_style( 'wp-spinner' );
1417 wp_localize_script(
1418 'top-ten-admin-js',
1419 'tptn_admin',
1420 array(
1421 'thumb_default' => Display::get_default_thumbnail(),
1422 )
1423 );
1424 wp_localize_script(
1425 'top-ten-admin-js',
1426 'top_ten_admin_data',
1427 array(
1428 'security' => wp_create_nonce( 'tptn-admin' ),
1429 'strings' => array(
1430 'confirm_message' => esc_html__( 'Are you sure you want to clear the cache?', 'top-10' ),
1431 'clearing_text' => esc_html__( 'Clearing...', 'top-10' ),
1432 'success_message' => esc_html__( 'Cache cleared successfully!', 'top-10' ),
1433 'fail_message' => esc_html__( 'Failed to clear cache. Please try again.', 'top-10' ),
1434 'request_fail_message' => esc_html__( 'Request failed: ', 'top-10' ),
1435 'left_thumbs_message' => esc_html__( 'Note: This setting cannot be changed as the Popular posts style is set to Left thumbnails. You can change the style in the Styles tab.', 'top-10' ),
1436 'grid_thumbs_message' => esc_html__( 'Note: This setting cannot be changed as the Popular posts style is set to Grid thumbnails. You can change the style in the Styles tab.', 'top-10' ),
1437 'text_only_message' => esc_html__( 'Note: This setting cannot be changed as the Popular posts style is set to Text only. You can change the style in the Styles tab.', 'top-10' ),
1438 ),
1439 )
1440 );
1441 }
1442
1443 /**
1444 * Modify settings when they are being saved.
1445 *
1446 * @since 3.3.0
1447 *
1448 * @param array $settings Settings array.
1449 * @return array Sanitized settings array.
1450 */
1451 public function change_settings_on_save( $settings ) {
1452
1453 Settings_Sanitize::sanitize_tax_slugs( $settings, 'exclude_cat_slugs', 'exclude_categories' );
1454 Settings_Sanitize::sanitize_tax_slugs( $settings, 'exclude_on_cat_slugs', 'exclude_on_categories' );
1455 Settings_Sanitize::sanitize_tax_slugs( $settings, 'feed_category_slugs', 'feed_categories' );
1456
1457 // Save cron settings.
1458 $settings['cron_hour'] = min( 23, absint( $settings['cron_hour'] ) );
1459 $settings['cron_min'] = min( 59, absint( $settings['cron_min'] ) );
1460
1461 if ( ! empty( $settings['cron_on'] ) ) {
1462 \WebberZone\Top_Ten\Admin\Cron::enable_run( $settings['cron_hour'], $settings['cron_min'], $settings['cron_recurrence'] );
1463 } else {
1464 \WebberZone\Top_Ten\Admin\Cron::disable_run();
1465 }
1466
1467 // Force thumb_width and thumb_height if either are zero.
1468 if ( empty( $settings['thumb_width'] ) || empty( $settings['thumb_height'] ) ) {
1469 list( $settings['thumb_width'], $settings['thumb_height'] ) = Media_Handler::get_thumb_size( $settings['thumb_size'] );
1470 }
1471
1472 // Overwrite settings based on selected style; guard against missing keys on reset.
1473 $style = $settings['tptn_styles'] ?? '';
1474
1475 $inline_thumb_styles = array(
1476 'left_thumbs' => esc_html__( 'Note: Thumbnail location can only be Inline or Thumbnails only when the Popular posts style is set to Left thumbnails. You can change the style in the Styles tab.', 'top-10' ),
1477 'grid_thumbs' => esc_html__( 'Note: Thumbnail location can only be Inline or Thumbnails only when the Popular posts style is set to Grid thumbnails. You can change the style in the Styles tab.', 'top-10' ),
1478 );
1479
1480 if ( array_key_exists( $style, $inline_thumb_styles ) ) {
1481 $post_thumb_op = $settings['post_thumb_op'] ?? '';
1482 if ( 'inline' !== $post_thumb_op && 'thumbs_only' !== $post_thumb_op ) {
1483 $settings['post_thumb_op'] = 'inline';
1484 }
1485
1486 add_settings_error(
1487 self::$prefix . '-notices',
1488 '',
1489 $inline_thumb_styles[ $style ],
1490 'warning'
1491 );
1492 }
1493 // Overwrite settings if text_only style is selected.
1494 if ( 'text_only' === $style ) {
1495 $settings['post_thumb_op'] = 'text_only';
1496
1497 add_settings_error(
1498 self::$prefix . '-notices',
1499 '',
1500 esc_html__( 'Note: Thumbnail location set to Text only as the Popular posts style is set to Text only. You can change the style in the Styles tab.', 'top-10' ),
1501 'warning'
1502 );
1503 }
1504
1505 // Delete the cache.
1506 \WebberZone\Top_Ten\Util\Cache::delete();
1507
1508 return $settings;
1509 }
1510
1511 /**
1512 * Display the default thumbnail below the setting.
1513 *
1514 * @since 3.3.0
1515 *
1516 * @param string $html Current HTML.
1517 * @param array $args Argument array of the setting.
1518 * @return string
1519 */
1520 public function display_admin_thumbnail( $html, $args ) {
1521
1522 $thumb_default = \tptn_get_option( 'thumb_default' );
1523
1524 if ( 'thumb_default' === $args['id'] && '' !== $thumb_default ) {
1525 $html .= '<br />';
1526 $html .= sprintf( '<img src="%1$s" style="max-width:200px" title="%2$s" alt="%2$s" />', esc_attr( $thumb_default ), esc_html__( 'Default thumbnail', 'top-10' ) );
1527 }
1528
1529 return $html;
1530 }
1531
1532 /**
1533 * Display the default thumbnail below the setting.
1534 *
1535 * @since 3.3.0
1536 *
1537 * @param string $html Current HTML.
1538 * @param array $args Argument array of the setting.
1539 * @return string
1540 */
1541 public function reset_default_thumb_setting( $html, $args ) {
1542
1543 $thumb_default = \tptn_get_option( 'thumb_default' );
1544
1545 if ( 'thumb_default' === $args['id'] && Display::get_default_thumbnail() !== $thumb_default ) {
1546 $html = '<span class="dashicons dashicons-undo reset-default-thumb" style="cursor: pointer;" title="' . __( 'Reset' ) . '"></span> <br />' . $html;
1547 }
1548
1549 return $html;
1550 }
1551
1552 /**
1553 * Add a link to the Tools page from the settings page.
1554 *
1555 * @since 3.5.0
1556 */
1557 public static function settings_page_header() {
1558 global $tptn_freemius;
1559 ?>
1560 <p>
1561 <?php if ( ! $tptn_freemius->is_paying() ) { ?>
1562 <a class="tptn_button tptn_button_gold" href="<?php echo esc_url( $tptn_freemius->get_upgrade_url() ); ?>">
1563 <?php esc_html_e( 'Upgrade to Pro', 'top-10' ); ?>
1564 </a>
1565 <?php } ?>
1566 </p>
1567
1568 <?php
1569 }
1570
1571 /**
1572 * Updated the settings fields to display a pro version link.
1573 *
1574 * @param string $output Settings field HTML.
1575 * @param array $args Settings field arguments.
1576 * @return string Updated HTML.
1577 */
1578 public static function after_setting_output( $output, $args ) {
1579 if ( isset( $args['pro'] ) && $args['pro'] ) {
1580 $output .= sprintf(
1581 '<a class="tptn_button tptn_button_gold" target="_blank" href="%s" title="%s">%s</a>',
1582 esc_url( \WebberZone\Top_Ten\tptn_freemius()->get_upgrade_url() ),
1583 esc_attr__( 'Upgrade to Pro', 'top-10' ),
1584 esc_html__( 'Upgrade to Pro', 'top-10' )
1585 );
1586 }
1587
1588 if ( isset( $args['id'] ) && 'tptn_styles' === $args['id'] ) {
1589 $post_thumb_op = \tptn_get_option( 'post_thumb_op' );
1590 $tptn_style = \tptn_get_option( 'tptn_styles' );
1591
1592 if ( 'text_only' === $post_thumb_op && 'text_only' !== $tptn_style ) {
1593 $output .= sprintf(
1594 '<p class="description" style="color:#9B0800;">%s</p>',
1595 esc_html__( 'Note: Thumbnail location is set to "Do not display thumbnails, only text". This may override the selected style.', 'top-10' )
1596 );
1597 }
1598 }
1599
1600 return $output;
1601 }
1602
1603 /**
1604 * Add a button to the settings page to start the settings wizard.
1605 *
1606 * @since 4.2.0
1607 */
1608 public function add_wizard_button() {
1609 printf(
1610 '<br /><a aria-label="%s" class="button button-secondary" href="%s" title="%s" style="margin-top: 10px;">%s</a>',
1611 esc_attr__( 'Start Settings Wizard', 'top-10' ),
1612 esc_url( admin_url( 'admin.php?page=tptn_wizard' ) ),
1613 esc_attr__( 'Start Settings Wizard', 'top-10' ),
1614 esc_html__( 'Start Settings Wizard', 'top-10' )
1615 );
1616 }
1617
1618 /**
1619 * Handle Tom Select taxonomy search AJAX requests.
1620 *
1621 * @since 4.2.0
1622 *
1623 * @return void
1624 */
1625 public static function taxonomy_search_tom_select() {
1626 // Verify nonce.
1627 if ( ! isset( $_REQUEST['nonce'] ) ) {
1628 wp_send_json_error( array( 'message' => 'Missing nonce' ) );
1629 }
1630
1631 $nonce_valid = wp_verify_nonce( sanitize_key( $_REQUEST['nonce'] ), self::$prefix . '_taxonomy_search_tom_select' );
1632
1633 if ( ! $nonce_valid ) {
1634 wp_send_json_error(
1635 array(
1636 'message' => 'Invalid nonce',
1637 'received_nonce' => sanitize_key( $_REQUEST['nonce'] ),
1638 'expected_action' => self::$prefix . '_taxonomy_search_tom_select',
1639 )
1640 );
1641 }
1642
1643 if ( ! isset( $_REQUEST['endpoint'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
1644 wp_send_json_error( 'Missing endpoint' );
1645 }
1646
1647 $endpoint = sanitize_key( $_REQUEST['endpoint'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
1648
1649 $search_term = isset( $_REQUEST['q'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['q'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
1650
1651 $comma = _x( ',', 'tag delimiter', 'top-10' );
1652 if ( ',' !== $comma ) {
1653 $search_term = str_replace( $comma, ',', $search_term );
1654 }
1655 if ( false !== strpos( $search_term, ',' ) ) {
1656 $search_term = explode( ',', $search_term );
1657 $search_term = $search_term[ count( $search_term ) - 1 ];
1658 }
1659 $search_term = trim( $search_term );
1660
1661 if ( 'public_taxonomies' === $endpoint ) {
1662 $taxonomies = (array) get_taxonomies( array( 'public' => true ), 'objects' );
1663 $taxonomy = array();
1664 $tax = null;
1665
1666 foreach ( $taxonomies as $taxonomy_name => $taxonomy_object ) {
1667 if ( empty( $taxonomy_object->cap->assign_terms ) ) {
1668 continue;
1669 }
1670
1671 if ( ! current_user_can( $taxonomy_object->cap->assign_terms ) ) {
1672 continue;
1673 }
1674
1675 $taxonomy[] = $taxonomy_object->name;
1676 }
1677
1678 if ( empty( $taxonomy ) ) {
1679 wp_send_json_success( array() );
1680 }
1681
1682 $tax = get_taxonomy( $taxonomy[0] );
1683 } else {
1684 $taxonomy = $endpoint;
1685 $tax = get_taxonomy( $taxonomy );
1686
1687 if ( ! $tax ) {
1688 wp_send_json_error( 'Invalid taxonomy' );
1689 }
1690
1691 if ( ! current_user_can( $tax->cap->assign_terms ) ) {
1692 wp_send_json_error( 'Insufficient permissions' );
1693 }
1694 }
1695
1696 /** This filter has been defined in /wp-admin/includes/ajax-actions.php */
1697 $term_search_min_chars = (int) apply_filters( 'term_search_min_chars', 2, $tax, $search_term );
1698
1699 /*
1700 * Require $term_search_min_chars chars for matching (default: 2)
1701 * ensure it's a non-negative, non-zero integer.
1702 */
1703 if ( ( 0 === $term_search_min_chars ) || ( strlen( $search_term ) < $term_search_min_chars ) ) {
1704 wp_send_json_success( array() );
1705 }
1706
1707 $terms = get_terms(
1708 array(
1709 'taxonomy' => $taxonomy,
1710 'name__like' => $search_term,
1711 'hide_empty' => false,
1712 )
1713 );
1714
1715 $results = array();
1716 foreach ( (array) $terms as $term ) {
1717 $formatted_string = "{$term->name} ({$term->taxonomy}:{$term->term_taxonomy_id})";
1718 $results[] = array(
1719 'value' => $formatted_string,
1720 'text' => $term->name,
1721 );
1722 }
1723
1724 wp_send_json_success( $results );
1725 }
1726
1727 /**
1728 * Get field attributes for Tom Select taxonomy search fields.
1729 *
1730 * @since 4.2.0
1731 *
1732 * @param string $taxonomy The taxonomy to search.
1733 * @param array $ts_config Optional Tom Select configuration.
1734 * @return array Field attributes array.
1735 */
1736 private static function get_taxonomy_search_field_attributes( $taxonomy, $ts_config = array() ) {
1737 $attributes = array(
1738 'data-wp-prefix' => strtoupper( (string) self::$prefix ),
1739 'data-wp-action' => self::$prefix . '_taxonomy_search_tom_select',
1740 'data-wp-nonce' => wp_create_nonce( self::$prefix . '_taxonomy_search_tom_select' ),
1741 'data-wp-endpoint' => $taxonomy,
1742 );
1743
1744 if ( ! empty( $ts_config ) ) {
1745 $attributes['data-ts-config'] = wp_json_encode( $ts_config );
1746 }
1747
1748 return $attributes;
1749 }
1750
1751 /**
1752 * Get field attributes for Tom Select meta key search fields.
1753 *
1754 * @since 4.2.0
1755 *
1756 * @param array $ts_config Optional Tom Select configuration.
1757 * @return array Field attributes array.
1758 */
1759 private static function get_meta_keys_search_field_attributes( $ts_config = array() ) {
1760 $attributes = array(
1761 'data-wp-prefix' => strtoupper( (string) self::$prefix ),
1762 'data-wp-action' => self::$prefix . '_taxonomy_search_tom_select',
1763 'data-wp-nonce' => wp_create_nonce( self::$prefix . '_taxonomy_search_tom_select' ),
1764 'data-wp-endpoint' => 'meta_keys',
1765 );
1766
1767 if ( ! empty( $ts_config ) ) {
1768 $attributes['data-ts-config'] = wp_json_encode( $ts_config );
1769 }
1770
1771 return $attributes;
1772 }
1773 }
1774