Make WordPress Core

Opened 7 years ago

Closed 6 years ago

Last modified 6 years ago

#47574 closed defect (bug) (fixed)

Public custom post status cannot be embedded

Reported by: goaroundagain Owned by: SergeyBiryukov
Priority: normal Milestone: 5.7
Component: Embeds Version: 5.2.2
Severity: normal Keywords: has-unit-tests has-patch has-dev-note
Cc: Focuses:

Description

Currently it is not possible to embend any post with a custom post status, even when the custom post status is set to

'public' => true

From register_post_status: ​https://codex.wordpress.org/Function_Reference/register_post_status
public: (bool) (optional) Whether posts of this status should be shown in the front end of the site.

For this reason, all post with a custom post status set to public should be embeddable.

The reason why thats not possible is in get_oembed_response_data: ​https://developer.wordpress.org/reference/functions/get_oembed_response_data/

if ( 'publish' !== get_post_status( $post ) ) {
    return false;
}

It just checks if the post status is "publish" and not if "public" on the post status object is set to "true".

To support custom public post status, this could be a solution:

if ( true !== get_post_status_object( get_post_status( $post ) )->public ) {
    return false;
}

Another possibility would be to provide a custom filter:

if ( true !== in_array( get_post_status( $post ), apply_filters( 'oembed_post_status', array( 'publish' ) ) ) {
    return false;
}

Attachments (3)

47574.diff​ (408 bytes ) - added by goaroundagain 7 years ago.
47574.2.diff​ (1.8 KB ) - added by goaroundagain 7 years ago.
Now with unit tests
47574.3.diff​ (2.1 KB ) - added by goaroundagain 7 years ago.
If the post status is not registered, treat it as a nonpublic

Download all attachments as: .zip

Change History (16)

@goaroundagain
7 years ago

Now with unit tests

#1 @goaroundagain
7 years ago

  • Keywords has-unit-tests has-patch added

@goaroundagain
7 years ago

If the post status is not registered, treat it as a nonpublic

#2 @SergeyBiryukov
7 years ago

  • Milestone Awaiting Review → 5.3

#3 @SergeyBiryukov
7 years ago

  • Owner set to SergeyBiryukov
  • Status new → reviewing

Related: #47911

#4 @davidbaumwald
7 years ago

@SergeyBiryukov Is this one going to make it in time for 5.3 RC1?

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


7 years ago

#6 @marybaum
7 years ago

  • Milestone 5.3 → Future Release

#7 @SergeyBiryukov
6 years ago

  • Milestone Future Release → 5.7

#8 @poena
6 years ago

I have tested 47574.3.diff and confirmed that posts with a custom post status can be embedded.
-I don't know enough to review the test.

#10 @peterwilsoncc
6 years ago

In the ​linked pull request, I've modified the patch to use the ​new `is_post_publicly_viewable()` function which allows for public custom statuses and post types rather than repeat the code.

I've replaced the existing check the post exists, as is_post_publicly_viewable() doesn't consider non-existent post as public. That would be silly :D

#11 @SergeyBiryukov
6 years ago

  • Resolution → fixed
  • Status reviewing → closed

In 50401:

Embeds: Allow posts with a public custom post status to be embedded.

Previously, only posts with the publish status could be embedded.

Props goaroundagain, peterwilsoncc, poena.
Fixes #47574.

#13 @desrosj
6 years ago

  • Keywords has-dev-note added

This was mentioned in the miscellaneous developer changes developer note: ​https://make.wordpress.org/core/2021/02/23/miscellaneous-developer-focused-changes-in-wordpress-5-7/.

Note: See TracTickets for help on using tickets.