AJAX
1 year ago
Admin_Page
1 year ago
Custom_WordPress_Columns
2 years ago
Data_Pruning
1 year ago
Date_Picker
1 year ago
Date_Range
1 year ago
Ecommerce
1 year ago
Email_Reports
1 year ago
Filter_Lists
2 years ago
Form_Submissions
1 year ago
Interval
2 years ago
Menu_Bar_Stats
1 year ago
Migrations
1 year ago
Models
1 year ago
Public_API
2 years ago
Rows
1 year ago
Statistics
1 year ago
Tables
1 year ago
Utils
1 year ago
Campaign_Builder.php
2 years ago
Capability_Manager.php
1 year ago
Chart.php
1 year ago
Chart_Geo.php
1 year ago
Cron_Job.php
1 year ago
Cron_Job_Autoloader.php
1 year ago
Cron_Manager.php
2 years ago
Current_Traffic_Finder.php
2 years ago
Dashboard_Options.php
2 years ago
Dashboard_Widget.php
2 years ago
Database.php
2 years ago
Database_Manager.php
2 years ago
Empty_Report_Option.php
2 years ago
Env.php
1 year ago
Filters.php
1 year ago
Geo_Database_Background_Job.php
2 years ago
Geo_Database_Manager.php
1 year ago
Geoposition.php
2 years ago
Icon_Directory.php
2 years ago
Icon_Directory_Factory.php
2 years ago
Illuminate_Builder.php
1 year ago
Independent_Analytics.php
1 year ago
Interrupt.php
1 year ago
Known_Referrers.php
2 years ago
Patch.php
1 year ago
Plugin_Conflict_Detector.php
1 year ago
Plugin_Group.php
1 year ago
Plugin_Group_Option.php
2 years ago
Query.php
1 year ago
Query_Taps.php
1 year ago
Quick_Stats.php
2 years ago
REST_API.php
1 year ago
Real_Time.php
1 year ago
Report.php
2 years ago
Report_Finder.php
2 years ago
Report_Options_Parser.php
1 year ago
Resource_Identifier.php
1 year ago
Settings.php
1 year ago
Sort_Configuration.php
2 years ago
Track_Resource_Changes.php
2 years ago
View.php
2 years ago
View_Counter.php
1 year ago
Visitors_Over_Time_Finder.php
2 years ago
WP_Option_Cache_Bust.php
2 years ago
Settings.php
355 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP; |
| 4 | |
| 5 | use IAWP\Data_Pruning\Pruning_Scheduler; |
| 6 | use IAWP\Ecommerce\WooCommerce_Status_Manager; |
| 7 | use IAWP\Email_Reports\Interval_Factory; |
| 8 | use IAWP\Utils\Request; |
| 9 | use IAWP\Utils\String_Util; |
| 10 | /** @internal */ |
| 11 | class Settings |
| 12 | { |
| 13 | public function __construct() |
| 14 | { |
| 15 | \add_action('admin_init', [$this, 'register_settings']); |
| 16 | \add_action('admin_init', [$this, 'register_view_counter_settings']); |
| 17 | \add_action('admin_init', [$this, 'register_blocked_ip_settings']); |
| 18 | \add_action('admin_init', [$this, 'register_block_by_role_settings']); |
| 19 | if (\IAWPSCOPED\iawp_is_pro()) { |
| 20 | \add_action('admin_init', [$this, 'register_email_report_settings']); |
| 21 | } |
| 22 | } |
| 23 | public function render_settings() |
| 24 | { |
| 25 | echo \IAWPSCOPED\iawp_blade()->run('settings.index'); |
| 26 | if (\IAWPSCOPED\iawp_is_pro()) { |
| 27 | $defaults = $this->email_report_colors(); |
| 28 | $saved = \IAWPSCOPED\iawp()->get_option('iawp_email_report_colors', $defaults); |
| 29 | // There were 6 colors and now 9, so there is a saved value but 7-9 don't exist |
| 30 | $input_defaults = $defaults; |
| 31 | for ($i = 0; $i < \count($saved); $i++) { |
| 32 | $input_defaults[$i] = $saved[$i]; |
| 33 | } |
| 34 | $interval = Interval_Factory::from_option(); |
| 35 | echo \IAWPSCOPED\iawp_blade()->run('settings.email-reports', ['is_scheduled' => \wp_next_scheduled('iawp_send_email_report'), 'scheduled_date' => \IAWPSCOPED\iawp()->email_reports->next_email_at_for_humans(), 'interval' => \IAWPSCOPED\iawp()->get_option('iawp_email_report_interval', 'monthly'), 'time' => \IAWPSCOPED\iawp()->get_option('iawp_email_report_time', 9), 'emails' => \IAWPSCOPED\iawp()->get_option('iawp_email_report_email_addresses', []), 'default_colors' => $defaults, 'input_default' => $input_defaults, 'timestamp' => $interval->next_interval_start()->getTimestamp()]); |
| 36 | } |
| 37 | $ips = \IAWPSCOPED\iawp()->get_option('iawp_blocked_ips', []); |
| 38 | echo \IAWPSCOPED\iawp_blade()->run('settings.block-ips', ['current_ip' => Request::ip(), 'ip_is_blocked' => Request::is_ip_address_blocked($ips), 'ips' => $ips]); |
| 39 | echo \IAWPSCOPED\iawp_blade()->run('settings.block-by-role', ['roles' => \wp_roles()->roles, 'blocked' => \IAWPSCOPED\iawp()->get_option('iawp_blocked_roles', [])]); |
| 40 | echo \IAWPSCOPED\iawp_blade()->run('settings.capabilities', ['editable_roles' => $this->get_editable_roles(), 'capabilities' => \IAWP\Capability_Manager::all_capabilities()]); |
| 41 | echo \IAWPSCOPED\iawp_blade()->run('settings.view-counter'); |
| 42 | if (\IAWPSCOPED\iawp()->is_woocommerce_support_enabled()) { |
| 43 | echo \IAWPSCOPED\iawp_blade()->run('settings.woocommerce', ['statuses' => new WooCommerce_Status_Manager()]); |
| 44 | } |
| 45 | echo \IAWPSCOPED\iawp_blade()->run('settings.export-reports', ['report_finder' => new \IAWP\Report_Finder()]); |
| 46 | echo \IAWPSCOPED\iawp_blade()->run('settings.export-data'); |
| 47 | echo \IAWPSCOPED\iawp_blade()->run('settings.pruner', ['pruner' => new Pruning_Scheduler()]); |
| 48 | echo \IAWPSCOPED\iawp_blade()->run('settings.delete', ['site_name' => \get_bloginfo('name'), 'site_url' => \site_url()]); |
| 49 | } |
| 50 | public function register_settings() |
| 51 | { |
| 52 | \add_settings_section('iawp-settings-section', \esc_html__('Basic Settings', 'independent-analytics'), function () { |
| 53 | }, 'independent-analytics-settings'); |
| 54 | $args = ['type' => 'boolean', 'default' => \false, 'sanitize_callback' => 'rest_sanitize_boolean']; |
| 55 | \register_setting('iawp_settings', 'iawp_dark_mode', $args); |
| 56 | \add_settings_field('iawp_dark_mode', \esc_html__('Dark mode', 'independent-analytics'), [$this, 'dark_mode_callback'], 'independent-analytics-settings', 'iawp-settings-section', ['class' => 'dark-mode']); |
| 57 | \register_setting('iawp_settings', 'iawp_track_authenticated_users', $args); |
| 58 | \add_settings_field('iawp_track_authenticated_users', \esc_html__('Track logged in users', 'independent-analytics'), [$this, 'track_authenticated_users_callback'], 'independent-analytics-settings', 'iawp-settings-section', ['class' => 'logged-in']); |
| 59 | \register_setting('iawp_settings', 'iawp_disable_admin_toolbar_analytics', $args); |
| 60 | \add_settings_field('iawp_disable_admin_toolbar_analytics', \esc_html__('Admin toolbar stats', 'independent-analytics'), [$this, 'disable_admin_toolbar_analytics_callback'], 'independent-analytics-settings', 'iawp-settings-section'); |
| 61 | \register_setting('iawp_settings', 'iawp_disable_widget', $args); |
| 62 | \add_settings_field('iawp_disable_widget', \esc_html__('Dashboard widget', 'independent-analytics'), [$this, 'disable_widget_callback'], 'independent-analytics-settings', 'iawp-settings-section'); |
| 63 | \register_setting('iawp_settings', 'iawp_disable_views_column', $args); |
| 64 | \add_settings_field('iawp_disable_views_column', \esc_html__('Views column', 'independent-analytics'), [$this, 'disable_views_column_callback'], 'independent-analytics-settings', 'iawp-settings-section'); |
| 65 | $args = ['type' => 'integer', 'default' => 0, 'sanitize_callback' => 'absint']; |
| 66 | \register_setting('iawp_settings', 'iawp_dow', $args); |
| 67 | \add_settings_field('iawp_dow', \esc_html__('First day of week', 'independent-analytics'), [$this, 'starting_dow_callback'], 'independent-analytics-settings', 'iawp-settings-section', ['class' => 'dow']); |
| 68 | $args = ['type' => 'boolean', 'default' => \false, 'sanitize_callback' => 'rest_sanitize_boolean']; |
| 69 | \register_setting('iawp_settings', 'iawp_refresh_salt', $args); |
| 70 | \add_settings_field('iawp_refresh_salt', \esc_html__('Salt refresh rate', 'independent-analytics'), [$this, 'refresh_salt_callback'], 'independent-analytics-settings', 'iawp-settings-section', ['class' => 'salt']); |
| 71 | } |
| 72 | public function dark_mode_callback() |
| 73 | { |
| 74 | echo \IAWPSCOPED\iawp_blade()->run('settings.dark-mode', ['dark_mode' => \IAWPSCOPED\iawp()->get_option('iawp_dark_mode', \false)]); |
| 75 | } |
| 76 | public function track_authenticated_users_callback() |
| 77 | { |
| 78 | echo \IAWPSCOPED\iawp_blade()->run('settings.track-authenticated-users', ['track_authenticated_users' => \IAWPSCOPED\iawp()->get_option('iawp_track_authenticated_users', \false)]); |
| 79 | } |
| 80 | public function disable_admin_toolbar_analytics_callback() |
| 81 | { |
| 82 | echo \IAWPSCOPED\iawp_blade()->run('settings.disable-admin-toolbar-analytics', ['value' => \IAWPSCOPED\iawp()->get_option('iawp_disable_admin_toolbar_analytics', \false)]); |
| 83 | } |
| 84 | public function disable_widget_callback() |
| 85 | { |
| 86 | echo \IAWPSCOPED\iawp_blade()->run('settings.disable-widget', ['value' => \IAWPSCOPED\iawp()->get_option('iawp_disable_widget', \false)]); |
| 87 | } |
| 88 | public function disable_views_column_callback() : void |
| 89 | { |
| 90 | echo \IAWPSCOPED\iawp_blade()->run('settings.disable-views-column', ['value' => \IAWPSCOPED\iawp()->get_option('iawp_disable_views_column', \false)]); |
| 91 | } |
| 92 | public function starting_dow_callback() |
| 93 | { |
| 94 | echo \IAWPSCOPED\iawp_blade()->run('settings.first-day-of-week', ['day_of_week' => \IAWPSCOPED\iawp()->get_option('iawp_dow', 0), 'days' => [0 => \esc_html__('Sunday', 'independent-analytics'), 1 => \esc_html__('Monday', 'independent-analytics'), 2 => \esc_html__('Tuesday', 'independent-analytics'), 3 => \esc_html__('Wednesday', 'independent-analytics'), 4 => \esc_html__('Thursday', 'independent-analytics'), 5 => \esc_html__('Friday', 'independent-analytics'), 6 => \esc_html__('Saturday', 'independent-analytics')]]); |
| 95 | } |
| 96 | public function refresh_salt_callback() |
| 97 | { |
| 98 | echo \IAWPSCOPED\iawp_blade()->run('settings.refresh-salt', ['refresh_salt' => \IAWPSCOPED\iawp()->get_option('iawp_refresh_salt', \false)]); |
| 99 | } |
| 100 | public function register_view_counter_settings() |
| 101 | { |
| 102 | \add_settings_section('iawp-view-counter-settings-section', \esc_html__('Public View Counter', 'independent-analytics'), function () { |
| 103 | }, 'independent-analytics-view-counter-settings'); |
| 104 | $args = ['type' => 'boolean', 'default' => \false, 'sanitize_callback' => 'rest_sanitize_boolean']; |
| 105 | \register_setting('iawp_view_counter_settings', 'iawp_view_counter_enable', $args); |
| 106 | \add_settings_field('iawp_view_counter_enable', \esc_html__('Enable the view counter', 'independent-analytics'), [$this, 'view_counter_enable_callback'], 'independent-analytics-view-counter-settings', 'iawp-view-counter-settings-section', ['class' => 'enable']); |
| 107 | $args = ['type' => 'array', 'default' => [], 'sanitize_callback' => [$this, 'sanitize_view_counter_post_types']]; |
| 108 | \register_setting('iawp_view_counter_settings', 'iawp_view_counter_post_types', $args); |
| 109 | \add_settings_field('iawp_view_counter_post_types', \esc_html__('Display on these post types', 'independent-analytics'), [$this, 'view_counter_post_types_callback'], 'independent-analytics-view-counter-settings', 'iawp-view-counter-settings-section', ['class' => 'post-types']); |
| 110 | // Position |
| 111 | $args = ['type' => 'string', 'default' => 'after', 'sanitize_callback' => [$this, 'sanitize_view_counter_position']]; |
| 112 | \register_setting('iawp_view_counter_settings', 'iawp_view_counter_position', $args); |
| 113 | \add_settings_field('iawp_view_counter_position', \esc_html__('Show it in this location', 'independent-analytics'), [$this, 'view_counter_position_callback'], 'independent-analytics-view-counter-settings', 'iawp-view-counter-settings-section', ['class' => 'position']); |
| 114 | // Views to count |
| 115 | \register_setting('iawp_view_counter_settings', 'iawp_view_counter_views_to_count', ['type' => 'string', 'default' => 'total', 'sanitize_callback' => [$this, 'sanitize_view_counter_views_to_count']]); |
| 116 | \add_settings_field('iawp_view_counter_views_to_count', \esc_html__('Date range to count views', 'independent-analytics'), [$this, 'view_counter_views_to_count_callback'], 'independent-analytics-view-counter-settings', 'iawp-view-counter-settings-section', ['class' => 'views-to-count']); |
| 117 | // Exclude |
| 118 | $args = ['type' => 'string', 'default' => '', 'sanitize_callback' => [$this, 'sanitize_view_counter_exclude']]; |
| 119 | \register_setting('iawp_view_counter_settings', 'iawp_view_counter_exclude', $args); |
| 120 | \add_settings_field('iawp_view_counter_exclude', \esc_html__('Exclude these pages', 'independent-analytics'), [$this, 'view_counter_exclude_callback'], 'independent-analytics-view-counter-settings', 'iawp-view-counter-settings-section', ['class' => 'exclude']); |
| 121 | // Label |
| 122 | $default = \function_exists('IAWPSCOPED\\pll__') ? pll__('Views:', 'independent-analytics') : \__('Views:', 'independent-analytics'); |
| 123 | $args = ['type' => 'string', 'default' => $default, 'sanitize_callback' => 'sanitize_text_field']; |
| 124 | \register_setting('iawp_view_counter_settings', 'iawp_view_counter_label', $args); |
| 125 | \add_settings_field('iawp_view_counter_label', \esc_html__('Edit the label', 'independent-analytics'), [$this, 'view_counter_label_callback'], 'independent-analytics-view-counter-settings', 'iawp-view-counter-settings-section', ['class' => 'counter-label']); |
| 126 | // Hide Label |
| 127 | $args = ['type' => 'boolean', 'default' => \true, 'sanitize_callback' => 'rest_sanitize_boolean']; |
| 128 | \register_setting('iawp_view_counter_settings', 'iawp_view_counter_label_show', $args); |
| 129 | \add_settings_field('iawp_view_counter_label_show', \esc_html__('Display the label', 'independent-analytics'), [$this, 'view_counter_label_show_callback'], 'independent-analytics-view-counter-settings', 'iawp-view-counter-settings-section', ['class' => 'hide-label']); |
| 130 | // Icon |
| 131 | $args = ['type' => 'boolean', 'default' => \true, 'sanitize_callback' => 'rest_sanitize_boolean']; |
| 132 | \register_setting('iawp_view_counter_settings', 'iawp_view_counter_icon', $args); |
| 133 | \add_settings_field('iawp_view_counter_icon', \esc_html__('Display the icon', 'independent-analytics'), [$this, 'view_counter_icon_callback'], 'independent-analytics-view-counter-settings', 'iawp-view-counter-settings-section', ['class' => 'icon']); |
| 134 | // Private |
| 135 | \register_setting('iawp_view_counter_settings', 'iawp_view_counter_private', ['type' => 'boolean', 'default' => \false, 'sanitize_callback' => 'rest_sanitize_boolean']); |
| 136 | \add_settings_field('iawp_view_counter_private', \esc_html__('Make the view counter private?', 'independent-analytics'), [$this, 'view_counter_private_callback'], 'independent-analytics-view-counter-settings', 'iawp-view-counter-settings-section', ['class' => 'private']); |
| 137 | // Allow manual adjustment |
| 138 | \register_setting('iawp_view_counter_settings', 'iawp_view_counter_manual_adjustment', ['type' => 'boolean', 'default' => \false, 'sanitize_callback' => 'rest_sanitize_boolean']); |
| 139 | \add_settings_field('iawp_view_counter_manual_adjustment', \esc_html__('Allow manual adjustment?', 'independent-analytics'), [$this, 'view_counter_manual_adjustment_callback'], 'independent-analytics-view-counter-settings', 'iawp-view-counter-settings-section', ['class' => 'manual-adjustment']); |
| 140 | } |
| 141 | public function view_counter_enable_callback() |
| 142 | { |
| 143 | echo \IAWPSCOPED\iawp_blade()->run('settings.view-counter.enable', ['enable' => \IAWPSCOPED\iawp()->get_option('iawp_view_counter_enable', \false)]); |
| 144 | } |
| 145 | public function view_counter_post_types_callback() |
| 146 | { |
| 147 | $site_post_types = \get_post_types(['public' => \true], 'objects'); |
| 148 | $counter = 0; |
| 149 | foreach ($site_post_types as $post_type) { |
| 150 | echo \IAWPSCOPED\iawp_blade()->run('settings.view-counter.post-types', ['counter' => $counter, 'post_type' => $post_type, 'saved' => \IAWPSCOPED\iawp()->get_option('iawp_view_counter_post_types', [])]); |
| 151 | $counter++; |
| 152 | } |
| 153 | ?> |
| 154 | <p class="description"><?php |
| 155 | \esc_html_e('Uncheck all boxes to only show view count manually. See shortcode documentation below for details.', 'independent-analytics'); |
| 156 | ?></p> |
| 157 | <?php |
| 158 | } |
| 159 | public function view_counter_position_callback() |
| 160 | { |
| 161 | echo \IAWPSCOPED\iawp_blade()->run('settings.view-counter.position', ['position' => \IAWPSCOPED\iawp()->get_option('iawp_view_counter_position', 'after')]); |
| 162 | } |
| 163 | public function view_counter_views_to_count_callback() |
| 164 | { |
| 165 | echo \IAWPSCOPED\iawp_blade()->run('settings.view-counter.views-to-count', ['value' => \IAWPSCOPED\iawp()->get_option('iawp_view_counter_views_to_count', 'total')]); |
| 166 | } |
| 167 | public function view_counter_exclude_callback() |
| 168 | { |
| 169 | echo \IAWPSCOPED\iawp_blade()->run('settings.view-counter.exclude', ['exclude' => \IAWPSCOPED\iawp()->get_option('iawp_view_counter_exclude', '')]); |
| 170 | } |
| 171 | public function view_counter_label_callback() |
| 172 | { |
| 173 | $default = \function_exists('IAWPSCOPED\\pll__') ? pll__('Views:', 'independent-analytics') : \__('Views:', 'independent-analytics'); |
| 174 | echo \IAWPSCOPED\iawp_blade()->run('settings.view-counter.label', ['label' => \IAWPSCOPED\iawp()->get_option('iawp_view_counter_label', $default)]); |
| 175 | } |
| 176 | public function view_counter_label_show_callback() |
| 177 | { |
| 178 | echo \IAWPSCOPED\iawp_blade()->run('settings.view-counter.label-show', ['show' => \get_option('iawp_view_counter_label_show', \true)]); |
| 179 | } |
| 180 | public function view_counter_icon_callback() |
| 181 | { |
| 182 | echo \IAWPSCOPED\iawp_blade()->run('settings.view-counter.icon', ['icon' => \get_option('iawp_view_counter_icon', \true)]); |
| 183 | } |
| 184 | public function view_counter_private_callback() |
| 185 | { |
| 186 | echo \IAWPSCOPED\iawp_blade()->run('settings.view-counter.private', ['private' => \IAWPSCOPED\iawp()->get_option('iawp_view_counter_private', \false)]); |
| 187 | } |
| 188 | public function view_counter_manual_adjustment_callback() |
| 189 | { |
| 190 | echo \IAWPSCOPED\iawp_blade()->run('settings.view-counter.manual-adjustment', ['value' => \IAWPSCOPED\iawp()->get_option('iawp_view_counter_manual_adjustment', \false)]); |
| 191 | } |
| 192 | public function register_blocked_ip_settings() |
| 193 | { |
| 194 | \add_settings_section('iawp-blocked-ips-settings-section', \esc_html__('Block IP Addresses', 'independent-analytics'), function () { |
| 195 | }, 'iawp-blocked-ips-settings'); |
| 196 | $args = ['type' => 'array', 'default' => [], 'sanitize_callback' => [$this, 'sanitize_blocked_ips']]; |
| 197 | \register_setting('iawp_blocked_ip_settings', 'iawp_blocked_ips', $args); |
| 198 | } |
| 199 | public function register_email_report_settings() |
| 200 | { |
| 201 | \add_settings_section('iawp-email-report-settings-section', \esc_html__('Scheduled Email Reports', 'independent-analytics'), function () { |
| 202 | }, 'iawp-email-report-settings'); |
| 203 | \register_setting('iawp_email_report_settings', 'iawp_email_report_interval', ['type' => 'string', 'default' => 'monthly', 'sanitize_callback' => [$this, 'sanitize_email_report_interval']]); |
| 204 | \register_setting('iawp_email_report_settings', 'iawp_email_report_time', ['type' => 'number', 'default' => 9, 'sanitize_callback' => [$this, 'sanitize_email_report_time']]); |
| 205 | \register_setting('iawp_email_report_settings', 'iawp_email_report_email_addresses', ['type' => 'array', 'default' => [], 'sanitize_callback' => [$this, 'sanitize_email_addresses']]); |
| 206 | \register_setting('iawp_email_report_settings', 'iawp_email_report_colors', ['type' => 'array', 'default' => $this->email_report_colors(), 'sanitize_callback' => [$this, 'sanitize_email_report_colors']]); |
| 207 | } |
| 208 | public function register_block_by_role_settings() |
| 209 | { |
| 210 | \add_settings_section('iawp-block-by-role-settings-section', \esc_html__('Block by User Role', 'independent-analytics'), function () { |
| 211 | }, 'iawp-block-by-role-settings'); |
| 212 | $args = ['type' => 'array', 'default' => [], 'sanitize_callback' => [$this, 'sanitize_blocked_roles']]; |
| 213 | \register_setting('iawp_block_by_role_settings', 'iawp_blocked_roles', $args); |
| 214 | } |
| 215 | public function sanitize_view_counter_post_types($user_input) |
| 216 | { |
| 217 | if (\is_null($user_input)) { |
| 218 | return []; |
| 219 | } |
| 220 | $site_post_types = \get_post_types(['public' => \true]); |
| 221 | $to_save = []; |
| 222 | foreach ($user_input as $post_type) { |
| 223 | if (\in_array($post_type, $site_post_types)) { |
| 224 | $to_save[] = $post_type; |
| 225 | } |
| 226 | } |
| 227 | return $to_save; |
| 228 | } |
| 229 | public function sanitize_view_counter_position($user_input) |
| 230 | { |
| 231 | if (\in_array($user_input, ['before', 'after', 'both'])) { |
| 232 | return $user_input; |
| 233 | } else { |
| 234 | return 'after'; |
| 235 | } |
| 236 | } |
| 237 | public function sanitize_view_counter_views_to_count($user_input) |
| 238 | { |
| 239 | if (\in_array($user_input, ['total', 'today', 'yesterday', 'this_week', 'last_week', 'last_seven', 'last_thirty', 'last_sixty', 'last_ninety', 'this_month', 'last_month', 'last_three_months', 'last_six_months', 'last_twelve_months', 'this_year', 'last_year'])) { |
| 240 | return $user_input; |
| 241 | } else { |
| 242 | return 'total'; |
| 243 | } |
| 244 | } |
| 245 | public function sanitize_view_counter_exclude($user_input) |
| 246 | { |
| 247 | $user_input = \explode(',', $user_input); |
| 248 | $to_save = []; |
| 249 | foreach ($user_input as $id) { |
| 250 | $save = \absint($id); |
| 251 | if ($save != 0) { |
| 252 | $to_save[] = $save; |
| 253 | } |
| 254 | } |
| 255 | $to_save = \implode(',', $to_save); |
| 256 | return $to_save; |
| 257 | } |
| 258 | public function sanitize_blocked_ips($user_input) |
| 259 | { |
| 260 | $to_save = []; |
| 261 | foreach ($user_input as $ip) { |
| 262 | // Limit to two wildcards |
| 263 | if (\substr_count($ip, '*') > 2) { |
| 264 | continue; |
| 265 | } |
| 266 | // If it's safe with wildcard replacements, it's safe with them |
| 267 | $safe_replacement = String_Util::str_contains($ip, '.') ? '172' : '2601'; |
| 268 | $wildcards_replaced = \str_replace('*', $safe_replacement, $ip); |
| 269 | if (\filter_var($wildcards_replaced, \FILTER_VALIDATE_IP)) { |
| 270 | $to_save[] = $ip; |
| 271 | } |
| 272 | } |
| 273 | return $to_save; |
| 274 | } |
| 275 | public function sanitize_email_addresses($emails) |
| 276 | { |
| 277 | $to_save = []; |
| 278 | foreach ($emails as $email) { |
| 279 | $cleaned = \sanitize_email($email); |
| 280 | if (\is_email($cleaned)) { |
| 281 | $to_save[] = $cleaned; |
| 282 | } |
| 283 | } |
| 284 | return $to_save; |
| 285 | } |
| 286 | public function sanitize_email_report_interval($input) |
| 287 | { |
| 288 | if (\in_array($input, ['monthly', 'weekly', 'daily'])) { |
| 289 | return $input; |
| 290 | } else { |
| 291 | return 'monthly'; |
| 292 | } |
| 293 | } |
| 294 | public function sanitize_email_report_time($user_time) |
| 295 | { |
| 296 | $accepted_times = []; |
| 297 | for ($i = 0; $i < 24; $i++) { |
| 298 | $accepted_times[] = $i; |
| 299 | } |
| 300 | if (\in_array($user_time, $accepted_times)) { |
| 301 | return $user_time; |
| 302 | } else { |
| 303 | return 9; |
| 304 | } |
| 305 | } |
| 306 | public function sanitize_blocked_roles($blocked_roles) |
| 307 | { |
| 308 | $to_save = []; |
| 309 | $user_roles = \array_keys(\wp_roles()->roles); |
| 310 | foreach ($blocked_roles as $blocked) { |
| 311 | if (\in_array($blocked, $user_roles)) { |
| 312 | $to_save[] = $blocked; |
| 313 | } |
| 314 | } |
| 315 | return $to_save; |
| 316 | } |
| 317 | public function sanitize_email_report_colors($colors) |
| 318 | { |
| 319 | $to_save = []; |
| 320 | // No idea why WP sometimes returns an array, so this is for my sanity |
| 321 | if (\is_string($colors)) { |
| 322 | $colors = \explode(',', $colors); |
| 323 | } |
| 324 | foreach ($colors as $color) { |
| 325 | $to_save[] = \sanitize_hex_color($color); |
| 326 | } |
| 327 | return $to_save; |
| 328 | } |
| 329 | /** |
| 330 | * @return array |
| 331 | */ |
| 332 | private function get_editable_roles() : array |
| 333 | { |
| 334 | $editable_roles = []; |
| 335 | $wp_roles = \wp_roles()->roles; |
| 336 | \array_walk($wp_roles, function ($role, $role_key) use(&$editable_roles) { |
| 337 | if ($role_key === 'administrator') { |
| 338 | return; |
| 339 | } |
| 340 | $capability = null; |
| 341 | foreach (\IAWP\Capability_Manager::all_capabilities() as $key => $name) { |
| 342 | if (\array_key_exists($key, $role['capabilities'])) { |
| 343 | $capability = $key; |
| 344 | } |
| 345 | } |
| 346 | $editable_roles[] = ['key' => $role_key, 'name' => $role['name'], 'capability' => $capability]; |
| 347 | }); |
| 348 | return $editable_roles; |
| 349 | } |
| 350 | private function email_report_colors() |
| 351 | { |
| 352 | return ['#5123a0', '#fafafa', '#3a1e6b', '#fafafa', '#5123a0', '#a985e6', '#ece9f2', '#f7f5fa', '#ece9f2', '#dedae6']; |
| 353 | } |
| 354 | } |
| 355 |