Make WordPress Core

Opened 3 years ago

Closed 2 years ago

Last modified 2 years ago

#60158 closed defect (bug) (fixed)

The description field for media doesn't automatically make paragraphs in the generated code

Reported by: juliemoynat Owned by: joedolson
Priority: normal Milestone: 6.6
Component: Media Version:
Severity: normal Keywords: has-patch commit
Cc: Focuses: accessibility

Description

There are two ways to edit a media:

  • via a modal window where all the contribution fields are only simple textareas;
  • via a dedicated web page where "alternative text" and "caption" fields are simple textareas and the "description" field is a WYSIWYG editor in text mode where TinyMCE is deactivated.

For some media, you can need to add a long description just like a transcript (for videos, audios, complex images like infographic, etc.).
So, in these cases, the description field can be used because it's totally appropriate.

But, there is a problem: usually, in editor fields, the paragraphs (<p> elements) are automatically added when you display the web page (in the front view). In this field, they are not.

For accessibility reason, paragraphs need to be HTML paragraphs (​WCAG Success Criterion 1.3.1: Info and Relationships (level A)).

I've tried to modify the code in the core to add TinyMCE that is explicitly deactivated and this is fixing the problem.

It's in wp-admin/includes/media.php, on line 3261 where you can just change "false" to "true" for "tinymce":

<?php
$quicktags_settings = array( 'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,close' );
$editor_args        = array(
        'textarea_name' => 'content',
        'textarea_rows' => 5,
        'media_buttons' => false,
        'tinymce'       => false,
        'quicktags'     => $quicktags_settings,
);

So, is it possible to activate TinyMCE for this field? Why is it deactivated?
Or, if it's not possible, is it possible to make this option hookable?

Thank you

Attachments (1)

60158.2.diff​ (678 bytes ) - added by joedolson 2 years ago.
Updated patch

Download all attachments as: .zip

Change History (16)

​@mukesh27 commented on ​PR #5822:


3 years ago
#2

Thanks @sebastienserre for the PR. Left one minor suggestion. Is it possible to add unit test for new filter?

#3 @mukesh27
3 years ago

  • Keywords changes-requested added
  • Version 6.4.2

#4 @sebastienserre
3 years ago

  • Keywords needs-unit-tests needs-testing added

I unfortunately don't know writing test for the moment :(

This ticket was mentioned in ​Slack in #core-test by webtechpooja. ​View the logs.


3 years ago

#6 @juliemoynat
3 years ago

Hi,

Is there any chance that someone who knows how to write unit tests will take over the rest of this small ticket?

Thanks!

#7 @joedolson
3 years ago

  • Owner set to joedolson
  • Status new → accepted

This ticket was mentioned in ​Slack in #accessibility by joedolson. ​View the logs.


3 years ago

#9 @joedolson
3 years ago

  • Milestone Awaiting Review → 6.6

This looks good. Since it's just adding a filter, and not actually changing the default behavior, it's pretty safe. I do think that it's not an option to just change the default, since it's very hard to know how the image description has been used on the front-end by existing tools.

Milestoning for 6.6.

This ticket was mentioned in ​Slack in #core-media by antpb. ​View the logs.


2 years ago

#11 @hmbashar
2 years ago

  • Keywords needs-testing-info added

#12 @joedolson
2 years ago

  • Keywords commit added; changes-requested needs-unit-tests needs-testing needs-testing-info removed

I think that this patch is OK; I'm not convinced it needs unit tests, or what those unit tests would actually be testing. There should be no change in what HTML the field accepts or outputs, just a change in the editor output.

I've modified the patch slightly to clarify the comment, update the version, and clearly state that this only enables TinyMCE in the attachment editing screen; the media modal would be a much bigger change, and probably not worth the effort.

I also want to observe that there are other solutions to getting automatic paragraphs in the description field, such as running wpautop on the output of the field when it's rendered; and the description field accepts HTML, so they can also be written directly into the text field.

@joedolson
2 years ago

Updated patch

#13 @joedolson
2 years ago

The only testing to do is to add a filter to enable the TinyMCE editor in the description field and verify that it is active on the attachment details screen; I've verified this.

#14 @joedolson
2 years ago

  • Resolution → fixed
  • Status accepted → closed

In 58372:

Media: Accessibility: Add filter for TinyMCE in media descriptions.

Add a filter to enable TinyMCE in the media description textarea on the attachment details screen.

The media description field may be used to provide extended descriptions of images and videos, such as a transcript or detailed graphic explanations. In these uses, it will generally require structural elements like paragraphs. Having the ability to enable TinyMCE makes it easier for users to add this content without HTML knowledge.

Props juliemoynat, sebastienserre, mukesh27, joedolson.
Fixes #60158.

#15 @SergeyBiryukov
2 years ago

In 58373:

Docs: Correct DocBlock formatting for activate_tinymce_for_media_description.

Follow-up to [58372].

See #60158.

Note: See TracTickets for help on using tickets.