Skip to content

Commit

Permalink
Elimiante Other/unrecognized template option since indistinguishable …
Browse files Browse the repository at this point in the history
…from is_home

* Devs should use filter to add support for custom templates
* When a custom template is added via amp_supportable_templates filter then is_home will be discarded if there is another match
  • Loading branch information
westonruter committed Jul 2, 2018
1 parent 3d07eac commit c32d76b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 38 deletions.
5 changes: 1 addition & 4 deletions includes/class-amp-theme-support.php
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,6 @@ public static function get_template_availability( $query = null ) {
$all_templates_supported = (
$all_templates_supported_by_theme_support || AMP_Options_Manager::get_option( 'all_templates_supported' )
);
$unrecognized_templates_supported = ( // @todo Get this from $supportable_templates.
isset( $theme_templates_supported['unrecognized'] ) ? true === $theme_templates_supported['unrecognized'] : AMP_Options_Manager::get_option( 'unrecognized_templates_supported' )
);

// Make sure global $wp_query is set in case of conditionals that unfortunately look at global scope.
$prev_query = $wp_query;
Expand Down Expand Up @@ -552,7 +549,7 @@ public static function get_template_availability( $query = null ) {

// If there aren't any matching templates left that are supported, then we consider it to not be available.
if ( ! $matching_template ) {
if ( $all_templates_supported || $unrecognized_templates_supported ) {
if ( $all_templates_supported ) {
return array_merge(
$default_response,
array(
Expand Down
20 changes: 8 additions & 12 deletions includes/options/class-amp-options-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ class AMP_Options_Manager {
* @var array
*/
protected static $defaults = array(
'theme_support' => 'disabled',
'supported_post_types' => array( 'post' ),
'analytics' => array(),
'force_sanitization' => false,
'accept_tree_shaking' => false,
'disable_admin_bar' => false,
'all_templates_supported' => true,
'unrecognized_templates_supported' => false,
'supported_templates' => array( 'is_singular' ),
'theme_support' => 'disabled',
'supported_post_types' => array( 'post' ),
'analytics' => array(),
'force_sanitization' => false,
'accept_tree_shaking' => false,
'disable_admin_bar' => false,
'all_templates_supported' => true,
'supported_templates' => array( 'is_singular' ),
);

/**
Expand Down Expand Up @@ -128,9 +127,6 @@ public static function validate_options( $new_options ) {
$is_template_support_required = ( isset( $theme_support_args['templates_supported'] ) && 'all' === $theme_support_args['templates_supported'] );
if ( ! $is_template_support_required ) {
$options['all_templates_supported'] = ! empty( $new_options['all_templates_supported'] );
if ( ! isset( $theme_support_args['templates_supported']['unrecognized'] ) ) {
$options['unrecognized_templates_supported'] = ! empty( $new_options['unrecognized_templates_supported'] );
}

// Validate post type support.
$options['supported_post_types'] = array();
Expand Down
10 changes: 0 additions & 10 deletions includes/options/class-amp-options-menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,16 +344,6 @@ public function render_supported_templates() {
<?php
self::list_template_conditional_options( AMP_Theme_Support::get_supportable_templates() );
?>
<p>
<?php
$disabled = isset( $theme_support_args['templates_supported']['unrecognized'] );
$checked = $disabled ? $theme_support_args['templates_supported']['unrecognized'] : AMP_Options_Manager::get_option( 'unrecognized_templates_supported' );
?>
<label for="unrecognized_templates_supported">
<input id="unrecognized_templates_supported" type="checkbox" name="<?php echo esc_attr( AMP_Options_Manager::OPTION_NAME . '[unrecognized_templates_supported]' ); ?>" <?php checked( $checked ); ?> <?php disabled( $disabled ); ?>>
<?php esc_html_e( 'Other', 'amp' ); ?>
</label>
</p>
<script>
// Let clicks on parent items automatically cause the children checkboxes to have same checked state applied.
(function ( $ ) {
Expand Down
1 change: 0 additions & 1 deletion tests/test-class-amp-meta-box.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ public function test_render_status() {
// No template is available to render the post.
add_filter( 'amp_supportable_templates', '__return_empty_array' );
AMP_Options_Manager::update_option( 'all_templates_supported', false );
AMP_Options_Manager::update_option( 'unrecognized_templates_supported', false );
ob_start();
$this->instance->render_status( $post );
$output = ob_get_clean();
Expand Down
17 changes: 8 additions & 9 deletions tests/test-class-amp-options-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,14 @@ public function test_get_and_set_options() {
delete_option( AMP_Options_Manager::OPTION_NAME );
$this->assertEquals(
array(
'theme_support' => 'disabled',
'supported_post_types' => array( 'post' ),
'analytics' => array(),
'force_sanitization' => false,
'accept_tree_shaking' => false,
'disable_admin_bar' => false,
'all_templates_supported' => true,
'unrecognized_templates_supported' => false,
'supported_templates' => array( 'is_singular' ),
'theme_support' => 'disabled',
'supported_post_types' => array( 'post' ),
'analytics' => array(),
'force_sanitization' => false,
'accept_tree_shaking' => false,
'disable_admin_bar' => false,
'all_templates_supported' => true,
'supported_templates' => array( 'is_singular' ),
),
AMP_Options_Manager::get_options()
);
Expand Down
2 changes: 0 additions & 2 deletions tests/test-class-amp-theme-support.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,6 @@ public function test_get_template_availability() {
// @todo Test with query, post, or page.
// @todo Test without availability of WP_Query (no_query_available).
// @todo Test without theme support (no_theme_support).
// @todo Test unrecognized by theme support arg.
// @todo Test unrecognized.
}

/**
Expand Down

0 comments on commit c32d76b

Please sign in to comment.