AJAX
1 year ago
Admin_Page
1 year ago
Click_Tracking
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
1 year ago
Form_Submissions
1 year ago
Interval
1 year ago
Menu_Bar_Stats
1 year ago
Migrations
1 year ago
Models
1 year ago
Overview
1 year ago
Public_API
1 year ago
Rows
1 year ago
Statistics
1 year ago
Tables
1 year ago
Utils
1 year ago
Campaign_Builder.php
1 year ago
Capability_Manager.php
1 year ago
Chart.php
1 year ago
Chart_Data.php
1 year ago
Click_Tracking.php
1 year ago
Cron_Job.php
1 year ago
Cron_Manager.php
1 year ago
Current_Traffic_Finder.php
1 year ago
Dashboard_Options.php
1 year ago
Dashboard_Widget.php
2 years ago
Database.php
1 year 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
MainWP.php
1 year ago
Map.php
1 year ago
Map_Data.php
1 year ago
Patch.php
1 year ago
Payload_Validator.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
1 year ago
REST_API.php
1 year ago
Real_Time.php
1 year ago
Report.php
1 year ago
Report_Finder.php
1 year ago
Report_Options_Parser.php
2 years ago
Resource_Identifier.php
1 year ago
Settings.php
1 year ago
Sort_Configuration.php
1 year ago
Tables.php
1 year ago
Track_Resource_Changes.php
1 year ago
View.php
1 year ago
View_Counter.php
1 year ago
Views_Over_Time_Finder.php
1 year ago
WP_Option_Cache_Bust.php
2 years ago
Settings.php
365 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_blade()->run('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_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', []), '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_blade()->run('settings.block-ips', ['current_ip' => Request::ip(), 'ip_is_blocked' => Request::is_ip_address_blocked(), 'ips' => $ips]); |
| 38 | echo \IAWPSCOPED\iawp_blade()->run('settings.block-by-role', ['roles' => \wp_roles()->roles, 'blocked' => \IAWPSCOPED\iawp()->get_option('iawp_blocked_roles', ['administrator'])]); |
| 39 | echo \IAWPSCOPED\iawp_blade()->run('settings.capabilities', ['editable_roles' => $this->get_editable_roles(), 'capabilities' => \IAWP\Capability_Manager::all_capabilities()]); |
| 40 | echo \IAWPSCOPED\iawp_blade()->run('settings.view-counter'); |
| 41 | if (\IAWPSCOPED\iawp()->is_woocommerce_support_enabled()) { |
| 42 | echo \IAWPSCOPED\iawp_blade()->run('settings.woocommerce', ['statuses' => new WooCommerce_Status_Manager()]); |
| 43 | } |
| 44 | echo \IAWPSCOPED\iawp_blade()->run('settings.export-reports', ['report_finder' => \IAWP\Report_Finder::new()]); |
| 45 | echo \IAWPSCOPED\iawp_blade()->run('settings.pruner', ['pruner' => new Pruning_Scheduler()]); |
| 46 | echo \IAWPSCOPED\iawp_blade()->run('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 | $args = ['type' => 'boolean', 'default' => \false, 'sanitize_callback' => 'rest_sanitize_boolean']; |
| 53 | \register_setting('iawp_settings', 'iawp_dark_mode', $args); |
| 54 | \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']); |
| 55 | \register_setting('iawp_settings', 'iawp_track_authenticated_users', $args); |
| 56 | \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']); |
| 57 | \register_setting('iawp_settings', 'iawp_disable_admin_toolbar_analytics', $args); |
| 58 | \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'); |
| 59 | \register_setting('iawp_settings', 'iawp_disable_widget', $args); |
| 60 | \add_settings_field('iawp_disable_widget', \esc_html__('Dashboard widget', 'independent-analytics'), [$this, 'disable_widget_callback'], 'independent-analytics-settings', 'iawp-settings-section'); |
| 61 | \register_setting('iawp_settings', 'iawp_disable_views_column', $args); |
| 62 | \add_settings_field('iawp_disable_views_column', \esc_html__('Views column', 'independent-analytics'), [$this, 'disable_views_column_callback'], 'independent-analytics-settings', 'iawp-settings-section'); |
| 63 | $args = ['type' => 'integer', 'default' => 0, 'sanitize_callback' => 'absint']; |
| 64 | \register_setting('iawp_settings', 'iawp_dow', $args); |
| 65 | \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']); |
| 66 | $args = ['type' => 'boolean', 'default' => \false, 'sanitize_callback' => 'rest_sanitize_boolean']; |
| 67 | \register_setting('iawp_settings', 'iawp_refresh_salt', $args); |
| 68 | \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']); |
| 69 | } |
| 70 | public function dark_mode_callback() |
| 71 | { |
| 72 | echo \IAWPSCOPED\iawp_blade()->run('settings.dark-mode', ['dark_mode' => \IAWPSCOPED\iawp()->get_option('iawp_dark_mode', \false)]); |
| 73 | } |
| 74 | public function track_authenticated_users_callback() |
| 75 | { |
| 76 | echo \IAWPSCOPED\iawp_blade()->run('settings.track-authenticated-users', ['track_authenticated_users' => \IAWPSCOPED\iawp()->get_option('iawp_track_authenticated_users', \false)]); |
| 77 | } |
| 78 | public function disable_admin_toolbar_analytics_callback() |
| 79 | { |
| 80 | echo \IAWPSCOPED\iawp_blade()->run('settings.disable-admin-toolbar-analytics', ['value' => \IAWPSCOPED\iawp()->get_option('iawp_disable_admin_toolbar_analytics', \false)]); |
| 81 | } |
| 82 | public function disable_widget_callback() |
| 83 | { |
| 84 | echo \IAWPSCOPED\iawp_blade()->run('settings.disable-widget', ['value' => \IAWPSCOPED\iawp()->get_option('iawp_disable_widget', \false)]); |
| 85 | } |
| 86 | public function disable_views_column_callback() : void |
| 87 | { |
| 88 | echo \IAWPSCOPED\iawp_blade()->run('settings.disable-views-column', ['value' => \IAWPSCOPED\iawp()->get_option('iawp_disable_views_column', \false)]); |
| 89 | } |
| 90 | public function starting_dow_callback() |
| 91 | { |
| 92 | 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')]]); |
| 93 | } |
| 94 | public function refresh_salt_callback() |
| 95 | { |
| 96 | echo \IAWPSCOPED\iawp_blade()->run('settings.refresh-salt', ['refresh_salt' => \IAWPSCOPED\iawp()->get_option('iawp_refresh_salt', \false)]); |
| 97 | } |
| 98 | public function register_view_counter_settings() |
| 99 | { |
| 100 | \add_settings_section('iawp-view-counter-settings-section', \esc_html__('Public View Counter', 'independent-analytics'), function () { |
| 101 | }, 'independent-analytics-view-counter-settings'); |
| 102 | $args = ['type' => 'boolean', 'default' => \false, 'sanitize_callback' => 'rest_sanitize_boolean']; |
| 103 | \register_setting('iawp_view_counter_settings', 'iawp_view_counter_enable', $args); |
| 104 | \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']); |
| 105 | $args = ['type' => 'array', 'default' => [], 'sanitize_callback' => [$this, 'sanitize_view_counter_post_types']]; |
| 106 | \register_setting('iawp_view_counter_settings', 'iawp_view_counter_post_types', $args); |
| 107 | \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']); |
| 108 | // Position |
| 109 | $args = ['type' => 'string', 'default' => 'after', 'sanitize_callback' => [$this, 'sanitize_view_counter_position']]; |
| 110 | \register_setting('iawp_view_counter_settings', 'iawp_view_counter_position', $args); |
| 111 | \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']); |
| 112 | // Views to count |
| 113 | \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']]); |
| 114 | \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']); |
| 115 | // Exclude |
| 116 | $args = ['type' => 'string', 'default' => '', 'sanitize_callback' => [$this, 'sanitize_view_counter_exclude']]; |
| 117 | \register_setting('iawp_view_counter_settings', 'iawp_view_counter_exclude', $args); |
| 118 | \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']); |
| 119 | // Label |
| 120 | $default = \function_exists('IAWPSCOPED\\pll__') ? pll__('Views:', 'independent-analytics') : \__('Views:', 'independent-analytics'); |
| 121 | $args = ['type' => 'string', 'default' => $default, 'sanitize_callback' => 'sanitize_text_field']; |
| 122 | \register_setting('iawp_view_counter_settings', 'iawp_view_counter_label', $args); |
| 123 | \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']); |
| 124 | // Hide Label |
| 125 | $args = ['type' => 'boolean', 'default' => \true, 'sanitize_callback' => 'rest_sanitize_boolean']; |
| 126 | \register_setting('iawp_view_counter_settings', 'iawp_view_counter_label_show', $args); |
| 127 | \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']); |
| 128 | // Icon |
| 129 | $args = ['type' => 'boolean', 'default' => \true, 'sanitize_callback' => 'rest_sanitize_boolean']; |
| 130 | \register_setting('iawp_view_counter_settings', 'iawp_view_counter_icon', $args); |
| 131 | \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']); |
| 132 | // Private |
| 133 | \register_setting('iawp_view_counter_settings', 'iawp_view_counter_private', ['type' => 'boolean', 'default' => \false, 'sanitize_callback' => 'rest_sanitize_boolean']); |
| 134 | \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']); |
| 135 | // Allow manual adjustment |
| 136 | \register_setting('iawp_view_counter_settings', 'iawp_view_counter_manual_adjustment', ['type' => 'boolean', 'default' => \false, 'sanitize_callback' => 'rest_sanitize_boolean']); |
| 137 | \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']); |
| 138 | } |
| 139 | public function view_counter_enable_callback() |
| 140 | { |
| 141 | echo \IAWPSCOPED\iawp_blade()->run('settings.view-counter.enable', ['enable' => \IAWPSCOPED\iawp()->get_option('iawp_view_counter_enable', \false)]); |
| 142 | } |
| 143 | public function view_counter_post_types_callback() |
| 144 | { |
| 145 | $site_post_types = \get_post_types(['public' => \true], 'objects'); |
| 146 | $counter = 0; |
| 147 | foreach ($site_post_types as $post_type) { |
| 148 | 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', [])]); |
| 149 | $counter++; |
| 150 | } |
| 151 | ?> |
| 152 | <p class="description"><?php |
| 153 | \esc_html_e('Uncheck all boxes to only show view count manually. See shortcode documentation below for details.', 'independent-analytics'); |
| 154 | ?></p> |
| 155 | <?php |
| 156 | } |
| 157 | public function view_counter_position_callback() |
| 158 | { |
| 159 | echo \IAWPSCOPED\iawp_blade()->run('settings.view-counter.position', ['position' => \IAWPSCOPED\iawp()->get_option('iawp_view_counter_position', 'after')]); |
| 160 | } |
| 161 | public function view_counter_views_to_count_callback() |
| 162 | { |
| 163 | echo \IAWPSCOPED\iawp_blade()->run('settings.view-counter.views-to-count', ['value' => \IAWPSCOPED\iawp()->get_option('iawp_view_counter_views_to_count', 'total')]); |
| 164 | } |
| 165 | public function view_counter_exclude_callback() |
| 166 | { |
| 167 | echo \IAWPSCOPED\iawp_blade()->run('settings.view-counter.exclude', ['exclude' => \IAWPSCOPED\iawp()->get_option('iawp_view_counter_exclude', '')]); |
| 168 | } |
| 169 | public function view_counter_label_callback() |
| 170 | { |
| 171 | $default = \function_exists('IAWPSCOPED\\pll__') ? pll__('Views:', 'independent-analytics') : \__('Views:', 'independent-analytics'); |
| 172 | echo \IAWPSCOPED\iawp_blade()->run('settings.view-counter.label', ['label' => \IAWPSCOPED\iawp()->get_option('iawp_view_counter_label', $default)]); |
| 173 | } |
| 174 | public function view_counter_label_show_callback() |
| 175 | { |
| 176 | echo \IAWPSCOPED\iawp_blade()->run('settings.view-counter.label-show', ['show' => \get_option('iawp_view_counter_label_show', \true)]); |
| 177 | } |
| 178 | public function view_counter_icon_callback() |
| 179 | { |
| 180 | echo \IAWPSCOPED\iawp_blade()->run('settings.view-counter.icon', ['icon' => \get_option('iawp_view_counter_icon', \true)]); |
| 181 | } |
| 182 | public function view_counter_private_callback() |
| 183 | { |
| 184 | echo \IAWPSCOPED\iawp_blade()->run('settings.view-counter.private', ['private' => \IAWPSCOPED\iawp()->get_option('iawp_view_counter_private', \false)]); |
| 185 | } |
| 186 | public function view_counter_manual_adjustment_callback() |
| 187 | { |
| 188 | echo \IAWPSCOPED\iawp_blade()->run('settings.view-counter.manual-adjustment', ['value' => \IAWPSCOPED\iawp()->get_option('iawp_view_counter_manual_adjustment', \false)]); |
| 189 | } |
| 190 | public function register_blocked_ip_settings() |
| 191 | { |
| 192 | \add_settings_section('iawp-blocked-ips-settings-section', \esc_html__('Block IP Addresses', 'independent-analytics'), function () { |
| 193 | }, 'iawp-blocked-ips-settings'); |
| 194 | $args = ['type' => 'array', 'default' => [], 'sanitize_callback' => [$this, 'sanitize_blocked_ips']]; |
| 195 | \register_setting('iawp_blocked_ip_settings', 'iawp_blocked_ips', $args); |
| 196 | } |
| 197 | public function register_email_report_settings() |
| 198 | { |
| 199 | \add_settings_section('iawp-email-report-settings-section', \esc_html__('Scheduled Email Reports', 'independent-analytics'), function () { |
| 200 | }, 'iawp-email-report-settings'); |
| 201 | \register_setting('iawp_email_report_settings', 'iawp_email_report_interval', ['type' => 'string', 'default' => 'monthly', 'sanitize_callback' => [$this, 'sanitize_email_report_interval']]); |
| 202 | \register_setting('iawp_email_report_settings', 'iawp_email_report_time', ['type' => 'number', 'default' => 9, 'sanitize_callback' => [$this, 'sanitize_email_report_time']]); |
| 203 | \register_setting('iawp_email_report_settings', 'iawp_email_report_email_addresses', ['type' => 'array', 'default' => [], 'sanitize_callback' => [$this, 'sanitize_email_addresses']]); |
| 204 | \register_setting('iawp_email_report_settings', 'iawp_email_report_colors', ['type' => 'array', 'default' => $this->email_report_colors(), 'sanitize_callback' => [$this, 'sanitize_email_report_colors']]); |
| 205 | \register_setting('iawp_email_report_settings', 'iawp_email_report_from_address', ['type' => 'string', 'default' => \get_option('admin_email'), 'sanitize_callback' => [$this, 'sanitize_email_address']]); |
| 206 | \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']]); |
| 207 | \register_setting('iawp_email_report_settings', 'iawp_email_report_footer', ['type' => 'string', 'default' => $this->email_footer(), 'sanitize_callback' => 'sanitize_text_field']); |
| 208 | } |
| 209 | public function register_block_by_role_settings() |
| 210 | { |
| 211 | \add_settings_section('iawp-block-by-role-settings-section', \esc_html__('Block by User Role', 'independent-analytics'), function () { |
| 212 | }, 'iawp-block-by-role-settings'); |
| 213 | $args = ['type' => 'array', 'default' => ['administrator'], 'sanitize_callback' => [$this, 'sanitize_blocked_roles']]; |
| 214 | \register_setting('iawp_block_by_role_settings', 'iawp_blocked_roles', $args); |
| 215 | } |
| 216 | public function sanitize_view_counter_post_types($user_input) |
| 217 | { |
| 218 | if (\is_null($user_input)) { |
| 219 | return []; |
| 220 | } |
| 221 | $site_post_types = \get_post_types(['public' => \true]); |
| 222 | $to_save = []; |
| 223 | foreach ($user_input as $post_type) { |
| 224 | if (\in_array($post_type, $site_post_types)) { |
| 225 | $to_save[] = $post_type; |
| 226 | } |
| 227 | } |
| 228 | return $to_save; |
| 229 | } |
| 230 | public function sanitize_view_counter_position($user_input) |
| 231 | { |
| 232 | if (\in_array($user_input, ['before', 'after', 'both'])) { |
| 233 | return $user_input; |
| 234 | } else { |
| 235 | return 'after'; |
| 236 | } |
| 237 | } |
| 238 | public function sanitize_view_counter_views_to_count($user_input) |
| 239 | { |
| 240 | 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'])) { |
| 241 | return $user_input; |
| 242 | } else { |
| 243 | return 'total'; |
| 244 | } |
| 245 | } |
| 246 | public function sanitize_view_counter_exclude($user_input) |
| 247 | { |
| 248 | $user_input = \explode(',', $user_input); |
| 249 | $to_save = []; |
| 250 | foreach ($user_input as $id) { |
| 251 | $save = \absint($id); |
| 252 | if ($save != 0) { |
| 253 | $to_save[] = $save; |
| 254 | } |
| 255 | } |
| 256 | $to_save = \implode(',', $to_save); |
| 257 | return $to_save; |
| 258 | } |
| 259 | public function sanitize_blocked_ips($ips) |
| 260 | { |
| 261 | $valid_ips = []; |
| 262 | foreach ($ips as $ip) { |
| 263 | $address = \IAWPSCOPED\IPLib\Factory::parseRangeString($ip); |
| 264 | // Skip invalid ip address ranges |
| 265 | if ($address === null) { |
| 266 | continue; |
| 267 | } |
| 268 | $valid_ips[] = $ip; |
| 269 | } |
| 270 | return $valid_ips; |
| 271 | } |
| 272 | public function sanitize_email_address($email) |
| 273 | { |
| 274 | $save = ''; |
| 275 | $cleaned = \sanitize_email($email); |
| 276 | if (\is_email($cleaned)) { |
| 277 | $save = $cleaned; |
| 278 | } |
| 279 | return $save; |
| 280 | } |
| 281 | public function sanitize_email_addresses($emails) |
| 282 | { |
| 283 | $to_save = []; |
| 284 | foreach ($emails as $email) { |
| 285 | $cleaned = \sanitize_email($email); |
| 286 | if (\is_email($cleaned)) { |
| 287 | $to_save[] = $cleaned; |
| 288 | } |
| 289 | } |
| 290 | return $to_save; |
| 291 | } |
| 292 | public function sanitize_email_report_interval($input) |
| 293 | { |
| 294 | if (\in_array($input, ['monthly', 'weekly', 'daily'])) { |
| 295 | return $input; |
| 296 | } else { |
| 297 | return 'monthly'; |
| 298 | } |
| 299 | } |
| 300 | public function sanitize_email_report_time($user_time) |
| 301 | { |
| 302 | $accepted_times = []; |
| 303 | for ($i = 0; $i < 24; $i++) { |
| 304 | $accepted_times[] = $i; |
| 305 | } |
| 306 | if (\in_array($user_time, $accepted_times)) { |
| 307 | return $user_time; |
| 308 | } else { |
| 309 | return 9; |
| 310 | } |
| 311 | } |
| 312 | public function sanitize_blocked_roles($blocked_roles) |
| 313 | { |
| 314 | $to_save = []; |
| 315 | $user_roles = \array_keys(\wp_roles()->roles); |
| 316 | foreach ($blocked_roles as $blocked) { |
| 317 | if (\in_array($blocked, $user_roles)) { |
| 318 | $to_save[] = $blocked; |
| 319 | } |
| 320 | } |
| 321 | return $to_save; |
| 322 | } |
| 323 | public function sanitize_email_report_colors($colors) |
| 324 | { |
| 325 | $to_save = []; |
| 326 | // No idea why WP sometimes returns an array, so this is for my sanity |
| 327 | if (\is_string($colors)) { |
| 328 | $colors = \explode(',', $colors); |
| 329 | } |
| 330 | foreach ($colors as $color) { |
| 331 | $to_save[] = \sanitize_hex_color($color); |
| 332 | } |
| 333 | return $to_save; |
| 334 | } |
| 335 | /** |
| 336 | * @return array |
| 337 | */ |
| 338 | private function get_editable_roles() : array |
| 339 | { |
| 340 | $editable_roles = []; |
| 341 | $wp_roles = \wp_roles()->roles; |
| 342 | \array_walk($wp_roles, function ($role, $role_key) use(&$editable_roles) { |
| 343 | if ($role_key === 'administrator') { |
| 344 | return; |
| 345 | } |
| 346 | $capability = null; |
| 347 | foreach (\IAWP\Capability_Manager::all_capabilities() as $key => $name) { |
| 348 | if (\array_key_exists($key, $role['capabilities'])) { |
| 349 | $capability = $key; |
| 350 | } |
| 351 | } |
| 352 | $editable_roles[] = ['key' => $role_key, 'name' => $role['name'], 'capability' => $capability]; |
| 353 | }); |
| 354 | return $editable_roles; |
| 355 | } |
| 356 | private function email_report_colors() |
| 357 | { |
| 358 | return ['#5123a0', '#fafafa', '#3a1e6b', '#fafafa', '#5123a0', '#a985e6', '#ece9f2', '#f7f5fa', '#ece9f2', '#dedae6']; |
| 359 | } |
| 360 | private function email_footer() |
| 361 | { |
| 362 | return \sprintf(\esc_html__('This email was generated and delivered by %s', 'independent-analytics'), \esc_url(\get_site_url())); |
| 363 | } |
| 364 | } |
| 365 |