Make WordPress Core

Opened 3 years ago

Closed 2 years ago

#54965 closed defect (bug) (invalid)

Custom post type set as not public breaks media uploader functionality

Reported by: catacaustic's profile catacaustic Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.9
Component: Media Keywords: reporter-feedback
Focuses: Cc:

Description

In 5.9 having a custom post type that is not public disables the media uploader option to select media files for 'Uploaded to this post' and does not attach any uploaded media files to that post.

Setting the values for either 'public' or 'publicly_queryable' to false when using register_post_type() causes this problem. If the values are set to true then the media uploader works as expected.

Change History (5)

#1 @costdev
3 years ago

  • Keywords reporter-feedback added

Test Report

Environment

  • WordPress: 5.9 and 6.0-alpha-52448-src
  • Browser: Chrome 97.0.4692.71
  • OS: Windows 10
  • Editor: Block Editor
  • Theme(s): Twenty Twenty-One and Twenty Twenty-Two
  • Plugin(s): None activated

Steps to reproduce

  1. Add a new post type using:
<?php

add_action(
        'init',
        function() {
                register_post_type(
                        'my_cpt',
                        array(
                                'labels'       => array( 'name' => 'My CPT' ),
                                'public'       => false,
                                'show_ui'      => true,
                                'show_in_rest' => true
                        )
                );
        },
        999
);
  1. Open the dashboard and navigate to My CPT > Add New.
  2. Insert a Gallery block.
  3. Click Upload and proceed to upload an image.
  4. Click Media Library.
  5. Under Filter Media, select Uploaded to this post.
  6. The image you uploaded should be displayed.
  7. Click Publish, then Publish.
  8. Navigate to Media > Library.
  9. Click the list view icon (the first one).
  10. In the Uploaded to column for the image you uploaded, it should say (Private post) with a Detach link underneath.

Results

  • Uploaded image is displayed under Uploaded to this post. ✅
  • Uploaded to column for the uploaded image says (Private post). ✅
  • Cannot reproduce. ❌

Hi @catacaustic, welcome to Trac!

I was unable to reproduce this issue. Can you let us know if any of the steps above are incorrect, or if there are any missing steps?

#2 @catacaustic
3 years ago

The only difference that I have here is that 'show_in_rest' is false.

<?php
$labels = array (
        'name' => __ ('Content'),
        'singular_name' => __ ('Block'),
        'add_new' => __ ('Add New', 'empire'),
        'add_new_item' => __ ('Add New Block'),
        'edit_item' => __ ('Edit Bock'),
        'new_item' => __ ('New Block'),
        'view_item' => __ ('View Block'),
        'search_items' => __ ('Search Blocks'),
        'not_found' =>  __ ('Nothing found'),
        'not_found_in_trash' => __ ('Nothing found in Trash'),
        'parent_item_colon' => ''
);

$args = array (
        'labels' => $labels,
        'public' => false,
        'publicly_queryable' => false,
        'show_ui' => true,
        'query_var' => false,
        'show_in_rest' => true,
        'rewrite' => false,
        'capability_type' => 'post',
        'hierarchical' => false,
        'has_archive' => false,
        'menu_position' => null,
        'supports' => array (
                'title',
                'editor',
                'page-attributes'
        )
);
                        
register_post_type ('customblock', $args);

#3 @costdev
3 years ago

Thanks for the quick response @catacaustic!

I still can't seem to reproduce the issue after copying the snippet you posted. I also noted that your comment had show_in_rest set to true. I tested your snippet with both true and false for show_in_rest. Both times, the Uploaded to this post option showed the images I uploaded.

A couple of additional questions:

  1. What theme are you using?
  2. What plugins are installed and activated?

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


2 years ago

#5 @antpb
2 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

As this has not received feedback and there was difficulty in reproducing this issue I'm going to close it. Feel free to reopen if invalid.

Note: See TracTickets for help on using tickets.