Skip to content

Commit 402d599

Browse files
authored
Merge pull request #111 from pluginkollektiv/settingsPage
Introduce settings page and more options
2 parents 47a83fb + ab7af21 commit 402d599

8 files changed

+399
-43
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Changelog
22
All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/).
33

4+
## Unreleased
5+
* Introduced separate settinge page and reduced widget backview to widget settings only
6+
* Add options to track logged in users, feeds and search requests
7+
48
## 1.6.3
59
* Fix compatibility issue with some PHP implementations not populating `INPUT_SERVER`
610
* Fix failing blacklist check for empty referrers

inc/class-statify-backend.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public static function add_meta_link( $input, $file ) {
5858
public static function add_action_link( $input ) {
5959

6060
// Rights?
61-
if ( ! current_user_can( 'edit_dashboard' ) ) {
61+
if ( ! current_user_can( 'manage_options' ) ) {
6262
return $input;
6363
}
6464

@@ -70,8 +70,8 @@ public static function add_action_link( $input ) {
7070
/* @lang Disable language injection for Url query argument. */
7171
'<a href="%s">%s</a>',
7272
add_query_arg(
73-
array( 'edit' => 'statify_dashboard#statify_dashboard' ),
74-
admin_url( '/' )
73+
array( 'page' => 'statify-settings' ),
74+
admin_url( '/options-general.php' )
7575
),
7676
esc_html__( 'Settings', 'statify' )
7777
),

inc/class-statify-dashboard.php

+22-20
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ public static function init() {
4242
return;
4343
}
4444

45+
// Check if user can edit the widget.
46+
$can_edit = apply_filters( 'statify__user_can_see_stats', current_user_can( 'edit_dashboard' ) );
47+
4548
// Load textdomain.
4649
load_plugin_textdomain(
4750
'statify',
@@ -57,7 +60,7 @@ public static function init() {
5760
'statify_dashboard',
5861
'Statify',
5962
array( __CLASS__, 'print_frontview' ),
60-
array( __CLASS__, 'print_backview' )
63+
$can_edit ? array( __CLASS__, 'print_backview' ) : null
6164
);
6265

6366
// Init CSS.
@@ -183,7 +186,7 @@ public static function print_backview() {
183186
if ( ! empty( $_POST['statify'] ) ) {
184187
check_admin_referer( 'statify-dashboard' );
185188

186-
self::_save_options();
189+
self::_save_widget_options();
187190
}
188191

189192
// Load view.
@@ -194,36 +197,35 @@ public static function print_backview() {
194197

195198

196199
/**
197-
* Save plugin options
200+
* Save dashboard widget options.
198201
*
199202
* @since 1.4.0
200-
* @version 2017-01-10
203+
* @sicnce 1.7.0 Renamed to _save_widget_options()
204+
*
205+
* @return void
201206
*/
202-
private static function _save_options() {
207+
private static function _save_widget_options() {
203208
// Check the nonce field from the dashboard form.
204209
if ( ! check_admin_referer( 'statify-dashboard' ) ) {
205210
return;
206211
}
207212

208-
// Get numeric values from POST variables.
209-
$options = array();
210-
foreach ( array( 'days', 'limit' ) as $option_name ) {
211-
$options[ $option_name ] = Statify::$_options[ $option_name ];
212-
if ( isset( $_POST['statify'][ $option_name ] ) && (int) $_POST['statify'][ $option_name ] > 0 ) {
213-
$options[ $option_name ] = (int) $_POST['statify'][ $option_name ];
214-
}
213+
// We only do a partial update, so initialize with current values.
214+
$options = Statify::$_options;
215+
216+
// Parse numeric "limit" value.
217+
if ( isset( $_POST['statify']['limit'] ) && (int) $_POST['statify']['limit'] > 0 ) {
218+
$options['limit'] = (int) $_POST['statify']['limit'];
215219
}
216-
if ( (int) $options['limit'] > 100 ) {
220+
if ( $options['limit'] > 100 ) {
217221
$options['limit'] = 100;
218222
}
219223

220-
// Get checkbox values from POST variables.
221-
foreach ( array( 'today', 'snippet', 'blacklist' ) as $option_name ) {
222-
if ( isset( $_POST['statify'][ $option_name ] ) && 1 === (int) $_POST['statify'][ $option_name ] ) {
223-
$options[ $option_name ] = 1;
224-
} else {
225-
$options[ $option_name ] = 0;
226-
}
224+
// Parse "today" checkbox.
225+
if ( isset( $_POST['statify']['today'] ) && 1 === (int) $_POST['statify']['today'] ) {
226+
$options['today'] = 1;
227+
} else {
228+
$options['today'] = 0;
227229
}
228230

229231
// Update values.

inc/class-statify-frontend.php

+29-5
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,23 @@ private static function _skip_tracking() {
169169
return true;
170170
}
171171

172-
// Skip tracking via Referrer check and Conditional_Tags.
173-
return ( self::check_referrer() || is_trackback() || is_robots() || is_user_logged_in()
174-
|| self::_is_internal()
175-
);
172+
// Skip tracking via Referrer check.
173+
if ( self::check_referrer() ) {
174+
return true;
175+
}
176+
177+
// Skip for trackbacks and robots.
178+
if ( is_trackback() || is_robots() ) {
179+
return true;
180+
}
181+
182+
// Skip logged in users, if enabled.
183+
if ( self::$_options['skip']['logged_in'] && is_user_logged_in() ) {
184+
return true;
185+
}
186+
187+
// Skip for "internal" requests.
188+
return self::_is_internal();
176189
}
177190

178191
/**
@@ -183,7 +196,18 @@ private static function _skip_tracking() {
183196
* @return boolean $skip_hook TRUE if NO tracking is desired
184197
*/
185198
private static function _is_internal() {
186-
return is_feed() || is_preview() || is_404() || is_search();
199+
// Skip for feed access, if enabled.
200+
if ( self::$_options['skip']['feed'] && is_feed() ) {
201+
return true;
202+
}
203+
204+
// Skip for preview and 404 calls.
205+
if ( is_preview() || is_404() ) {
206+
return true;
207+
}
208+
209+
// Skip for seach requests, if enabled.
210+
return self::$_options['skip']['search'] && is_search();
187211
}
188212

189213
/**

0 commit comments

Comments
 (0)