Skip to content

Commit 04c708a

Browse files
kraftbjmatticbot
authored andcommitted
WPSC: Remove outside dependency device detection (#45879)
Co-authored-by: tbradsha <[email protected]> Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/19373262776 Upstream-Ref: Automattic/jetpack@3af959f
1 parent c696ec0 commit 04c708a

23 files changed

+120
-1303
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [3.0.4-alpha] - unreleased
9+
10+
This is an alpha version! The changes listed here are not final.
11+
12+
### Changed
13+
- Device Detection: use an embedded version instead of the Composer dependency
14+
815
## [3.0.3] - 2025-11-11
916
### Added
1017
- Tested up to WordPress 6.9. [#45571]
@@ -831,6 +838,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
831838

832839
Misc fixes
833840

841+
[3.0.4-alpha]: https://github.com/Automattic/wp-super-cache/compare/v3.0.3...v3.0.4-alpha
834842
[3.0.3]: https://github.com/Automattic/wp-super-cache/compare/v3.0.2...v3.0.3
835843
[3.0.2]: https://github.com/Automattic/wp-super-cache/compare/v3.0.1...v3.0.2
836844
[3.0.1]: https://github.com/Automattic/wp-super-cache/compare/v3.0.0...v3.0.1

composer.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
"description": "A very fast caching engine for WordPress that produces static html files.",
44
"type": "wordpress-plugin",
55
"license": "GPL-2.0-or-later",
6-
"require": {
7-
"automattic/jetpack-device-detection": "^3.3.0"
8-
},
96
"require-dev": {
107
"yoast/phpunit-polyfills": "^4.0.0",
118
"automattic/jetpack-changelogger": "^6.0.9",
@@ -46,6 +43,6 @@
4643
"wp-svn-autopublish": true
4744
},
4845
"config": {
49-
"autoloader-suffix": "6fe342bc02f0b440f7b3c8d8ade42286_super_cacheⓥ3_0_3"
46+
"autoloader-suffix": "6fe342bc02f0b440f7b3c8d8ade42286_super_cacheⓥ3_0_4_alpha"
5047
}
5148
}

composer.lock

Lines changed: 4 additions & 60 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@automattic/jetpack-super-cache",
3-
"version": "3.0.3",
3+
"version": "3.0.4-alpha",
44
"private": true,
55
"description": "A very fast caching engine for WordPress that produces static html files.",
66
"homepage": "https://jetpack.com",

plugins/jetpack.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
<?php
22

3-
if ( ! class_exists( 'Automattic\Jetpack\Device_Detection' ) ) {
4-
// Manually load Device_Detection before autoload is initialized.
5-
if ( defined( 'WPCACHEHOME' ) ) {
6-
if ( file_exists( WPCACHEHOME . '/vendor/automattic/jetpack-device-detection/src/class-device-detection.php' ) ) {
7-
require_once WPCACHEHOME . '/vendor/automattic/jetpack-device-detection/src/class-device-detection.php';
8-
}
3+
if ( defined( 'WPCACHEHOME' ) ) {
4+
if ( file_exists( WPCACHEHOME . '/src/device-detection/class-device-detection.php' ) ) {
5+
require_once WPCACHEHOME . '/src/device-detection/class-device-detection.php';
96
}
107
}
118

@@ -69,11 +66,11 @@ function wp_super_cache_jetpack_cookie_check( $cache_key ) {
6966
}
7067
}
7168

72-
if ( ! class_exists( 'Automattic\Jetpack\Device_Detection' ) ) {
69+
if ( ! class_exists( 'Automattic\WPSC\Device_Detection' ) ) {
7370
return 'normal';
7471
}
7572

76-
if ( \Automattic\Jetpack\Device_Detection::is_phone() ) {
73+
if ( \Automattic\WPSC\Device_Detection::is_phone() ) {
7774
return 'mobile';
7875
} else {
7976
return 'normal';
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
/**
3+
* Device detection for Jetpack.
4+
*
5+
* Since WPSC doesn't use an autoloader or composer, this is a simplified version of the package
6+
* as of November 11, 2025.
7+
*
8+
* @package automattic/jetpack-device-detection
9+
*/
10+
11+
namespace Automattic\WPSC;
12+
13+
require_once __DIR__ . '/functions.php';
14+
require_once __DIR__ . '/class-user-agent-info.php';
15+
16+
use Automattic\WPSC\Device_Detection\User_Agent_Info;
17+
use function Automattic\WPSC\Device_Detection\wp_unslash;
18+
19+
/**
20+
* Class Automattic\WPSC\Device_Detection
21+
*
22+
* Determine if the current User Agent matches the passed $kind.
23+
*
24+
* Note: str_contains() and other PHP8+ functions that have a polyfill in core are not used here,
25+
* as wp-includes/compat.php may not be loaded yet.
26+
*/
27+
class Device_Detection {
28+
29+
/**
30+
* Detects phone devices.
31+
*
32+
* @return bool
33+
*/
34+
public static function is_phone() {
35+
if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
36+
return false;
37+
}
38+
39+
$ua_info = new User_Agent_Info( $_SERVER['HTTP_USER_AGENT'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Handled in User_Agent_Info
40+
41+
$agent = strtolower( filter_var( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ) );
42+
if ( strpos( $agent, 'ipad' ) ) {
43+
return false;
44+
}
45+
46+
// Remove Samsung Galaxy tablets (SCH-I800) from being mobile devices.
47+
if ( strpos( $agent, 'sch-i800' ) ) {
48+
return false;
49+
}
50+
51+
if ( $ua_info->is_android_tablet() && false === $ua_info->is_kindle_touch() ) {
52+
return false;
53+
}
54+
55+
if ( $ua_info->is_blackberry_tablet() ) {
56+
return false;
57+
}
58+
59+
// checks for iPhoneTier devices & RichCSS devices.
60+
if ( $ua_info->isTierIphone() || $ua_info->isTierRichCSS() ) {
61+
return true;
62+
}
63+
64+
$dumb_agents = $ua_info->dumb_agents;
65+
66+
foreach ( $dumb_agents as $dumb_agent ) {
67+
if ( false !== strpos( $agent, $dumb_agent ) ) {
68+
return true;
69+
}
70+
}
71+
72+
if ( isset( $_SERVER['HTTP_X_WAP_PROFILE'] ) ) {
73+
return true;
74+
} elseif ( isset( $_SERVER['HTTP_ACCEPT'] ) && ( preg_match( '/wap\.|\.wap/i', $_SERVER['HTTP_ACCEPT'] ) || false !== strpos( strtolower( $_SERVER['HTTP_ACCEPT'] ), 'application/vnd.wap.xhtml+xml' ) ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- This is doing the validating.
75+
return true;
76+
}
77+
78+
return false;
79+
}
80+
}

vendor/automattic/jetpack-device-detection/src/class-user-agent-info.php renamed to src/device-detection/class-user-agent-info.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
/**
33
* User agent detection for Jetpack.
44
*
5+
* Since WPSC doesn't use an autoloader or composer, this is a simple copy/paste of the package
6+
* as of November 11, 2025.
7+
*
58
* @package automattic/jetpack-device-detection
69
*
710
* We don't want to rename public members.
@@ -12,7 +15,7 @@
1215
* @phpcs:disable WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid
1316
*/
1417

15-
namespace Automattic\Jetpack\Device_Detection;
18+
namespace Automattic\WPSC\Device_Detection;
1619

1720
require_once __DIR__ . '/functions.php';
1821

vendor/automattic/jetpack-device-detection/src/functions.php renamed to src/device-detection/functions.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
/**
33
* Utility functions for device detection.
44
*
5+
* Since WPSC doesn't use an autoloader or composer, this is a simple copy/paste of the package
6+
* as of November 11, 2025.
7+
*
58
* @package automattic/jetpack-device-detection
69
*/
710

8-
namespace Automattic\Jetpack\Device_Detection;
11+
namespace Automattic\WPSC\Device_Detection;
912

1013
// Check if the function is already defined, in case someone bypassed the autoloader or something
1114
// to get the two classes from different copies of the package.

src/example.php

Lines changed: 0 additions & 8 deletions
This file was deleted.

vendor/autoload.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919

2020
require_once __DIR__ . '/composer/autoload_real.php';
2121

22-
return ComposerAutoloaderInit6fe342bc02f0b440f7b3c8d8ade42286_super_cacheⓥ3_0_3::getLoader();
22+
return ComposerAutoloaderInit6fe342bc02f0b440f7b3c8d8ade42286_super_cacheⓥ3_0_4_alpha::getLoader();

0 commit comments

Comments
 (0)