-
Notifications
You must be signed in to change notification settings - Fork 382
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
Pass entire Reader mode templates through post-processor #3781
Changes from 20 commits
6717e4f
0c34778
8070c56
531d807
68c26e5
22c725b
82cd73c
6da568c
b1555eb
aed6c0e
29abc85
a3cb92a
8da4f68
93cede4
c9891b5
d536c8f
c74ba97
d9a3883
ca89bf9
5b0ec96
e8f290b
fcb344c
c31f190
9fb3514
56a7f1c
4e64c14
968f594
d10ab18
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -179,9 +179,11 @@ public static function init() { | |||||||
|
||||||||
self::$init_start_time = microtime( true ); | ||||||||
|
||||||||
if ( AMP_Options_Manager::is_website_experience_enabled() && current_theme_supports( self::SLUG ) ) { | ||||||||
// Ensure extra theme support for core themes is in place. | ||||||||
AMP_Core_Theme_Sanitizer::extend_theme_support(); | ||||||||
if ( AMP_Options_Manager::is_website_experience_enabled() ) { | ||||||||
if ( self::READER_MODE_SLUG !== self::get_support_mode() ) { | ||||||||
// Ensure extra theme support for core themes is in place. | ||||||||
AMP_Core_Theme_Sanitizer::extend_theme_support(); | ||||||||
} | ||||||||
|
||||||||
require_once AMP__DIR__ . '/includes/amp-post-template-functions.php'; | ||||||||
|
||||||||
|
@@ -417,15 +419,26 @@ public static function finish_init() { | |||||||
|
||||||||
self::ensure_proper_amp_location(); | ||||||||
|
||||||||
$theme_support = self::get_theme_support_args(); | ||||||||
$is_reader_mode = self::READER_MODE_SLUG === self::get_support_mode(); | ||||||||
$theme_support = self::get_theme_support_args(); | ||||||||
if ( ! empty( $theme_support['template_dir'] ) ) { | ||||||||
self::add_amp_template_filters(); | ||||||||
} elseif ( $is_reader_mode ) { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of having a separate condition for reader mode, it may be good to combine with amp-wp/includes/templates/class-amp-post-template.php Lines 198 to 199 in 451dd22
This would allow Reader templates to make use of the full template hierarchy, and ease transition to Transitional templates. In other words, if someone does: add_theme_support( 'amp', [ 'template_dir' => 'amp' ] ); This should either allow the templates in the In fact, there shouldn't be any real difference between Reader mode and Transitional mode when a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of detecting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As opposed to parsing the entire template file, I was intending to just use a simple check to see if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You'll still have to read the entire file to find a potential The compatibility wrapper I suggested would be read once and wrapped around each include. So most of the time, everything would still stay within the opcache. However, it adds complexity. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't
I'm not sure what these “memory mapping techniques” entail. Update: I suppose memory-mapped files. In any case, we're doing Line 55 in c900d84
Why would this be inherently different? In core I see There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In any case, migrating Reader mode templates to use a normal theme templates is beyond the scope of this PR. |
||||||||
add_filter( | ||||||||
'template_include', | ||||||||
static function() { | ||||||||
return __DIR__ . '/templates/reader-template-loader.php'; | ||||||||
westonruter marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
}, | ||||||||
PHP_INT_MAX | ||||||||
); | ||||||||
} | ||||||||
|
||||||||
self::add_hooks(); | ||||||||
self::$sanitizer_classes = amp_get_content_sanitizers(); | ||||||||
self::$sanitizer_classes = AMP_Validation_Manager::filter_sanitizer_args( self::$sanitizer_classes ); | ||||||||
self::$embed_handlers = self::register_content_embed_handlers(); | ||||||||
if ( ! $is_reader_mode ) { | ||||||||
self::$sanitizer_classes = AMP_Validation_Manager::filter_sanitizer_args( self::$sanitizer_classes ); | ||||||||
} | ||||||||
self::$embed_handlers = self::register_content_embed_handlers(); | ||||||||
self::$sanitizer_classes['AMP_Embed_Sanitizer']['embed_handlers'] = self::$embed_handlers; | ||||||||
|
||||||||
foreach ( self::$sanitizer_classes as $sanitizer_class => $args ) { | ||||||||
|
@@ -458,26 +471,36 @@ public static function ensure_proper_amp_location( $exit = true ) { | |||||||
if ( $has_query_var || $has_url_param ) { | ||||||||
return self::redirect_non_amp_url( current_user_can( 'manage_options' ) ? 302 : 301, $exit ); | ||||||||
} | ||||||||
} else { | ||||||||
} elseif ( self::READER_MODE_SLUG === self::get_support_mode() && is_singular() ) { | ||||||||
// Prevent infinite URL space under /amp/ endpoint. | ||||||||
global $wp; | ||||||||
$path_args = []; | ||||||||
wp_parse_str( $wp->matched_query, $path_args ); | ||||||||
if ( isset( $path_args[ amp_get_slug() ] ) && '' !== $path_args[ amp_get_slug() ] ) { | ||||||||
wp_safe_redirect( amp_get_permalink( get_queried_object_id() ), 301 ); | ||||||||
if ( $exit ) { | ||||||||
exit; | ||||||||
} | ||||||||
return true; | ||||||||
} | ||||||||
} elseif ( $has_query_var && ! $has_url_param ) { | ||||||||
/* | ||||||||
* 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 reader mode and transitional modes. | ||||||||
wp_safe_redirect( $new_url, current_user_can( 'manage_options' ) ? 302 : 301 ); | ||||||||
// @codeCoverageIgnoreStart | ||||||||
if ( $exit ) { | ||||||||
exit; | ||||||||
} | ||||||||
return true; | ||||||||
// @codeCoverageIgnoreEnd | ||||||||
$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 reader mode and transitional modes. | ||||||||
wp_safe_redirect( $new_url, current_user_can( 'manage_options' ) ? 302 : 301 ); | ||||||||
// @codeCoverageIgnoreStart | ||||||||
if ( $exit ) { | ||||||||
exit; | ||||||||
} | ||||||||
return true; | ||||||||
// @codeCoverageIgnoreEnd | ||||||||
} | ||||||||
} | ||||||||
return false; | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, it's great to see
amp.php
simplified.