Skip to content

Improve determination of eligible post types for AMP #6883

Closed
@westonruter

Description

@westonruter

Feature Description

As noted in #6881 (comment):

the only post types that are eligible for being AMP-enabled are those which have 'public' => true:

public static function get_eligible_post_types() {
$post_types = array_values(
get_post_types(
[
'public' => true,
],
'names'
)
);
/**
* Filters the list of post types which may be supported for AMP.
*
* By default the list includes those which are public.
*
* @since 2.0
*
* @param string[] $post_types Post types.
*/
return array_values( (array) apply_filters( 'amp_supportable_post_types', $post_types ) );
}

It's true that a post type could have public set to true but have publicly_queryable set to false, I think, and in that case it may be possible that we could accidentally show or hide the preview button. It would be marginally better to here instead do the following since there is now a is_post_type_viewable filter in WP 5.9:

diff --git a/includes/class-amp-post-type-support.php b/includes/class-amp-post-type-support.php
index 3d4560641..17eb6519b 100644
--- a/includes/class-amp-post-type-support.php
+++ b/includes/class-amp-post-type-support.php
@@ -42,14 +42,9 @@ public static function get_builtin_supported_post_types() {
 	 * @return string[] Post types eligible for AMP.
 	 */
 	public static function get_eligible_post_types() {
-		$post_types = array_values(
-			get_post_types(
-				[
-					'public' => true,
-				],
-				'names'
-			)
-		);
+		$post_types = array_values( get_post_types( [], 'names' ) );
+
+		$post_types = array_filter( $post_types, 'is_post_type_viewable' );
 
 		/**
 		 * Filters the list of post types which may be supported for AMP.

Acceptance Criteria

Only post types for which is_post_type_viewable() returns true should be listed among the post types for which AMP can be enabled. Only these post types should have an AMP preview button shown in a paired AMP mode (transitional or reader).

Implementation Brief

No response

QA Testing Instructions

No response

Demo

No response

Changelog Entry

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    ChangeloggedWhether the issue/PR has been added to release notes.EnhancementNew feature or improvement of an existing one

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions