diff --git a/amp.php b/amp.php index 5e9d6acd192..56756588371 100644 --- a/amp.php +++ b/amp.php @@ -63,15 +63,6 @@ function amp_init() { add_rewrite_endpoint( AMP_QUERY_VAR, EP_PERMALINK ); add_post_type_support( 'post', AMP_QUERY_VAR ); - // Listen to post types settings. - $post_types_supported = AMP_Settings_Post_Types::get_instance()->get_settings_value(); - - foreach ( $post_types_supported as $post_type_name => $enabled ) { - if ( true === (bool) $enabled ) { - add_post_type_support( $post_type_name, AMP_QUERY_VAR ); - } - } - add_filter( 'request', 'amp_force_query_var_value' ); add_action( 'wp', 'amp_maybe_add_actions' ); diff --git a/includes/amp-helper-functions.php b/includes/amp-helper-functions.php index d9c5d86ea93..62568471a31 100644 --- a/includes/amp-helper-functions.php +++ b/includes/amp-helper-functions.php @@ -18,8 +18,11 @@ function amp_get_permalink( $post_id ) { } function post_supports_amp( $post ) { - // Because `add_rewrite_endpoint` doesn't let us target specific post_types :( - if ( ! post_type_supports( $post->post_type, AMP_QUERY_VAR ) ) { + // Listen to post types settings. + $is_enabled_via_setting = (bool) AMP_Settings_Post_Types::get_instance()->get_settings_value( $post->post_type ); + + // Because `add_rewrite_endpoint` doesn't let us target specific post_types. + if ( ! post_type_supports( $post->post_type, AMP_QUERY_VAR ) && true !== $is_enabled_via_setting ) { return false; } diff --git a/includes/settings/class-amp-settings-post-types.php b/includes/settings/class-amp-settings-post-types.php index 0ce2050c861..b53b6c0727b 100644 --- a/includes/settings/class-amp-settings-post-types.php +++ b/includes/settings/class-amp-settings-post-types.php @@ -24,13 +24,6 @@ class AMP_Settings_Post_Types { */ protected $setting = array(); - /** - * List of post types which are always AMPlified. - * - * @var array - */ - protected $always_on = array( 'post' ); - /** * Constructor. */ @@ -73,32 +66,17 @@ public function register_settings() { /** * Getter for settings value. * - * The value(s) return are not sanitized. - * * @param string $post_type The post type name. - * @return bool|array Return true if the post type is always on; the setting value otherwise. + * @return bool Return the setting value. */ - public function get_settings_value( $post_type = false ) { + public function get_settings_value( $post_type ) { $settings = get_option( AMP_Settings::SETTINGS_KEY, array() ); - if ( false !== $post_type ) { - // Always return true if the post type is always on. - if ( true === $this->is_always_on( $post_type ) ) { - return true; - } - - if ( isset( $settings[ $this->setting['id'] ][ $post_type ] ) ) { - return $settings[ $this->setting['id'] ][ $post_type ]; - } - - return false; + if ( isset( $settings[ $this->setting['id'] ][ $post_type ] ) ) { + return (bool) $settings[ $this->setting['id'] ][ $post_type ]; } - if ( empty( $settings[ $this->setting['id'] ] ) || ! is_array( $settings[ $this->setting['id'] ] ) ) { - return array(); - } - - return $settings[ $this->setting['id'] ]; + return false; } /** @@ -130,16 +108,6 @@ public function get_setting_name( $post_type ) { return AMP_Settings::SETTINGS_KEY . "[{$id}][{$post_type}]"; } - /** - * Check if a post type is always on. - * - * @param string $post_type The post type name. - * @return bool True if the post type is always on; false otherwise. - */ - public function is_always_on( $post_type ) { - return in_array( $post_type, $this->always_on, true ); - } - /** * Setting renderer. */ diff --git a/templates/admin/settings/fields/checkbox-post-types.php b/templates/admin/settings/fields/checkbox-post-types.php index 0bc1d8c0dde..e34166eb0ff 100644 --- a/templates/admin/settings/fields/checkbox-post-types.php +++ b/templates/admin/settings/fields/checkbox-post-types.php @@ -13,7 +13,7 @@