@@ -953,7 +953,8 @@ function wp_admin_bar_command_palette_menu( WP_Admin_Bar $wp_admin_bar ): void {
953953 'appleOS ' => _x ( '⌘K ' , 'keyboard shortcut to open the command palette ' ),
954954 'default ' => _x ( 'Ctrl+K ' , 'keyboard shortcut to open the command palette ' ),
955955 );
956- $ is_apple_os = (bool ) preg_match ( '/Macintosh|Mac OS X|Mac_PowerPC/i ' , $ _SERVER ['HTTP_USER_AGENT ' ] ?? '' );
956+ $ apple_pattern = 'Macintosh|Mac OS X|Mac_PowerPC ' ;
957+ $ is_apple_os = (bool ) preg_match ( "/ {$ apple_pattern }/i " , $ _SERVER ['HTTP_USER_AGENT ' ] ?? '' );
957958 $ shortcut_label = $ is_apple_os ? $ shortcut_labels ['appleOS ' ] : $ shortcut_labels ['default ' ];
958959 $ title = sprintf (
959960 '<span class="ab-icon" aria-hidden="true"></span><span class="ab-label"><kbd>%s</kbd><span class="screen-reader-text"> %s</span></span> ' ,
@@ -969,15 +970,16 @@ function wp_admin_bar_command_palette_menu( WP_Admin_Bar $wp_admin_bar ): void {
969970 * wp-i18n to be loaded as a dependency.
970971 */
971972 $ function = <<<'JS'
972- ( appleOSLabel ) => {
973- if ( navigator.platform.startsWith("Mac") || navigator.platform === "iPhone" || navigator.platform === "iPad" ) {
973+ ( applePattern, appleOSLabel ) => {
974+ if ( ( new RegExp( applePattern ) ).test( navigator.userAgent ) ) {
974975 document.querySelector( '#wp-admin-bar-command-palette .ab-label kbd' ).textContent = appleOSLabel;
975976 }
976977 }
977978 JS;
978979 $ script = sprintf (
979- '( %s )( %s ); ' ,
980+ '( %s )( %s, %s ); ' ,
980981 $ function ,
982+ wp_json_encode ( $ apple_pattern , JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
981983 wp_json_encode ( $ shortcut_labels ['appleOS ' ], JSON_HEX_TAG | JSON_UNESCAPED_SLASHES )
982984 );
983985 $ script .= "\n//# sourceURL= " . rawurlencode ( __FUNCTION__ );
0 commit comments