diff --git a/includes/class-amp-theme-support.php b/includes/class-amp-theme-support.php index eed6ec0cd31..09c62518338 100644 --- a/includes/class-amp-theme-support.php +++ b/includes/class-amp-theme-support.php @@ -504,13 +504,7 @@ public static function get_template_availability( $query = null ) { if ( $is_match ) { $matching_templates[ $id ] = array( 'template' => $id, - 'supported' => ( - ! empty( $supportable_template['supported'] ) - || - ( AMP_Options_Manager::get_option( 'all_templates_supported' ) && empty( $supportable_template['immutable'] ) ) - || - $all_templates_supported_by_theme_support // Make sure theme support flag is given final say. - ), + 'supported' => ! empty( $supportable_template['supported'] ), 'immutable' => ! empty( $supportable_template['immutable'] ), ); } @@ -692,16 +686,6 @@ public static function get_supportable_templates() { ); } - // Pre-populate template supported state by theme support flag. - $theme_support_args = self::get_theme_support_args( array( 'initial' => true ) ); - if ( isset( $theme_support_args['templates_supported'] ) && is_array( $theme_support_args['templates_supported'] ) ) { - foreach ( $templates as $id => &$template ) { - if ( isset( $theme_support_args['templates_supported'][ $id ] ) ) { - $templates[ $id ]['supported'] = $theme_support_args['templates_supported'][ $id ]; - } - } - } - /** * Filters list of supportable templates. * @@ -721,11 +705,34 @@ public static function get_supportable_templates() { */ $templates = apply_filters( 'amp_supportable_templates', $templates ); + // Obtain the initial template supported state by theme support flag. + $theme_support_args = self::get_theme_support_args( array( 'initial' => true ) ); + $theme_supported_templates = array(); + if ( isset( $theme_support_args['templates_supported'] ) ) { + $theme_supported_templates = $theme_support_args['templates_supported']; + } + $supported_templates = AMP_Options_Manager::get_option( 'supported_templates' ); foreach ( $templates as $id => &$template ) { + + // Capture user-elected support from options. This allows us to preserve the original user selection through programmatic overrides. + $template['user_supported'] = in_array( $id, $supported_templates, true ); + + // Consider supported templates from theme support args. + if ( ! isset( $template['supported'] ) ) { + if ( 'all' === $theme_supported_templates ) { + $template['supported'] = true; + } elseif ( is_array( $theme_supported_templates ) && isset( $theme_supported_templates[ $id ] ) ) { + $template['supported'] = $theme_supported_templates[ $id ]; + } + } + + // Make supported state immutable if it was programmatically set. $template['immutable'] = isset( $template['supported'] ); + + // Set supported state from user preference. if ( ! $template['immutable'] ) { - $template['supported'] = AMP_Options_Manager::get_option( 'all_templates_supported' ) || in_array( $id, $supported_templates, true ); + $template['supported'] = AMP_Options_Manager::get_option( 'all_templates_supported' ) || $template['user_supported']; } } diff --git a/includes/options/class-amp-options-manager.php b/includes/options/class-amp-options-manager.php index 6dee88a3046..fd052b5f93d 100644 --- a/includes/options/class-amp-options-manager.php +++ b/includes/options/class-amp-options-manager.php @@ -24,7 +24,7 @@ class AMP_Options_Manager { */ protected static $defaults = array( 'theme_support' => 'disabled', - 'supported_post_types' => array( 'post' ), + 'supported_post_types' => array( 'post' ), // @todo Try updating from 0.7 to 1.0. 'analytics' => array(), 'force_sanitization' => false, 'accept_tree_shaking' => false, @@ -32,7 +32,7 @@ class AMP_Options_Manager { 'all_templates_supported' => true, 'unrecognized_templates_supported' => true, 'supported_templates' => array( - 'is_singular', + 'is_singular', // @todo Why? ), ); @@ -132,6 +132,7 @@ public static function validate_options( $new_options ) { $options['unrecognized_templates_supported'] = ! empty( $new_options['unrecognized_templates_supported'] ); } + // @todo Store associative array instead? // Validate post type support. $options['supported_post_types'] = array(); if ( isset( $new_options['supported_post_types'] ) ) { @@ -144,6 +145,7 @@ public static function validate_options( $new_options ) { } } + // @todo Store associative array instead. // Validate supported templates. $options['supported_templates'] = array(); if ( isset( $new_options['supported_templates'] ) ) { diff --git a/includes/options/class-amp-options-menu.php b/includes/options/class-amp-options-menu.php index da1ad1a895f..5c5b70557f5 100644 --- a/includes/options/class-amp-options-menu.php +++ b/includes/options/class-amp-options-menu.php @@ -419,14 +419,25 @@ private function list_template_conditional_options( $options, $parent = null ) { ?>
  • - - - > + + + > + + + + > + + + +