From 7091b35ec7f316680cf5d1c6cf77a66dd6aa47b8 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Mon, 2 Jul 2018 11:44:37 -0700 Subject: [PATCH] Fix generation of AMP permalink for attachments --- includes/amp-helper-functions.php | 3 +++ includes/class-amp-theme-support.php | 1 + 2 files changed, 4 insertions(+) diff --git a/includes/amp-helper-functions.php b/includes/amp-helper-functions.php index 964a563ce94..aa2d825554d 100644 --- a/includes/amp-helper-functions.php +++ b/includes/amp-helper-functions.php @@ -123,6 +123,9 @@ function amp_get_permalink( $post_id ) { || // If the post type is hierarchical then the /amp/ endpoint isn't available. is_post_type_hierarchical( get_post_type( $post_id ) ) + || + // Attachment pages don't accept the /amp/ endpoint. + 'attachment' === get_post_type( $post_id ) ); if ( $use_query_var ) { $amp_url = add_query_arg( amp_get_slug(), '', $permalink ); diff --git a/includes/class-amp-theme-support.php b/includes/class-amp-theme-support.php index fbc25ba3050..709d1082208 100644 --- a/includes/class-amp-theme-support.php +++ b/includes/class-amp-theme-support.php @@ -172,6 +172,7 @@ public static function read_theme_support() { // Validate theme support usage. $keys = array( 'template_dir', 'comments_live_list', 'mode', 'optional', 'templates_supported', 'available_callback' ); if ( ! is_array( self::$initial_theme_support_args ) ) { + self::$initial_theme_support_args = array(); _doing_it_wrong( 'add_theme_support', esc_html__( 'Expected AMP theme support arg to be array.', 'amp' ), '1.0' ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error } elseif ( count( array_diff( array_keys( self::$initial_theme_support_args ), $keys ) ) !== 0 ) { _doing_it_wrong( 'add_theme_support', esc_html( sprintf( // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error