Make WordPress Core


Ignore:
Timestamp:
01/24/2025 01:30:27 PM (4 months ago)
Author:
swissspidy
Message:

Posts, Post Types: Embeds: Add new embeddable argument to post types.

This new argument, which defaults to the value of public, can be used to determine whether a post can be embedded using oEmbed. A new is_post_embeddable() function is added to easily check this.

Props pampfelimetten, swissspidy, bradleyt, DrewAPicture, gadelhas, mukesh27.
Fixes #35567.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/embed.php

    r59493 r59700  
    332332 *
    333333 * @since 4.4.0
     334 * @since 6.8.0 Output was adjusted to only embed if the post supports it.
    334335 */
    335336function wp_oembed_add_discovery_links() {
    336337    $output = '';
    337338
    338     if ( is_singular() ) {
     339    if ( is_singular() && is_post_embeddable() ) {
    339340        $output .= '<link rel="alternate" title="' . _x( 'oEmbed (JSON)', 'oEmbed resource link name' ) . '" type="application/json+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink() ) ) . '" />' . "\n";
    340341
     
    539540 *
    540541 * @since 4.4.0
     542 * @since 6.8.0 Output was adjusted to only embed if the post type supports it.
    541543 *
    542544 * @param WP_Post|int $post  Post ID or post object.
    543545 * @param int         $width The requested width.
    544  * @return array|false Response data on success, false if post doesn't exist
    545  *                     or is not publicly viewable.
     546 * @return array|false Response data on success, false if post doesn't exist,
     547 *                     is not publicly viewable or post type is not embeddable.
    546548 */
    547549function get_oembed_response_data( $post, $width ) {
     
    554556
    555557    if ( ! is_post_publicly_viewable( $post ) ) {
     558        return false;
     559    }
     560
     561    if ( ! is_post_embeddable( $post ) ) {
    556562        return false;
    557563    }
Note: See TracChangeset for help on using the changeset viewer.