Skip to content

Commit

Permalink
Discard matching is_home when there are other matching templates
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed Jul 2, 2018
1 parent 221c3f0 commit 3d07eac
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion includes/class-amp-theme-support.php
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ public static function get_template_availability( $query = null ) {
if ( is_string( $callback ) && 'is_' === substr( $callback, 0, 3 ) && method_exists( $query, $callback ) ) {
$is_match = call_user_func( array( $query, $callback ) );
} elseif ( is_callable( $callback ) ) {
$is_match = call_user_func( $callback );
$is_match = call_user_func( $callback, $query );
} else {
/* translators: %s is the supportable template ID. */
_doing_it_wrong( __FUNCTION__, esc_html__( 'Supportable template "%s" does not have a callable callback.', 'amp' ), '1.0' );
Expand Down Expand Up @@ -535,6 +535,15 @@ public static function get_template_availability( $query = null ) {
}
}

// The is_home() condition is the default so discard it if there are other matching templates.
if ( count( $matching_templates ) > 1 && isset( $matching_templates['is_home'] ) ) {
unset( $matching_templates['is_home'] );
}

/*
* If there are more than one matching templates, then something is probably not right.
* Template conditions need to be set up properly to prevent this from happening.
*/
if ( count( $matching_templates ) > 1 ) {
_doing_it_wrong( __FUNCTION__, esc_html__( 'Did not expect there to be more than one matching template. Did you filter amp_supportable_templates to not honor the template hierarchy?', 'amp' ), '1.0' );
}
Expand Down

0 comments on commit 3d07eac

Please sign in to comment.