Make WordPress Core

Opened 2 months ago

Last modified 2 months ago

#54438 new enhancement

"Required fields are marked" shows up without required fields being present

Reported by: webzunft Owned by:
Milestone: Awaiting Review Priority: normal
Severity: minor Version: 5.8.2
Component: Media Keywords: required-fields needs-patch
Focuses: ui Cc:

Description

A support ticket for my Image Source Control (ISC) plugin made me investigate this.

https://wordpress.org/support/topic/erforderliche-felder-sind-mit-markiert/

Whenever a custom field is added to the attachment edit page, the notice "Required fields are marked" is displayed by WordPress core.

ISC uses the attachment_fields_to_edit filter for that.

I looked into wp-admin/includes/media.php. The code responsible for showing the message is

if ( $item ) {
		$item = '<p class="media-types media-types-required-info">' .
			/* translators: %s: Asterisk symbol (*). */
			sprintf( __( 'Required fields are marked %s' ), '<span class="required">*</span>' ) .
			'</p>' .
			'<table class="compat-attachment-fields">' . $item . '</table>';
	}

The foreach loop that goes through all fields could easily check if any field has the "required" attribute and rather use that as a condition to show the message instead of $item.

Change History (2)

#1 @sabernhardt
2 months ago

  • Component changed from General to Media
  • Keywords required-fields needs-patch added

Thanks for the report!

That code is in the get_compat_media_markup function. The if ( $item ) condition is necessary to determine whether to output the table tag (which lacks role="presentation"), but another condition could be added inside that one for the required field message.

#2 @sabernhardt
2 months ago

And get_media_item probably should have something similar, though that function adds the required field message before the foreach loop.

(wp_media_insert_url_form has the message, too, but that always includes required fields)

Note: See TracTickets for help on using tickets.