From d4f3ace989d70059b35e5a988cb81049b3d8569f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?M=C3=A1rio=20Santos?=
<3957598+gadelhas@users.noreply.github.com>
Date: Sat, 16 Dec 2023 15:57:22 +0000
Subject: [PATCH 1/9] Add `is_embeddable` argument to post types.
---
src/wp-includes/class-wp-post-type.php | 6 +++
src/wp-includes/embed.php | 12 +++--
src/wp-includes/post.php | 34 +++++++++++++
tests/phpunit/tests/oembed/discovery.php | 14 ++++++
tests/phpunit/tests/oembed/template.php | 63 ++++++++++++++++++++++++
tests/phpunit/tests/post/types.php | 24 +++++++++
6 files changed, 150 insertions(+), 3 deletions(-)
diff --git a/src/wp-includes/class-wp-post-type.php b/src/wp-includes/class-wp-post-type.php
index 7a2769ed88327..1b15453aacd81 100644
--- a/src/wp-includes/class-wp-post-type.php
+++ b/src/wp-includes/class-wp-post-type.php
@@ -521,6 +521,7 @@ public function set_props( $args ) {
'hierarchical' => false,
'exclude_from_search' => null,
'publicly_queryable' => null,
+ 'is_embeddable' => null,
'show_ui' => null,
'show_in_menu' => null,
'show_in_nav_menus' => null,
@@ -565,6 +566,11 @@ public function set_props( $args ) {
$args['show_ui'] = $args['public'];
}
+ // If not set, default to the setting for 'public'.
+ if ( null === $args['is_embeddable'] ) {
+ $args['is_embeddable'] = $args['public'];
+ }
+
// If not set, default rest_namespace to wp/v2 if show_in_rest is true.
if ( false === $args['rest_namespace'] && ! empty( $args['show_in_rest'] ) ) {
$args['rest_namespace'] = 'wp/v2';
diff --git a/src/wp-includes/embed.php b/src/wp-includes/embed.php
index 9e59f1abc05b4..2af4f9f9b8ba5 100644
--- a/src/wp-includes/embed.php
+++ b/src/wp-includes/embed.php
@@ -331,11 +331,12 @@ function wp_oembed_register_route() {
* Adds oEmbed discovery links in the head element of the website.
*
* @since 4.4.0
+ * @since x.x.x Output was adjusted to only embed if the post supports it.
*/
function wp_oembed_add_discovery_links() {
$output = '';
- if ( is_singular() ) {
+ if ( is_singular() && is_post_embeddable() ) {
$output .= '' . "\n";
if ( class_exists( 'SimpleXMLElement' ) ) {
@@ -538,11 +539,12 @@ function get_post_embed_html( $width, $height, $post = null ) {
* Retrieves the oEmbed response data for a given post.
*
* @since 4.4.0
+ * @since x.x.x Output was adjusted to only embed if the post type supports it.
*
* @param WP_Post|int $post Post ID or post object.
* @param int $width The requested width.
- * @return array|false Response data on success, false if post doesn't exist
- * or is not publicly viewable.
+ * @return array|false Response data on success, false if post doesn't exist,
+ * is not publicly viewable or post type is not embeddable.
*/
function get_oembed_response_data( $post, $width ) {
$post = get_post( $post );
@@ -556,6 +558,10 @@ function get_oembed_response_data( $post, $width ) {
return false;
}
+ if ( ! is_post_embeddable( $post ) ) {
+ return false;
+ }
+
/**
* Filters the allowed minimum and maximum widths for the oEmbed response.
*
diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php
index d6b6bc6649cc9..d02249197d215 100644
--- a/src/wp-includes/post.php
+++ b/src/wp-includes/post.php
@@ -2384,6 +2384,40 @@ function is_post_publicly_viewable( $post = null ) {
return is_post_type_viewable( $post_type ) && is_post_status_viewable( $post_status );
}
+/**
+ * Determines whether a post is "embeddable".
+ *
+ * The "is_embeddable" value of the post's type will be evaluated.
+ *
+ * @since x.x.x
+ *
+ * @param int|WP_Post|null $post Optional. Post ID or `WP_Post` object. Defaults to global $post.
+ * @return bool Whether the post should be considered embeddable.
+ */
+function is_post_embeddable( $post = null ) {
+ $post = get_post( $post );
+
+ if ( ! $post ) {
+ return false;
+ }
+
+ $is_embeddable = false;
+
+ if ( $post_type = get_post_type_object( $post->post_type ) ) {
+ $is_embeddable = $post_type->is_embeddable;
+ }
+
+ /**
+ * Filter whether a post is embeddable.
+ *
+ * @since x.x.x
+ *
+ * $param bool $is_embeddable Whether the post is embeddable.
+ * @param WP_Post $post Post object.
+ */
+ return apply_filters( 'is_post_embeddable', $is_embeddable, $post );
+}
+
/**
* Retrieves an array of the latest posts, or posts matching the given criteria.
*
diff --git a/tests/phpunit/tests/oembed/discovery.php b/tests/phpunit/tests/oembed/discovery.php
index 38ad167b3c152..2650b0f31960e 100644
--- a/tests/phpunit/tests/oembed/discovery.php
+++ b/tests/phpunit/tests/oembed/discovery.php
@@ -85,4 +85,18 @@ public function test_add_oembed_discovery_links_to_attachment() {
$this->assertSame( $expected, get_echo( 'wp_oembed_add_discovery_links' ) );
}
+
+
+ /**
+ * @ticket 35567
+ */
+ function test_wp_oembed_add_discovery_links_non_embeddable_post_type_output_should_be_empty() {
+ register_post_type( 'not_embeddable', array( 'is_embeddable' => false ) );
+
+ $post = self::factory()->post->create_and_get( array(
+ 'post_type' => 'not_embeddable',
+ ) );
+
+ $this->assertFalse( get_oembed_response_data( $post, 100 ) );
+ }
}
diff --git a/tests/phpunit/tests/oembed/template.php b/tests/phpunit/tests/oembed/template.php
index 12092ff66999f..505c82afd8a48 100644
--- a/tests/phpunit/tests/oembed/template.php
+++ b/tests/phpunit/tests/oembed/template.php
@@ -345,4 +345,67 @@ public function test_wp_maybe_enqueue_oembed_host_js_without_wp_head_action() {
wp_maybe_enqueue_oembed_host_js( $post_embed );
$this->assertFalse( $scripts->query( 'wp-embed', 'enqueued' ) );
}
+
+ /**
+ * @ticket 35567
+ */
+ public function test_is_embeddable_post_non_existent_post() {
+ $this->assertFalse( is_post_embeddable( 0 ) );
+ }
+
+ /**
+ * @ticket 35567
+ */
+ public function test_is_embeddable_post_non_existent_post_type() {
+ $post = self::factory()->post->create_and_get( array(
+ 'post_type' => rand_str(),
+ ) );
+
+ $this->assertFalse( is_post_embeddable( $post ) );
+ }
+
+ /**
+ * @ticket 35567
+ */
+ public function test_is_embeddable_post_should_return_false_for_non_embeddable_post_type() {
+ register_post_type( 'not_embeddable', array( 'is_embeddable' => false ) );
+
+ $post = self::factory()->post->create_and_get( array(
+ 'post_type' => 'not_embeddable',
+ ) );
+
+ $this->assertFalse( is_post_embeddable( $post ) );
+ }
+
+ /**
+ * @ticket 35567
+ */
+ public function test_is_embeddable_post_should_return_true_for_embeddable_post_type() {
+ register_post_type( 'embeddable', array( 'is_embeddable' => true ) );
+
+ $post = self::factory()->post->create_and_get( array(
+ 'post_type' => 'embeddable',
+ ) );
+
+ $this->assertTrue( is_post_embeddable( $post ) );
+ }
+
+ /**
+ * @ticket 35567
+ */
+ public function test_is_embeddable_post_filtered() {
+ register_post_type( 'not_embeddable', array( 'is_embeddable' => false ) );
+
+ $post = self::factory()->post->create_and_get( array(
+ 'post_type' => 'not_embeddable',
+ ) );
+
+ add_filter( 'is_post_embeddable', '__return_true' );
+ $embeddable = is_post_embeddable( $post );
+ remove_filter( 'is_post_embeddable', '__return_true' );
+
+ $this->assertTrue( $embeddable );
+ }
+
+
}
diff --git a/tests/phpunit/tests/post/types.php b/tests/phpunit/tests/post/types.php
index df1543fa0c9ca..e0ac824a87eeb 100644
--- a/tests/phpunit/tests/post/types.php
+++ b/tests/phpunit/tests/post/types.php
@@ -589,4 +589,28 @@ public function test_get_post_types_by_support_excluding_features() {
public function test_get_post_types_by_support_non_existant_feature() {
$this->assertSameSets( array(), get_post_types_by_support( 'somefeature' ) );
}
+
+ /**
+ * @group oembed
+ * @ticket 35567
+ */
+ public function test_register_post_type_is_embeddable_defaults_to_public_argument() {
+ $post_type = register_post_type( rand_str( 10) );
+ $this->assertFalse( $post_type->is_embeddable );
+
+ $post_type = register_post_type( rand_str( 10 ), array( 'public' => true ) );
+ $this->assertTrue( $post_type->is_embeddable );
+ }
+
+ /**
+ * @group oembed
+ * @ticket 35567
+ */
+ public function test_register_post_type_override_is_embeddable() {
+ $post_type = register_post_type( rand_str( 10 ), array( 'is_embeddable' => true ) );
+ $this->assertTrue( $post_type->is_embeddable );
+
+ $post_type = register_post_type( rand_str( 10 ), array( 'public' => true, 'is_embeddable' => false ) );
+ $this->assertFalse( $post_type->is_embeddable );
+ }
}
From 76b959c615e4c6496adb612af7a7d60ddebac1db Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?M=C3=A1rio=20Santos?=
<3957598+gadelhas@users.noreply.github.com>
Date: Sat, 16 Dec 2023 16:08:12 +0000
Subject: [PATCH 2/9] =?UTF-8?q?=F0=9F=92=85=20cs=20fixes?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/wp-includes/class-wp-post-type.php | 2 +-
src/wp-includes/post.php | 13 ++++----
tests/phpunit/tests/oembed/discovery.php | 8 +++--
tests/phpunit/tests/oembed/template.php | 42 ++++++++++++++----------
tests/phpunit/tests/post/types.php | 10 ++++--
5 files changed, 45 insertions(+), 30 deletions(-)
diff --git a/src/wp-includes/class-wp-post-type.php b/src/wp-includes/class-wp-post-type.php
index 1b15453aacd81..e4b0ce2ecca88 100644
--- a/src/wp-includes/class-wp-post-type.php
+++ b/src/wp-includes/class-wp-post-type.php
@@ -521,7 +521,7 @@ public function set_props( $args ) {
'hierarchical' => false,
'exclude_from_search' => null,
'publicly_queryable' => null,
- 'is_embeddable' => null,
+ 'is_embeddable' => null,
'show_ui' => null,
'show_in_menu' => null,
'show_in_nav_menus' => null,
diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php
index d02249197d215..eff63c010e96e 100644
--- a/src/wp-includes/post.php
+++ b/src/wp-includes/post.php
@@ -2386,11 +2386,11 @@ function is_post_publicly_viewable( $post = null ) {
/**
* Determines whether a post is "embeddable".
- *
+ *
* The "is_embeddable" value of the post's type will be evaluated.
- *
+ *
* @since x.x.x
- *
+ *
* @param int|WP_Post|null $post Optional. Post ID or `WP_Post` object. Defaults to global $post.
* @return bool Whether the post should be considered embeddable.
*/
@@ -2403,15 +2403,16 @@ function is_post_embeddable( $post = null ) {
$is_embeddable = false;
- if ( $post_type = get_post_type_object( $post->post_type ) ) {
+ $post_type = get_post_type_object( $post->post_type );
+ if ( $post_type ) {
$is_embeddable = $post_type->is_embeddable;
}
/**
* Filter whether a post is embeddable.
- *
+ *
* @since x.x.x
- *
+ *
* $param bool $is_embeddable Whether the post is embeddable.
* @param WP_Post $post Post object.
*/
diff --git a/tests/phpunit/tests/oembed/discovery.php b/tests/phpunit/tests/oembed/discovery.php
index 2650b0f31960e..fe178f56d6afb 100644
--- a/tests/phpunit/tests/oembed/discovery.php
+++ b/tests/phpunit/tests/oembed/discovery.php
@@ -93,9 +93,11 @@ public function test_add_oembed_discovery_links_to_attachment() {
function test_wp_oembed_add_discovery_links_non_embeddable_post_type_output_should_be_empty() {
register_post_type( 'not_embeddable', array( 'is_embeddable' => false ) );
- $post = self::factory()->post->create_and_get( array(
- 'post_type' => 'not_embeddable',
- ) );
+ $post = self::factory()->post->create_and_get(
+ array(
+ 'post_type' => 'not_embeddable',
+ )
+ );
$this->assertFalse( get_oembed_response_data( $post, 100 ) );
}
diff --git a/tests/phpunit/tests/oembed/template.php b/tests/phpunit/tests/oembed/template.php
index 505c82afd8a48..9d210f96aaae8 100644
--- a/tests/phpunit/tests/oembed/template.php
+++ b/tests/phpunit/tests/oembed/template.php
@@ -357,10 +357,12 @@ public function test_is_embeddable_post_non_existent_post() {
* @ticket 35567
*/
public function test_is_embeddable_post_non_existent_post_type() {
- $post = self::factory()->post->create_and_get( array(
- 'post_type' => rand_str(),
- ) );
-
+ $post = self::factory()->post->create_and_get(
+ array(
+ 'post_type' => rand_str(),
+ )
+ );
+
$this->assertFalse( is_post_embeddable( $post ) );
}
@@ -370,10 +372,12 @@ public function test_is_embeddable_post_non_existent_post_type() {
public function test_is_embeddable_post_should_return_false_for_non_embeddable_post_type() {
register_post_type( 'not_embeddable', array( 'is_embeddable' => false ) );
- $post = self::factory()->post->create_and_get( array(
- 'post_type' => 'not_embeddable',
- ) );
-
+ $post = self::factory()->post->create_and_get(
+ array(
+ 'post_type' => 'not_embeddable',
+ )
+ );
+
$this->assertFalse( is_post_embeddable( $post ) );
}
@@ -383,10 +387,12 @@ public function test_is_embeddable_post_should_return_false_for_non_embeddable_p
public function test_is_embeddable_post_should_return_true_for_embeddable_post_type() {
register_post_type( 'embeddable', array( 'is_embeddable' => true ) );
- $post = self::factory()->post->create_and_get( array(
- 'post_type' => 'embeddable',
- ) );
-
+ $post = self::factory()->post->create_and_get(
+ array(
+ 'post_type' => 'embeddable',
+ )
+ );
+
$this->assertTrue( is_post_embeddable( $post ) );
}
@@ -396,16 +402,16 @@ public function test_is_embeddable_post_should_return_true_for_embeddable_post_t
public function test_is_embeddable_post_filtered() {
register_post_type( 'not_embeddable', array( 'is_embeddable' => false ) );
- $post = self::factory()->post->create_and_get( array(
- 'post_type' => 'not_embeddable',
- ) );
+ $post = self::factory()->post->create_and_get(
+ array(
+ 'post_type' => 'not_embeddable',
+ )
+ );
add_filter( 'is_post_embeddable', '__return_true' );
$embeddable = is_post_embeddable( $post );
remove_filter( 'is_post_embeddable', '__return_true' );
-
+
$this->assertTrue( $embeddable );
}
-
-
}
diff --git a/tests/phpunit/tests/post/types.php b/tests/phpunit/tests/post/types.php
index e0ac824a87eeb..e5591a1faa6ce 100644
--- a/tests/phpunit/tests/post/types.php
+++ b/tests/phpunit/tests/post/types.php
@@ -595,7 +595,7 @@ public function test_get_post_types_by_support_non_existant_feature() {
* @ticket 35567
*/
public function test_register_post_type_is_embeddable_defaults_to_public_argument() {
- $post_type = register_post_type( rand_str( 10) );
+ $post_type = register_post_type( rand_str( 10 ) );
$this->assertFalse( $post_type->is_embeddable );
$post_type = register_post_type( rand_str( 10 ), array( 'public' => true ) );
@@ -610,7 +610,13 @@ public function test_register_post_type_override_is_embeddable() {
$post_type = register_post_type( rand_str( 10 ), array( 'is_embeddable' => true ) );
$this->assertTrue( $post_type->is_embeddable );
- $post_type = register_post_type( rand_str( 10 ), array( 'public' => true, 'is_embeddable' => false ) );
+ $post_type = register_post_type(
+ rand_str( 10 ),
+ array(
+ 'public' => true,
+ 'is_embeddable' => false,
+ )
+ );
$this->assertFalse( $post_type->is_embeddable );
}
}
From 7564e3beb4f1498fc86f26b60e8e488d502a3e47 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?M=C3=A1rio=20Santos?=
<3957598+gadelhas@users.noreply.github.com>
Date: Sat, 16 Dec 2023 16:10:05 +0000
Subject: [PATCH 3/9] Fix function visibility
---
tests/phpunit/tests/oembed/discovery.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/phpunit/tests/oembed/discovery.php b/tests/phpunit/tests/oembed/discovery.php
index fe178f56d6afb..3c8ed62795059 100644
--- a/tests/phpunit/tests/oembed/discovery.php
+++ b/tests/phpunit/tests/oembed/discovery.php
@@ -90,7 +90,7 @@ public function test_add_oembed_discovery_links_to_attachment() {
/**
* @ticket 35567
*/
- function test_wp_oembed_add_discovery_links_non_embeddable_post_type_output_should_be_empty() {
+ public function test_wp_oembed_add_discovery_links_non_embeddable_post_type_output_should_be_empty() {
register_post_type( 'not_embeddable', array( 'is_embeddable' => false ) );
$post = self::factory()->post->create_and_get(
From 46174d5fe663e13e4b97c67cf7fc8e24400fa643 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?M=C3=A1rio=20Santos?=
<3957598+gadelhas@users.noreply.github.com>
Date: Tue, 2 Jan 2024 23:17:32 +0000
Subject: [PATCH 4/9] Address PR comments
---
src/wp-includes/post.php | 2 +-
tests/phpunit/tests/oembed/discovery.php | 1 -
2 files changed, 1 insertion(+), 2 deletions(-)
diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php
index eff63c010e96e..d6041eebebc13 100644
--- a/src/wp-includes/post.php
+++ b/src/wp-includes/post.php
@@ -2413,7 +2413,7 @@ function is_post_embeddable( $post = null ) {
*
* @since x.x.x
*
- * $param bool $is_embeddable Whether the post is embeddable.
+ * @param bool $is_embeddable Whether the post is embeddable.
* @param WP_Post $post Post object.
*/
return apply_filters( 'is_post_embeddable', $is_embeddable, $post );
diff --git a/tests/phpunit/tests/oembed/discovery.php b/tests/phpunit/tests/oembed/discovery.php
index 3c8ed62795059..290a8e5d6ef27 100644
--- a/tests/phpunit/tests/oembed/discovery.php
+++ b/tests/phpunit/tests/oembed/discovery.php
@@ -86,7 +86,6 @@ public function test_add_oembed_discovery_links_to_attachment() {
$this->assertSame( $expected, get_echo( 'wp_oembed_add_discovery_links' ) );
}
-
/**
* @ticket 35567
*/
From a540b1dd58f18b15436f56b5a18d2b98f1eb98dc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?M=C3=A1rio=20Santos?=
<3957598+gadelhas@users.noreply.github.com>
Date: Tue, 2 Jan 2024 23:32:03 +0000
Subject: [PATCH 5/9] Remove testing for non existent post type as you can't
create a post with wrong post type.
---
tests/phpunit/tests/oembed/template.php | 13 -------------
1 file changed, 13 deletions(-)
diff --git a/tests/phpunit/tests/oembed/template.php b/tests/phpunit/tests/oembed/template.php
index 9d210f96aaae8..03ef61b156df4 100644
--- a/tests/phpunit/tests/oembed/template.php
+++ b/tests/phpunit/tests/oembed/template.php
@@ -353,19 +353,6 @@ public function test_is_embeddable_post_non_existent_post() {
$this->assertFalse( is_post_embeddable( 0 ) );
}
- /**
- * @ticket 35567
- */
- public function test_is_embeddable_post_non_existent_post_type() {
- $post = self::factory()->post->create_and_get(
- array(
- 'post_type' => rand_str(),
- )
- );
-
- $this->assertFalse( is_post_embeddable( $post ) );
- }
-
/**
* @ticket 35567
*/
From 75bbc64c30ae9ea096d8bbe9b70e5b0f776f67fe Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?M=C3=A1rio=20Santos?=
<3957598+gadelhas@users.noreply.github.com>
Date: Tue, 2 Jan 2024 23:49:35 +0000
Subject: [PATCH 6/9] force retesting
From 39948019bebc8d7e2e3b3342dae67cc3cb6918e6 Mon Sep 17 00:00:00 2001
From: Pascal Birchler
Date: Thu, 23 Jan 2025 14:39:47 +0100
Subject: [PATCH 7/9] Apply suggestions from code review
---
src/wp-includes/post.php | 10 ++++------
tests/phpunit/tests/oembed/template.php | 2 +-
tests/phpunit/tests/post/types.php | 18 +++++++++---------
3 files changed, 14 insertions(+), 16 deletions(-)
diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php
index d6041eebebc13..56507ac1eaa24 100644
--- a/src/wp-includes/post.php
+++ b/src/wp-includes/post.php
@@ -2385,11 +2385,9 @@ function is_post_publicly_viewable( $post = null ) {
}
/**
- * Determines whether a post is "embeddable".
+ * Determines whether a post is embeddable.
*
- * The "is_embeddable" value of the post's type will be evaluated.
- *
- * @since x.x.x
+ * @since 6.8.0
*
* @param int|WP_Post|null $post Optional. Post ID or `WP_Post` object. Defaults to global $post.
* @return bool Whether the post should be considered embeddable.
@@ -2411,10 +2409,10 @@ function is_post_embeddable( $post = null ) {
/**
* Filter whether a post is embeddable.
*
- * @since x.x.x
+ * @since 6.8.0
*
* @param bool $is_embeddable Whether the post is embeddable.
- * @param WP_Post $post Post object.
+ * @param WP_Post $post Post object.
*/
return apply_filters( 'is_post_embeddable', $is_embeddable, $post );
}
diff --git a/tests/phpunit/tests/oembed/template.php b/tests/phpunit/tests/oembed/template.php
index 03ef61b156df4..ab9ff53562c4f 100644
--- a/tests/phpunit/tests/oembed/template.php
+++ b/tests/phpunit/tests/oembed/template.php
@@ -350,7 +350,7 @@ public function test_wp_maybe_enqueue_oembed_host_js_without_wp_head_action() {
* @ticket 35567
*/
public function test_is_embeddable_post_non_existent_post() {
- $this->assertFalse( is_post_embeddable( 0 ) );
+ $this->assertFalse( is_post_embeddable( 99999 ) );
}
/**
diff --git a/tests/phpunit/tests/post/types.php b/tests/phpunit/tests/post/types.php
index e5591a1faa6ce..0dfead3d42a28 100644
--- a/tests/phpunit/tests/post/types.php
+++ b/tests/phpunit/tests/post/types.php
@@ -594,12 +594,12 @@ public function test_get_post_types_by_support_non_existant_feature() {
* @group oembed
* @ticket 35567
*/
- public function test_register_post_type_is_embeddable_defaults_to_public_argument() {
- $post_type = register_post_type( rand_str( 10 ) );
- $this->assertFalse( $post_type->is_embeddable );
+ public function test_register_post_type_is_embeddable_should_default_to_value_of_public() {
+ $post_type = register_post_type( $this->post_type );
+ $this->assertFalse( $post_type->is_embeddable, 'Non-public post type should not be embeddable by default' );
- $post_type = register_post_type( rand_str( 10 ), array( 'public' => true ) );
- $this->assertTrue( $post_type->is_embeddable );
+ $post_type = register_post_type( $this->post_type, array( 'public' => true ) );
+ $this->assertTrue( $post_type->is_embeddable, 'Public post type should be embeddable by default' );
}
/**
@@ -607,16 +607,16 @@ public function test_register_post_type_is_embeddable_defaults_to_public_argumen
* @ticket 35567
*/
public function test_register_post_type_override_is_embeddable() {
- $post_type = register_post_type( rand_str( 10 ), array( 'is_embeddable' => true ) );
- $this->assertTrue( $post_type->is_embeddable );
+ $post_type = register_post_type( $this->post_type, array( 'is_embeddable' => true ) );
+ $this->assertTrue( $post_type->is_embeddable, 'Post type should be embeddable even though it is not public' );
$post_type = register_post_type(
- rand_str( 10 ),
+ $this->post_type,
array(
'public' => true,
'is_embeddable' => false,
)
);
- $this->assertFalse( $post_type->is_embeddable );
+ $this->assertFalse( $post_type->is_embeddable, 'Post type should not be embeddable even though it is public' );
}
}
From e8090c3cc9b65779e1b47d2def74fbdabc9e7222 Mon Sep 17 00:00:00 2001
From: Pascal Birchler
Date: Thu, 23 Jan 2025 14:44:57 +0100
Subject: [PATCH 8/9] Update version numbers
---
src/wp-includes/embed.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/wp-includes/embed.php b/src/wp-includes/embed.php
index 7c9055cae05c8..b5b30acead880 100644
--- a/src/wp-includes/embed.php
+++ b/src/wp-includes/embed.php
@@ -331,7 +331,7 @@ function wp_oembed_register_route() {
* Adds oEmbed discovery links in the head element of the website.
*
* @since 4.4.0
- * @since x.x.x Output was adjusted to only embed if the post supports it.
+ * @since 6.8.0 Output was adjusted to only embed if the post supports it.
*/
function wp_oembed_add_discovery_links() {
$output = '';
@@ -539,7 +539,7 @@ function get_post_embed_html( $width, $height, $post = null ) {
* Retrieves the oEmbed response data for a given post.
*
* @since 4.4.0
- * @since x.x.x Output was adjusted to only embed if the post type supports it.
+ * @since 6.8.0 Output was adjusted to only embed if the post type supports it.
*
* @param WP_Post|int $post Post ID or post object.
* @param int $width The requested width.
From 409d7602e4cec8fb73ea7d2f244901a2e8d965f1 Mon Sep 17 00:00:00 2001
From: Pascal Birchler
Date: Fri, 24 Jan 2025 13:32:16 +0100
Subject: [PATCH 9/9] Rename to `embeddable`, add property
---
src/wp-includes/class-wp-post-type.php | 16 +++++++++++++---
src/wp-includes/post.php | 9 +++++----
tests/phpunit/tests/oembed/discovery.php | 2 +-
tests/phpunit/tests/oembed/template.php | 6 +++---
tests/phpunit/tests/post/types.php | 14 +++++++-------
5 files changed, 29 insertions(+), 18 deletions(-)
diff --git a/src/wp-includes/class-wp-post-type.php b/src/wp-includes/class-wp-post-type.php
index c0e30a45a888d..400fd0b698c1e 100644
--- a/src/wp-includes/class-wp-post-type.php
+++ b/src/wp-includes/class-wp-post-type.php
@@ -113,6 +113,16 @@ final class WP_Post_Type {
*/
public $publicly_queryable = null;
+ /**
+ * Whether this post type is embeddable.
+ *
+ * Default is the value of $public.
+ *
+ * @since 6.8.0
+ * @var bool $embeddable
+ */
+ public $embeddable = null;
+
/**
* Whether to generate and allow a UI for managing this post type in the admin.
*
@@ -521,7 +531,7 @@ public function set_props( $args ) {
'hierarchical' => false,
'exclude_from_search' => null,
'publicly_queryable' => null,
- 'is_embeddable' => null,
+ 'embeddable' => null,
'show_ui' => null,
'show_in_menu' => null,
'show_in_nav_menus' => null,
@@ -567,8 +577,8 @@ public function set_props( $args ) {
}
// If not set, default to the setting for 'public'.
- if ( null === $args['is_embeddable'] ) {
- $args['is_embeddable'] = $args['public'];
+ if ( null === $args['embeddable'] ) {
+ $args['embeddable'] = $args['public'];
}
// If not set, default rest_namespace to wp/v2 if show_in_rest is true.
diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php
index a74c2862dcf7d..a78e97b6c1dd9 100644
--- a/src/wp-includes/post.php
+++ b/src/wp-includes/post.php
@@ -2490,13 +2490,14 @@ function is_post_embeddable( $post = null ) {
return false;
}
- $is_embeddable = false;
-
$post_type = get_post_type_object( $post->post_type );
- if ( $post_type ) {
- $is_embeddable = $post_type->is_embeddable;
+
+ if ( ! $post_type ) {
+ return false;
}
+ $is_embeddable = $post_type->embeddable;
+
/**
* Filter whether a post is embeddable.
*
diff --git a/tests/phpunit/tests/oembed/discovery.php b/tests/phpunit/tests/oembed/discovery.php
index 1318ec1bac009..41efe1cc2a378 100644
--- a/tests/phpunit/tests/oembed/discovery.php
+++ b/tests/phpunit/tests/oembed/discovery.php
@@ -90,7 +90,7 @@ public function test_add_oembed_discovery_links_to_attachment() {
* @ticket 35567
*/
public function test_wp_oembed_add_discovery_links_non_embeddable_post_type_output_should_be_empty() {
- register_post_type( 'not_embeddable', array( 'is_embeddable' => false ) );
+ register_post_type( 'not_embeddable', array( 'embeddable' => false ) );
$post = self::factory()->post->create_and_get(
array(
diff --git a/tests/phpunit/tests/oembed/template.php b/tests/phpunit/tests/oembed/template.php
index 66d072137b384..bce26bbcd8ddd 100644
--- a/tests/phpunit/tests/oembed/template.php
+++ b/tests/phpunit/tests/oembed/template.php
@@ -355,7 +355,7 @@ public function test_is_embeddable_post_non_existent_post() {
* @ticket 35567
*/
public function test_is_embeddable_post_should_return_false_for_non_embeddable_post_type() {
- register_post_type( 'not_embeddable', array( 'is_embeddable' => false ) );
+ register_post_type( 'not_embeddable', array( 'embeddable' => false ) );
$post = self::factory()->post->create_and_get(
array(
@@ -370,7 +370,7 @@ public function test_is_embeddable_post_should_return_false_for_non_embeddable_p
* @ticket 35567
*/
public function test_is_embeddable_post_should_return_true_for_embeddable_post_type() {
- register_post_type( 'embeddable', array( 'is_embeddable' => true ) );
+ register_post_type( 'embeddable', array( 'embeddable' => true ) );
$post = self::factory()->post->create_and_get(
array(
@@ -385,7 +385,7 @@ public function test_is_embeddable_post_should_return_true_for_embeddable_post_t
* @ticket 35567
*/
public function test_is_embeddable_post_filtered() {
- register_post_type( 'not_embeddable', array( 'is_embeddable' => false ) );
+ register_post_type( 'not_embeddable', array( 'embeddable' => false ) );
$post = self::factory()->post->create_and_get(
array(
diff --git a/tests/phpunit/tests/post/types.php b/tests/phpunit/tests/post/types.php
index 71623d2298e9a..96519586d6cff 100644
--- a/tests/phpunit/tests/post/types.php
+++ b/tests/phpunit/tests/post/types.php
@@ -653,10 +653,10 @@ public function test_removing_editor_support_does_not_remove_autosave_support()
*/
public function test_register_post_type_is_embeddable_should_default_to_value_of_public() {
$post_type = register_post_type( $this->post_type );
- $this->assertFalse( $post_type->is_embeddable, 'Non-public post type should not be embeddable by default' );
+ $this->assertFalse( $post_type->embeddable, 'Non-public post type should not be embeddable by default' );
$post_type = register_post_type( $this->post_type, array( 'public' => true ) );
- $this->assertTrue( $post_type->is_embeddable, 'Public post type should be embeddable by default' );
+ $this->assertTrue( $post_type->embeddable, 'Public post type should be embeddable by default' );
}
/**
@@ -664,16 +664,16 @@ public function test_register_post_type_is_embeddable_should_default_to_value_of
* @ticket 35567
*/
public function test_register_post_type_override_is_embeddable() {
- $post_type = register_post_type( $this->post_type, array( 'is_embeddable' => true ) );
- $this->assertTrue( $post_type->is_embeddable, 'Post type should be embeddable even though it is not public' );
+ $post_type = register_post_type( $this->post_type, array( 'embeddable' => true ) );
+ $this->assertTrue( $post_type->embeddable, 'Post type should be embeddable even though it is not public' );
$post_type = register_post_type(
$this->post_type,
array(
- 'public' => true,
- 'is_embeddable' => false,
+ 'public' => true,
+ 'embeddable' => false,
)
);
- $this->assertFalse( $post_type->is_embeddable, 'Post type should not be embeddable even though it is public' );
+ $this->assertFalse( $post_type->embeddable, 'Post type should not be embeddable even though it is public' );
}
}