From 8c51443059d227496554d075f8859526378cff4a Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 17 Jan 2018 11:21:37 -0800 Subject: [PATCH] Distinguish enabled-status from support-error --- assets/js/amp-post-meta-box.js | 5 +++-- includes/admin/class-amp-post-meta-box.php | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/assets/js/amp-post-meta-box.js b/assets/js/amp-post-meta-box.js index 17b077c197d..54485dfb36f 100644 --- a/assets/js/amp-post-meta-box.js +++ b/assets/js/amp-post-meta-box.js @@ -19,7 +19,8 @@ var ampPostMetaBox = ( function( $ ) { */ data: { previewLink: '', - enabled: '', + enabled: true, // Overridden by post_supports_amp( $post ). + canSupport: true, // Overridden by count( AMP_Post_Type_Support::get_support_errors( $post ) ) === 0. statusInputName: '', l10n: { ampPreviewBtnLabel: '' @@ -164,7 +165,7 @@ var ampPostMetaBox = ( function( $ ) { $container.slideToggle( component.toggleSpeed ); // Update status. - if ( component.data.enabled ) { + if ( component.data.canSupport ) { $container.data( 'amp-status', status ); $checked.prop( 'checked', true ); $( '.amp-status-text' ).text( $checked.next().text() ); diff --git a/includes/admin/class-amp-post-meta-box.php b/includes/admin/class-amp-post-meta-box.php index 45c1415cd93..4c0e1ab4ce8 100644 --- a/includes/admin/class-amp-post-meta-box.php +++ b/includes/admin/class-amp-post-meta-box.php @@ -116,6 +116,7 @@ public function enqueue_admin_assets() { wp_json_encode( array( 'previewLink' => esc_url_raw( add_query_arg( AMP_QUERY_VAR, '', get_preview_post_link( $post ) ) ), 'enabled' => post_supports_amp( $post ), + 'canSupport' => count( AMP_Post_Type_Support::get_support_errors( $post ) ) === 0, 'statusInputName' => self::STATUS_INPUT_NAME, 'l10n' => array( 'ampPreviewBtnLabel' => __( 'Preview changes in AMP (opens in new window)', 'amp' ),