PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.14.8
Independent Analytics – WordPress Analytics Plugin v2.14.8
2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 1.19.1 1.2 1.20.0 1.21.0 1.22.0 1.22.1 1.23.0 1.23.1 1.24.0 1.24.1 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.28.1 1.28.2 1.28.3 1.29.0 1.3 1.30.0 1.30.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0.0 2.0.1 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.10 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.11.9 2.12.0 2.12.1 2.12.2 2.13.1 2.13.2 2.13.5 2.13.6 2.14.0 2.14.1 2.14.2 2.14.4 2.14.6 2.14.7 2.14.8 2.14.9 2.2.0 2.2.1 2.3.1 2.3.2 2.4.2 2.4.3 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7
independent-analytics / IAWP / Settings.php
independent-analytics / IAWP Last commit date
AJAX 3 months ago Admin_Page 3 months ago Click_Tracking 5 months ago ColumnOptions 6 months ago Cron 8 months ago Custom_WordPress_Columns 8 months ago Data_Pruning 5 months ago Date_Picker 3 months ago Date_Range 5 months ago Ecommerce 5 months ago Email_Reports 3 months ago Examiner 3 months ago Favicon 5 months ago Form_Submissions 5 months ago Integrations 3 months ago Interval 1 year ago Journey 5 months ago Migrations 5 months ago Models 5 months ago Overview 3 months ago Public_API 5 months ago Rows 3 months ago Statistics 3 months ago Tables 3 months ago Utils 5 months ago Views 5 months ago WooCommerceOrderMetaBox 5 months ago ActivationLifecycle.php 3 months ago Admin_Bar_Stats.php 3 months ago Appearance.php 1 year ago Campaign_Builder.php 3 months ago Capability_Manager.php 3 months ago Chart.php 3 months ago Chart_Data.php 1 year ago Click_Tracking.php 3 months ago ComplianzIntegration.php 3 months ago Cron_Job.php 5 months ago Cron_Manager.php 5 months ago Current_Traffic_Finder.php 1 year ago Dashboard_Options.php 6 months ago Dashboard_Widget.php 2 years ago Database.php 8 months ago Database_Manager.php 5 months ago Empty_Report_Option.php 2 years ago Env.php 6 months ago Examiner_Config.php 11 months ago FetchFaviconsJob.php 5 months ago Filters.php 3 months ago Geo_Database_Health_Check_Job.php 8 months ago Geo_Database_Manager.php 6 months ago Geoposition.php 1 year ago Icon_Directory.php 6 months ago Icon_Directory_Factory.php 2 years ago Illuminate_Builder.php 10 months ago Independent_Analytics.php 5 months ago Interrupt.php 3 months ago Known_Referrers.php 6 months ago MainWP.php 1 year ago Map.php 8 months ago Map_Data.php 1 year ago Migration_Fixer_Job.php 5 months ago Patch.php 1 year ago Payload_Validator.php 8 months ago Plugin_Conflict_Detector.php 6 months ago Plugin_Group.php 6 months ago Plugin_Group_Option.php 2 years ago Query.php 1 year ago Query_Taps.php 3 months ago Quick_Stats.php 3 months ago REST_API.php 3 months ago Real_Time.php 3 months ago Report.php 1 year ago Report_Finder.php 6 months ago Report_Options_Parser.php 8 months ago Resource_Identifier.php 8 months ago Settings.php 3 months ago Sort_Configuration.php 8 months ago Tables.php 8 months ago Track_Resource_Changes.php 1 year ago View_Counter.php 6 months ago Views_Over_Time_Finder.php 1 year ago VisitorSaltRefreshInterval.php 6 months ago WP_Option_Cache_Bust.php 2 years ago
Settings.php
379 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 /** @internal */
10 class Settings
11 {
12 public function __construct()
13 {
14 \add_action('admin_init', [$this, 'register_settings']);
15 \add_action('admin_init', [$this, 'register_view_counter_settings']);
16 \add_action('admin_init', [$this, 'register_blocked_ip_settings']);
17 \add_action('admin_init', [$this, 'register_block_by_role_settings']);
18 if (\IAWPSCOPED\iawp_is_pro()) {
19 \add_action('admin_init', [$this, 'register_email_report_settings']);
20 }
21 }
22 public function render_settings()
23 {
24 echo \IAWPSCOPED\iawp_render('settings.index');
25 if (\IAWPSCOPED\iawp_is_pro()) {
26 $default_colors = $this->email_report_colors();
27 $saved = \IAWPSCOPED\iawp()->get_option('iawp_email_report_colors', $default_colors);
28 // There were 6 colors and now 9, so there is a saved value but 7-9 don't exist
29 $input_defaults = $default_colors;
30 for ($i = 0; $i < \count($saved); $i++) {
31 $input_defaults[$i] = $saved[$i];
32 }
33 $interval = Interval_Factory::from_option();
34 echo \IAWPSCOPED\iawp_render('settings.email-reports', ['is_scheduled' => \wp_next_scheduled('iawp_send_email_report'), 'scheduled_date' => \IAWPSCOPED\iawp()->email_reports->next_email_at_for_humans(), 'is_paused' => \IAWPSCOPED\iawp()->get_option('iawp_email_report_paused', '0') === '1', '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', []), 'from' => \IAWPSCOPED\iawp()->get_option('iawp_email_report_from_address', \get_option('admin_email')), 'reply_to' => \IAWPSCOPED\iawp()->get_option('iawp_email_report_reply_to_address', \get_option('admin_email')), 'footer_text' => \IAWPSCOPED\iawp()->get_option('iawp_email_report_footer', $this->email_footer()), 'default_colors' => $default_colors, 'input_default' => $input_defaults, 'timestamp' => $interval->next_interval_start()->getTimestamp()]);
35 }
36 $ips = \IAWPSCOPED\iawp()->get_option('iawp_blocked_ips', []);
37 echo \IAWPSCOPED\iawp_render('settings.block-ips', ['current_ip' => Request::ip(), 'ip_is_blocked' => Request::is_ip_address_blocked(), 'ips' => $ips]);
38 echo \IAWPSCOPED\iawp_render('settings.block-by-role', ['roles' => \wp_roles()->roles, 'blocked' => \IAWPSCOPED\iawp()->get_option('iawp_blocked_roles', ['administrator']), 'ignore_cookie' => \IAWPSCOPED\iawp()->get_option('iawp_ignore_via_cookie', \false)]);
39 echo \IAWPSCOPED\iawp_render('settings.capabilities', ['editable_roles' => $this->get_editable_roles(), 'capabilities' => \IAWP\Capability_Manager::all_capabilities()]);
40 echo \IAWPSCOPED\iawp_render('settings.view-counter');
41 if (\IAWPSCOPED\iawp()->is_woocommerce_support_enabled()) {
42 echo \IAWPSCOPED\iawp_render('settings.woocommerce', ['statuses' => new WooCommerce_Status_Manager()]);
43 }
44 echo \IAWPSCOPED\iawp_render('settings.export-reports', ['report_finder' => \IAWP\Report_Finder::new()]);
45 echo \IAWPSCOPED\iawp_render('settings.pruner', ['pruner' => new Pruning_Scheduler()]);
46 echo \IAWPSCOPED\iawp_render('settings.delete', ['site_name' => \get_bloginfo('name'), 'site_url' => \site_url(), 'is_pro' => \IAWPSCOPED\iawp_is_pro()]);
47 }
48 public function register_settings()
49 {
50 \add_settings_section('iawp-settings-section', \esc_html__('Basic Settings', 'independent-analytics'), function () {
51 }, 'independent-analytics-settings');
52 \register_setting('iawp_settings', 'iawp_appearance', ['type' => 'string', 'default' => \IAWP\Appearance::get_default_appearance(), 'sanitize_callback' => function ($input) {
53 return \array_key_exists($input, \IAWP\Appearance::options()) ? $input : \IAWP\Appearance::get_appearance();
54 }]);
55 \add_settings_field('iawp_appearance', \esc_html__('Color scheme', 'independent-analytics'), [$this, 'appearance_callback'], 'independent-analytics-settings', 'iawp-settings-section', ['class' => 'appearance']);
56 $boolean_options = ['type' => 'boolean', 'default' => \false, 'sanitize_callback' => 'rest_sanitize_boolean'];
57 \register_setting('iawp_settings', 'iawp_track_authenticated_users', $boolean_options);
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', $boolean_options);
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', $boolean_options);
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', $boolean_options);
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 $boolean_options = ['type' => 'integer', 'default' => 0, 'sanitize_callback' => 'absint'];
66 \register_setting('iawp_settings', 'iawp_dow', $boolean_options);
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 // Salt refresh interval
69 \register_setting('iawp_settings', 'iawp_visitor_salt_refresh_interval', ['type' => 'int', 'default' => \IAWP\VisitorSaltRefreshInterval::default_interval(), 'sanitize_callback' => function ($input) {
70 return \array_key_exists($input, \IAWP\VisitorSaltRefreshInterval::options()) ? $input : \IAWP\VisitorSaltRefreshInterval::interval();
71 }]);
72 \add_settings_field('iawp_visitor_salt_refresh_interval', \esc_html__('Salt refresh rate', 'independent-analytics'), [$this, 'visitor_salt_refresh_interval_callback'], 'independent-analytics-settings', 'iawp-settings-section', ['class' => 'visitor_salt_refresh_interval']);
73 }
74 public function appearance_callback()
75 {
76 echo \IAWPSCOPED\iawp_render('settings.appearance', ['appearance' => \IAWP\Appearance::get_appearance(), 'options' => \IAWP\Appearance::options()]);
77 }
78 public function visitor_salt_refresh_interval_callback()
79 {
80 echo \IAWPSCOPED\iawp_render('settings.visitor-salt-refresh-interval', ['interval' => \IAWP\VisitorSaltRefreshInterval::interval(), 'options' => \IAWP\VisitorSaltRefreshInterval::options()]);
81 }
82 public function track_authenticated_users_callback()
83 {
84 echo \IAWPSCOPED\iawp_render('settings.track-authenticated-users', ['track_authenticated_users' => \IAWPSCOPED\iawp()->get_option('iawp_track_authenticated_users', \false)]);
85 }
86 public function disable_admin_toolbar_analytics_callback()
87 {
88 echo \IAWPSCOPED\iawp_render('settings.disable-admin-toolbar-analytics', ['value' => \IAWPSCOPED\iawp()->get_option('iawp_disable_admin_toolbar_analytics', \false)]);
89 }
90 public function disable_widget_callback()
91 {
92 echo \IAWPSCOPED\iawp_render('settings.disable-widget', ['value' => \IAWPSCOPED\iawp()->get_option('iawp_disable_widget', \false)]);
93 }
94 public function disable_views_column_callback() : void
95 {
96 echo \IAWPSCOPED\iawp_render('settings.disable-views-column', ['value' => \IAWPSCOPED\iawp()->get_option('iawp_disable_views_column', \false)]);
97 }
98 public function starting_dow_callback()
99 {
100 echo \IAWPSCOPED\iawp_render('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')]]);
101 }
102 public function register_view_counter_settings()
103 {
104 \add_settings_section('iawp-view-counter-settings-section', \esc_html__('Public View Counter', 'independent-analytics'), function () {
105 }, 'independent-analytics-view-counter-settings');
106 $args = ['type' => 'boolean', 'default' => \false, 'sanitize_callback' => 'rest_sanitize_boolean'];
107 \register_setting('iawp_view_counter_settings', 'iawp_view_counter_enable', $args);
108 \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']);
109 $args = ['type' => 'array', 'default' => [], 'sanitize_callback' => [$this, 'sanitize_view_counter_post_types']];
110 \register_setting('iawp_view_counter_settings', 'iawp_view_counter_post_types', $args);
111 \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']);
112 // Position
113 $args = ['type' => 'string', 'default' => 'after', 'sanitize_callback' => [$this, 'sanitize_view_counter_position']];
114 \register_setting('iawp_view_counter_settings', 'iawp_view_counter_position', $args);
115 \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']);
116 // Views to count
117 \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']]);
118 \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']);
119 // Exclude
120 $args = ['type' => 'string', 'default' => '', 'sanitize_callback' => [$this, 'sanitize_view_counter_exclude']];
121 \register_setting('iawp_view_counter_settings', 'iawp_view_counter_exclude', $args);
122 \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']);
123 // Minimum threshold
124 $args = ['type' => 'int', 'default' => 0, 'sanitize_callback' => 'absint'];
125 \register_setting('iawp_view_counter_settings', 'iawp_view_counter_threshold', $args);
126 \add_settings_field('iawp_view_counter_threshold', \esc_html__('Minimum views required', 'independent-analytics'), [$this, 'view_counter_threshold_callback'], 'independent-analytics-view-counter-settings', 'iawp-view-counter-settings-section', ['class' => 'threshold']);
127 // Label
128 $default = \function_exists('IAWPSCOPED\\pll__') ? pll__('Views:', 'independent-analytics') : \__('Views:', 'independent-analytics');
129 $args = ['type' => 'string', 'default' => $default, 'sanitize_callback' => 'sanitize_text_field'];
130 \register_setting('iawp_view_counter_settings', 'iawp_view_counter_label', $args);
131 \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']);
132 // Hide Label
133 $args = ['type' => 'boolean', 'default' => \true, 'sanitize_callback' => 'rest_sanitize_boolean'];
134 \register_setting('iawp_view_counter_settings', 'iawp_view_counter_label_show', $args);
135 \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']);
136 // Icon
137 $args = ['type' => 'boolean', 'default' => \true, 'sanitize_callback' => 'rest_sanitize_boolean'];
138 \register_setting('iawp_view_counter_settings', 'iawp_view_counter_icon', $args);
139 \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']);
140 // Private
141 \register_setting('iawp_view_counter_settings', 'iawp_view_counter_private', ['type' => 'boolean', 'default' => \false, 'sanitize_callback' => 'rest_sanitize_boolean']);
142 \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']);
143 // Allow manual adjustment
144 \register_setting('iawp_view_counter_settings', 'iawp_view_counter_manual_adjustment', ['type' => 'boolean', 'default' => \false, 'sanitize_callback' => 'rest_sanitize_boolean']);
145 \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']);
146 }
147 public function view_counter_enable_callback()
148 {
149 echo \IAWPSCOPED\iawp_render('settings.view-counter.enable', ['enable' => \IAWPSCOPED\iawp()->get_option('iawp_view_counter_enable', \false)]);
150 }
151 public function view_counter_post_types_callback()
152 {
153 $site_post_types = \get_post_types(['public' => \true], 'objects');
154 $counter = 0;
155 foreach ($site_post_types as $post_type) {
156 echo \IAWPSCOPED\iawp_render('settings.view-counter.post-types', ['counter' => $counter, 'post_type' => $post_type, 'saved' => \IAWPSCOPED\iawp()->get_option('iawp_view_counter_post_types', [])]);
157 $counter++;
158 }
159 ?>
160 <p class="description"><?php
161 \esc_html_e('Uncheck all boxes to only show view count manually. See shortcode documentation below for details.', 'independent-analytics');
162 ?></p>
163 <?php
164 }
165 public function view_counter_position_callback()
166 {
167 echo \IAWPSCOPED\iawp_render('settings.view-counter.position', ['position' => \IAWPSCOPED\iawp()->get_option('iawp_view_counter_position', 'after')]);
168 }
169 public function view_counter_views_to_count_callback()
170 {
171 echo \IAWPSCOPED\iawp_render('settings.view-counter.views-to-count', ['value' => \IAWPSCOPED\iawp()->get_option('iawp_view_counter_views_to_count', 'total')]);
172 }
173 public function view_counter_exclude_callback()
174 {
175 echo \IAWPSCOPED\iawp_render('settings.view-counter.exclude', ['exclude' => \IAWPSCOPED\iawp()->get_option('iawp_view_counter_exclude', '')]);
176 }
177 public function view_counter_threshold_callback()
178 {
179 echo \IAWPSCOPED\iawp_render('settings.view-counter.threshold', ['threshold' => \IAWPSCOPED\iawp()->get_option('iawp_view_counter_threshold', 0)]);
180 }
181 public function view_counter_label_callback()
182 {
183 $default = \function_exists('IAWPSCOPED\\pll__') ? pll__('Views:', 'independent-analytics') : \__('Views:', 'independent-analytics');
184 echo \IAWPSCOPED\iawp_render('settings.view-counter.label', ['label' => \IAWPSCOPED\iawp()->get_option('iawp_view_counter_label', $default)]);
185 }
186 public function view_counter_label_show_callback()
187 {
188 echo \IAWPSCOPED\iawp_render('settings.view-counter.label-show', ['show' => \get_option('iawp_view_counter_label_show', \true)]);
189 }
190 public function view_counter_icon_callback()
191 {
192 echo \IAWPSCOPED\iawp_render('settings.view-counter.icon', ['icon' => \get_option('iawp_view_counter_icon', \true)]);
193 }
194 public function view_counter_private_callback()
195 {
196 echo \IAWPSCOPED\iawp_render('settings.view-counter.private', ['private' => \IAWPSCOPED\iawp()->get_option('iawp_view_counter_private', \false)]);
197 }
198 public function view_counter_manual_adjustment_callback()
199 {
200 echo \IAWPSCOPED\iawp_render('settings.view-counter.manual-adjustment', ['value' => \IAWPSCOPED\iawp()->get_option('iawp_view_counter_manual_adjustment', \false)]);
201 }
202 public function register_blocked_ip_settings()
203 {
204 \add_settings_section('iawp-blocked-ips-settings-section', \esc_html__('Block IP Addresses', 'independent-analytics'), function () {
205 }, 'iawp-blocked-ips-settings');
206 $args = ['type' => 'array', 'default' => [], 'sanitize_callback' => [$this, 'sanitize_blocked_ips']];
207 \register_setting('iawp_blocked_ip_settings', 'iawp_blocked_ips', $args);
208 }
209 public function register_email_report_settings()
210 {
211 \add_settings_section('iawp-email-report-settings-section', \esc_html__('Scheduled Email Reports', 'independent-analytics'), function () {
212 }, 'iawp-email-report-settings');
213 \register_setting('iawp_email_report_settings', 'iawp_email_report_interval', ['type' => 'string', 'default' => 'monthly', 'sanitize_callback' => [$this, 'sanitize_email_report_interval']]);
214 \register_setting('iawp_email_report_settings', 'iawp_email_report_time', ['type' => 'number', 'default' => 9, 'sanitize_callback' => [$this, 'sanitize_email_report_time']]);
215 \register_setting('iawp_email_report_settings', 'iawp_email_report_email_addresses', ['type' => 'array', 'default' => [], 'sanitize_callback' => [$this, 'sanitize_email_addresses']]);
216 \register_setting('iawp_email_report_settings', 'iawp_email_report_colors', ['type' => 'array', 'default' => $this->email_report_colors(), 'sanitize_callback' => [$this, 'sanitize_email_report_colors']]);
217 \register_setting('iawp_email_report_settings', 'iawp_email_report_from_address', ['type' => 'string', 'default' => \get_option('admin_email'), 'sanitize_callback' => [$this, 'sanitize_email_address']]);
218 \register_setting('iawp_email_report_settings', 'iawp_email_report_reply_to_address', ['type' => 'string', 'default' => \get_option('admin_email'), 'sanitize_callback' => [$this, 'sanitize_email_address']]);
219 \register_setting('iawp_email_report_settings', 'iawp_email_report_footer', ['type' => 'string', 'default' => $this->email_footer(), 'sanitize_callback' => 'sanitize_text_field']);
220 }
221 public function register_block_by_role_settings()
222 {
223 \add_settings_section('iawp-block-by-role-settings-section', \esc_html__('Block by User Role', 'independent-analytics'), function () {
224 }, 'iawp-block-by-role-settings');
225 $args = ['type' => 'array', 'default' => ['administrator'], 'sanitize_callback' => [$this, 'sanitize_blocked_roles']];
226 \register_setting('iawp_block_by_role_settings', 'iawp_blocked_roles', $args);
227 $args = ['type' => 'boolean', 'default' => \false, 'sanitize_callback' => 'rest_sanitize_boolean'];
228 \register_setting('iawp_block_by_role_settings', 'iawp_ignore_via_cookie', $args);
229 }
230 public function sanitize_view_counter_post_types($user_input)
231 {
232 if (\is_null($user_input)) {
233 return [];
234 }
235 $site_post_types = \get_post_types(['public' => \true]);
236 $to_save = [];
237 foreach ($user_input as $post_type) {
238 if (\in_array($post_type, $site_post_types)) {
239 $to_save[] = $post_type;
240 }
241 }
242 return $to_save;
243 }
244 public function sanitize_view_counter_position($user_input)
245 {
246 if (\in_array($user_input, ['before', 'after', 'both'])) {
247 return $user_input;
248 } else {
249 return 'after';
250 }
251 }
252 public function sanitize_view_counter_views_to_count($user_input)
253 {
254 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'])) {
255 return $user_input;
256 } else {
257 return 'total';
258 }
259 }
260 public function sanitize_view_counter_exclude($user_input)
261 {
262 $user_input = \explode(',', $user_input);
263 $to_save = [];
264 foreach ($user_input as $id) {
265 $save = \absint($id);
266 if ($save != 0) {
267 $to_save[] = $save;
268 }
269 }
270 $to_save = \implode(',', $to_save);
271 return $to_save;
272 }
273 public function sanitize_blocked_ips($ips)
274 {
275 $valid_ips = [];
276 foreach ($ips as $ip) {
277 $address = \IAWPSCOPED\IPLib\Factory::parseRangeString($ip);
278 // Skip invalid ip address ranges
279 if ($address === null) {
280 continue;
281 }
282 $valid_ips[] = $ip;
283 }
284 return $valid_ips;
285 }
286 public function sanitize_email_address($email)
287 {
288 $save = '';
289 $cleaned = \sanitize_email($email);
290 if (\is_email($cleaned)) {
291 $save = $cleaned;
292 }
293 return $save;
294 }
295 public function sanitize_email_addresses($emails)
296 {
297 $to_save = [];
298 foreach ($emails as $email) {
299 $cleaned = \sanitize_email($email);
300 if (\is_email($cleaned)) {
301 $to_save[] = $cleaned;
302 }
303 }
304 return $to_save;
305 }
306 public function sanitize_email_report_interval($input)
307 {
308 if (\in_array($input, ['monthly', 'weekly', 'daily'])) {
309 return $input;
310 } else {
311 return 'monthly';
312 }
313 }
314 public function sanitize_email_report_time($user_time)
315 {
316 $accepted_times = [];
317 for ($i = 0; $i < 24; $i++) {
318 $accepted_times[] = $i;
319 }
320 if (\in_array($user_time, $accepted_times)) {
321 return $user_time;
322 } else {
323 return 9;
324 }
325 }
326 public function sanitize_blocked_roles($blocked_roles)
327 {
328 $to_save = [];
329 $user_roles = \array_keys(\wp_roles()->roles);
330 foreach ($blocked_roles as $blocked) {
331 if (\in_array($blocked, $user_roles)) {
332 $to_save[] = $blocked;
333 }
334 }
335 return $to_save;
336 }
337 public function sanitize_email_report_colors($colors)
338 {
339 $to_save = [];
340 // No idea why WP sometimes returns an array, so this is for my sanity
341 if (\is_string($colors)) {
342 $colors = \explode(',', $colors);
343 }
344 foreach ($colors as $color) {
345 $to_save[] = \sanitize_hex_color($color);
346 }
347 return $to_save;
348 }
349 /**
350 * @return array
351 */
352 private function get_editable_roles() : array
353 {
354 $editable_roles = [];
355 $wp_roles = \wp_roles()->roles;
356 \array_walk($wp_roles, function ($role, $role_key) use(&$editable_roles) {
357 if ($role_key === 'administrator') {
358 return;
359 }
360 $capability = null;
361 foreach (\IAWP\Capability_Manager::all_capabilities() as $key => $name) {
362 if (\array_key_exists($key, $role['capabilities'])) {
363 $capability = $key;
364 }
365 }
366 $editable_roles[] = ['key' => $role_key, 'name' => $role['name'], 'capability' => $capability];
367 });
368 return $editable_roles;
369 }
370 private function email_report_colors()
371 {
372 return ['#5123a0', '#fafafa', '#3a1e6b', '#fafafa', '#5123a0', '#a985e6', '#ece9f2', '#f7f5fa', '#ece9f2', '#dedae6'];
373 }
374 private function email_footer()
375 {
376 return \sprintf(\esc_html__('This email was generated and delivered by %s', 'independent-analytics'), \esc_url(\get_site_url()));
377 }
378 }
379