obile reader on iOS has an incorrect UA when loading the reader // currently it is the default one provided by the iOS framework which // causes problems with 2-step-auth // User-Agent WordPress/3.1.4 CFNetwork/609 Darwin/13.0.0. $app_agents[] = 'wordpress/3.1'; foreach ( $app_agents as $app_agent ) { if ( false !== strpos( $agent, $app_agent ) ) { return true; } } return false; } /** * Detects if the current browser is Nintendo 3DS handheld. * * Example: Mozilla/5.0 (Nintendo 3DS; U; ; en) Version/1.7498.US * can differ in language, version and region */ public static function is_Nintendo_3DS() { if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { return false; } $ua = strtolower( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- This is validating. if ( strpos( $ua, 'nintendo 3ds' ) !== false ) { return true; } return false; } /** * Was the current request made by a known bot? * * @return boolean */ public static function is_bot() { static $is_bot = null; if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { return false; } if ( $is_bot === null ) { $is_bot = self::is_bot_user_agent( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- This is validating. } return $is_bot; } /** * Is the given user-agent a known bot? * If you want an is_bot check for the current request's UA, use is_bot() instead of passing a user-agent to this method. * * @param string $ua A user-agent string. * * @return boolean */ public static function is_bot_user_agent( $ua = null ) { if ( empty( $ua ) ) { return false; } $bot_agents = array( 'alexa', 'altavista', 'ask jeeves', 'attentio', 'baiduspider', 'bingbot', 'chtml generic', 'crawler', 'fastmobilecrawl', 'feedfetcher-google', 'firefly', 'froogle', 'gigabot', 'googlebot', 'googlebot-mobile', 'heritrix', 'httrack', 'ia_archiver', 'irlbot', 'iescholar', 'infoseek', 'jumpbot', 'linkcheck', 'lycos', 'mediapartners', 'mediobot', 'motionbot', 'msnbot', 'mshots', 'openbot', 'pss-webkit-request', 'pythumbnail', 'scooter', 'slurp', 'snapbot', 'spider', 'taptubot', 'technoratisnoop', 'teoma', 'twiceler', 'yahooseeker', 'yahooysmcm', 'yammybot', 'ahrefsbot', 'pingdom.com_bot', 'kraken', 'yandexbot', 'twitterbot', 'tweetmemebot', 'openhosebot', 'queryseekerspider', 'linkdexbot', 'grokkit-crawler', 'livelapbot', 'germcrawler', 'domaintunocrawler', 'grapeshotcrawler', 'cloudflare-alwaysonline', 'cookieinformationscanner', // p1699315886066389-slack-C0438NHCLSY 'facebookexternalhit', // https://www.facebook.com/externalhit_uatext.php ); foreach ( $bot_agents as $bot_agent ) { if ( false !== stripos( $ua, $bot_agent ) ) { return true; } } return false; } }