Skip to content

Commit 079ed38

Browse files
committed
Merge branch 'develop' into update/polyfills-service [skip ci]
2 parents 6b4de79 + bbc5c1c commit 079ed38

File tree

3 files changed

+64
-23
lines changed

3 files changed

+64
-23
lines changed

assets/src/block-editor/helpers/index.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import { isFunction, isObject, isString } from 'lodash';
99
*/
1010
import { __ } from '@wordpress/i18n';
1111
import { ToggleControl, PanelBody } from '@wordpress/components';
12-
import { InspectorControls } from '@wordpress/block-editor';
12+
import {
13+
InspectorControls,
14+
InspectorAdvancedControls,
15+
} from '@wordpress/block-editor';
1316
import { select, useSelect } from '@wordpress/data';
1417
import { cloneElement, isValidElement } from '@wordpress/element';
1518

@@ -340,12 +343,10 @@ ImageBlockLayoutAttributes.propTypes = {
340343
* @return {Object} Inspector Controls.
341344
*/
342345
const GalleryBlockLayoutAttributes = (props) => (
343-
<InspectorControls>
344-
<PanelBody title={__('AMP Settings', 'amp')}>
345-
<AmpLightboxToggle {...props} />
346-
<AmpCarouselToggle {...props} />
347-
</PanelBody>
348-
</InspectorControls>
346+
<InspectorAdvancedControls>
347+
<AmpLightboxToggle {...props} />
348+
<AmpCarouselToggle {...props} />
349+
</InspectorAdvancedControls>
349350
);
350351

351352
/**

src/MobileRedirection.php

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,27 +64,31 @@ public function register() {
6464
add_filter( 'amp_default_options', [ $this, 'filter_default_options' ] );
6565
add_filter( 'amp_options_updating', [ $this, 'sanitize_options' ], 10, 2 );
6666

67-
$is_mobile_redirect_enabled = AMP_Options_Manager::get_option( Option::MOBILE_REDIRECT );
68-
$sandboxing_level = amp_get_sandboxing_level();
67+
if ( ! amp_is_canonical() ) {
68+
$sandboxing_level = amp_get_sandboxing_level();
69+
$is_mobile_redirect_enabled = AMP_Options_Manager::get_option( Option::MOBILE_REDIRECT );
6970

70-
// Add alternative link if mobile redirection is enabled or sandboxing level is set to loose or moderate.
71-
if ( ! amp_is_canonical() && ( $is_mobile_redirect_enabled || ( 1 === $sandboxing_level || 2 === $sandboxing_level ) ) ) {
72-
add_action( 'wp_head', [ $this, 'add_mobile_alternative_link' ] );
73-
}
71+
// Add alternative link if mobile redirection is enabled or sandboxing level is set to loose or moderate.
72+
if ( $is_mobile_redirect_enabled || ( 1 === $sandboxing_level || 2 === $sandboxing_level ) ) {
73+
add_action( 'wp_head', [ $this, 'add_mobile_alternative_link' ] );
74+
}
7475

75-
if ( $is_mobile_redirect_enabled && ! amp_is_canonical() ) {
76-
add_action( 'template_redirect', [ $this, 'redirect' ], PHP_INT_MAX );
76+
if ( ! $is_mobile_redirect_enabled ) {
77+
add_action( 'template_redirect', [ $this, 'maybe_add_mobile_switcher_link' ], PHP_INT_MAX );
78+
} else {
79+
add_action( 'template_redirect', [ $this, 'redirect' ], PHP_INT_MAX );
7780

78-
// Enable AMP-to-AMP linking by default to avoid redirecting to AMP version when navigating.
79-
// A low priority is used so that sites can continue overriding this if they have done so.
80-
add_filter( 'amp_to_amp_linking_enabled', '__return_true', 0 );
81+
// Enable AMP-to-AMP linking by default to avoid redirecting to AMP version when navigating.
82+
// A low priority is used so that sites can continue overriding this if they have done so.
83+
add_filter( 'amp_to_amp_linking_enabled', '__return_true', 0 );
8184

82-
add_filter( 'comment_post_redirect', [ $this, 'filter_comment_post_redirect' ] );
85+
add_filter( 'comment_post_redirect', [ $this, 'filter_comment_post_redirect' ] );
8386

84-
// Amend the comments/respond links to go to non-AMP page when in legacy Reader mode.
85-
if ( amp_is_legacy() ) {
86-
add_filter( 'get_comments_link', [ $this, 'add_noamp_mobile_query_var' ] ); // For get_comments_link().
87-
add_filter( 'respond_link', [ $this, 'add_noamp_mobile_query_var' ] ); // For comments_popup_link().
87+
// Amend the comments/respond links to go to non-AMP page when in legacy Reader mode.
88+
if ( amp_is_legacy() ) {
89+
add_filter( 'get_comments_link', [ $this, 'add_noamp_mobile_query_var' ] ); // For get_comments_link().
90+
add_filter( 'respond_link', [ $this, 'add_noamp_mobile_query_var' ] ); // For comments_popup_link().
91+
}
8892
}
8993
}
9094
}
@@ -184,6 +188,16 @@ public function redirect() {
184188
}
185189
}
186190

191+
/**
192+
* Add mobile switcher link in footer when serving an AMP page.
193+
*/
194+
public function maybe_add_mobile_switcher_link() {
195+
if ( amp_is_request() ) {
196+
$this->add_mobile_switcher_head_hooks();
197+
$this->add_mobile_switcher_footer_hooks();
198+
}
199+
}
200+
187201
/**
188202
* Add mobile version switcher head hooks.
189203
*/

tests/php/src/MobileRedirectionTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,32 @@ public function test_redirect_on_transitional_and_available_and_server_side_on_a
451451
$this->assertEquals( 10, has_action( 'amp_post_template_footer', [ $this->instance, 'add_mobile_version_switcher_link' ] ) );
452452
}
453453

454+
/**
455+
* @covers ::maybe_add_mobile_switcher_link()
456+
*/
457+
public function test_maybe_add_mobile_switcher_link() {
458+
AMP_Options_Manager::update_option( Option::THEME_SUPPORT, AMP_Theme_Support::TRANSITIONAL_MODE_SLUG );
459+
460+
$this->go_to( '/' );
461+
$this->instance->maybe_add_mobile_switcher_link();
462+
463+
$this->assertFalse( amp_is_request() );
464+
$this->assertFalse( has_action( 'wp_head', [ $this->instance, 'add_mobile_version_switcher_styles' ] ) );
465+
$this->assertFalse( has_action( 'amp_post_template_head', [ $this->instance, 'add_mobile_version_switcher_styles' ] ) );
466+
$this->assertFalse( has_action( 'wp_footer', [ $this->instance, 'add_mobile_version_switcher_link' ] ) );
467+
$this->assertFalse( has_action( 'amp_post_template_footer', [ $this->instance, 'add_mobile_version_switcher_link' ] ) );
468+
469+
$this->go_to( '/' );
470+
set_query_var( QueryVar::AMP, '1' );
471+
$this->instance->maybe_add_mobile_switcher_link();
472+
473+
$this->assertTrue( amp_is_request() );
474+
$this->assertEquals( 10, has_action( 'wp_head', [ $this->instance, 'add_mobile_version_switcher_styles' ] ) );
475+
$this->assertEquals( 10, has_action( 'amp_post_template_head', [ $this->instance, 'add_mobile_version_switcher_styles' ] ) );
476+
$this->assertEquals( 10, has_action( 'wp_footer', [ $this->instance, 'add_mobile_version_switcher_link' ] ) );
477+
$this->assertEquals( 10, has_action( 'amp_post_template_footer', [ $this->instance, 'add_mobile_version_switcher_link' ] ) );
478+
}
479+
454480
/**
455481
* @covers ::add_mobile_switcher_head_hooks()
456482
* @covers ::add_mobile_switcher_footer_hooks()

0 commit comments

Comments
 (0)