Skip to content

Commit

Permalink
Simplify logic in AMP_Post_Meta_Box::render_status
Browse files Browse the repository at this point in the history
[ci skip]
  • Loading branch information
westonruter committed Jun 30, 2018
1 parent a616e84 commit a7371d1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
15 changes: 6 additions & 9 deletions includes/admin/class-amp-post-meta-box.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,20 +184,17 @@ public function render_status( $post ) {
return;
}

$errors = AMP_Post_Type_Support::get_support_errors( $post );
$status = empty( $errors ) ? self::ENABLED_STATUS : self::DISABLED_STATUS;
$errors = array_diff( $errors, array( 'post-status-disabled' ) ); // Subtract the status which the metabox will allow to be toggled.

// Handle special case of the static front page or page for posts.
if ( current_theme_supports( 'amp' ) ) {
$availability = AMP_Theme_Support::get_template_availability( $post );
$status = $availability['supported'] ? self::ENABLED_STATUS : self::DISABLED_STATUS;
$errors = array_diff( $availability['errors'], array( 'post-status-disabled' ) ); // Subtract the status which the metabox will allow to be toggled.
if ( true === $availability['immutable'] ) {
$errors[] = 'status_immutable';
$status = $availability['supported'] ? self::ENABLED_STATUS : self::DISABLED_STATUS;
} elseif ( ! $availability['supported'] && in_array( 'template_unsupported', $availability['errors'], true ) ) {
$errors[] = 'template_unsupported';
$status = self::DISABLED_STATUS;
}
} else {
$errors = AMP_Post_Type_Support::get_support_errors( $post );
$status = empty( $errors ) ? self::ENABLED_STATUS : self::DISABLED_STATUS;
$errors = array_diff( $errors, array( 'post-status-disabled' ) ); // Subtract the status which the metabox will allow to be toggled.
}

$labels = array(
Expand Down
1 change: 1 addition & 0 deletions tests/test-amp-helper-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ public function test_amp_add_amphtml_link( $canonical_url, $amphtml_url ) {
* @covers \is_amp_endpoint()
*/
public function test_is_amp_endpoint() {
$this->go_to( get_permalink( $this->factory()->post->create() ) );
$this->assertFalse( is_amp_endpoint() );

// Legacy query var.
Expand Down

0 comments on commit a7371d1

Please sign in to comment.