PluginProbe
WebberZone Top 10 — Popular Posts / 4.4.2
WebberZone Top 10 — Popular Posts v4.4.2
4.5.2 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 All 118 releases
top-10 / includes / admin / class-settings.php

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

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