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/post.php

    r59657 r59700  
    24772477
    24782478/**
     2479 * Determines whether a post is embeddable.
     2480 *
     2481 * @since 6.8.0
     2482 *
     2483 * @param int|WP_Post|null $post Optional. Post ID or `WP_Post` object. Defaults to global $post.
     2484 * @return bool Whether the post should be considered embeddable.
     2485 */
     2486function is_post_embeddable( $post = null ) {
     2487    $post = get_post( $post );
     2488
     2489    if ( ! $post ) {
     2490        return false;
     2491    }
     2492
     2493    $post_type = get_post_type_object( $post->post_type );
     2494
     2495    if ( ! $post_type ) {
     2496        return false;
     2497    }
     2498
     2499    $is_embeddable = $post_type->embeddable;
     2500
     2501    /**
     2502     * Filter whether a post is embeddable.
     2503     *
     2504     * @since 6.8.0
     2505     *
     2506     * @param bool    $is_embeddable Whether the post is embeddable.
     2507     * @param WP_Post $post          Post object.
     2508     */
     2509    return apply_filters( 'is_post_embeddable', $is_embeddable, $post );
     2510}
     2511
     2512/**
    24792513 * Retrieves an array of the latest posts, or posts matching the given criteria.
    24802514 *
Note: See TracChangeset for help on using the changeset viewer.