Make WordPress Core

Opened 6 years ago

Last modified 35 hours ago

#51190 reviewing defect (bug)

The display of the Media Uploads settings section should be improved

Reported by: imath Owned by: audrasjb
Priority: low Milestone: 7.2
Component: Administration Version: 4.0
Severity: minor Keywords: has-patch has-screenshots
Cc: Focuses:

Description

If a plugin adds new media uploads settings fields when it's not possible to edit the uploads path/url, the table's first row unlike following is displayed in one cell instead of using the full row space. See screenshot below.

https://cldup.com/WoQoROPrzP.png

I believe checking for existing custom media uploads settings should also be checked when choosing whether to use the colspan="2" attribute of the the first cell. See attached patch.

Attachments (6)

51190.diff​ (2.8 KB ) - added by imath 6 years ago.
51190.2.diff​ (931 bytes ) - added by dpknauss 2 months ago.
Closes the conditional above the row and restores the single unconditional cell — the pre-4.8 structure — while keeping the td/td-full markup r40823 was actually trying to fix.
before-uploads-table.png​ (6.7 KB ) - added by dilip2615 8 weeks ago.
after-uploads-table.png​ (6.0 KB ) - added by dilip2615 8 weeks ago.
before-viewport.png​ (61.2 KB ) - added by dilip2615 8 weeks ago.
after-viewport.png​ (60.6 KB ) - added by dilip2615 8 weeks ago.

Download all attachments as: .zip

Change History (16)

#1 @helen
6 years ago

  • Version trunk → 4.0

I'm going to guess this has existed since at least 4.0 if not pre-3.0, just bumping the version back to clear a trunk report.

#2 @dpknauss
2 months ago

This is a 4.8 regression rather than 4.0, if the version field is worth narrowing.

Before [40823] the checkbox row sat outside the conditional and always spanned both columns:

<?php endif; ?>
<tr>
<th scope="row" colspan="2" class="th-full">

[40823] (#37004, HTML validation fixes) moved the row inside the conditional in order to change the th to a td, and carried colspan="2" onto only the editable-paths branch:

<tr>
<td colspan="2" class="td-full">
<?php else : ?>
<tr>
<td class="td-full">
<?php endif; ?>

forms.css still dates it from the other side: .form-table th.th-full, /* Not used by core. Back-compat for pre-4.8 */.

So on the else branch — what a site with default upload paths gets — the cell has no colspan. With no plugin fields the table has one column and the cell fills it, so nothing looks wrong. do_settings_fields( 'media', 'uploads' ) on the next line invites a second column, and once anything takes it, .form-table th { width: 200px } claims the first and the core label wraps, which is the screenshot above.

I measured this on a local install at a 1238px content width, with one plugin field registered in the uploads section:

cell width label height
no plugin fields, no colspan (trunk) 1238px 17px
no plugin fields, colspan="2" 1238px 17px
one plugin field, no colspan (trunk) 210px 55px
one plugin field, colspan="2" 1238px 17px

The first two rows are identical because colspan="2" on a lone cell in a one-column table spans what it already spanned. The branch therefore does not need to know whether fields exist: restoring the unconditional row fixes the reported case and leaves the no-fields case unchanged.

That would make has_settings_fields() unnecessary for this, which seems worth avoiding — a new public function is a larger commitment than the bug needs, and the @since 5.6.0 on the current patch has aged out. Refreshed patch attached: it closes the conditional above the row and restores a single <td colspan="2" class="td-full">, keeping the td/td-full markup [40823] introduced.

@dpknauss
2 months ago

Closes the conditional above the row and restores the single unconditional cell — the pre-4.8 structure — while keeping the td/td-full markup r40823 was actually trying to fix.

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


2 months ago
#3

## Problem

On Settings > Media, "Organize my uploads into month- and year-based folders" wraps onto three lines as soon as any plugin registers a field in the uploads settings section.

## Cause

The row spanned both columns unconditionally until [40823] (#37004, HTML validation fixes) moved it inside the upload-path conditional in order to change its th to a td. That carried colspan="2" onto the editable-paths branch only:

<tr>
<td colspan="2" class="td-full">
<?php else : ?>
<tr>
<td class="td-full">
<?php endif; ?>

The else branch is what a site with default upload paths gets. With no fields registered the table has one column and the cell fills it, so nothing looks wrong. The do_settings_fields( 'media', 'uploads' ) call on the next line invites a second column, and once anything takes it, .form-table th { width: 200px } claims the first and the core label wraps.

forms.css dates the change from the other side: .form-table th.th-full, /* Not used by core. Back-compat for pre-4.8 */.

## Fix

Close the conditional above the row and restore the single unconditional cell, keeping the td/td-full markup [40823] introduced.

Measured at a 1238px content width:

cell width label height
no plugin fields, no colspan (trunk) 1238px 17px
no plugin fields, colspan="2" 1238px 17px
one plugin field, no colspan (trunk) 210px 55px
one plugin field, colspan="2" 1238px 17px

The first two rows are identical because colspan="2" on a lone cell in a one-column table spans what it already spanned, so no check for registered fields is needed and rendering is unchanged for sites without them.

## Testing instructions

  1. Make sure upload_path and upload_url_path are at their defaults, so the paths are locked (the common case).
  2. Visit Settings > Media and confirm the checkbox is on one line.
  3. Drop this in wp-content/mu-plugins/:
<?php
add_action( 'admin_init', function () {
        add_settings_field(
                'demo_field',
                'Demo Field',
                function () {
                        echo '<input type="text" class="regular-text">';
                },
                'media',
                'uploads'
        );
} );
  1. Reload Settings > Media. On trunk the checkbox label wraps onto three lines in a 200px column; with this change it stays on one line and the new field renders below it.

Props imath for the report and diagnosis.

#4 @SergeyBiryukov
2 months ago

  • Milestone Awaiting Review → 7.2

​@dpknauss commented on ​PR #13322:


2 months ago
#5

The props line above credits only me. imath reported this on #51190, worked out the cause, and attached the first patch — this PR takes a different route to the same fix, but the diagnosis is theirs.

For SVN:

Props imath, dpknauss.

#6 @audrasjb
2 months ago

  • Owner set to audrasjb
  • Status new → reviewing

Self assigning for review/tests.

​@dhruvang21 commented on ​PR #13322:


2 months ago
#7

@dknauss tested in WP playground looks good to me
https://github.com/user-attachments/assets/bd8927ce-6172-4d70-adfc-8632bb91ac0b

#8 @dilip2615
8 weeks ago

## Test Report

### Environment

### Reproduction steps

  1. Keep default upload path / URL (locked uploads path UI).
  2. Register a custom settings field on the media / uploads section via a must-use plugin.
  3. Open Settings → Media and inspect the “Organize my uploads into month- and year-based folders” row.

### Results
Before (trunk):

  • The checkbox cell renders as <td class="td-full"> with no colspan.
  • Measured width ~210px inside a ~1078px table, so the row does not span full width when a plugin field is present.

After (PR #13322):

  • The checkbox cell renders as <td colspan="2" class="td-full">.
  • Measured width matches the table width (~1078px).
  • Layout looks correct with the custom uploads field present.

### Conclusion
The issue is reproducible on trunk, and PR #13322 fixes it cleanly.

Screenshots (before/after) attached.

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


35 hours ago

#10 @im3dabasia1
35 hours ago

As per today’s 7.2 bug scrub:

the ​PR is approved and tested. @audrasjb, does it need a second look, or is it ready to go in for 7.2?

Note: See TracTickets for help on using tickets.