Make WordPress Core

Opened 2 years ago

#56744 new defect (bug)

Inaccuracy in user_can_richedit() function on /wp-includes/general-template.php

Reported by: tassiocoelho's profile tassiocoelho Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 6.0.2
Component: Editor Keywords: needs-patch needs-refresh
Focuses: Cc:

Description

The user_can_richedit function assumes that the Editor can only be displayed for supported browsers, but it only considers known browsers (user-agent). Any others not known will be considered "unsupported" by the Editor. Below is the code snippet that handles this logic:

<?php
$wp_rich_edit = false;

if ( 'true' === get_user_option( 'rich_editing' ) || ! 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 ) && (int) $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;
                }
}

The effect of this logic is that if the user-agent is not known, the Editor will be displayed "broken" in the graphical interface, as shown in the example below:

https://resource.voelivre.com.br/wordpress_editor.jpg

This is because in /wp-includes/class-wp-editor.php the print_default_editor_scripts function checks user_can_richedit to define the $settings variable that is used to load the editor settings according to the code snippet below:

window.wp.editor.getDefaultSettings = function() {
	return {
			tinymce: <?php echo $settings; ?>,
			quicktags: {
					buttons: 'strong,em,link,ul,ol,li,code'
			}
	};
};

This premise, of only considering the Editor compatible with known user-agents, can affect environments such as CloudFront from AWS because by default CloudFront uses the User-Agent "Amazon CloudFront" which is obviously not recognized by the user_can_richedit function and causes the breaking of the Editor without any notice to the user.

I suggest that some message be included in the graphical interface informing that the Editor is not compatible with the specific user-agent, informing its name. Or that some specific message is created for CloudFront, informing about a bad configuration in the AWS environment.

Attachments (1)

wordpress_editor.jpg (185.5 KB) - added by tassiocoelho 2 years ago.

Download all attachments as: .zip

Change History (1)

Note: See TracTickets for help on using tickets.