[wp-trac] [WordPress Trac] #50483: WYSIWYG editor: Use feature detection instead of User-Agent string
WordPress Trac
noreply at wordpress.org
Fri Jun 26 17:16:06 UTC 2020
#50483: WYSIWYG editor: Use feature detection instead of User-Agent string
-------------------------+-----------------------------
Reporter: mallorydxw | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Editor | Version: 5.4.2
Severity: normal | Keywords:
Focuses: |
-------------------------+-----------------------------
In both Gutenberg and the Classic Editor, the JavaScript for the
WYSIWYG/visual editor is only loaded if `user_can_richedit()` returns
true. This function takes into account a user option, a filter, and the
`User-Agent` string the browser sends:
{{{
function user_can_richedit() {
global $wp_rich_edit, $is_gecko, $is_opera, $is_safari,
$is_chrome, $is_IE, $is_edge;
if ( ! isset( $wp_rich_edit ) ) {
$wp_rich_edit = false;
if ( get_user_option( 'rich_editing' ) == 'true' || !
is_user_logged_in() ) { // Default to 'true' for logged out users.
if ( $is_safari ) {
$wp_rich_edit = ! wp_is_mobile() || (
preg_match( '!AppleWebKit/(\d+)!', $_SERVER['HTTP_USER_AGENT'], $match )
&& intval( $match[1] ) >= 534 );
} elseif ( $is_IE ) {
$wp_rich_edit = ( strpos(
$_SERVER['HTTP_USER_AGENT'], 'Trident/7.0;' ) !== false );
} elseif ( $is_gecko || $is_chrome || $is_edge ||
( $is_opera && ! wp_is_mobile() ) ) {
$wp_rich_edit = true;
}
}
}
/**
* Filters whether the user can access the visual editor.
*
* @since 2.1.0
*
* @param bool $wp_rich_edit Whether the user can access the
visual editor.
*/
return apply_filters( 'user_can_richedit', $wp_rich_edit );
}
}}}
We recently encountered this error when testing a new WordPress hosting
environment which uses CloudFront. CloudFront by default overrides the
`User-Agent` header meaning we found that no users were able to edit posts
except by editing raw HTML.
We were able to resolve this quickly, but I think WordPress should move on
from User-Agent strings and on to using feature detection.
Feature detection is the best practice for this kind of thing. It gives
more accurate results. And if you Google "cloudfront wordpress visual
editor" or "cloudflare wordpress visual editor" you'll see that this is
making WordPress harder to configure for a lot of people.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/50483>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list