models
4 years ago
queries
4 years ago
utils
4 years ago
chart.php
4 years ago
db.php
4 years ago
filters-ajax.php
4 years ago
filters.php
4 years ago
rest-api.php
4 years ago
settings-ajax.php
4 years ago
settings.php
4 years ago
super-secret-content-generator.php
4 years ago
table-referrers.php
4 years ago
table-views.php
4 years ago
table.php
4 years ago
track-resource-changes.php
4 years ago
settings.php
96 lines
| 1 | <?php |
| 2 | |
| 3 | if (!class_exists('IAWP_Settings')) { |
| 4 | class IAWP_Settings |
| 5 | { |
| 6 | public function __construct() |
| 7 | { |
| 8 | add_action('admin_init', [$this, 'register_settings']); |
| 9 | } |
| 10 | |
| 11 | public function render_settings() |
| 12 | { |
| 13 | $this->output_settings(); |
| 14 | |
| 15 | $template = IAWP()->twig->load('settings/settings.html'); |
| 16 | |
| 17 | echo $template->render([ |
| 18 | 'export_views_url' => get_site_url() . '/?rest_route=/iawp/export/views', |
| 19 | 'export_referrers_url' => get_site_url() . '/?rest_route=/iawp/export/referrers', |
| 20 | ]); |
| 21 | } |
| 22 | |
| 23 | public function register_settings() |
| 24 | { |
| 25 | add_settings_section('iawp-settings-section', esc_html__('Settings', 'iawp'), '', 'independent-analytics-settings'); |
| 26 | |
| 27 | $args = [ |
| 28 | 'type' => 'boolean', |
| 29 | 'default' => false, |
| 30 | 'sanitize_callback' => 'rest_sanitize_boolean', |
| 31 | ]; |
| 32 | register_setting('iawp_settings', 'iawp_dark_mode', $args); |
| 33 | register_setting('iawp_settings', 'iawp_track_authenticated_users', $args); |
| 34 | add_settings_field('iawp_dark_mode', esc_html__('Dark mode', 'iawp'), [$this, 'dark_mode_callback'], 'independent-analytics-settings', 'iawp-settings-section', ['class' => 'dark-mode']); |
| 35 | add_settings_field('iawp_track_authenticated_users', esc_html__('Track logged in users', 'iawp'), [$this, 'track_authenticated_users_callback'], 'independent-analytics-settings', 'iawp-settings-section', ['class' => 'logged-in']); |
| 36 | |
| 37 | $args = [ |
| 38 | 'type' => 'integer', |
| 39 | 'default' => 1, |
| 40 | 'sanitize_callback' => 'absint', |
| 41 | ]; |
| 42 | register_setting('iawp_settings', 'iawp_dow', $args); |
| 43 | add_settings_field('iawp_dow', esc_html__('Calendar first day of the week', 'iawp'), [$this, 'starting_dow_callback'], 'independent-analytics-settings', 'iawp-settings-section', ['class' => 'dow']); |
| 44 | } |
| 45 | |
| 46 | public function dark_mode_callback() |
| 47 | { |
| 48 | $saved = IAWP()->get_option('iawp_dark_mode', false); ?> |
| 49 | <label class="column-label" for="iawp_dark_mode"> |
| 50 | <input type="checkbox" name="iawp_dark_mode" id="iawp_dark_mode" <?php checked(true, $saved, true); ?>> |
| 51 | <span><?php esc_html_e('Enable dark mode', 'iawp'); ?></span> |
| 52 | </label><?php |
| 53 | } |
| 54 | |
| 55 | public function track_authenticated_users_callback() |
| 56 | { |
| 57 | $saved = IAWP()->get_option('iawp_track_authenticated_users', false); ?> |
| 58 | <label class="column-label" for="iawp_track_authenticated_users"> |
| 59 | <input type="checkbox" name="iawp_track_authenticated_users" id="iawp_track_authenticated_users" <?php checked(true, $saved, true); ?>> |
| 60 | <span><?php esc_html_e('Track logged in users', 'iawp'); ?></span> |
| 61 | </label><?php |
| 62 | } |
| 63 | |
| 64 | public function starting_dow_callback() |
| 65 | { |
| 66 | $saved = IAWP()->get_option('iawp_dow', 1); |
| 67 | $dows = [ |
| 68 | 0 => esc_html__('Sunday', 'iawp'), |
| 69 | 1 => esc_html__('Monday', 'iawp'), |
| 70 | 2 => esc_html__('Tuesday', 'iawp'), |
| 71 | 3 => esc_html__('Wednesday', 'iawp'), |
| 72 | 4 => esc_html__('Thursday', 'iawp'), |
| 73 | 5 => esc_html__('Friday', 'iawp'), |
| 74 | 6 => esc_html__('Saturday', 'iawp'), |
| 75 | ]; |
| 76 | |
| 77 | echo '<select id="iawp_dow" name="iawp_dow" value="' . esc_attr($saved) . '" >'; |
| 78 | foreach ($dows as $key => $value) { |
| 79 | echo '<option value="' . esc_attr($key) . '" ' . selected($saved, $key, false) . '>' . esc_html($value) . '</option>'; |
| 80 | } |
| 81 | echo '</select>'; |
| 82 | } |
| 83 | |
| 84 | public function output_settings() |
| 85 | { |
| 86 | echo '<div id="iawp-settings" class="iawp-settings settings-container">'; |
| 87 | echo '<form method="post" action="options.php">'; |
| 88 | settings_fields('iawp_settings'); |
| 89 | do_settings_sections('independent-analytics-settings'); |
| 90 | submit_button(esc_html__('Save settings', 'iawp'), 'iawp-button purple', 'save-settings'); |
| 91 | echo '</form>'; |
| 92 | echo '</div>'; |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 |