'general', 'help_sidebar' => $this->get_help_sidebar(), 'help_tabs' => $this->get_help_tabs(), 'admin_footer_text' => $this->get_admin_footer_text(), 'menus' => $this->get_menus(), ); $args = array( 'props' => $props, 'translation_strings' => $this->get_translation_strings(), 'settings_sections' => $this->get_settings_sections(), 'registered_settings' => $this->get_registered_settings(), 'upgraded_settings' => array(), ); $this->settings_api = new Settings_API( $this->settings_key, self::$prefix, $args ); } /** * Array containing the settings' sections. * * @since 1.8.0 * * @return array Settings array */ public function get_translation_strings() { $strings = array( 'page_header' => esc_html__( 'Top 10 Settings', 'top-10' ), 'reset_message' => esc_html__( 'Settings have been reset to their default values. Reload this page to view the updated settings.', 'top-10' ), 'success_message' => esc_html__( 'Settings updated.', 'top-10' ), 'save_changes' => esc_html__( 'Save Changes', 'top-10' ), 'reset_settings' => esc_html__( 'Reset all settings', 'top-10' ), 'reset_button_confirm' => esc_html__( 'Do you really want to reset all these settings to their default values?', 'top-10' ), 'checkbox_modified' => esc_html__( 'Modified from default setting', 'top-10' ), ); /** * Filter the array containing the settings' sections. * * @since 1.8.0 * * @param array $strings Translation strings. */ return apply_filters( self::$prefix . '_translation_strings', $strings ); } /** * Get the admin menus. * * @return array Admin menus. */ public function get_menus() { $menus = array(); // Settings menu. $menus[] = array( 'settings_page' => true, 'type' => 'submenu', 'parent_slug' => 'tptn_dashboard', 'page_title' => esc_html__( 'Top 10 Settings', 'top-10' ), 'menu_title' => esc_html__( 'Settings', 'top-10' ), 'menu_slug' => $this->menu_slug, ); return $menus; } /** * Array containing the settings' sections. * * @since 3.3.0 * * @return array Settings array */ public static function get_settings_sections() { $settings_sections = array( 'general' => __( 'General', 'top-10' ), 'counter' => __( 'Counter/Tracker', 'top-10' ), 'list' => __( 'Posts list', 'top-10' ), 'thumbnail' => __( 'Thumbnail', 'top-10' ), 'styles' => __( 'Styles', 'top-10' ), 'maintenance' => __( 'Maintenance', 'top-10' ), 'feed' => __( 'Feed', 'top-10' ), ); /** * Filter the array containing the settings' sections. * * @since 1.2.0 * * @param array $settings_sections Settings array */ return apply_filters( self::$prefix . '_settings_sections', $settings_sections ); } /** * Retrieve the array of plugin settings * * @since 3.3.0 * * @return array Settings array */ public static function get_registered_settings() { $settings = array(); $sections = self::get_settings_sections(); foreach ( $sections as $section => $value ) { $method_name = 'settings_' . $section; if ( method_exists( __CLASS__, $method_name ) ) { $settings[ $section ] = self::$method_name(); } } /** * Filters the settings array * * @since 1.2.0 * * @param array $tptn_setings Settings array */ return apply_filters( self::$prefix . '_registered_settings', $settings ); } /** * Retrieve the array of General settings * * @since 3.3.0 * * @return array General settings array */ public static function settings_general() { $settings = array( 'cache' => array( 'id' => 'cache', 'name' => esc_html__( 'Enable cache', 'top-10' ), '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' ), 'type' => 'checkbox', 'default' => true, ), 'cache_time' => array( 'id' => 'cache_time', 'name' => esc_html__( 'Time to cache', 'top-10' ), 'desc' => esc_html__( 'Enter the number of seconds to cache the output.', 'top-10' ), 'type' => 'text', 'default' => HOUR_IN_SECONDS, ), 'uninstall_clean_options' => array( 'id' => 'uninstall_clean_options', 'name' => esc_html__( 'Delete options on uninstall', 'top-10' ), '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' ), 'type' => 'checkbox', 'default' => true, ), 'uninstall_clean_tables' => array( 'id' => 'uninstall_clean_tables', 'name' => esc_html__( 'Delete counter data on uninstall', 'top-10' ), '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' ), 'type' => 'checkbox', 'default' => false, ), 'show_credit' => array( 'id' => 'show_credit', 'name' => esc_html__( 'Link to Top 10 plugin page', 'top-10' ), 'desc' => esc_html__( 'A no-follow link to the plugin homepage will be added as the last item of the popular posts.', 'top-10' ), 'type' => 'checkbox', 'default' => false, ), 'admin_header' => array( 'id' => 'admin_header', 'name' => '
<?php if ( function_exists( 'echo_tptn_post_count' ) ) { echo_tptn_post_count(); } ?>" ),
'type' => 'multicheck',
'default' => 'single,page',
'options' => array(
'single' => esc_html__( 'Posts', 'top-10' ),
'page' => esc_html__( 'Pages', 'top-10' ),
'home' => esc_html__( 'Home page', 'top-10' ),
'feed' => esc_html__( 'Feeds', 'top-10' ),
'category_archives' => esc_html__( 'Category archives', 'top-10' ),
'tag_archives' => esc_html__( 'Tag archives', 'top-10' ),
'other_archives' => esc_html__( 'Other archives', 'top-10' ),
),
),
'count_disp_form' => array(
'id' => 'count_disp_form',
'name' => esc_html__( 'Format to display the post views', 'top-10' ),
/* translators: 1: Opening a tag, 2: Closing a tag, 3: Opening code tage, 4. Closing code tag. */
'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' ), '%totalcount%', '%dailycount%', '%overallcount%', 'Visited %totalcount% times, %dailycount% visit(s) today' ),
'type' => 'textarea',
'default' => 'Visited %totalcount% times, %dailycount% visit(s) today',
),
'count_disp_form_zero' => array(
'id' => 'count_disp_form_zero',
'name' => esc_html__( 'No visits text', 'top-10' ),
'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' ),
'type' => 'textarea',
'default' => 'No visits yet',
),
'number_format_count' => array(
'id' => 'number_format_count',
'name' => esc_html__( 'Number format post count', 'top-10' ),
'desc' => esc_html__( 'Activating this option will convert the post counts into a number format based on the locale', 'top-10' ),
'type' => 'checkbox',
'default' => true,
),
'daily_midnight' => array(
'id' => 'daily_midnight',
'name' => esc_html__( 'Start daily counts at midnight', 'top-10' ),
'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' ),
'type' => 'checkbox',
'default' => true,
),
'range_desc' => array(
'id' => 'range_desc',
'name' => esc_html__( 'Default custom period range', 'top-10' ),
'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' ),
'type' => 'descriptive_text',
),
'daily_range' => array(
'id' => 'daily_range',
'name' => esc_html__( 'Day(s)', 'top-10' ),
'desc' => '',
'type' => 'number',
'default' => '1',
'min' => '0',
'size' => 'small',
),
'hour_range' => array(
'id' => 'hour_range',
'name' => esc_html__( 'Hour(s)', 'top-10' ),
'desc' => '',
'type' => 'number',
'default' => '0',
'min' => '0',
'max' => '23',
'size' => 'small',
),
'dynamic_post_count' => array(
'id' => 'dynamic_post_count',
'name' => esc_html__( 'Always display latest post count', 'top-10' ),
'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' ),
'type' => 'checkbox',
'default' => false,
),
'exclude_on_post_ids' => array(
'id' => 'exclude_on_post_ids',
'name' => esc_html__( 'Exclude display on these post IDs', 'top-10' ),
'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' ),
'type' => 'numbercsv',
'default' => '',
),
'tracker_header' => array(
'id' => 'tracker_header',
'name' => 'style="max-width:250px;max-height:250px"' ),
/* translators: %s: Code. */
'html' => sprintf( esc_html__( 'Use HTML attributes to set the width and height: e.g. %s', 'top-10' ), 'width="250" height="250"' ),
'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' ),
),
),
'thumb_meta' => array(
'id' => 'thumb_meta',
'name' => esc_html__( 'Thumbnail meta field name', 'top-10' ),
'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' ),
'type' => 'text',
'default' => 'post-image',
),
'scan_images' => array(
'id' => 'scan_images',
'name' => esc_html__( 'Get first image', 'top-10' ),
'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' ),
'type' => 'checkbox',
'default' => true,
),
'thumb_default_show' => array(
'id' => 'thumb_default_show',
'name' => esc_html__( 'Use default thumbnail', 'top-10' ),
'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' ),
'type' => 'checkbox',
'default' => true,
),
'thumb_default' => array(
'id' => 'thumb_default',
'name' => esc_html__( 'Default thumbnail', 'top-10' ),
'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' ),
'type' => 'file',
'default' => Display::get_default_thumbnail(),
'size' => 'large',
),
);
/**
* Filters the Thumbnail settings array
*
* @since 3.3.0
*
* @param array $settings Thumbnail settings array
*/
return apply_filters( self::$prefix . '_settings_thumbnail', $settings );
}
/**
* Retrieve the array of Styles settings
*
* @since 3.3.0
*
* @return array Styles settings array
*/
public static function settings_styles() {
$settings = array(
'tptn_styles' => array(
'id' => 'tptn_styles',
'name' => esc_html__( 'Popular posts style', 'top-10' ),
'desc' => '',
'type' => 'select',
'default' => 'no_style',
'options' => wp_list_pluck( self::get_styles(), 'name', 'id' ),
),
'custom_css' => array(
'id' => 'custom_css',
'name' => esc_html__( 'Custom CSS', 'top-10' ),
'desc' => sprintf(
/* translators: 1: Opening a tag, 2: Closing a tag, 3: Opening code tage, 4. Closing code tag. */
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' ),
'',
'',
'',
''
),
'type' => 'css',
'default' => '',
'field_class' => 'codemirror_css',
),
);
/**
* Filters the Styles settings array
*
* @since 3.3.0
*
* @param array $settings Styles settings array
*/
return apply_filters( self::$prefix . '_settings_styles', $settings );
}
/**
* Retrieve the array of Maintenance settings
*
* @since 3.3.0
*
* @return array Maintenance settings array
*/
public static function settings_maintenance() {
$settings = array(
'cron_on' => array(
'id' => 'cron_on',
'name' => esc_html__( 'Enable scheduled maintenance', 'top-10' ),
'desc' => sprintf(
/* translators: 1: Constant holding number of days data is stored. */
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' ),
'' . (int) apply_filters( 'tptn_maintenance_days', TOP_TEN_STORE_DATA ) . ''
),
'type' => 'checkbox',
'default' => false,
),
'maintenance_days' => array(
'id' => 'maintenance_days',
'name' => esc_html__( 'Daily table retention period', 'top-10' ),
'desc' => sprintf(
/* translators: 1: Constant holding number of days data is stored. */
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' ),
'' . TOP_TEN_STORE_DATA . ''
),
'type' => 'number',
'default' => 0,
'min' => 0,
'size' => 'small',
'pro' => true,
),
'log_retention_days' => array(
'id' => 'log_retention_days',
'name' => esc_html__( 'Visits log retention period', 'top-10' ),
'desc' => sprintf(
/* translators: 1: Default number of days for visits log retention. */
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' ),
'' . TOP_TEN_LOG_STORE_DATA . ''
),
'type' => 'number',
'default' => 0,
'min' => 0,
'size' => 'small',
'pro' => true,
),
'cron_range_desc' => array(
'id' => 'cron_range_desc',
'name' => esc_html__( 'Time to run maintenance', 'top-10' ),
'desc' => esc_html__( 'The next two options allow you to set the time to run the cron.', 'top-10' ),
'type' => 'descriptive_text',
),
'cron_hour' => array(
'id' => 'cron_hour',
'name' => esc_html__( 'Hour', 'top-10' ),
'desc' => '',
'type' => 'number',
'default' => '0',
'min' => '0',
'max' => '23',
'size' => 'small',
),
'cron_min' => array(
'id' => 'cron_min',
'name' => esc_html__( 'Minute', 'top-10' ),
'desc' => '',
'type' => 'number',
'default' => '0',
'min' => '0',
'max' => '59',
'size' => 'small',
),
'cron_recurrence' => array(
'id' => 'cron_recurrence',
'name' => esc_html__( 'Run maintenance', 'top-10' ),
'desc' => '',
'type' => 'radio',
'default' => 'weekly',
'options' => array(
'daily' => esc_html__( 'Daily', 'top-10' ),
'weekly' => esc_html__( 'Weekly', 'top-10' ),
'fortnightly' => esc_html__( 'Fortnightly', 'top-10' ),
'monthly' => esc_html__( 'Monthly', 'top-10' ),
),
),
);
/**
* Filters the Maintenance settings array
*
* @since 3.3.0
*
* @param array $settings Maintenance settings array
*/
return apply_filters( self::$prefix . '_settings_maintenance', $settings );
}
/**
* Retrieve the array of Feed settings
*
* @since 2.8.0
*
* @return array Feed settings array
*/
public static function settings_feed() {
$settings = array(
'feed_permalink_overall' => array(
'id' => 'feed_permalink_overall',
'name' => esc_html__( 'Permalink - Overall', 'top-10' ),
/* translators: 1: Opening link tag, 2: Closing link tag. */
'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' ), '', '' ),
'type' => 'text',
'default' => 'popular-posts',
'size' => 'large',
),
'feed_permalink_daily' => array(
'id' => 'feed_permalink_daily',
'name' => esc_html__( 'Permalink - Daily', 'top-10' ),
/* translators: 1: Opening link tag, 2: Closing link tag. */
'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' ), '', '' ),
'type' => 'text',
'default' => 'popular-posts-daily',
'size' => 'large',
),
'feed_limit' => array(
'id' => 'feed_limit',
'name' => esc_html__( 'Number of posts to display', 'top-10' ),
'desc' => esc_html__( 'Maximum number of posts that will be displayed in the custom feed.', 'top-10' ),
'type' => 'number',
'default' => '10',
'size' => 'small',
),
'feed_daily_range' => array(
'id' => 'feed_daily_range',
'name' => esc_html__( 'Custom period in day(s)', 'top-10' ),
'desc' => '',
'type' => 'number',
'default' => '1',
'min' => '0',
'size' => 'small',
),
'feed_category_slugs' => array(
'id' => 'feed_category_slugs',
'name' => esc_html__( 'Filter Categories', 'top-10' ),
'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' ),
'type' => 'csv',
'default' => '',
'size' => 'large',
'field_class' => 'ts_autocomplete',
'field_attributes' => self::get_taxonomy_search_field_attributes( 'category' ),
'pro' => true,
),
);
/**
* Filters the Feed settings array
*
* @since 2.8.0
*
* @param array $settings Feed settings array
*/
return apply_filters( self::$prefix . '_settings_feed', $settings );
}
/**
* Get the various styles.
*
* @since 2.5.0
* @return array Style options.
*/
public static function get_styles() {
$styles = array(
array(
'id' => 'no_style',
'name' => esc_html__( 'No styles', 'top-10' ),
'description' => esc_html__( 'Select this option if you plan to add your own styles', 'top-10' ) . '' . sprintf( __( 'For more information or how to get support visit the support site.', 'top-10' ), esc_url( 'https://webberzone.com/support/' ) ) . '
' . /* translators: 1: WordPress.org support forums link. */ '' . sprintf( __( 'Support queries should be posted in the WordPress.org support forums.', 'top-10' ), esc_url( 'https://wordpress.org/support/plugin/top-10' ) ) . '
' . '' . sprintf( /* translators: 1: Github issues link, 2: Github plugin page link. */ __( 'Post an issue on GitHub (bug reports only).', 'top-10' ), esc_url( 'https://github.com/ajaydsouza/top-10/issues' ), esc_url( 'https://github.com/ajaydsouza/top-10' ) ) . '
'; /** * Filter to modify the help sidebar content. * * @since 1.8.0 * * @param string $help_sidebar Help sidebar content. */ return apply_filters( self::$prefix . '_settings_help', $help_sidebar ); } /** * Get the help tabs to display on the plugin settings page. * * @since 1.8.0 */ public function get_help_tabs() { $help_tabs = array( array( 'id' => 'tptn-settings-general-help', 'title' => esc_html__( 'General', 'top-10' ), 'content' => '' . esc_html__( 'This tab provides global settings for how Top 10 works across your site.', 'top-10' ) . '
' . '' . 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' ) . '
', ), array( 'id' => 'tptn-settings-counter-help', 'title' => esc_html__( 'Counter / Tracker', 'top-10' ), 'content' => '' . esc_html__( 'This tab controls how Top 10 tracks and displays view counts.', 'top-10' ) . '
' . '' . 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' ) . '
', ), array( 'id' => 'tptn-settings-list-help', 'title' => esc_html__( 'Posts list', 'top-10' ), 'content' => '' . esc_html__( 'This tab controls the popular posts list output.', 'top-10' ) . '
' . '' . 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' ) . '
', ), array( 'id' => 'tptn-settings-thumbnail-help', 'title' => esc_html__( 'Thumbnail', 'top-10' ), 'content' => '' . esc_html__( 'This tab manages thumbnail settings for the popular posts list.', 'top-10' ) . '
' . '' . 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' ) . '
', ), array( 'id' => 'tptn-settings-styles-help', 'title' => esc_html__( 'Styles', 'top-10' ), 'content' => '' . esc_html__( 'This tab controls how the popular posts list is styled.', 'top-10' ) . '
' . '' . esc_html__( 'Select a built-in style or disable styles if you want to fully control the look using your own CSS.', 'top-10' ) . '
', ), array( 'id' => 'tptn-settings-maintenance-help', 'title' => esc_html__( 'Maintenance', 'top-10' ), 'content' => '' . esc_html__( 'This tab handles tools and maintenance-related options.', 'top-10' ) . '
' . '' . 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' ) . '
', ), array( 'id' => 'tptn-settings-feed-help', 'title' => esc_html__( 'Feed', 'top-10' ), 'content' => '' . esc_html__( 'This tab controls how Top 10 content appears in your site feed.', 'top-10' ) . '
' . '' . esc_html__( 'Configure copyright text and additional HTML that is added before or after the content in your feeds.', 'top-10' ) . '
', ), ); /** * Filter to add more help tabs. * * @since 1.8.0 * * @param array $help_tabs Associative array of help tabs. */ return apply_filters( self::$prefix . '_settings_help', $help_tabs ); } /** * Function returns the different types of trackers. * * @since 3.3.0 * @return array Tracker types. */ public static function get_tracker_types() { $trackers = array( array( 'id' => 'rest_based', 'name' => __( 'REST API based', 'top-10' ), 'description' => __( 'Uses the REST API to record visits', 'top-10' ), ), array( 'id' => 'query_based', 'name' => __( 'Query variable based', 'top-10' ), 'description' => __( 'Uses query variables to record visits', 'top-10' ), ), array( 'id' => 'ajaxurl', 'name' => __( 'Ajaxurl based', 'top-10' ), 'description' => __( 'Uses admin-ajax.php which is inbuilt within WordPress to process the tracker', 'top-10' ), ), ); /** * Filter the array containing the types of trackers to add your own. * * @since 2.4.0 * * @param array $trackers Different trackers. */ return apply_filters( self::$prefix . '_get_tracker_types', $trackers ); } /** * Add footer text on the plugin page. * * @since 2.0.0 */ public static function get_admin_footer_text() { return sprintf( /* translators: 1: Opening achor tag with Plugin page link, 2: Closing anchor tag, 3: Opening anchor tag with review link. */ __( 'Thank you for using %1$sWebberZone Top 10%2$s! Please %3$srate us%2$s on WordPress.org', 'top-10' ), '', '', '' ); } /** * Enqueue scripts and styles. * * @since 3.3.0 * * @param string $hook Current hook. */ public function admin_enqueue_scripts( $hook ) { if ( ! isset( $this->settings_api->settings_page ) || $this->settings_api->settings_page !== $hook ) { return; } wp_enqueue_script( 'top-ten-admin-js' ); wp_enqueue_style( 'top-ten-admin-css' ); wp_enqueue_style( 'wp-spinner' ); wp_localize_script( 'top-ten-admin-js', 'tptn_admin', array( 'thumb_default' => Display::get_default_thumbnail(), ) ); wp_localize_script( 'top-ten-admin-js', 'top_ten_admin_data', array( 'security' => wp_create_nonce( 'tptn-admin' ), 'strings' => array( 'confirm_message' => esc_html__( 'Are you sure you want to clear the cache?', 'top-10' ), 'clearing_text' => esc_html__( 'Clearing...', 'top-10' ), 'success_message' => esc_html__( 'Cache cleared successfully!', 'top-10' ), 'fail_message' => esc_html__( 'Failed to clear cache. Please try again.', 'top-10' ), 'request_fail_message' => esc_html__( 'Request failed: ', 'top-10' ), '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' ), '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' ), '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' ), ), ) ); } /** * Modify settings when they are being saved. * * @since 3.3.0 * * @param array $settings Settings array. * @return array Sanitized settings array. */ public function change_settings_on_save( $settings ) { Settings_Sanitize::sanitize_tax_slugs( $settings, 'exclude_cat_slugs', 'exclude_categories' ); Settings_Sanitize::sanitize_tax_slugs( $settings, 'exclude_on_cat_slugs', 'exclude_on_categories' ); Settings_Sanitize::sanitize_tax_slugs( $settings, 'feed_category_slugs', 'feed_categories' ); // Save cron settings. $settings['cron_hour'] = min( 23, absint( $settings['cron_hour'] ) ); $settings['cron_min'] = min( 59, absint( $settings['cron_min'] ) ); if ( ! empty( $settings['cron_on'] ) ) { \WebberZone\Top_Ten\Admin\Cron::enable_run( $settings['cron_hour'], $settings['cron_min'], $settings['cron_recurrence'] ); } else { \WebberZone\Top_Ten\Admin\Cron::disable_run(); } // Force thumb_width and thumb_height if either are zero. if ( empty( $settings['thumb_width'] ) || empty( $settings['thumb_height'] ) ) { list( $settings['thumb_width'], $settings['thumb_height'] ) = Media_Handler::get_thumb_size( $settings['thumb_size'] ); } // Overwrite settings based on selected style; guard against missing keys on reset. $style = $settings['tptn_styles'] ?? ''; $inline_thumb_styles = array( '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' ), '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' ), ); if ( array_key_exists( $style, $inline_thumb_styles ) ) { $post_thumb_op = $settings['post_thumb_op'] ?? ''; if ( 'inline' !== $post_thumb_op && 'thumbs_only' !== $post_thumb_op ) { $settings['post_thumb_op'] = 'inline'; } add_settings_error( self::$prefix . '-notices', '', $inline_thumb_styles[ $style ], 'warning' ); } // Overwrite settings if text_only style is selected. if ( 'text_only' === $style ) { $settings['post_thumb_op'] = 'text_only'; add_settings_error( self::$prefix . '-notices', '', 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' ), 'warning' ); } // Delete the cache. \WebberZone\Top_Ten\Util\Cache::delete(); return $settings; } /** * Display the default thumbnail below the setting. * * @since 3.3.0 * * @param string $html Current HTML. * @param array $args Argument array of the setting. * @return string */ public function display_admin_thumbnail( $html, $args ) { $thumb_default = \tptn_get_option( 'thumb_default' ); if ( 'thumb_default' === $args['id'] && '' !== $thumb_default ) { $html .= '%s
', esc_html__( 'Note: Thumbnail location is set to "Do not display thumbnails, only text". This may override the selected style.', 'top-10' ) ); } } return $output; } /** * Add a button to the settings page to start the settings wizard. * * @since 4.2.0 */ public function add_wizard_button() { printf( '