Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rebrand Classic as Reader mode and Paired as Transitional mode; add Exit Reader Mode link #2034

Merged
merged 19 commits into from
Apr 6, 2019
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
3418a56
Rebrand Classic mode as Reader mode.
felixarntz Mar 28, 2019
7d2c9ac
Add link for exiting reader mode to reader mode templates.
felixarntz Mar 28, 2019
33a4cb4
Fix incorrect screenshot numbering in readme.
felixarntz Mar 28, 2019
d5cdd94
Update reader mode description.
felixarntz Apr 1, 2019
089fc62
Restore spaces in readme.
felixarntz Apr 1, 2019
09df6d8
Rebrand Paired as Transitional mode.
felixarntz Apr 1, 2019
982bf65
Introduce Customizer UI for controlling reader mode exit link and mak…
felixarntz Apr 1, 2019
5f58a72
Merge branch 'develop' of github.com:ampproject/amp-wp into add/reade…
westonruter Apr 5, 2019
c269707
Update mode descriptions
westonruter Apr 5, 2019
b360935
Prevent showing any reader Customizer settings when AMP theme support…
westonruter Apr 5, 2019
11ea84c
Reuse rest_sanitize_boolean function instead of adding sanitize_boole…
westonruter Apr 5, 2019
611f53c
Fix position of exit reader link when site icon present
westonruter Apr 5, 2019
5df747d
Revert changes to legacy 0.3 templates since obsolete
westonruter Apr 5, 2019
297e668
Merge branch 'develop' of github.com:ampproject/amp-wp into add/reade…
westonruter Apr 5, 2019
e35d629
Add note about dev work being needed for non-reader mode
westonruter Apr 5, 2019
a35e51f
Add clarification about mobile redirections
amedina Apr 6, 2019
c007f2f
Update screenshots and squooshify
westonruter Apr 6, 2019
cabdf2b
Always include amp-wp-canonical-link style in customizer preview
westonruter Apr 6, 2019
8026f7a
Update behavior description in readme
westonruter Apr 6, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions amp.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ function amp_force_query_var_value( $query_vars ) {
}

/**
* Conditionally add AMP actions or render the 'paired mode' template(s).
* Conditionally add AMP actions or render the transitional mode template(s).
*
* If the request is for an AMP page and this is in 'canonical mode,' redirect to the non-AMP page.
* It won't need this plugin's template system, nor the frontend actions like the 'rel' link.
Expand All @@ -327,7 +327,7 @@ function amp_maybe_add_actions() {
return;
}

// The remaining logic here is for paired mode running in themes that don't support AMP, the template system in AMP<=0.6.
// The remaining logic here is for transitional mode running in themes that don't support AMP, the template system in AMP<=0.6.
global $wp_query;
if ( ! ( is_singular() || $wp_query->is_posts_page ) || is_feed() ) {
return;
Expand All @@ -344,7 +344,7 @@ function amp_maybe_add_actions() {
if ( ! post_supports_amp( $post ) ) {
if ( $is_amp_endpoint ) {
/*
* Temporary redirect is used for admin users because classic mode and AMP support can be enabled by user at any time,
* Temporary redirect is used for admin users because reader mode and AMP support can be enabled by user at any time,
* so they will be able to make AMP available for this URL and see the change without wrestling with the redirect cache.
*/
wp_safe_redirect( get_permalink( $post->ID ), current_user_can( 'manage_options' ) ? 302 : 301 );
Expand Down Expand Up @@ -417,13 +417,13 @@ function amp_correct_query_when_is_front_page( WP_Query $query ) {
* add_theme_support( AMP_Theme_Support::SLUG );
*
* This will serve templates in native AMP, allowing you to use AMP components in your theme templates.
* If you want to make available in paired mode, where templates are served in AMP or non-AMP documents, do:
* If you want to make available in transitional mode, where templates are served in AMP or non-AMP documents, do:
*
* add_theme_support( AMP_Theme_Support::SLUG, array(
* 'paired' => true,
* ) );
*
* Paired mode is also implied if you define a template_dir:
* Transitional mode is also implied if you define a template_dir:
*
* add_theme_support( AMP_Theme_Support::SLUG, array(
* 'template_dir' => 'amp',
Expand Down Expand Up @@ -464,7 +464,7 @@ function amp_is_canonical() {
return empty( $args['paired'] );
}

// If there is a template_dir, then paired mode is implied.
// If there is a template_dir, then transitional mode is implied.
return empty( $args['template_dir'] );
}

Expand Down
9 changes: 8 additions & 1 deletion back-compat/templates-v0-3/header-bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* @package AMP
*/

$site_icon_url = $this->get( 'site_icon_url' );
$site_icon_url = $this->get( 'site_icon_url' );
$canonical_link_url = $this->get( 'post_canonical_link_url' );
?>

<nav class="amp-wp-title-bar">
Expand All @@ -17,5 +18,11 @@

<?php echo esc_html( $this->get( 'blog_name' ) ); ?>
</a>
<?php if ( $canonical_link_url ) : ?>
<?php $canonical_link_text = $this->get( 'post_canonical_link_text' ); ?>
<a class="amp-wp-canonical-link" href="<?php echo esc_url( $canonical_link_url ); ?>">
<?php echo esc_html( $canonical_link_text ); ?>
</a>
<?php endif; ?>
</div>
</nav>
7 changes: 7 additions & 0 deletions back-compat/templates-v0-3/style.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@
}

nav.amp-wp-title-bar div {
display: flex;
justify-content: space-between;
line-height: 54px;
color: <?php echo esc_html( $this->get_customizer_setting( 'navbar_color', self::DEFAULT_NAVBAR_COLOR ) ); ?>;
}
Expand All @@ -202,6 +204,11 @@
text-decoration: none;
}

nav.amp-wp-title-bar .amp-wp-canonical-link {
font-size: 20px;
text-decoration: underline;
}

nav.amp-wp-title-bar .amp-wp-site-icon {
/** site icon is 32px **/
float: left;
Expand Down
2 changes: 1 addition & 1 deletion includes/admin/class-amp-admin-pointer.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function get_pointer_data() {
'<h3>%s</h3><p><strong>%s</strong></p><p>%s</p>',
__( 'AMP', 'amp' ),
__( 'New AMP Template Modes', 'amp' ),
__( 'You can now reuse your theme\'s templates and styles in AMP responses, in both &#8220;Paired&#8221; and &#8220;Native&#8221; modes.', 'amp' )
__( 'You can now reuse your theme\'s templates and styles in AMP responses, in both &#8220;Transitional&#8221; and &#8220;Native&#8221; modes.', 'amp' )
),
'position' => array(
'edge' => 'left',
Expand Down
2 changes: 1 addition & 1 deletion includes/admin/class-amp-editor-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function init() {
* then the non-AMP blog page need to load the AMP runtime scripts so that the AMP components
* in the posts displayed there will be rendered properly. This is only relevant on native AMP
* sites because the AMP Gutenberg blocks are only made available in that mode; they are not
* presented in the Gutenberg inserter in paired mode. In general, using AMP components in
* presented in the Gutenberg inserter in transitional mode. In general, using AMP components in
* non-AMP documents is still not officially supported, so it's occurrence is being minimized
* as much as possible. For more, see <https://github.com/ampproject/amp-wp/issues/1192>.
*/
Expand Down
10 changes: 5 additions & 5 deletions includes/amp-helper-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ function post_supports_amp( $post ) {
* This function cannot be called before the parse_query action because it needs to be able
* to determine the queried object is able to be served as AMP. If 'amp' theme support is not
* present, this function returns true just if the query var is present. If theme support is
* present, then it returns true in paired mode if an AMP template is available and the query
* present, then it returns true in transitional mode if an AMP template is available and the query
* var is present, or else in native mode if just the template is available.
*
* @return bool Whether it is the AMP endpoint.
Expand Down Expand Up @@ -372,9 +372,9 @@ function amp_add_generator_metadata() {
if ( amp_is_canonical() ) {
$mode = 'native';
} elseif ( current_theme_supports( AMP_Theme_Support::SLUG ) ) {
$mode = 'paired';
$mode = 'transitional';
} else {
$mode = 'classic';
$mode = 'reader';
}
printf( '<meta name="generator" content="%s">', esc_attr( sprintf( 'AMP Plugin v%s; mode=%s', AMP__VERSION, $mode ) ) );
}
Expand Down Expand Up @@ -566,7 +566,7 @@ function amp_filter_script_loader_tag( $tag, $handle ) {
*
* This explicitly triggers a CORS request, and gets back a non-opaque response, ensuring that a service
* worker caching the external stylesheet will not inflate the storage quota. This must be done in AMP
* and non-AMP alike because in paired mode the service worker could cache the font stylesheets in a
* and non-AMP alike because in transitional mode the service worker could cache the font stylesheets in a
* non-AMP document without CORS (crossorigin="anonymous") in which case the service worker could then
* fail to serve the cached font resources in an AMP document with the warning:
*
Expand Down Expand Up @@ -619,7 +619,7 @@ function amp_get_analytics( $analytics = array() ) {
* Add amp-analytics tags.
*
* This filter allows you to easily insert any amp-analytics tags without needing much heavy lifting.
* This filter should be used to alter entries for paired mode.
* This filter should be used to alter entries for transitional mode.
*
* @since 0.7
*
Expand Down
2 changes: 1 addition & 1 deletion includes/class-amp-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public function validate_site( $args, $assoc_args ) {
} else {
WP_CLI::error(
sprintf(
'The current template mode is Classic, which does not allow crawling the site. Please pass the --%s flag in order to force crawling for validation.',
'Your templates are currently in Reader mode, which does not allow crawling the site. Please pass the --%s flag in order to force crawling for validation.',
self::FLAG_NAME_FORCE_VALIDATION
)
);
Expand Down
12 changes: 6 additions & 6 deletions includes/class-amp-theme-support.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public static function finish_init() {
if ( ! is_amp_endpoint() ) {
/*
* Redirect to AMP-less variable if AMP is not available for this URL and yet the query var is present.
* Temporary redirect is used for admin users because implied paired mode and template support can be
* Temporary redirect is used for admin users because implied transitional mode and template support can be
* enabled by user ay any time, so they will be able to make AMP available for this URL and see the change
* without wrestling with the redirect cache.
*/
Expand Down Expand Up @@ -305,16 +305,16 @@ public static function ensure_proper_amp_location( $exit = true ) {
}
} else {
/*
* When in AMP paired mode *with* theme support, then the proper AMP URL has the 'amp' URL param
* and not the /amp/ endpoint. The URL param is now the exclusive way to mark AMP in paired mode
* When in AMP transitional mode *with* theme support, then the proper AMP URL has the 'amp' URL param
* and not the /amp/ endpoint. The URL param is now the exclusive way to mark AMP in transitional mode
* when amp theme support present. This is important for plugins to be able to reliably call
* is_amp_endpoint() before the parse_query action.
*/
if ( $has_query_var && ! $has_url_param ) {
$old_url = amp_get_current_url();
$new_url = add_query_arg( amp_get_slug(), '', amp_remove_endpoint( $old_url ) );
if ( $old_url !== $new_url ) {
// A temporary redirect is used for admin users to allow them to see changes between classic and paired modes.
// A temporary redirect is used for admin users to allow them to see changes between reader mode and transitional modes.
wp_safe_redirect( $new_url, current_user_can( 'manage_options' ) ? 302 : 301 );
// @codeCoverageIgnoreStart
if ( $exit ) {
Expand Down Expand Up @@ -358,7 +358,7 @@ public static function redirect_non_amp_url( $status = 302, $exit = true ) {
}

/**
* Determines whether paired mode is available.
* Determines whether transitional mode is available.
*
* When 'amp' theme support has not been added or canonical mode is enabled, then this returns false.
*
Expand Down Expand Up @@ -1075,7 +1075,7 @@ public static function amend_comment_form() {
}

/**
* Prepends template hierarchy with template_dir for AMP paired mode templates.
* Prepends template hierarchy with template_dir for AMP transitional mode templates.
*
* @param array $templates Template hierarchy.
* @return array Templates.
Expand Down
8 changes: 4 additions & 4 deletions includes/options/class-amp-options-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ 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 native/paired theme support.
// If all templates are supported then skip check since all post types are also supported. This option only applies with native/transitional theme support.
if ( self::get_option( 'all_templates_supported', false ) && 'disabled' !== self::get_option( 'theme_support' ) ) {
return;
}
Expand Down Expand Up @@ -521,7 +521,7 @@ public static function handle_updated_theme_support_option() {
$theme_support['paired'] = 'paired' === $template_mode;
add_theme_support( AMP_Theme_Support::SLUG, $theme_support );
} else {
remove_theme_support( AMP_Theme_Support::SLUG ); // So that the amp_get_permalink() will work for classic URL.
remove_theme_support( AMP_Theme_Support::SLUG ); // So that the amp_get_permalink() will work for reader mode URL.
}

$url = amp_admin_get_preview_permalink();
Expand Down Expand Up @@ -639,7 +639,7 @@ public static function handle_updated_theme_support_option() {
}
break;
case 'paired':
$message = esc_html__( 'Paired mode activated!', 'amp' );
$message = esc_html__( 'Transitional mode activated!', 'amp' );
if ( $review_messages ) {
$message .= ' ' . join( ' ', $review_messages );
}
Expand All @@ -648,7 +648,7 @@ public static function handle_updated_theme_support_option() {
$message = wp_kses_post(
sprintf(
/* translators: %s is an AMP URL */
__( 'Classic mode activated! View the <a href="%s">AMP version of a recent post</a>. It is recommended that you upgrade to Native or Paired mode.', 'amp' ),
__( 'Reader mode activated! View the <a href="%s">AMP version of a recent post</a>. It is recommended that you upgrade to Native or Transitional mode.', 'amp' ),
esc_url( $url )
)
);
Expand Down
28 changes: 15 additions & 13 deletions includes/options/class-amp-options-menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,11 @@ public function add_menu_items() {
* @since 1.0
*/
public function render_theme_support() {
$theme_support = AMP_Options_Manager::get_option( 'theme_support' );
$native_description = __( 'Reuses active theme\'s templates to display AMP responses but does not use separate URLs for AMP. This means your site is <b>AMP-first</b> and your canonical URLs are AMP.', 'amp' );
$paired_description = __( 'Reuses active theme\'s templates to display AMP responses, but uses separate URLs for AMP. Each canonical URL may have a corresponding AMP URL, if the content is fully AMP valid.', 'amp' );
$theme_support = AMP_Options_Manager::get_option( 'theme_support' );

$native_description = __( 'Integrates AMP as the framework for your site, using the active’s theme templates and styles to render AMP responses. This means your site is <b>AMP-first</b> and your canonical URLs are AMP! Depending on your theme/plugins, some development work may be required.', 'amp' );
$transitional_description = __( 'Generates AMP content reusing the active theme’s templates, allowing for each canonical URL to have a corresponding (paired) AMP URL. Depending on your theme/plugins, some development work may be required.', 'amp' );
$reader_description = __( 'Formerly called the <b>classic mode</b>, this mode generates paired AMP content using simplified templates which may not match the look-and-feel of your site. Only posts/pages can be served as AMP in Reader mode. No redirection is performed for mobile visitors; AMP pages are served by AMP consumption platforms.', 'amp' );

$builtin_support = in_array( get_template(), AMP_Core_Theme_Sanitizer::get_supported_themes(), true );
?>
Expand All @@ -153,15 +155,15 @@ public function render_theme_support() {
<strong><?php esc_html_e( 'Native:', 'amp' ); ?></strong>
<?php echo wp_kses_post( $native_description ); ?>
<?php else : ?>
<strong><?php esc_html_e( 'Paired:', 'amp' ); ?></strong>
<?php echo wp_kses_post( $paired_description ); ?>
<strong><?php esc_html_e( 'Transitional:', 'amp' ); ?></strong>
<?php echo wp_kses_post( $transitional_description ); ?>
<?php endif; ?>
</p>
<?php else : ?>
<fieldset <?php disabled( ! current_user_can( 'manage_options' ) ); ?>>
<?php if ( $builtin_support ) : ?>
<div class="notice notice-success notice-alt inline">
<p><?php esc_html_e( 'Your active theme is known to work well in paired or native mode.', 'amp' ); ?></p>
<p><?php esc_html_e( 'Your active theme is known to work well in transitional or native mode.', 'amp' ); ?></p>
</div>
<?php endif; ?>
<dl>
Expand All @@ -175,22 +177,22 @@ public function render_theme_support() {
<?php echo wp_kses_post( $native_description ); ?>
</dd>
<dt>
<input type="radio" id="theme_support_paired" name="<?php echo esc_attr( AMP_Options_Manager::OPTION_NAME . '[theme_support]' ); ?>" value="paired" <?php checked( $theme_support, 'paired' ); ?>>
<label for="theme_support_paired">
<strong><?php esc_html_e( 'Paired', 'amp' ); ?></strong>
<input type="radio" id="theme_support_transitional" name="<?php echo esc_attr( AMP_Options_Manager::OPTION_NAME . '[theme_support]' ); ?>" value="paired" <?php checked( $theme_support, 'paired' ); ?>>
<label for="theme_support_transitional">
<strong><?php esc_html_e( 'Transitional', 'amp' ); ?></strong>
</label>
</dt>
<dd>
<?php echo wp_kses_post( $paired_description ); ?>
<?php echo wp_kses_post( $transitional_description ); ?>
</dd>
<dt>
<input type="radio" id="theme_support_disabled" name="<?php echo esc_attr( AMP_Options_Manager::OPTION_NAME . '[theme_support]' ); ?>" value="disabled" <?php checked( $theme_support, 'disabled' ); ?>>
<label for="theme_support_disabled">
<strong><?php esc_html_e( 'Classic', 'amp' ); ?></strong>
<strong><?php esc_html_e( 'Reader', 'amp' ); ?></strong>
</label>
</dt>
<dd>
<?php esc_html_e( 'Display AMP responses in classic (legacy) post templates in a basic design that does not match your theme\'s templates.', 'amp' ); ?>
<?php echo wp_kses_post( $reader_description ); ?>

<?php if ( ! current_theme_supports( AMP_Theme_Support::SLUG ) && wp_count_posts( AMP_Validated_URL_Post_Type::POST_TYPE_SLUG )->publish > 0 ) : ?>
<div class="notice notice-info inline notice-alt">
Expand All @@ -199,7 +201,7 @@ public function render_theme_support() {
echo wp_kses_post(
sprintf(
/* translators: %1$s is link to invalid URLs and %2$s is link to validation errors */
__( 'View current site compatibility results for native and paired modes: %1$s and %2$s.', 'amp' ),
__( 'View current site compatibility results for native and transitional modes: %1$s and %2$s.', 'amp' ),
sprintf(
'<a href="%s">%s</a>',
esc_url( add_query_arg( 'post_type', AMP_Validated_URL_Post_Type::POST_TYPE_SLUG, admin_url( 'edit.php' ) ) ),
Expand Down
32 changes: 31 additions & 1 deletion includes/settings/class-amp-customizer-design-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,17 @@ class AMP_Customizer_Design_Settings {
/**
* Returns whether the AMP design settings are enabled.
*
* @since 1.1 This always return false when AMP theme support is present.
* @since 0.6
*
* @return bool AMP Customizer design settings enabled.
*/
public static function is_amp_customizer_enabled() {

if ( current_theme_supports( 'amp' ) ) {
return false;
}

/**
* Filter whether to enable the AMP default template design settings.
*
Expand Down Expand Up @@ -110,6 +116,17 @@ public static function register_customizer_settings( $wp_customize ) {
'transport' => 'postMessage',
)
);

// Display exit link.
$wp_customize->add_setting(
'amp_customizer[display_exit_link]',
array(
'type' => 'option',
'default' => false,
'sanitize_callback' => 'rest_sanitize_boolean',
'transport' => 'postMessage',
)
);
}

/**
Expand Down Expand Up @@ -167,12 +184,24 @@ public static function register_customizer_ui( $wp_customize ) {
)
);

// Display exit link.
$wp_customize->add_control(
'amp_display_exit_link',
array(
'settings' => 'amp_customizer[display_exit_link]',
'label' => __( 'Display link to exit reader mode?', 'amp' ),
'section' => 'amp_design',
'type' => 'checkbox',
'priority' => 40,
)
);

// Header.
$wp_customize->selective_refresh->add_partial(
'amp-wp-header',
array(
'selector' => '.amp-wp-header',
'settings' => array( 'blogname' ), // @todo Site Icon.
'settings' => array( 'blogname', 'amp_customizer[display_exit_link]' ), // @todo Site Icon.
'render_callback' => array( __CLASS__, 'render_header_bar' ),
'fallback_refresh' => false,
)
Expand Down Expand Up @@ -257,6 +286,7 @@ public static function append_settings( $settings ) {
'header_color' => self::DEFAULT_HEADER_COLOR,
'header_background_color' => self::DEFAULT_HEADER_BACKGROUND_COLOR,
'color_scheme' => self::DEFAULT_COLOR_SCHEME,
'display_exit_link' => false,
)
);

Expand Down
Loading