[wp-trac] [WordPress Trac] #56744: Inaccuracy in user_can_richedit() function on /wp-includes/general-template.php

WordPress Trac noreply at wordpress.org
Thu Oct 6 03:45:14 UTC 2022


#56744: Inaccuracy in user_can_richedit() function on /wp-includes/general-
template.php
--------------------------+---------------------------------------
 Reporter:  tassiocoelho  |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Editor        |    Version:  6.0.2
 Severity:  normal        |   Keywords:  needs-patch needs-refresh
  Focuses:                |
--------------------------+---------------------------------------
 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
 <?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:

 [[Image("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.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/56744>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list