Skip to content

Commit fb1df59

Browse files
add hook for other plugins to add koko analytics related settings
1 parent f55a116 commit fb1df59

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/class-admin.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,16 +211,19 @@ public function reset_statistics(): void
211211
public function save_settings(): void
212212
{
213213
check_admin_referer('koko_analytics_save_settings');
214-
$new_settings = $_POST['koko_analytics_settings'];
214+
$posted = $_POST['koko_analytics_settings'];
215215
$settings = get_settings();
216-
$settings['exclude_ip_addresses'] = array_filter(array_map('trim', explode(PHP_EOL, str_replace(',', PHP_EOL, strip_tags($new_settings['exclude_ip_addresses'])))), function ($value) {
216+
217+
$settings['exclude_ip_addresses'] = array_filter(array_map('trim', explode(PHP_EOL, str_replace(',', PHP_EOL, strip_tags($posted['exclude_ip_addresses'])))), function ($value) {
217218
return $value !== '';
218219
});
219-
$settings['exclude_user_roles'] = $new_settings['exclude_user_roles'] ?? array();
220-
$settings['prune_data_after_months'] = abs((int) $new_settings['prune_data_after_months']);
221-
$settings['use_cookie'] = (int) $new_settings['use_cookie'];
222-
$settings['is_dashboard_public'] = (int) $new_settings['is_dashboard_public'];
223-
$settings['default_view'] = trim($new_settings['default_view']);
220+
$settings['exclude_user_roles'] = $posted['exclude_user_roles'] ?? array();
221+
$settings['prune_data_after_months'] = abs((int) $posted['prune_data_after_months']);
222+
$settings['use_cookie'] = (int) $posted['use_cookie'];
223+
$settings['is_dashboard_public'] = (int) $posted['is_dashboard_public'];
224+
$settings['default_view'] = trim($posted['default_view']);
225+
226+
$settings = apply_filters('koko_analytics_sanitize_settings', $settings, $posted);
224227
update_option('koko_analytics_settings', $settings, true);
225228
wp_safe_redirect(add_query_arg(array('settings-updated' => true), wp_get_referer()));
226229
exit;

src/views/settings-page.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@
9999
<input id="ka-prune-after-input" name="koko_analytics_settings[prune_data_after_months]" type="number" step="1" min="0" max="600" value="<?php echo esc_attr($settings['prune_data_after_months']); ?>"> <?php esc_html_e('months', 'koko-analytics'); ?>
100100
<p class="description"><?php esc_html_e('Statistics older than the number of months configured here will automatically be deleted. Set to 0 to disable.', 'koko-analytics'); ?></p>
101101
</div>
102+
103+
<?php do_action('koko_analytics_show_settings_rows', $settings); ?>
104+
102105
<div class="ka-margin-m">
103106
<?php submit_button(null, 'primary', 'submit', false); ?>
104107
</div>

0 commit comments

Comments
 (0)