diff --git a/includes/admin/functions.php b/includes/admin/functions.php index ace4f332343..ba9ad3b7c55 100644 --- a/includes/admin/functions.php +++ b/includes/admin/functions.php @@ -6,6 +6,7 @@ */ use AmpProject\AmpWP\Admin\SiteHealth; +use AmpProject\AmpWP\Option; /** * Obsolete constant for flagging when Customizer is opened for AMP. @@ -22,7 +23,7 @@ * And this does not need to toggle between the AMP and normal display. */ function amp_init_customizer() { - if ( AMP_Theme_Support::READER_MODE_SLUG !== AMP_Options_Manager::get_option( 'theme_support' ) ) { + if ( AMP_Theme_Support::READER_MODE_SLUG !== AMP_Options_Manager::get_option( Option::THEME_SUPPORT ) ) { return; } diff --git a/includes/amp-helper-functions.php b/includes/amp-helper-functions.php index 01097193218..05b6ef58b32 100644 --- a/includes/amp-helper-functions.php +++ b/includes/amp-helper-functions.php @@ -5,6 +5,7 @@ * @package AMP */ +use AmpProject\AmpWP\Option; use AmpProject\AmpWP\Services; /** @@ -118,12 +119,12 @@ function amp_init() { /* * Broadcast plugin updates. - * Note that AMP_Options_Manager::get_option( 'version', '0.0' ) cannot be used because + * Note that AMP_Options_Manager::get_option( Option::VERSION, '0.0' ) cannot be used because * version was new option added, and in that case default would never be used for a site * upgrading from a version prior to 1.0. So this is why get_option() is currently used. */ $options = get_option( AMP_Options_Manager::OPTION_NAME, [] ); - $old_version = isset( $options['version'] ) ? $options['version'] : '0.0'; + $old_version = isset( $options[ Option::VERSION ] ) ? $options[ Option::VERSION ] : '0.0'; if ( AMP__VERSION !== $old_version && is_admin() && current_user_can( 'manage_options' ) ) { /** * Triggers when after amp_init when the plugin version has updated. @@ -131,7 +132,7 @@ function amp_init() { * @param string $old_version Old version. */ do_action( 'amp_plugin_update', $old_version ); - AMP_Options_Manager::update_option( 'version', AMP__VERSION ); + AMP_Options_Manager::update_option( Option::VERSION, AMP__VERSION ); } } @@ -948,7 +949,7 @@ function amp_filter_font_style_loader_tag_with_crossorigin_anonymous( $tag, $han * @return array Analytics. */ function amp_get_analytics( $analytics = [] ) { - $analytics_entries = AMP_Options_Manager::get_option( 'analytics', [] ); + $analytics_entries = AMP_Options_Manager::get_option( Option::ANALYTICS, [] ); /** * Add amp-analytics tags. diff --git a/includes/class-amp-post-type-support.php b/includes/class-amp-post-type-support.php index d307a3e7559..e1129a6a285 100644 --- a/includes/class-amp-post-type-support.php +++ b/includes/class-amp-post-type-support.php @@ -6,6 +6,8 @@ * @since 0.6 */ +use AmpProject\AmpWP\Option; + /** * Class AMP_Post_Type_Support. */ @@ -56,10 +58,10 @@ public static function get_eligible_post_types() { * @since 0.6 */ public static function add_post_type_support() { - if ( current_theme_supports( AMP_Theme_Support::SLUG ) && AMP_Options_Manager::get_option( 'all_templates_supported' ) ) { + if ( current_theme_supports( AMP_Theme_Support::SLUG ) && AMP_Options_Manager::get_option( Option::ALL_TEMPLATES_SUPPORTED ) ) { $post_types = self::get_eligible_post_types(); } else { - $post_types = AMP_Options_Manager::get_option( 'supported_post_types', [] ); + $post_types = AMP_Options_Manager::get_option( Option::SUPPORTED_POST_TYPES, [] ); } foreach ( $post_types as $post_type ) { add_post_type_support( $post_type, self::SLUG ); diff --git a/includes/class-amp-theme-support.php b/includes/class-amp-theme-support.php index 47170285c1b..4cd2d7452c9 100644 --- a/includes/class-amp-theme-support.php +++ b/includes/class-amp-theme-support.php @@ -6,6 +6,7 @@ */ use AmpProject\Amp; +use AmpProject\AmpWP\Option; use AmpProject\AmpWP\RemoteRequest\CachedRemoteGetRequest; use AmpProject\AmpWP\ConfigurationArgument; use AmpProject\AmpWP\Transformer; @@ -253,7 +254,7 @@ public static function read_theme_support() { self::$support_added_via_theme = null; self::$support_added_via_option = null; - $theme_support_option = AMP_Options_Manager::get_option( 'theme_support' ); + $theme_support_option = AMP_Options_Manager::get_option( Option::THEME_SUPPORT ); if ( current_theme_supports( self::SLUG ) ) { $args = self::get_theme_support_args(); @@ -282,7 +283,7 @@ public static function read_theme_support() { /* translators: 1: available_callback. 2: supported_templates */ esc_html__( 'The %1$s is deprecated when adding amp theme support in favor of declaratively setting the %2$s.', 'amp' ), 'available_callback', - 'supported_templates' + Option::SUPPORTED_TEMPLATES // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ), '1.0' ); @@ -669,7 +670,7 @@ public static function get_template_availability( $query = null ) { $all_templates_supported_by_theme_support = 'all' === $theme_support_args['templates_supported']; } $all_templates_supported = ( - $all_templates_supported_by_theme_support || AMP_Options_Manager::get_option( 'all_templates_supported' ) + $all_templates_supported_by_theme_support || AMP_Options_Manager::get_option( Option::ALL_TEMPLATES_SUPPORTED ) ); // Make sure global $wp_query is set in case of conditionals that unfortunately look at global scope. @@ -1008,7 +1009,7 @@ public static function get_supportable_templates() { $theme_supported_templates = $theme_support_args['templates_supported']; } - $supported_templates = AMP_Options_Manager::get_option( 'supported_templates' ); + $supported_templates = AMP_Options_Manager::get_option( 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. @@ -1028,7 +1029,7 @@ public static function get_supportable_templates() { // Set supported state from user preference. if ( ! $template['immutable'] ) { - $template['supported'] = AMP_Options_Manager::get_option( 'all_templates_supported' ) || $template['user_supported']; + $template['supported'] = AMP_Options_Manager::get_option( 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 429974c8a87..28096a8e6b5 100644 --- a/includes/options/class-amp-options-manager.php +++ b/includes/options/class-amp-options-manager.php @@ -25,12 +25,12 @@ class AMP_Options_Manager { * @var array */ protected static $defaults = [ - 'theme_support' => AMP_Theme_Support::READER_MODE_SLUG, - 'supported_post_types' => [ 'post' ], - 'analytics' => [], - 'all_templates_supported' => true, - 'supported_templates' => [ 'is_singular' ], - 'version' => AMP__VERSION, + Option::THEME_SUPPORT => AMP_Theme_Support::READER_MODE_SLUG, + Option::SUPPORTED_POST_TYPES => [ 'post' ], + Option::ANALYTICS => [], + Option::ALL_TEMPLATES_SUPPORTED => true, + Option::SUPPORTED_TEMPLATES => [ 'is_singular' ], + Option::VERSION => AMP__VERSION, ]; /** @@ -61,8 +61,8 @@ public static function register_settings() { * @param array $new_options New options. */ public static function maybe_flush_rewrite_rules( $old_options, $new_options ) { - $old_post_types = isset( $old_options['supported_post_types'] ) ? $old_options['supported_post_types'] : []; - $new_post_types = isset( $new_options['supported_post_types'] ) ? $new_options['supported_post_types'] : []; + $old_post_types = isset( $old_options[ Option::SUPPORTED_POST_TYPES ] ) ? $old_options[ Option::SUPPORTED_POST_TYPES ] : []; + $new_post_types = isset( $new_options[ Option::SUPPORTED_POST_TYPES ] ) ? $new_options[ Option::SUPPORTED_POST_TYPES ] : []; sort( $old_post_types ); sort( $new_post_types ); if ( $old_post_types !== $new_post_types ) { @@ -86,17 +86,17 @@ public static function get_options() { $defaults = self::$defaults; if ( current_theme_supports( 'amp' ) ) { - $defaults['theme_support'] = amp_is_canonical() ? AMP_Theme_Support::STANDARD_MODE_SLUG : AMP_Theme_Support::TRANSITIONAL_MODE_SLUG; + $defaults[ Option::THEME_SUPPORT ] = amp_is_canonical() ? AMP_Theme_Support::STANDARD_MODE_SLUG : AMP_Theme_Support::TRANSITIONAL_MODE_SLUG; } $options = array_merge( $defaults, $options ); // Migrate theme support slugs. - if ( 'native' === $options['theme_support'] ) { - $options['theme_support'] = AMP_Theme_Support::STANDARD_MODE_SLUG; - } elseif ( 'paired' === $options['theme_support'] ) { - $options['theme_support'] = AMP_Theme_Support::TRANSITIONAL_MODE_SLUG; - } elseif ( 'disabled' === $options['theme_support'] ) { + if ( 'native' === $options[ Option::THEME_SUPPORT ] ) { + $options[ Option::THEME_SUPPORT ] = AMP_Theme_Support::STANDARD_MODE_SLUG; + } elseif ( 'paired' === $options[ Option::THEME_SUPPORT ] ) { + $options[ Option::THEME_SUPPORT ] = AMP_Theme_Support::TRANSITIONAL_MODE_SLUG; + } elseif ( 'disabled' === $options[ Option::THEME_SUPPORT ] ) { /* * Prior to 1.2, the theme support slug for Reader mode was 'disabled'. This would be saved in options for * themes that had 'amp' theme support defined. Also prior to 1.2, the user could not switch between modes @@ -108,7 +108,7 @@ public static function get_options() { * become 'transitional'. Otherwise, if the theme lacks 'amp' theme support, then this will become the * default 'reader' mode. */ - $options['theme_support'] = $defaults['theme_support']; + $options[ Option::THEME_SUPPORT ] = $defaults[ Option::THEME_SUPPORT ]; } unset( @@ -117,28 +117,30 @@ public static function get_options() { * * @since 1.4.0 */ - $options['auto_accept_sanitization'], + $options[ Option::AUTO_ACCEPT_SANITIZATION ], /** * Remove Story related options. * + * Option::ENABLE_AMP_STORIES was added in 1.2-beta and later migrated into the `experiences` option. + * * @since 1.5.0 */ - $options['story_templates_version'], - $options['story_export_base_url'], - $options['story_settings'], - $options['enable_amp_stories'], // This was added in 1.2-beta and later migrated into the `experiences` option. + $options[ Option::STORY_TEMPLATES_VERSION ], + $options[ Option::STORY_EXPORT_BASE_URL ], + $options[ Option::STORY_SETTINGS ], + $options[ Option::ENABLE_AMP_STORIES ], /** * Remove 'experiences' option. * * @since 1.5.0 */ - $options['experiences'], + $options[ Option::EXPERIENCES ], /** * Remove 'enable_response_caching' option. * * @since 1.5.0 */ - $options['enable_response_caching'] + $options[ Option::ENABLE_RESPONSE_CACHING ] ); return $options; @@ -181,24 +183,24 @@ public static function validate_options( $new_options ) { AMP_Theme_Support::TRANSITIONAL_MODE_SLUG, AMP_Theme_Support::STANDARD_MODE_SLUG, ]; - if ( isset( $new_options['theme_support'] ) && in_array( $new_options['theme_support'], $recognized_theme_supports, true ) ) { - $options['theme_support'] = $new_options['theme_support']; + if ( isset( $new_options[ Option::THEME_SUPPORT ] ) && in_array( $new_options[ Option::THEME_SUPPORT ], $recognized_theme_supports, true ) ) { + $options[ Option::THEME_SUPPORT ] = $new_options[ Option::THEME_SUPPORT ]; // If this option was changed, display a notice with the new template mode. - if ( self::get_option( 'theme_support' ) !== $new_options['theme_support'] ) { + if ( self::get_option( Option::THEME_SUPPORT ) !== $new_options[ Option::THEME_SUPPORT ] ) { add_action( 'update_option_' . self::OPTION_NAME, [ __CLASS__, 'handle_updated_theme_support_option' ] ); } } // Validate post type support. - if ( isset( $new_options['supported_post_types'] ) ) { - $options['supported_post_types'] = []; + if ( isset( $new_options[ Option::SUPPORTED_POST_TYPES ] ) ) { + $options[ Option::SUPPORTED_POST_TYPES ] = []; - foreach ( $new_options['supported_post_types'] as $post_type ) { + foreach ( $new_options[ Option::SUPPORTED_POST_TYPES ] as $post_type ) { if ( ! post_type_exists( $post_type ) ) { add_settings_error( self::OPTION_NAME, 'unknown_post_type', __( 'Unrecognized post type.', 'amp' ) ); } else { - $options['supported_post_types'][] = $post_type; + $options[ Option::SUPPORTED_POST_TYPES ][] = $post_type; } } } @@ -207,21 +209,21 @@ public static function validate_options( $new_options ) { $is_template_support_required = ( isset( $theme_support_args['templates_supported'] ) && 'all' === $theme_support_args['templates_supported'] ); if ( ! $is_template_support_required && ! isset( $theme_support_args['available_callback'] ) ) { - $options['all_templates_supported'] = ! empty( $new_options['all_templates_supported'] ); + $options[ Option::ALL_TEMPLATES_SUPPORTED ] = ! empty( $new_options[ Option::ALL_TEMPLATES_SUPPORTED ] ); // Validate supported templates. - $options['supported_templates'] = []; - if ( isset( $new_options['supported_templates'] ) ) { - $options['supported_templates'] = array_intersect( - $new_options['supported_templates'], + $options[ Option::SUPPORTED_TEMPLATES ] = []; + if ( isset( $new_options[ Option::SUPPORTED_TEMPLATES ] ) ) { + $options[ Option::SUPPORTED_TEMPLATES ] = array_intersect( + $new_options[ Option::SUPPORTED_TEMPLATES ], array_keys( AMP_Theme_Support::get_supportable_templates() ) ); } } // Validate analytics. - if ( isset( $new_options['analytics'] ) ) { - foreach ( $new_options['analytics'] as $id => $data ) { + if ( isset( $new_options[ Option::ANALYTICS ] ) ) { + foreach ( $new_options[ Option::ANALYTICS ] as $id => $data ) { // Check save/delete pre-conditions and proceed if correct. if ( empty( $data['type'] ) || empty( $data['config'] ) ) { @@ -247,16 +249,16 @@ public static function validate_options( $new_options ) { $entry_id = substr( md5( $entry_vendor_type . $entry_config ), 0, 12 ); // Avoid duplicates. - if ( isset( $options['analytics'][ $entry_id ] ) ) { + if ( isset( $options[ Option::ANALYTICS ][ $entry_id ] ) ) { add_settings_error( self::OPTION_NAME, 'duplicate_analytics_entry', __( 'Duplicate analytics entry found.', 'amp' ) ); continue; } } if ( isset( $data['delete'] ) ) { - unset( $options['analytics'][ $entry_id ] ); + unset( $options[ Option::ANALYTICS ][ $entry_id ] ); } else { - $options['analytics'][ $entry_id ] = [ + $options[ Option::ANALYTICS ][ $entry_id ] = [ 'type' => $entry_vendor_type, 'config' => $entry_config, ]; @@ -271,7 +273,7 @@ public static function validate_options( $new_options ) { } // Store the current version with the options so we know the format. - $options['version'] = AMP__VERSION; + $options[ Option::VERSION ] = AMP__VERSION; return $options; } @@ -284,11 +286,11 @@ public static function validate_options( $new_options ) { */ public static function check_supported_post_type_update_errors() { // If all templates are supported then skip check since all post types are also supported. This option only applies with standard/transitional theme support. - if ( self::get_option( 'all_templates_supported', false ) && AMP_Theme_Support::READER_MODE_SLUG !== self::get_option( 'theme_support' ) ) { + if ( self::get_option( Option::ALL_TEMPLATES_SUPPORTED, false ) && AMP_Theme_Support::READER_MODE_SLUG !== self::get_option( Option::THEME_SUPPORT ) ) { return; } - $supported_types = self::get_option( 'supported_post_types', [] ); + $supported_types = self::get_option( Option::SUPPORTED_POST_TYPES, [] ); foreach ( AMP_Post_Type_Support::get_eligible_post_types() as $name ) { $post_type = get_post_type_object( $name ); if ( empty( $post_type ) ) { @@ -354,8 +356,8 @@ public static function handle_analytics_submit() { // Ensure request is coming from analytics option form. check_admin_referer( 'analytics-options', 'analytics-options' ); - if ( isset( $_POST['amp-options']['analytics'] ) ) { - self::update_option( 'analytics', wp_unslash( $_POST['amp-options']['analytics'] ) ); + if ( isset( $_POST[ self::OPTION_NAME ][ Option::ANALYTICS ] ) ) { + self::update_option( Option::ANALYTICS, wp_unslash( $_POST[ self::OPTION_NAME ][ Option::ANALYTICS ] ) ); $errors = get_settings_errors( self::OPTION_NAME ); if ( empty( $errors ) ) { @@ -383,7 +385,7 @@ public static function handle_analytics_submit() { */ public static function update_analytics_options( $data ) { _deprecated_function( __METHOD__, '0.6', __CLASS__ . '::update_option' ); - return self::update_option( 'analytics', wp_unslash( $data ) ); + return self::update_option( Option::ANALYTICS, wp_unslash( $data ) ); } /** @@ -537,7 +539,7 @@ public static function insecure_connection_notice() { * Adds a message for an update of the theme support setting. */ public static function handle_updated_theme_support_option() { - $template_mode = self::get_option( 'theme_support' ); + $template_mode = self::get_option( Option::THEME_SUPPORT ); // Make sure post type support has been added for sake of amp_admin_get_preview_permalink(). foreach ( AMP_Post_Type_Support::get_eligible_post_types() as $post_type ) { diff --git a/includes/options/class-amp-options-menu.php b/includes/options/class-amp-options-menu.php index da9638354ae..b313a63b0cc 100644 --- a/includes/options/class-amp-options-menu.php +++ b/includes/options/class-amp-options-menu.php @@ -5,6 +5,8 @@ * @package AMP */ +use AmpProject\AmpWP\Option; + /** * AMP_Options_Menu class. */ @@ -80,7 +82,7 @@ public function add_menu_items() { ); add_settings_field( - 'theme_support', + Option::THEME_SUPPORT, __( 'Template Mode', 'amp' ), [ $this, 'render_theme_support' ], AMP_Options_Manager::OPTION_NAME, @@ -91,7 +93,7 @@ public function add_menu_items() { ); add_settings_field( - 'supported_templates', + Option::SUPPORTED_TEMPLATES, __( 'Supported Templates', 'amp' ), [ $this, 'render_supported_templates' ], AMP_Options_Manager::OPTION_NAME, @@ -246,7 +248,7 @@ public function render_supported_templates() {

@@ -272,7 +274,7 @@ public function render_supported_templates() {

diff --git a/includes/options/views/class-amp-analytics-options-submenu-page.php b/includes/options/views/class-amp-analytics-options-submenu-page.php index 17eb250eb27..2d5f9521b45 100644 --- a/includes/options/views/class-amp-analytics-options-submenu-page.php +++ b/includes/options/views/class-amp-analytics-options-submenu-page.php @@ -5,6 +5,8 @@ * @package AMP */ +use AmpProject\AmpWP\Option; + /** * Class AMP_Analytics_Options_Submenu_Page */ @@ -186,7 +188,7 @@ protected function render_scripts() { public function render() { $this->render_styles(); - $analytics_entries = AMP_Options_Manager::get_option( 'analytics', [] ); + $analytics_entries = AMP_Options_Manager::get_option( Option::ANALYTICS, [] ); $this->render_title( ! empty( $analytics_entries ) ); diff --git a/includes/settings/class-amp-customizer-design-settings.php b/includes/settings/class-amp-customizer-design-settings.php index 154f732fe08..f345d93d159 100644 --- a/includes/settings/class-amp-customizer-design-settings.php +++ b/includes/settings/class-amp-customizer-design-settings.php @@ -5,6 +5,8 @@ * @package AMP */ +use AmpProject\AmpWP\Option; + /** * Class AMP_Customizer_Design_Settings */ @@ -41,7 +43,7 @@ class AMP_Customizer_Design_Settings { */ public static function is_amp_customizer_enabled() { - if ( AMP_Theme_Support::READER_MODE_SLUG !== AMP_Options_Manager::get_option( 'theme_support' ) ) { + if ( AMP_Theme_Support::READER_MODE_SLUG !== AMP_Options_Manager::get_option( Option::THEME_SUPPORT ) ) { return false; } diff --git a/src/Admin/SiteHealth.php b/src/Admin/SiteHealth.php index 519e01699c3..10a75bd157f 100644 --- a/src/Admin/SiteHealth.php +++ b/src/Admin/SiteHealth.php @@ -409,7 +409,7 @@ public function add_debug_information( $debugging_information ) { * @return string The supported template(s), in a comma-separated string. */ private function get_supported_templates() { - $possible_post_types = AMP_Options_Manager::get_option( 'supported_post_types' ); + $possible_post_types = AMP_Options_Manager::get_option( Option::SUPPORTED_POST_TYPES ); // Get the supported content types, like 'post'. $supported_templates = array_filter( @@ -461,7 +461,7 @@ private function get_serve_all_templates() { } // Not translated, as this is debugging information, and it could be confusing getting this from different languages. - return AMP_Options_Manager::get_option( 'all_templates_supported' ) ? 'true' : 'false'; + return AMP_Options_Manager::get_option( Option::ALL_TEMPLATES_SUPPORTED ) ? 'true' : 'false'; } /** diff --git a/src/Option.php b/src/Option.php index b5428ac66cf..f32ec0878cf 100644 --- a/src/Option.php +++ b/src/Option.php @@ -10,16 +10,144 @@ /** * An interface to share knowledge about options stored in the AMP Options Manager. * - * @todo Other options used throughout the plugin should use constants in this interface as well. - * * @package AmpProject\AmpWP */ interface Option { + /** + * Serve all templates as AMP regardless of what is being queried. + * + * Default value: true + * + * @var string + */ + const ALL_TEMPLATES_SUPPORTED = 'all_templates_supported'; + + /** + * List of JSON objects that should be injected into the component. + * + * @see https://developers.google.com/analytics/devguides/collection/amp-analytics/ + * + * Default value: [] + * + * @var string + */ + const ANALYTICS = 'analytics'; + /** * Persist the fact that the transient caching of stylesheets needs to be disabled. * * @var string */ const DISABLE_CSS_TRANSIENT_CACHING = 'amp_css_transient_monitor_disable_caching'; + + /** + * The list of post types that have support for AMP. + * + * The provided value should be an array of WordPress post-type slugs. + * + * Default value: [ 'post' ] + * + * @var string + */ + const SUPPORTED_POST_TYPES = 'supported_post_types'; + + /** + * List of WordPress template conditionals to define what templates are supported by AMP. + * + * Default value: [ 'is_singular' ] + * + * @var string + */ + const SUPPORTED_TEMPLATES = 'supported_templates'; + + /** + * The template mode that is being used for AMP support. + * + * Currently valid values are: + * - AMP_Theme_Support::STANDARD_MODE_SLUG + * - AMP_Theme_Support::TRANSITIONAL_MODE_SLUG + * - AMP_Theme_Support::READER_MODE_SLUG + * + * Default value: AMP_Theme_Support::READER_MODE_SLUG + * + * @var string + */ + const THEME_SUPPORT = 'theme_support'; + + /** + * Version of the AMP plugin for which the options were last saved. + * + * This allows for recognizing updates and triggering update-specific logic. + * + * @var string + */ + const VERSION = 'version'; + + // ---------------------- Deprecated options down below ---------------------- // + + /** + * Whether to accept or reject sanitization results by default. + * + * @deprecated Removed with version 1.4.0 + * + * @var string + */ + const AUTO_ACCEPT_SANITIZATION = 'auto_accept_sanitization'; + + /** + * Whether the AMP stories experience is enabled. + * + * @deprecated Removed with version 1.5.0 + * + * @var string + */ + const ENABLE_AMP_STORIES = 'enable_amp_stories'; + + /** + * Whether responses should be statically cached. + * + * @deprecated Removed with version 1.5.0 + * + * @var string + */ + const ENABLE_RESPONSE_CACHING = 'enable_response_caching'; + + /** + * List of AMP experiences that are currently active. + * + * @deprecated Removed with version 1.5.0 + * + * @var string + */ + const EXPERIENCES = 'experiences'; + + /** + * Base URL to use when exporting a story to the file system. + * + * @deprecated Removed with version 1.5.0 + * + * @var string + */ + const STORY_EXPORT_BASE_URL = 'story_export_base_url'; + + /** + * Settings for the AMP stories experience. + * + * @deprecated Removed with version 1.5.0 + * + * @var string + */ + const STORY_SETTINGS = 'story_settings'; + + /** + * Version string at which the story templates were generated and persisted. + * + * This allows for recognizing story template updates and triggering update-specific logic. + * + * @deprecated Removed with version 1.5.0 + * + * @var string + */ + const STORY_TEMPLATES_VERSION = 'story_templates_version'; } diff --git a/tests/php/test-amp-analytics-options.php b/tests/php/test-amp-analytics-options.php index cf98ad2c030..5bb0f498329 100644 --- a/tests/php/test-amp-analytics-options.php +++ b/tests/php/test-amp-analytics-options.php @@ -1,5 +1,6 @@ compact( 'type', 'config' ), ] diff --git a/tests/php/test-amp-helper-functions.php b/tests/php/test-amp-helper-functions.php index 9376a8ee06a..364852c864c 100644 --- a/tests/php/test-amp-helper-functions.php +++ b/tests/php/test-amp-helper-functions.php @@ -5,6 +5,7 @@ * @package AMP */ +use AmpProject\AmpWP\Option; use AmpProject\AmpWP\Tests\AssertContainsCompatibility; use AmpProject\AmpWP\Tests\HandleValidation; @@ -436,7 +437,7 @@ function( $provider ) { */ public function test_amp_add_amphtml_link_transitional_mode( $data_provider ) { list( $canonical_url, $amphtml_url, $available ) = $data_provider(); - AMP_Options_Manager::update_option( 'theme_support', AMP_Theme_Support::TRANSITIONAL_MODE_SLUG ); + AMP_Options_Manager::update_option( Option::THEME_SUPPORT, AMP_Theme_Support::TRANSITIONAL_MODE_SLUG ); $this->accept_sanitization_by_default( false ); AMP_Theme_Support::read_theme_support(); AMP_Theme_Support::init(); @@ -529,8 +530,8 @@ public function test_is_amp_endpoint() { * Simulate a user unchecking almost all of the boxes in 'AMP Settings' > 'Supported Templates'. * The user has chosen not to show them as AMP, so most URLs should not be AMP endpoints. */ - AMP_Options_Manager::update_option( 'all_templates_supported', false ); - AMP_Options_Manager::update_option( 'supported_templates', [ 'is_author' ] ); + AMP_Options_Manager::update_option( Option::ALL_TEMPLATES_SUPPORTED, false ); + AMP_Options_Manager::update_option( Option::SUPPORTED_TEMPLATES, [ 'is_author' ] ); // A post shouldn't be an AMP endpoint, as it was unchecked in the UI via the options above. $this->go_to( self::factory()->post->create() ); diff --git a/tests/php/test-class-amp-cli-validation-command.php b/tests/php/test-class-amp-cli-validation-command.php index c8df06b1695..4f48fcb5485 100644 --- a/tests/php/test-class-amp-cli-validation-command.php +++ b/tests/php/test-class-amp-cli-validation-command.php @@ -5,6 +5,7 @@ * @package AMP */ +use AmpProject\AmpWP\Option; use AmpProject\AmpWP\Tests\AssertContainsCompatibility; use AmpProject\AmpWP\Tests\PrivateAccess; @@ -162,7 +163,7 @@ public function test_does_taxonomy_support_amp() { $custom_taxonomy = 'foo_custom_taxonomy'; register_taxonomy( $custom_taxonomy, 'post' ); $taxonomies_to_test = [ $custom_taxonomy, 'category', 'post_tag' ]; - AMP_Options_Manager::update_option( 'supported_templates', [ 'is_category', 'is_tag', sprintf( 'is_tax[%s]', $custom_taxonomy ) ] ); + AMP_Options_Manager::update_option( Option::SUPPORTED_TEMPLATES, [ 'is_category', 'is_tag', sprintf( 'is_tax[%s]', $custom_taxonomy ) ] ); // When these templates are not unchecked in the 'AMP Settings' UI, these should be supported. foreach ( $taxonomies_to_test as $taxonomy ) { @@ -170,8 +171,8 @@ public function test_does_taxonomy_support_amp() { } // When the user has not checked the boxes for 'Categories' and 'Tags,' this should be false. - AMP_Options_Manager::update_option( 'supported_templates', [ 'is_author' ] ); - AMP_Options_Manager::update_option( 'all_templates_supported', false ); + AMP_Options_Manager::update_option( Option::SUPPORTED_TEMPLATES, [ 'is_author' ] ); + AMP_Options_Manager::update_option( Option::ALL_TEMPLATES_SUPPORTED, false ); foreach ( $taxonomies_to_test as $taxonomy ) { $this->assertFalse( $this->call_private_method( $this->validation, 'does_taxonomy_support_amp', [ $taxonomy ] ) ); } @@ -183,12 +184,12 @@ public function test_does_taxonomy_support_amp() { } $this->validation->force_crawl_urls = false; - // When the user has checked the 'all_templates_supported' box, this should always be true. - AMP_Options_Manager::update_option( 'all_templates_supported', true ); + // When the user has checked the Option::ALL_TEMPLATES_SUPPORTED box, this should always be true. + AMP_Options_Manager::update_option( Option::ALL_TEMPLATES_SUPPORTED, true ); foreach ( $taxonomies_to_test as $taxonomy ) { $this->assertTrue( $this->call_private_method( $this->validation, 'does_taxonomy_support_amp', [ $taxonomy ] ) ); } - AMP_Options_Manager::update_option( 'all_templates_supported', false ); + AMP_Options_Manager::update_option( Option::ALL_TEMPLATES_SUPPORTED, false ); /* * If the user passed allowed conditionals to the WP-CLI command like wp amp validate-site --include=is_category,is_tag @@ -211,12 +212,12 @@ public function test_is_template_supported() { $author_conditional = 'is_author'; $search_conditional = 'is_search'; - AMP_Options_Manager::update_option( 'supported_templates', [ $author_conditional ] ); - AMP_Options_Manager::update_option( 'all_templates_supported', false ); + AMP_Options_Manager::update_option( Option::SUPPORTED_TEMPLATES, [ $author_conditional ] ); + AMP_Options_Manager::update_option( Option::ALL_TEMPLATES_SUPPORTED, false ); $this->assertTrue( $this->call_private_method( $this->validation, 'is_template_supported', [ $author_conditional ] ) ); $this->assertFalse( $this->call_private_method( $this->validation, 'is_template_supported', [ $search_conditional ] ) ); - AMP_Options_Manager::update_option( 'supported_templates', [ $search_conditional ] ); + AMP_Options_Manager::update_option( Option::SUPPORTED_TEMPLATES, [ $search_conditional ] ); $this->assertTrue( $this->call_private_method( $this->validation, 'is_template_supported', [ $search_conditional ] ) ); $this->assertFalse( $this->call_private_method( $this->validation, 'is_template_supported', [ $author_conditional ] ) ); } diff --git a/tests/php/test-class-amp-customizer-design-settings.php b/tests/php/test-class-amp-customizer-design-settings.php index 4f9d1b7be20..22ab324c558 100644 --- a/tests/php/test-class-amp-customizer-design-settings.php +++ b/tests/php/test-class-amp-customizer-design-settings.php @@ -5,6 +5,8 @@ * @package AMP */ +use AmpProject\AmpWP\Option; + /** * Class Test_AMP_Customizer_Design_Settings * @@ -23,10 +25,10 @@ public static function setUpBeforeClass() { * @covers AMP_Customizer_Design_Settings::is_amp_customizer_enabled */ public function test_is_amp_customizer_enabled() { - AMP_Options_Manager::update_option( 'theme_support', 'foo' ); + AMP_Options_Manager::update_option( Option::THEME_SUPPORT, 'foo' ); $this->assertEquals( false, AMP_Customizer_Design_Settings::is_amp_customizer_enabled() ); - AMP_Options_Manager::update_option( 'theme_support', AMP_Theme_Support::READER_MODE_SLUG ); + AMP_Options_Manager::update_option( Option::THEME_SUPPORT, AMP_Theme_Support::READER_MODE_SLUG ); $this->assertEquals( true, AMP_Customizer_Design_Settings::is_amp_customizer_enabled() ); add_filter( 'amp_customizer_is_enabled', '__return_false' ); diff --git a/tests/php/test-class-amp-meta-box.php b/tests/php/test-class-amp-meta-box.php index 1f07ab3389d..357f8f7940a 100644 --- a/tests/php/test-class-amp-meta-box.php +++ b/tests/php/test-class-amp-meta-box.php @@ -5,6 +5,7 @@ * @package AMP */ +use AmpProject\AmpWP\Option; use AmpProject\AmpWP\Tests\AssertContainsCompatibility; /** @@ -209,7 +210,7 @@ public function test_render_status() { // No template is available to render the post. add_filter( 'amp_supportable_templates', '__return_empty_array' ); - AMP_Options_Manager::update_option( 'all_templates_supported', false ); + AMP_Options_Manager::update_option( Option::ALL_TEMPLATES_SUPPORTED, false ); $output = get_echo( [ $this->instance, 'render_status' ], [ $post ] ); $this->assertStringContains( 'no supported templates to display this in AMP.', wp_strip_all_tags( $output ) ); $this->assertStringNotContains( $checkbox_enabled, $output ); @@ -266,7 +267,7 @@ public function test_get_status_and_errors() { // There's no template to render this post, so this method should also return AMP as disabled. add_filter( 'amp_supportable_templates', '__return_empty_array' ); - AMP_Options_Manager::update_option( 'all_templates_supported', false ); + AMP_Options_Manager::update_option( Option::ALL_TEMPLATES_SUPPORTED, false ); $this->assertEquals( [ 'status' => 'disabled', diff --git a/tests/php/test-class-amp-options-manager.php b/tests/php/test-class-amp-options-manager.php index 367178d7645..8b906f63eef 100644 --- a/tests/php/test-class-amp-options-manager.php +++ b/tests/php/test-class-amp-options-manager.php @@ -5,6 +5,7 @@ * @package AMP */ +use AmpProject\AmpWP\Option; use AmpProject\AmpWP\Tests\AssertContainsCompatibility; /** @@ -68,7 +69,7 @@ public function test_maybe_flush_rewrite_rules() { // Check change to supported_post_types. update_option( 'rewrite_rules', $dummy_rewrite_rules ); AMP_Options_Manager::maybe_flush_rewrite_rules( - [ 'supported_post_types' => [ 'page' ] ], + [ Option::SUPPORTED_POST_TYPES => [ 'page' ] ], [] ); $this->assertEmpty( get_option( 'rewrite_rules' ) ); @@ -78,8 +79,8 @@ public function test_maybe_flush_rewrite_rules() { update_option( AMP_Options_Manager::OPTION_NAME, [ - [ 'supported_post_types' => [ 'page' ] ], - [ 'supported_post_types' => [ 'page' ] ], + [ Option::SUPPORTED_POST_TYPES => [ 'page' ] ], + [ Option::SUPPORTED_POST_TYPES => [ 'page' ] ], ] ); $this->assertEquals( $dummy_rewrite_rules, get_option( 'rewrite_rules' ) ); @@ -113,12 +114,12 @@ public function test_get_and_set_options() { delete_option( AMP_Options_Manager::OPTION_NAME ); $this->assertEquals( [ - 'theme_support' => AMP_Theme_Support::READER_MODE_SLUG, - 'supported_post_types' => [ 'post' ], - 'analytics' => [], - 'all_templates_supported' => true, - 'supported_templates' => [ 'is_singular' ], - 'version' => AMP__VERSION, + Option::THEME_SUPPORT => AMP_Theme_Support::READER_MODE_SLUG, + Option::SUPPORTED_POST_TYPES => [ 'post' ], + Option::ANALYTICS => [], + Option::ALL_TEMPLATES_SUPPORTED => true, + Option::SUPPORTED_TEMPLATES => [ 'is_singular' ], + Option::VERSION => AMP__VERSION, ], AMP_Options_Manager::get_options() ); @@ -126,19 +127,19 @@ public function test_get_and_set_options() { $this->assertSame( 'default', AMP_Options_Manager::get_option( 'foo', 'default' ) ); // Test supported_post_types validation. - AMP_Options_Manager::update_option( 'supported_post_types', [ 'post', 'page', 'attachment' ] ); + AMP_Options_Manager::update_option( Option::SUPPORTED_POST_TYPES, [ 'post', 'page', 'attachment' ] ); $this->assertSame( [ 'post', 'page', 'attachment', ], - AMP_Options_Manager::get_option( 'supported_post_types' ) + AMP_Options_Manager::get_option( Option::SUPPORTED_POST_TYPES ) ); // Test analytics validation with missing fields. AMP_Options_Manager::update_option( - 'analytics', + Option::ANALYTICS, [ 'bad' => [], ] @@ -149,7 +150,7 @@ public function test_get_and_set_options() { // Test analytics validation with bad JSON. AMP_Options_Manager::update_option( - 'analytics', + Option::ANALYTICS, [ '__new__' => [ 'type' => 'foo', @@ -163,7 +164,7 @@ public function test_get_and_set_options() { // Test analytics validation with good fields. AMP_Options_Manager::update_option( - 'analytics', + Option::ANALYTICS, [ '__new__' => [ 'type' => 'foo', @@ -175,7 +176,7 @@ public function test_get_and_set_options() { // Test analytics validation with duplicate check. AMP_Options_Manager::update_option( - 'analytics', + Option::ANALYTICS, [ '__new__' => [ 'type' => 'foo', @@ -188,7 +189,7 @@ public function test_get_and_set_options() { $wp_settings_errors = []; // Confirm format of entry ID. - $entries = AMP_Options_Manager::get_option( 'analytics' ); + $entries = AMP_Options_Manager::get_option( Option::ANALYTICS ); $entry = current( $entries ); $id = substr( md5( $entry['type'] . $entry['config'] ), 0, 12 ); $this->assertArrayHasKey( $id, $entries ); @@ -197,7 +198,7 @@ public function test_get_and_set_options() { // Confirm adding another entry works. AMP_Options_Manager::update_option( - 'analytics', + Option::ANALYTICS, [ '__new__' => [ 'type' => 'bar', @@ -205,13 +206,13 @@ public function test_get_and_set_options() { ], ] ); - $entries = AMP_Options_Manager::get_option( 'analytics' ); - $this->assertCount( 2, AMP_Options_Manager::get_option( 'analytics' ) ); + $entries = AMP_Options_Manager::get_option( Option::ANALYTICS ); + $this->assertCount( 2, AMP_Options_Manager::get_option( Option::ANALYTICS ) ); $this->assertArrayHasKey( $id, $entries ); // Confirm updating an entry works. AMP_Options_Manager::update_option( - 'analytics', + Option::ANALYTICS, [ $id => [ 'id' => $id, @@ -220,13 +221,13 @@ public function test_get_and_set_options() { ], ] ); - $entries = AMP_Options_Manager::get_option( 'analytics' ); + $entries = AMP_Options_Manager::get_option( Option::ANALYTICS ); $this->assertEquals( 'foo', $entries[ $id ]['type'] ); $this->assertEquals( '{"very_good":true}', $entries[ $id ]['config'] ); // Confirm deleting an entry works. AMP_Options_Manager::update_option( - 'analytics', + Option::ANALYTICS, [ $id => [ 'id' => $id, @@ -236,7 +237,7 @@ public function test_get_and_set_options() { ], ] ); - $entries = AMP_Options_Manager::get_option( 'analytics' ); + $entries = AMP_Options_Manager::get_option( Option::ANALYTICS ); $this->assertCount( 1, $entries ); $this->assertArrayNotHasKey( $id, $entries ); } @@ -279,14 +280,14 @@ public function get_test_get_options_defaults_data() { null, AMP_Theme_Support::STANDARD_MODE_SLUG, [ - 'theme_support' => 'native', + Option::THEME_SUPPORT => 'native', ], ], 'standard_via_native' => [ null, AMP_Theme_Support::TRANSITIONAL_MODE_SLUG, [ - 'theme_support' => 'paired', + Option::THEME_SUPPORT => 'paired', ], ], 'standard_upon_upgrade' => [ @@ -295,7 +296,7 @@ public function get_test_get_options_defaults_data() { ], AMP_Theme_Support::STANDARD_MODE_SLUG, [ - 'theme_support' => 'disabled', + Option::THEME_SUPPORT => 'disabled', ], ], 'transitional_upon_upgrade' => [ @@ -304,7 +305,7 @@ public function get_test_get_options_defaults_data() { ], AMP_Theme_Support::TRANSITIONAL_MODE_SLUG, [ - 'theme_support' => 'disabled', + Option::THEME_SUPPORT => 'disabled', ], ], ]; @@ -326,7 +327,7 @@ public function test_get_options_theme_support_defaults( $args, $expected_mode, if ( isset( $args ) ) { add_theme_support( 'amp', $args ); } - $this->assertEquals( $expected_mode, AMP_Options_Manager::get_option( 'theme_support' ) ); + $this->assertEquals( $expected_mode, AMP_Options_Manager::get_option( Option::THEME_SUPPORT ) ); } /** @@ -347,30 +348,30 @@ public function test_check_supported_post_type_update_errors() { ); AMP_Post_Type_Support::add_post_type_support(); - // Test when 'all_templates_supported' is selected. - AMP_Options_Manager::update_option( 'theme_support', AMP_Theme_Support::STANDARD_MODE_SLUG ); - AMP_Options_Manager::update_option( 'all_templates_supported', true ); - AMP_Options_Manager::update_option( 'supported_post_types', [ 'post' ] ); + // Test when Option::ALL_TEMPLATES_SUPPORTED is selected. + AMP_Options_Manager::update_option( Option::THEME_SUPPORT, AMP_Theme_Support::STANDARD_MODE_SLUG ); + AMP_Options_Manager::update_option( Option::ALL_TEMPLATES_SUPPORTED, true ); + AMP_Options_Manager::update_option( Option::SUPPORTED_POST_TYPES, [ 'post' ] ); AMP_Options_Manager::check_supported_post_type_update_errors(); $this->assertEmpty( get_settings_errors() ); - // Test when 'all_templates_supported' is not selected. - AMP_Options_Manager::update_option( 'theme_support', AMP_Theme_Support::STANDARD_MODE_SLUG ); - AMP_Options_Manager::update_option( 'all_templates_supported', false ); + // Test when Option::ALL_TEMPLATES_SUPPORTED is not selected. + AMP_Options_Manager::update_option( Option::THEME_SUPPORT, AMP_Theme_Support::STANDARD_MODE_SLUG ); + AMP_Options_Manager::update_option( Option::ALL_TEMPLATES_SUPPORTED, false ); foreach ( get_post_types() as $post_type ) { if ( 'foo' !== $post_type ) { remove_post_type_support( $post_type, AMP_Post_Type_Support::SLUG ); } } - AMP_Options_Manager::update_option( 'supported_post_types', [ 'foo' ] ); + AMP_Options_Manager::update_option( Option::SUPPORTED_POST_TYPES, [ 'foo' ] ); AMP_Options_Manager::check_supported_post_type_update_errors(); $this->assertEmpty( get_settings_errors() ); - // Test when 'all_templates_supported' is not selected, and theme support is also disabled. + // Test when Option::ALL_TEMPLATES_SUPPORTED is not selected, and theme support is also disabled. add_post_type_support( 'post', AMP_Post_Type_Support::SLUG ); - AMP_Options_Manager::update_option( 'theme_support', AMP_Theme_Support::READER_MODE_SLUG ); - AMP_Options_Manager::update_option( 'all_templates_supported', false ); - AMP_Options_Manager::update_option( 'supported_post_types', [ 'post' ] ); + AMP_Options_Manager::update_option( Option::THEME_SUPPORT, AMP_Theme_Support::READER_MODE_SLUG ); + AMP_Options_Manager::update_option( Option::ALL_TEMPLATES_SUPPORTED, false ); + AMP_Options_Manager::update_option( Option::SUPPORTED_POST_TYPES, [ 'post' ] ); AMP_Options_Manager::check_supported_post_type_update_errors(); $settings_errors = get_settings_errors(); $wp_settings_errors = []; @@ -380,8 +381,8 @@ public function test_check_supported_post_type_update_errors() { // Activation error. remove_post_type_support( 'post', AMP_Post_Type_Support::SLUG ); remove_post_type_support( 'foo', AMP_Post_Type_Support::SLUG ); - AMP_Options_Manager::update_option( 'supported_post_types', [ 'foo' ] ); - AMP_Options_Manager::update_option( 'theme_support', AMP_Theme_Support::READER_MODE_SLUG ); + AMP_Options_Manager::update_option( Option::SUPPORTED_POST_TYPES, [ 'foo' ] ); + AMP_Options_Manager::update_option( Option::THEME_SUPPORT, AMP_Theme_Support::READER_MODE_SLUG ); AMP_Options_Manager::check_supported_post_type_update_errors(); $settings_errors = get_settings_errors(); $this->assertCount( 1, $settings_errors ); @@ -390,7 +391,7 @@ public function test_check_supported_post_type_update_errors() { $wp_settings_errors = []; // Deactivation error. - AMP_Options_Manager::update_option( 'supported_post_types', [] ); + AMP_Options_Manager::update_option( Option::SUPPORTED_POST_TYPES, [] ); add_post_type_support( 'foo', AMP_Post_Type_Support::SLUG ); AMP_Options_Manager::check_supported_post_type_update_errors(); $errors = get_settings_errors(); @@ -438,8 +439,8 @@ public function test_handle_updated_theme_support_option_disabled() { AMP_Validation_Manager::init(); $page_id = self::factory()->post->create( [ 'post_type' => 'page' ] ); - AMP_Options_Manager::update_option( 'supported_post_types', [ 'page' ] ); - AMP_Options_Manager::update_option( 'theme_support', AMP_Theme_Support::READER_MODE_SLUG ); + AMP_Options_Manager::update_option( Option::SUPPORTED_POST_TYPES, [ 'page' ] ); + AMP_Options_Manager::update_option( Option::THEME_SUPPORT, AMP_Theme_Support::READER_MODE_SLUG ); AMP_Options_Manager::handle_updated_theme_support_option(); $amp_settings_errors = get_settings_errors( AMP_Options_Manager::OPTION_NAME ); $new_error = end( $amp_settings_errors ); @@ -458,8 +459,8 @@ public function test_handle_updated_theme_support_option_standard_success_but_er wp_set_current_user( self::factory()->user->create( [ 'role' => 'administrator' ] ) ); $post_id = self::factory()->post->create( [ 'post_type' => 'post' ] ); - AMP_Options_Manager::update_option( 'theme_support', AMP_Theme_Support::STANDARD_MODE_SLUG ); - AMP_Options_Manager::update_option( 'supported_post_types', [ 'post' ] ); + AMP_Options_Manager::update_option( Option::THEME_SUPPORT, AMP_Theme_Support::STANDARD_MODE_SLUG ); + AMP_Options_Manager::update_option( Option::SUPPORTED_POST_TYPES, [ 'post' ] ); $filter = static function() { $validation = [ @@ -503,8 +504,8 @@ public function test_handle_updated_theme_support_option_standard_validate_error wp_set_current_user( self::factory()->user->create( [ 'role' => 'administrator' ] ) ); self::factory()->post->create( [ 'post_type' => 'post' ] ); - AMP_Options_Manager::update_option( 'theme_support', AMP_Theme_Support::STANDARD_MODE_SLUG ); - AMP_Options_Manager::update_option( 'supported_post_types', [ 'post' ] ); + AMP_Options_Manager::update_option( Option::THEME_SUPPORT, AMP_Theme_Support::STANDARD_MODE_SLUG ); + AMP_Options_Manager::update_option( Option::SUPPORTED_POST_TYPES, [ 'post' ] ); $filter = static function() { return [ @@ -538,8 +539,8 @@ public function test_handle_updated_theme_support_option_paired() { wp_set_current_user( self::factory()->user->create( [ 'role' => 'administrator' ] ) ); $post_id = self::factory()->post->create( [ 'post_type' => 'post' ] ); - AMP_Options_Manager::update_option( 'theme_support', AMP_Theme_Support::TRANSITIONAL_MODE_SLUG ); - AMP_Options_Manager::update_option( 'supported_post_types', [ 'post' ] ); + AMP_Options_Manager::update_option( Option::THEME_SUPPORT, AMP_Theme_Support::TRANSITIONAL_MODE_SLUG ); + AMP_Options_Manager::update_option( Option::SUPPORTED_POST_TYPES, [ 'post' ] ); $filter = static function() { $validation = [ diff --git a/tests/php/test-class-amp-options-menu.php b/tests/php/test-class-amp-options-menu.php index af2fdacaea8..0db71b5a0d0 100644 --- a/tests/php/test-class-amp-options-menu.php +++ b/tests/php/test-class-amp-options-menu.php @@ -5,6 +5,7 @@ * @package AMP */ +use AmpProject\AmpWP\Option; use AmpProject\AmpWP\Tests\AssertContainsCompatibility; /** @@ -85,7 +86,7 @@ public function test_add_menu_items() { // Test add_setting_field(). $this->assertArrayHasKey( 'amp-options', $wp_settings_fields ); $this->assertArrayHasKey( 'general', $wp_settings_fields['amp-options'] ); - $this->assertArrayHasKey( 'supported_templates', $wp_settings_fields['amp-options']['general'] ); + $this->assertArrayHasKey( Option::SUPPORTED_TEMPLATES, $wp_settings_fields['amp-options']['general'] ); $this->assertArrayNotHasKey( 'stories_settings', $wp_settings_fields['amp-options']['general'] ); } diff --git a/tests/php/test-class-amp-post-type-support.php b/tests/php/test-class-amp-post-type-support.php index 18a269013f9..c36ea3bf948 100644 --- a/tests/php/test-class-amp-post-type-support.php +++ b/tests/php/test-class-amp-post-type-support.php @@ -6,6 +6,8 @@ * @since 0.6 */ +use AmpProject\AmpWP\Option; + /** * Tests for Post Type Support. * @@ -76,7 +78,7 @@ public function test_add_post_type_support() { 'public' => true, ] ); - AMP_Options_Manager::update_option( 'supported_post_types', [ 'post', 'poem' ] ); + AMP_Options_Manager::update_option( Option::SUPPORTED_POST_TYPES, [ 'post', 'poem' ] ); AMP_Post_Type_Support::add_post_type_support(); $this->assertTrue( post_type_supports( 'post', AMP_Post_Type_Support::SLUG ) ); diff --git a/tests/php/test-class-amp-theme-support.php b/tests/php/test-class-amp-theme-support.php index aae58284e1d..5ac5823396b 100644 --- a/tests/php/test-class-amp-theme-support.php +++ b/tests/php/test-class-amp-theme-support.php @@ -7,6 +7,7 @@ */ use AmpProject\AmpWP\ConfigurationArgument; +use AmpProject\AmpWP\Option; use AmpProject\AmpWP\Tests\AssertContainsCompatibility; use AmpProject\AmpWP\Tests\PrivateAccess; use AmpProject\Dom\Document; @@ -155,7 +156,7 @@ public function test_read_theme_support_and_support_args() { AMP_Theme_Support::SLUG, [ AMP_Theme_Support::PAIRED_FLAG => false ] ); - $this->assertEquals( AMP_Theme_Support::STANDARD_MODE_SLUG, AMP_Options_Manager::get_option( 'theme_support' ) ); + $this->assertEquals( AMP_Theme_Support::STANDARD_MODE_SLUG, AMP_Options_Manager::get_option( Option::THEME_SUPPORT ) ); AMP_Theme_Support::read_theme_support(); $this->assertEquals( AMP_Theme_Support::STANDARD_MODE_SLUG, AMP_Theme_Support::get_support_mode() ); add_theme_support( @@ -167,13 +168,13 @@ public function test_read_theme_support_and_support_args() { // Test that reader mode being set via option overrides theme support flag. add_theme_support( AMP_Theme_Support::SLUG ); - AMP_Options_Manager::update_option( 'theme_support', AMP_Theme_Support::READER_MODE_SLUG ); // Will override the theme support flag. + AMP_Options_Manager::update_option( Option::THEME_SUPPORT, AMP_Theme_Support::READER_MODE_SLUG ); // Will override the theme support flag. AMP_Theme_Support::read_theme_support(); $this->assertSame( AMP_Theme_Support::READER_MODE_SLUG, AMP_Theme_Support::get_support_mode() ); // Test that Standard mode in theme does not override Transitional mode set via option (user option prevails). add_theme_support( AMP_Theme_Support::SLUG ); - AMP_Options_Manager::update_option( 'theme_support', AMP_Theme_Support::TRANSITIONAL_MODE_SLUG ); + AMP_Options_Manager::update_option( Option::THEME_SUPPORT, AMP_Theme_Support::TRANSITIONAL_MODE_SLUG ); AMP_Theme_Support::read_theme_support(); $this->assertSame( AMP_Theme_Support::TRANSITIONAL_MODE_SLUG, AMP_Theme_Support::get_support_mode() ); @@ -184,7 +185,7 @@ public function test_read_theme_support_and_support_args() { 'comments_live_list' => true, ]; add_theme_support( AMP_Theme_Support::SLUG, $args ); - AMP_Options_Manager::update_option( 'theme_support', AMP_Theme_Support::STANDARD_MODE_SLUG ); // Will override the theme support flag. + AMP_Options_Manager::update_option( Option::THEME_SUPPORT, AMP_Theme_Support::STANDARD_MODE_SLUG ); // Will override the theme support flag. AMP_Theme_Support::read_theme_support(); $this->assertEquals( array_merge( @@ -202,7 +203,7 @@ public function test_read_theme_support_and_support_args() { // Test that standard via theme does not trump transitional option. add_theme_support( AMP_Theme_Support::SLUG ); - AMP_Options_Manager::update_option( 'theme_support', AMP_Theme_Support::TRANSITIONAL_MODE_SLUG ); // Will be ignored since standard in theme overrides transitional option. + AMP_Options_Manager::update_option( Option::THEME_SUPPORT, AMP_Theme_Support::TRANSITIONAL_MODE_SLUG ); // Will be ignored since standard in theme overrides transitional option. AMP_Theme_Support::read_theme_support(); $this->assertTrue( current_theme_supports( AMP_Theme_Support::SLUG ) ); $this->assertSame( AMP_Theme_Support::TRANSITIONAL_MODE_SLUG, AMP_Theme_Support::get_support_mode_added_via_option() ); @@ -212,7 +213,7 @@ public function test_read_theme_support_and_support_args() { // Test that no support via theme can be overridden with option. remove_theme_support( AMP_Theme_Support::SLUG ); - AMP_Options_Manager::update_option( 'theme_support', AMP_Theme_Support::STANDARD_MODE_SLUG ); + AMP_Options_Manager::update_option( Option::THEME_SUPPORT, AMP_Theme_Support::STANDARD_MODE_SLUG ); AMP_Theme_Support::read_theme_support(); $this->assertNull( AMP_Theme_Support::get_support_mode_added_via_theme() ); $this->assertSame( AMP_Theme_Support::STANDARD_MODE_SLUG, AMP_Theme_Support::get_support_mode_added_via_option() ); @@ -220,7 +221,7 @@ public function test_read_theme_support_and_support_args() { // Test that no support via theme can be overridden with option. remove_theme_support( AMP_Theme_Support::SLUG ); - AMP_Options_Manager::update_option( 'theme_support', AMP_Theme_Support::TRANSITIONAL_MODE_SLUG ); + AMP_Options_Manager::update_option( Option::THEME_SUPPORT, AMP_Theme_Support::TRANSITIONAL_MODE_SLUG ); AMP_Theme_Support::read_theme_support(); $this->assertNull( AMP_Theme_Support::get_support_mode_added_via_theme() ); $this->assertSame( AMP_Theme_Support::TRANSITIONAL_MODE_SLUG, AMP_Theme_Support::get_support_mode_added_via_option() ); @@ -718,7 +719,7 @@ public function test_get_template_availability() { // Test successful match of singular template. $this->assertTrue( is_singular() ); - AMP_Options_Manager::update_option( 'all_templates_supported', false ); + AMP_Options_Manager::update_option( Option::ALL_TEMPLATES_SUPPORTED, false ); add_theme_support( AMP_Theme_Support::SLUG ); $availability = AMP_Theme_Support::get_template_availability(); $this->assertEmpty( $availability['errors'] ); @@ -738,7 +739,7 @@ public function test_get_template_availability() { $this->assertNull( $wp_query ); // Make sure it is reset. // Test nested hierarchy. - AMP_Options_Manager::update_option( 'supported_templates', [ 'is_special', 'is_custom' ] ); + AMP_Options_Manager::update_option( Option::SUPPORTED_TEMPLATES, [ 'is_special', 'is_custom' ] ); add_filter( 'amp_supportable_templates', static function( $templates ) { @@ -827,7 +828,7 @@ static function( $vars ) { * @covers AMP_Theme_Support::get_template_availability() */ public function test_get_template_availability_with_ambiguity() { - AMP_Options_Manager::update_option( 'all_templates_supported', true ); + AMP_Options_Manager::update_option( Option::ALL_TEMPLATES_SUPPORTED, true ); add_theme_support( AMP_Theme_Support::SLUG ); $custom_post_type = 'book'; register_post_type( @@ -869,7 +870,7 @@ public function test_get_template_availability_with_ambiguity() { * @covers AMP_Theme_Support::get_template_availability() */ public function test_get_template_availability_with_missing_parent() { - AMP_Options_Manager::update_option( 'supported_templates', [ 'missing_parent' ] ); + AMP_Options_Manager::update_option( Option::SUPPORTED_TEMPLATES, [ 'missing_parent' ] ); add_theme_support( AMP_Theme_Support::SLUG ); add_filter( 'amp_supportable_templates', @@ -931,7 +932,7 @@ public function test_get_supportable_templates() { // Test default case with non-static front page. update_option( 'show_on_front', 'posts' ); - AMP_Options_Manager::update_option( 'all_templates_supported', true ); + AMP_Options_Manager::update_option( Option::ALL_TEMPLATES_SUPPORTED, true ); $supportable_templates = AMP_Theme_Support::get_supportable_templates(); foreach ( $supportable_templates as $id => $supportable_template ) { $this->assertNotInternalType( 'numeric', $id ); @@ -1001,14 +1002,14 @@ static function( $templates ) { remove_all_filters( 'amp_supportable_templates' ); // Test supporting templates by theme support args: all. - AMP_Options_Manager::update_option( 'all_templates_supported', false ); + AMP_Options_Manager::update_option( Option::ALL_TEMPLATES_SUPPORTED, false ); add_theme_support( AMP_Theme_Support::SLUG, [ 'templates_supported' => 'all', ] ); - AMP_Options_Manager::update_option( 'theme_support', AMP_Theme_Support::STANDARD_MODE_SLUG ); + AMP_Options_Manager::update_option( Option::THEME_SUPPORT, AMP_Theme_Support::STANDARD_MODE_SLUG ); AMP_Theme_Support::read_theme_support(); AMP_Theme_Support::init(); @@ -1019,7 +1020,7 @@ static function( $templates ) { } // Test supporting templates by theme support args: selective templates. - AMP_Options_Manager::update_option( 'all_templates_supported', false ); + AMP_Options_Manager::update_option( Option::ALL_TEMPLATES_SUPPORTED, false ); add_theme_support( AMP_Theme_Support::SLUG, [ diff --git a/tests/php/test-class-site-health.php b/tests/php/test-class-site-health.php index 25617250367..30d37a341ed 100644 --- a/tests/php/test-class-site-health.php +++ b/tests/php/test-class-site-health.php @@ -287,9 +287,9 @@ public function get_supported_templates_data() { * @param string $expected The expected string of supported templates. */ public function test_get_supported_templates( $supported_content_types, $supported_templates, $theme_support, $expected ) { - AMP_Options_Manager::update_option( 'all_templates_supported', false ); - AMP_Options_Manager::update_option( 'supported_templates', $supported_templates ); - AMP_Options_Manager::update_option( 'theme_support', $theme_support ); + AMP_Options_Manager::update_option( Option::ALL_TEMPLATES_SUPPORTED, false ); + AMP_Options_Manager::update_option( Option::SUPPORTED_TEMPLATES, $supported_templates ); + AMP_Options_Manager::update_option( Option::THEME_SUPPORT, $theme_support ); AMP_Theme_Support::read_theme_support(); $basic_post_types = [ 'post', 'page' ]; @@ -355,8 +355,8 @@ public function get_serve_all_templates_data() { * @param string $expected The expected return value. */ public function test_get_serve_all_templates( $theme_support, $do_serve_all_templates, $expected ) { - AMP_Options_Manager::update_option( 'theme_support', $theme_support ); - AMP_Options_Manager::update_option( 'all_templates_supported', $do_serve_all_templates ); + AMP_Options_Manager::update_option( Option::THEME_SUPPORT, $theme_support ); + AMP_Options_Manager::update_option( Option::ALL_TEMPLATES_SUPPORTED, $do_serve_all_templates ); AMP_Theme_Support::read_theme_support(); $this->assertEquals( $expected, $this->call_private_method( $this->instance, 'get_serve_all_templates' ) ); diff --git a/tests/php/validation/test-class-amp-validation-manager.php b/tests/php/validation/test-class-amp-validation-manager.php index 47fc427240e..211ccd91870 100644 --- a/tests/php/validation/test-class-amp-validation-manager.php +++ b/tests/php/validation/test-class-amp-validation-manager.php @@ -7,6 +7,7 @@ // phpcs:disable Generic.Formatting.MultipleStatementAlignment.NotSameWarning +use AmpProject\AmpWP\Option; use AmpProject\AmpWP\Tests\AssertContainsCompatibility; use AmpProject\AmpWP\Tests\HandleValidation; use AmpProject\AmpWP\Tests\PrivateAccess; @@ -309,12 +310,12 @@ public function test_add_admin_bar_menu_items() { wp_set_current_user( self::factory()->user->create( [ 'role' => 'administrator' ] ) ); $this->assertTrue( AMP_Validation_Manager::has_cap() ); add_filter( 'amp_supportable_templates', '__return_empty_array' ); - AMP_Options_Manager::update_option( 'all_templates_supported', false ); + AMP_Options_Manager::update_option( Option::ALL_TEMPLATES_SUPPORTED, false ); $admin_bar = new WP_Admin_Bar(); AMP_Validation_Manager::add_admin_bar_menu_items( $admin_bar ); $this->assertNull( $admin_bar->get_node( 'amp' ) ); remove_filter( 'amp_supportable_templates', '__return_empty_array' ); - AMP_Options_Manager::update_option( 'all_templates_supported', true ); + AMP_Options_Manager::update_option( Option::ALL_TEMPLATES_SUPPORTED, true ); // Admin bar item available in AMP-first mode. add_theme_support( AMP_Theme_Support::SLUG, [ AMP_Theme_Support::PAIRED_FLAG => false ] );