-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Search: use classic search for ios<16 devices (#33929)
Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/6846181431
- Loading branch information
Showing
7 changed files
with
132 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
jetpack_vendor/automattic/jetpack-search/compatibility/unsupported-browsers.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php // phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase | ||
/** | ||
* Compatibility for browsers that don't support Instant Search. | ||
* | ||
* @package automattic/jetpack-search | ||
*/ | ||
namespace Automattic\Jetpack\Search\Compatibility; | ||
|
||
add_filter( 'jetpack_search_classic_search_enabled', __NAMESPACE__ . '\enable_classic_search_for_unsupported_browsers', 10, 1 ); | ||
|
||
/** | ||
* Get the iOS version from the user agent. | ||
* | ||
* @param string $user_agent The user agent string. | ||
* @return null|string The iOS version, or null if not found. | ||
*/ | ||
function get_ios_version_from_user_agent( $user_agent ) { | ||
preg_match( '#\((iPhone|iPad|iPod).*?OS (\d+_?\d?_?\d?).*?\)#', $user_agent, $matches ); | ||
|
||
if ( empty( $matches[2] ) ) { | ||
return null; | ||
} | ||
|
||
$version = str_replace( '_', '.', $matches[2] ); | ||
return $version; | ||
} | ||
|
||
/** | ||
* Force enable Classic Search for browsers for iOS versions < 16. | ||
* | ||
* @param boolean $classic_search_enabled whether Classic Search is enabled. | ||
*/ | ||
function enable_classic_search_for_unsupported_browsers( $classic_search_enabled ) { | ||
$ios_version = get_ios_version_from_user_agent( isset( $_SERVER['HTTP_USER_AGENT'] ) ? filter_var( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ) : '' ); | ||
if ( $ios_version && version_compare( $ios_version, '16.0', '<' ) ) { | ||
return true; | ||
} | ||
return $classic_search_enabled; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.