Skip to content

Commit c5c21ba

Browse files
authored
Replaced bot detection with JayBizzle/Crawler-Detect
1 parent 84d107e commit c5c21ba

File tree

5 files changed

+13
-30
lines changed

5 files changed

+13
-30
lines changed

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
"statistics"
1010
],
1111
"require": {
12-
"php": "^5.2|^7|^8",
12+
"php": "^5.3|^7|^8",
1313
"npm-asset/chartist": "^1.3.0",
14-
"npm-asset/chartist-plugin-tooltips-updated": "^1.0.0"
14+
"npm-asset/chartist-plugin-tooltips-updated": "^1.0.0",
15+
"jaybizzle/crawler-detect": "^1.2"
1516
},
1617
"require-dev": {
1718
"dealerdirect/phpcodesniffer-composer-installer": "^0.7",

inc/class-statify-frontend.php

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ private static function _skip_tracking() {
184184
$user_agent = sanitize_text_field( isset( $_SERVER['HTTP_USER_AGENT'] ) ? wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) : '' );
185185
if ( is_null( $user_agent )
186186
|| false === $user_agent
187-
|| self::is_bot( $user_agent ) ) {
187+
|| self::is_bot() ) {
188188
return true;
189189
}
190190

@@ -212,33 +212,13 @@ private static function _skip_tracking() {
212212
*
213213
* @since 1.7.0
214214
*
215-
* @param string $user_agent Server user agent string.
216-
*
217-
* @return boolean $is_bot TRUE if user agent is a bot, FALSE if not.
215+
* @return boolean $is_bot true if user agent is a bot, false if not.
218216
*/
219-
private static function is_bot( $user_agent ) {
220-
$user_agent = strtolower( $user_agent );
221-
222-
$identifiers = array(
223-
'bot',
224-
'slurp',
225-
'crawler',
226-
'spider',
227-
'curl',
228-
'facebook',
229-
'fetch',
230-
'python',
231-
'wget',
232-
'monitor',
233-
);
217+
private static function is_bot() {
218+
$crawler_detect = new \Jaybizzle\CrawlerDetect\CrawlerDetect();
234219

235-
foreach ( $identifiers as $identifier ) {
236-
if ( strpos( $user_agent, $identifier ) !== false ) {
237-
return true;
238-
}
239-
}
240-
241-
return false;
220+
// Check the user agent of the current 'visitor' via the user agent and http_from header.
221+
return $crawler_detect->isCrawler();
242222
}
243223

244224
/**

phpcs.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@
3636
</rule>
3737

3838
<!-- Include sniffs for PHP cross-version compatibility. -->
39-
<config name="testVersion" value="5.2-"/>
39+
<config name="testVersion" value="5.3-"/>
4040
<rule ref="PHPCompatibilityWP"/>
4141
</ruleset>

readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Tags: analytics, dashboard, pageviews, privacy, statistics, stats, visits, web stats, widget
55
* Requires at least: 4.7
66
* Tested up to: 6.1
7-
* Requires PHP: 5.2
7+
* Requires PHP: 5.3
88
* Stable tag: 1.8.4
99
* License: GPLv3 or later
1010
* License URI: https://www.gnu.org/licenses/gpl-3.0.html

statify.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
)
5454
);
5555

56+
/* Composer Autoload */
57+
require __DIR__ . '/vendor/autoload.php';
5658

5759
/* Autoload */
5860
spl_autoload_register( 'statify_autoload' );

0 commit comments

Comments
 (0)