Make WordPress Core

Opened 5 years ago

Last modified 3 months ago

#54438 new enhancement

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

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

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 (6)

#1 @sabernhardt
5 years ago

  • Component General → 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
5 years 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)

#3 @archon810
3 years ago

Any updates on resolving this one please? Just ran into the same issue and found this ticket.

This ticket was mentioned in ​Slack in #core by svunz. ​View the logs.


3 years ago

This ticket was mentioned in ​PR #12536 on ​WordPress/wordpress-develop by ​@arkaprabhachowdhury.


4 months ago
#5

  • Keywords has-patch has-unit-tests added; needs-patch removed

## Trac ticket

https://core.trac.wordpress.org/ticket/54438

## Description

Only displays the required fields message in the legacy media attachment forms when at least one visible rendered field is required.

This updates both get_media_item() and get_compat_media_markup(), and adds regression tests for forms with and without required fields.

## Testing

  • PHPCS passes for the changed files with warnings disabled; the full source file has three unrelated pre-existing warnings.
  • PHP syntax checks pass.
  • Focused PHPUnit could not complete locally because Docker Desktop's Linux engine stopped after the MySQL container startup. CI is expected to provide the authoritative PHPUnit result.

#6 @arkaprabhachowdhury
3 months ago

Opened [PR #12536](​https://github.com/WordPress/wordpress-develop/pull/12536) to address this ticket. It displays the required-fields message in legacy media attachment forms only when a visible rendered field is required, updating both relevant markup paths and adding regression coverage.

I picked this up because the ticket describes a user-facing form-message condition that remains relevant in current WordPress. The change is scoped to the ticket and submitted here for code review.

Last edited 3 months ago by arkaprabhachowdhury (previous) (diff)
Note: See TracTickets for help on using tickets.