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

    r58211 r59700  
    647647        $this->assertTrue( post_type_supports( 'foo', 'autosave' ), 'Post type should still support autosaves.' );
    648648    }
     649
     650    /**
     651     * @group oembed
     652     * @ticket 35567
     653     */
     654    public function test_register_post_type_is_embeddable_should_default_to_value_of_public() {
     655        $post_type = register_post_type( $this->post_type );
     656        $this->assertFalse( $post_type->embeddable, 'Non-public post type should not be embeddable by default' );
     657
     658        $post_type = register_post_type( $this->post_type, array( 'public' => true ) );
     659        $this->assertTrue( $post_type->embeddable, 'Public post type should be embeddable by default' );
     660    }
     661
     662    /**
     663     * @group oembed
     664     * @ticket 35567
     665     */
     666    public function test_register_post_type_override_is_embeddable() {
     667        $post_type = register_post_type( $this->post_type, array( 'embeddable' => true ) );
     668        $this->assertTrue( $post_type->embeddable, 'Post type should be embeddable even though it is not public' );
     669
     670        $post_type = register_post_type(
     671            $this->post_type,
     672            array(
     673                'public'     => true,
     674                'embeddable' => false,
     675            )
     676        );
     677        $this->assertFalse( $post_type->embeddable, 'Post type should not be embeddable even though it is public' );
     678    }
    649679}
Note: See TracChangeset for help on using the changeset viewer.