diff --git a/amp.php b/amp.php index c3b48806efd..0b6001e75ca 100644 --- a/amp.php +++ b/amp.php @@ -127,10 +127,11 @@ function amp_force_query_var_value( $query_vars ) { * @return void */ function amp_maybe_add_actions() { + $is_amp_endpoint = is_amp_endpoint(); // Add hooks for when a themes that support AMP. if ( current_theme_supports( 'amp' ) ) { - if ( amp_is_canonical() || is_amp_endpoint() ) { + if ( $is_amp_endpoint ) { AMP_Theme_Support::init(); } else { amp_add_frontend_actions(); @@ -143,8 +144,6 @@ function amp_maybe_add_actions() { return; } - $is_amp_endpoint = is_amp_endpoint(); - // Cannot use `get_queried_object` before canonical redirect; see . global $wp_query; $post = $wp_query->post; diff --git a/includes/amp-frontend-actions.php b/includes/amp-frontend-actions.php index 8252bdb5700..f62b93f6b70 100644 --- a/includes/amp-frontend-actions.php +++ b/includes/amp-frontend-actions.php @@ -28,6 +28,5 @@ function amp_frontend_add_canonical() { return; } - $amp_url = amp_get_permalink( get_queried_object_id() ); - printf( '', esc_url( $amp_url ) ); + printf( '', esc_url( amp_get_permalink( get_queried_object_id() ) ) ); } diff --git a/includes/class-amp-theme-support.php b/includes/class-amp-theme-support.php index 6592e5aa04f..889e7e91f8d 100644 --- a/includes/class-amp-theme-support.php +++ b/includes/class-amp-theme-support.php @@ -12,6 +12,11 @@ */ class AMP_Theme_Support { + /** + * Replaced with the necessary scripts depending on components used in output. + * + * @var string + */ const COMPONENT_SCRIPTS_PLACEHOLDER = ''; /** @@ -45,10 +50,9 @@ class AMP_Theme_Support { public static function init() { require_once AMP__DIR__ . '/includes/amp-post-template-actions.php'; if ( amp_is_canonical() ) { - $is_amp_endpoint = ( false !== get_query_var( AMP_QUERY_VAR, false ) ); // Because is_amp_endpoint() now returns true if amp_is_canonical(). // Permanently redirect to canonical URL if the AMP URL was loaded, since canonical is now AMP. - if ( $is_amp_endpoint ) { + if ( false !== get_query_var( AMP_QUERY_VAR, false ) ) { // Because is_amp_endpoint() now returns true if amp_is_canonical(). wp_safe_redirect( self::get_current_canonical_url(), 301 ); exit; } @@ -76,7 +80,7 @@ public static function is_paired_available() { $args = array_shift( $support ); if ( isset( $args['available_callback'] ) && is_callable( $args['available_callback'] ) ) { - return $args['available_callback'](); + return call_user_func( $args['available_callback'] ); } return true; }