This commit is contained in:
2026-07-02 15:54:39 -06:00
commit 9883323161
17470 changed files with 4470592 additions and 0 deletions
@@ -0,0 +1,32 @@
<?php
/**
* Jetpack compatibility
*
* @package automattic/jetpack-search
*/
namespace Automattic\Jetpack\Search\Compatibility\Jetpack;
use Jetpack;
if ( ! defined( 'ABSPATH' ) ) {
exit( 0 );
}
/**
* Override the condition to show Search submenu when Jetpack plugin exists.
*/
function should_show_jetpack_search_submenu() {
if ( ! current_user_can( 'manage_options' ) ) {
return false;
}
// If site is in Offline Mode or not connected yet.
if ( ! Jetpack::is_active_and_not_offline_mode() ) {
return false;
}
return true;
}
add_filter( 'jetpack_search_should_add_search_submenu', __NAMESPACE__ . '\should_show_jetpack_search_submenu' );
@@ -0,0 +1,30 @@
<?php // phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase
/**
* Compatibility for Jetpack Search version <= 0.15.2.
*
* @package automattic/jetpack-search
*/
namespace Automattic\Jetpack\Search\Compatibility\Jetpack;
use Automattic\Jetpack\Search\Instant_Search;
if ( ! defined( 'ABSPATH' ) ) {
exit( 0 );
}
add_filter( 'option_sidebars_widgets', __NAMESPACE__ . '\convert_old_jetpack_search_sidebar', 10, 2 );
/**
* Map the old Jetpack Search sidebar to the new Instant Search sidebar.
*
* @param array $sidebars_widgets Value of `sidebars_widgets` option.
*/
function convert_old_jetpack_search_sidebar( $sidebars_widgets ) {
if ( ! empty( $sidebars_widgets[ Instant_Search::INSTANT_SEARCH_SIDEBAR ] ) || empty( $sidebars_widgets[ Instant_Search::OLD_INSTANT_SEARCH_SIDEBAR ] ) ) {
return $sidebars_widgets;
}
$sidebars_widgets[ Instant_Search::INSTANT_SEARCH_SIDEBAR ] = $sidebars_widgets[ Instant_Search::OLD_INSTANT_SEARCH_SIDEBAR ];
unset( $sidebars_widgets[ Instant_Search::OLD_INSTANT_SEARCH_SIDEBAR ] );
return $sidebars_widgets;
}
@@ -0,0 +1,23 @@
<?php // phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase
/**
* Compatibility for Jetpack Search version <= 0.17.0.
*
* @package automattic/jetpack-search
*/
namespace Automattic\Jetpack\Search\Compatibility\Jetpack;
if ( ! defined( 'ABSPATH' ) ) {
exit( 0 );
}
add_filter( 'option_jetpack_search_overlay_trigger', __NAMESPACE__ . '\map_results_overlay_trigger', 10, 2 );
/**
* We've retired the 'results' overlay trigger and want to migrate users to the similar 'immediate' setting.
*
* @param string $overlay_trigger Overlay trigger.
*/
function map_results_overlay_trigger( $overlay_trigger ) {
return 'results' === $overlay_trigger ? \Automattic\Jetpack\Search\Options::OVERLAY_TRIGGER_IMMEDIATE : $overlay_trigger;
}
@@ -0,0 +1,43 @@
<?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;
if ( ! defined( 'ABSPATH' ) ) {
exit( 0 );
}
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;
}