Skip to content

Commit

Permalink
Fix initialization of paried mode and Customizer, and fix support opt…
Browse files Browse the repository at this point in the history
…ions on admin screen
  • Loading branch information
westonruter committed Jul 2, 2018
1 parent 7091b35 commit 328bba5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
10 changes: 10 additions & 0 deletions amp.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,16 @@ function amp_is_canonical() {
$support = get_theme_support( 'amp' );
if ( is_array( $support ) ) {
$args = array_shift( $support );

if ( ! empty( $args['optional'] ) ) {
$support = AMP_Options_Manager::get_option( 'theme_support' );
if ( 'disabled' === $support ) {
return false;
} elseif ( ! isset( $args['mode'] ) ) {
return 'native' === $support;
}
}

if ( isset( $args['mode'] ) ) {
$mode = $args['mode'];
} elseif ( ! empty( $args['template_dir'] ) ) {
Expand Down
14 changes: 4 additions & 10 deletions includes/options/class-amp-options-menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,15 @@ public function render_theme_support() {
$support_args = AMP_Theme_Support::get_theme_support_args( array( 'initial' => true ) );

$theme_support_mutable = (
empty( $support_args )
||
! empty( $support_args['optional'] )
||
AMP_Theme_Support::is_support_added_via_option()
);

$mode_mutable = ! ( is_array( $support_args ) && isset( $support_args['mode'] ) );
$mode_mutable = ! isset( $support_args['mode'] );

if ( ! $theme_support_mutable || ( ! $mode_mutable && 'disabled' !== $theme_support ) ) {
if ( amp_is_canonical() ) {
$theme_support = 'native';
} else {
$theme_support = 'paired';
}
$theme_support = isset( $support_args['mode'] ) ? $support_args['mode'] : 'native';
}

$should_have_theme_support = in_array( get_template(), array( 'twentyfifteen', 'twentysixteen', 'twentyseventeen' ), true );
Expand All @@ -168,7 +162,7 @@ public function render_theme_support() {
<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' ); ?>
</dd>
<?php if ( $mode_mutable || ! amp_is_canonical() ) : ?>
<?php if ( $mode_mutable || 'paired' === $support_args['mode'] ) : ?>
<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' ); ?> <?php disabled( ! $theme_support_mutable ); ?>>
<label for="theme_support_paired">
Expand All @@ -179,7 +173,7 @@ public function render_theme_support() {
<?php esc_html_e( 'Reuse active theme\'s templates to display AMP responses, but use separate URLs for AMP. The canonical URLs for your site will not have AMP. If there are AMP validation errors encountered in the AMP response and the validation errors are not accepted for sanitization, then the AMP version will redirect to the non-AMP version.', 'amp' ); ?>
</dd>
<?php endif; ?>
<?php if ( $mode_mutable || amp_is_canonical() ) : ?>
<?php if ( $mode_mutable || 'native' === $support_args['mode'] ) : ?>
<dt>
<input type="radio" id="theme_support_native" name="<?php echo esc_attr( AMP_Options_Manager::OPTION_NAME . '[theme_support]' ); ?>" value="native" <?php checked( $theme_support, 'native' ); ?> <?php disabled( ! $theme_support_mutable ); ?>>
<label for="theme_support_native">
Expand Down

0 comments on commit 328bba5

Please sign in to comment.