Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
41.67% |
5 / 12 |
|
50.00% |
1 / 2 |
CRAP | n/a |
0 / 0 |
|
| Automattic\Jetpack\Search\Compatibility\get_ios_version_from_user_agent | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
| Automattic\Jetpack\Search\Compatibility\enable_classic_search_for_unsupported_browsers | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php // phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase |
| 2 | /** |
| 3 | * Compatibility for browsers that don't support Instant Search. |
| 4 | * |
| 5 | * @package automattic/jetpack-search |
| 6 | */ |
| 7 | namespace Automattic\Jetpack\Search\Compatibility; |
| 8 | |
| 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 10 | exit( 0 ); |
| 11 | } |
| 12 | |
| 13 | add_filter( 'jetpack_search_classic_search_enabled', __NAMESPACE__ . '\enable_classic_search_for_unsupported_browsers', 10, 1 ); |
| 14 | |
| 15 | /** |
| 16 | * Get the iOS version from the user agent. |
| 17 | * |
| 18 | * @param string $user_agent The user agent string. |
| 19 | * @return null|string The iOS version, or null if not found. |
| 20 | */ |
| 21 | function get_ios_version_from_user_agent( $user_agent ) { |
| 22 | preg_match( '#\((iPhone|iPad|iPod).*?OS (\d+_?\d?_?\d?).*?\)#', $user_agent, $matches ); |
| 23 | |
| 24 | if ( empty( $matches[2] ) ) { |
| 25 | return null; |
| 26 | } |
| 27 | |
| 28 | $version = str_replace( '_', '.', $matches[2] ); |
| 29 | return $version; |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Force enable Classic Search for browsers for iOS versions < 16. |
| 34 | * |
| 35 | * @param boolean $classic_search_enabled whether Classic Search is enabled. |
| 36 | */ |
| 37 | function enable_classic_search_for_unsupported_browsers( $classic_search_enabled ) { |
| 38 | $ios_version = get_ios_version_from_user_agent( isset( $_SERVER['HTTP_USER_AGENT'] ) ? filter_var( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ) : '' ); |
| 39 | if ( $ios_version && version_compare( $ios_version, '16.0', '<' ) ) { |
| 40 | return true; |
| 41 | } |
| 42 | return $classic_search_enabled; |
| 43 | } |