[wp-trac] [WordPress Trac] #62361: Set filter "activate_tinymce_for_media_description" to "true" is breaking meadia_descripton by running it through "htmlspecialchars()"

WordPress Trac noreply at wordpress.org
Fri Nov 8 10:55:36 UTC 2024


#62361: Set filter "activate_tinymce_for_media_description" to "true"  is breaking
meadia_descripton by running it through "htmlspecialchars()"
-------------------------------+-----------------------------
 Reporter:  dagobert24         |      Owner:  (none)
     Type:  defect (bug)       |     Status:  new
 Priority:  normal             |  Milestone:  Awaiting Review
Component:  Media              |    Version:  6.6.2
 Severity:  normal             |   Keywords:
  Focuses:  ui, accessibility  |
-------------------------------+-----------------------------
 Adding filter {{{ activate_tinymce_for_media_description }}} was great but
 it creates an issue.

 == Bug

 When activating it [https://core.trac.wordpress.org/browser/tags/6.6.2/src
 /wp-admin/includes/media.php#L3277 see here]

 {{{#!php
 <?php
         $editor_args        = array(
                 'textarea_name' => 'content',
                 'textarea_rows' => 5,
                 'media_buttons' => false,
                 /**
                  * Filters the TinyMCE argument for the media description
 field on the attachment details screen.
                  *
                  * @since 6.6.0
                  *
                  * @param bool $tinymce Whether to activate TinyMCE in
 media description field. Default false.
                  */
                 'tinymce'       => apply_filters(
 'activate_tinymce_for_media_description', false ),
                 'quicktags'     => $quicktags_settings,
         );

 }}}

 The textarea will be
 [https://core.trac.wordpress.org/browser/tags/6.6.2/src/wp-
 admin/includes/media.php#L3292 processed]


 {{{#!php
 <?php
         <?php wp_editor( format_to_edit( $post->post_content ),
 'attachment_content', $editor_args ); ?>
 }}}

 The function {{{format_to_edit()}}}
 [https://core.trac.wordpress.org/browser/tags/6.6.2/src/wp-
 admin/includes/media.php#L2738 here] will than execute
 {{{esc_textarea()}}}
 [https://core.trac.wordpress.org/browser/tags/6.6.2/src/wp-
 admin/includes/media.php#L4704 here] and "convert" all HTML tags using
 {{{htmlspecialchars()}}}.


 == Solution

 The reason why the HTML tags are convertred is that the parameter
 {{{$rich_text}}} for {{{format_to_edit()}}} is not set to {{{true}}}.
 Since {{{$editor_args['tinymce'] = true;}}} and {{{format_to_edit()}}}
 parameter {{{$rich_text}}} is directly dependend it is simple to correct
 by changing line [https://core.trac.wordpress.org/browser/tags/6.6.2/src
 /wp-admin/includes/media.php#L3292 3292] from

 {{{#!php
 <?php
         <?php wp_editor( format_to_edit( $post->post_content ),
 'attachment_content', $editor_args ); ?>
 }}}

 to

 {{{#!php
 <?php
         <?php wp_editor( format_to_edit( $post->post_content,
 $editor_args['tinymce'] ), 'attachment_content', $editor_args ); ?>
 }}}


 == Additional comment

 If someone wants to use tinymce to edit textareas one surely wants to add
 more than just a few words but rich content such as within a normal post.
 Hence I propose to change the value

 {{{$editor_args['textare_rows'] = 5; }}}

 to

 {{{$editor_args['textare_rows'] = 20; }}}

 This will give the user a nice-sized textarea to enter rich content
 without having to resize it every time.

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


More information about the wp-trac mailing list