Opened 4 years ago
Last modified 4 years ago
#52397 new enhancement
The function wp_is_mobile should accept also lower case strings as user agents
Reported by: | giuse | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | low |
Severity: | normal | Version: | 3.4 |
Component: | General | Keywords: | reporter-feedback |
Focuses: | Cc: |
Description
The actual version of the function wp_is_mobile is case sensitive and detects a mobile device only if the first letter of the User Agent is capital.
https://developer.wordpress.org/reference/functions/wp_is_mobile/
For example, I would replace
strpos( $_SERVER['HTTP_USER_AGENT'], 'Mobile' ) !== false
with
strpos( strtolower( $_SERVER['HTTP_USER_AGENT'] ),'mobile' ) !== false
The same for the other User Agents.
Change History (4)
#2
@
4 years ago
- Keywords reporter-feedback added
- Priority changed from normal to low
Which user agents does this affect?
#3
@
4 years ago
I've opened this thread because W3 Total Cache was giving a problem with my plugin that uses this function.
If you save the option related to the User Agent of W3 Total Cache, it saves "mobile" instead of "Mobile". I know this is something that W3 Total Cache should solve, but what's the problem in adding a strtolower? The performance would be the same, and you would prevent issues with other plugins. Moreover, you never know if a certain browser uses "mobile" instead of "Mobile". This function would be more robust and prevent issues if it wasn't case sensitive.
I think it would be faster and easier adding strtolower than going ahead commenting on this function, we are not speaking about something that is a risk for performance or security. If you don't add strtolower I will replace this function with another one in my plugin, so if you don't want to add strtolower, I suggest closing this thread.
Consider that also other plugins may replace this function, this would be not good for the WP ecosystem if the reason is only a missing strtolower.
(I updated the version because the function has been around since WordPress 3.4 - changeset:20417)
Could the
stripos
function be appropriate and/or better here?