Make WordPress Core

Opened 3 months ago

Last modified 6 weeks ago

#59308 new defect (bug)

Attachment custom fields not rendered in some cases

Reported by: sebsz's profile SeBsZ Owned by:
Milestone: 6.5 Priority: normal
Severity: normal Version: 6.3.1
Component: Media Keywords:
Focuses: javascript Cc:

Description

This is a follow-up to #58051.

I've noticed that in some cases custom fields added via attachment_fields_to_edit do not show up when the "Featured Image" modal is opened after clicking a "featured image". I then need to first click on another attachment and then back to have the custom fields show up.

It seems that this bug only happens when you have a lot of images (more than 1 page) and the featured image you're looking at is not on the first page. It's easy to reproduce.

If absolutely necessary I can set up a clean WordPress and make a screen recording of this bug, as I rather not share the images and data in our WordPress installation.

Change History (7)

#1 @archon810
3 months ago

This is quite an annoying bug that is probably easy to fix because it's just a corner case of something that already works correctly.

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


2 months ago

#3 @SeBsZ
8 weeks ago

@antpb I managed to make a video for you which you requested. I'm running the latest nightly version of WordPress, which you can see in the video. It's a clean install. I activated the Twenty Twenty-Two theme and uploaded about 150 stock images to the media library. I then set one of the images to be the featured image for the default Hello World post. I picked the last image in the media library (not on the first page).

I added very little custom code to the theme's function.php, which I pasted below. Notably I had to disable the block editor since we don't use it. Interestingly, with the block editor enabled the bug does NOT occur!

add_filter('use_block_editor_for_post', '__return_false');

/**
 * Add some custom fields to attachment edit page.
 */
\add_filter(
    'attachment_fields_to_edit',

    function ($form_fields, $post) {
        $form_fields['extra_field'] = array(
            'label' => 'Extra field',
            'input' => 'html',
            'html'  => '<input type="text" class="text" readonly="readonly" value="' . \esc_attr(\get_the_title($post->ID)) . '" />',
        );

        return $form_fields;
    },
    10,
    2
);

Video showing bug without block editor: https://1drv.ms/v/s!AtabcxrS-Zu3l64cKFmTKdp5ikwqqg?e=r8xK6u
Video showing no bug with block editor: https://1drv.ms/v/s!AtabcxrS-Zu3l64j3UQFux6yceADfQ?e=REOcnC

Please let me know if more information is needed!

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


8 weeks ago

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


8 weeks ago

#6 @SeBsZ
6 weeks ago

Any update here?

#7 @antpb
6 weeks ago

  • Milestone changed from Awaiting Review to 6.5

No update as I have not had time to investigate further. Moving to the 6.5 milestone for investigation during the next release cycle.

Note: See TracTickets for help on using tickets.