Skip to content

Commit

Permalink
Cleanup: removing unnecessary variables, add PHPDoc for new const, re…
Browse files Browse the repository at this point in the history
…adability improvements.
  • Loading branch information
kaitnyl committed Jan 15, 2018
1 parent 9b1828d commit 34c18cc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
5 changes: 2 additions & 3 deletions amp.php
Expand Up @@ -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();
Expand All @@ -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 <https://core.trac.wordpress.org/ticket/35344>.
global $wp_query;
$post = $wp_query->post;
Expand Down
3 changes: 1 addition & 2 deletions includes/amp-frontend-actions.php
Expand Up @@ -28,6 +28,5 @@ function amp_frontend_add_canonical() {
return;
}

$amp_url = amp_get_permalink( get_queried_object_id() );
printf( '<link rel="amphtml" href="%s">', esc_url( $amp_url ) );
printf( '<link rel="amphtml" href="%s">', esc_url( amp_get_permalink( get_queried_object_id() ) ) );
}
10 changes: 7 additions & 3 deletions includes/class-amp-theme-support.php
Expand Up @@ -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 = '<!--AMP_COMPONENT_SCRIPTS_PLACEHOLDER-->';

/**
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 34c18cc

Please sign in to comment.