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/oembed/template.php

    r58143 r59700  
    344344        $this->assertFalse( $scripts->query( 'wp-embed', 'enqueued' ) );
    345345    }
     346
     347    /**
     348     * @ticket 35567
     349     */
     350    public function test_is_embeddable_post_non_existent_post() {
     351        $this->assertFalse( is_post_embeddable( 99999 ) );
     352    }
     353
     354    /**
     355     * @ticket 35567
     356     */
     357    public function test_is_embeddable_post_should_return_false_for_non_embeddable_post_type() {
     358        register_post_type( 'not_embeddable', array( 'embeddable' => false ) );
     359
     360        $post = self::factory()->post->create_and_get(
     361            array(
     362                'post_type' => 'not_embeddable',
     363            )
     364        );
     365
     366        $this->assertFalse( is_post_embeddable( $post ) );
     367    }
     368
     369    /**
     370     * @ticket 35567
     371     */
     372    public function test_is_embeddable_post_should_return_true_for_embeddable_post_type() {
     373        register_post_type( 'embeddable', array( 'embeddable' => true ) );
     374
     375        $post = self::factory()->post->create_and_get(
     376            array(
     377                'post_type' => 'embeddable',
     378            )
     379        );
     380
     381        $this->assertTrue( is_post_embeddable( $post ) );
     382    }
     383
     384    /**
     385     * @ticket 35567
     386     */
     387    public function test_is_embeddable_post_filtered() {
     388        register_post_type( 'not_embeddable', array( 'embeddable' => false ) );
     389
     390        $post = self::factory()->post->create_and_get(
     391            array(
     392                'post_type' => 'not_embeddable',
     393            )
     394        );
     395
     396        add_filter( 'is_post_embeddable', '__return_true' );
     397        $embeddable = is_post_embeddable( $post );
     398        remove_filter( 'is_post_embeddable', '__return_true' );
     399
     400        $this->assertTrue( $embeddable );
     401    }
    346402}
Note: See TracChangeset for help on using the changeset viewer.