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 b54fcc0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
16 changes: 15 additions & 1 deletion amp.php
Expand Up @@ -301,6 +301,7 @@ function amp_correct_query_when_is_front_page( WP_Query $query ) {
* 'templates_supported' => 'all',
* ) );
*
* @see AMP_Theme_Support::read_theme_support()
* @return boolean Whether this is in AMP 'canonical' mode, that is whether it is native and there is not separate AMP URL current URL.
*/
function amp_is_canonical() {
Expand All @@ -311,9 +312,22 @@ function amp_is_canonical() {
$mode = 'native';
$support = get_theme_support( 'amp' );
if ( is_array( $support ) ) {
$args = array_shift( $support );
$args = array_shift( $support );
$support = AMP_Options_Manager::get_option( 'theme_support' );

// If support is optional, look at DB option if mode is not explicitly set in theme support.
if ( ! empty( $args['optional'] ) ) {
if ( 'disabled' === $support ) {
return false;
} elseif ( ! isset( $args['mode'] ) ) {
return 'native' === $support;
}
}

if ( isset( $args['mode'] ) ) {
$mode = $args['mode'];
} elseif ( 'disabled' !== $support ) {
$mode = $support; // Supplied via admin screen.
} elseif ( ! empty( $args['template_dir'] ) ) {
$mode = 'paired'; // If there is a template_dir, then paired mode is implied.
}
Expand Down
14 changes: 4 additions & 10 deletions includes/options/class-amp-options-menu.php
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 b54fcc0

Please sign in to comment.