From 3377ecfd3ac02471ee50c5e0dc311a5e3c935533 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 27 Jun 2018 22:22:01 -0700 Subject: [PATCH] WIP7 --- includes/class-amp-theme-support.php | 37 ++++++++++++------- .../options/class-amp-options-manager.php | 15 ++++++-- includes/options/class-amp-options-menu.php | 30 ++++++++++----- 3 files changed, 54 insertions(+), 28 deletions(-) diff --git a/includes/class-amp-theme-support.php b/includes/class-amp-theme-support.php index 4a4752799e6..48f59590eee 100644 --- a/includes/class-amp-theme-support.php +++ b/includes/class-amp-theme-support.php @@ -468,16 +468,16 @@ public static function get_template_conditional_options() { 'label' => __( 'Archives', 'amp' ), 'description' => __( 'Including index pages for categories, tags, authors, and dates.', 'amp' ), 'callback' => 'is_archive', - 'children' => array( - 'author' => array( - 'label' => __( 'Author', 'amp' ), - 'callback' => 'is_author', - ), - 'date' => array( - 'label' => __( 'Date', 'amp' ), - 'callback' => 'is_date', - ), - ), + ), + 'author' => array( + 'label' => __( 'Author', 'amp' ), + 'callback' => 'is_author', + 'parent' => 'archives', + ), + 'date' => array( + 'label' => __( 'Date', 'amp' ), + 'callback' => 'is_date', + 'parent' => 'archives', ), 'search' => array( 'label' => __( 'Search', 'amp' ), @@ -494,24 +494,28 @@ public static function get_template_conditional_options() { ); if ( taxonomy_exists( 'category' ) ) { - $templates['archives']['children']['category'] = array( + $templates['tax[category]'] = array( 'label' => get_taxonomy( 'category' )->labels->name, 'callback' => 'is_category', + 'parent' => 'archives', ); } if ( taxonomy_exists( 'post_tag' ) ) { - $templates['archives']['children']['tag'] = array( + $templates['tax[post_tag]'] = array( 'label' => get_taxonomy( 'post_tag' )->labels->name, 'callback' => 'is_tag', + 'parent' => 'archives', ); } + $taxonomy_args = array( '_builtin' => false, 'publicly_queryable' => true, ); foreach ( get_taxonomies( $taxonomy_args, 'objects' ) as $taxonomy ) { - $templates['archives']['children'][ 'tax_' . $taxonomy->name ] = array( + $templates[ sprintf( 'tax[%s]', $taxonomy->name ) ] = array( 'label' => $taxonomy->labels->name, + 'parent' => 'archives', 'callback' => function ( WP_Query $query ) use ( $taxonomy ) { return $query->is_tax( $taxonomy->name ); }, @@ -523,7 +527,7 @@ public static function get_template_conditional_options() { 'publicly_queryable' => true, ); foreach ( get_post_types( $post_type_args, 'objects' ) as $post_type ) { - $templates['archives']['children'][ 'post_type_archive_' . $post_type->name ] = array( + $templates[ sprintf( 'post_type_archive[%s]', $post_type->name ) ] = array( 'label' => $post_type->labels->archives, 'callback' => function ( WP_Query $query ) use ( $post_type ) { return $query->is_post_type_archive( $post_type->name ); @@ -531,6 +535,11 @@ public static function get_template_conditional_options() { ); } + $supported_templates = AMP_Options_Manager::get_option( 'supported_templates' ); + foreach ( $templates as $id => &$template ) { + $template['supported'] = in_array( $id, $supported_templates, true ); + } + return $templates; } diff --git a/includes/options/class-amp-options-manager.php b/includes/options/class-amp-options-manager.php index f87f89b6a54..a089832a633 100644 --- a/includes/options/class-amp-options-manager.php +++ b/includes/options/class-amp-options-manager.php @@ -29,10 +29,8 @@ class AMP_Options_Manager { 'force_sanitization' => false, 'accept_tree_shaking' => false, 'disable_admin_bar' => false, - 'all_templates_supported' => false, - 'supported_templates' => array( - 'single', - ), + 'all_templates_supported' => true, + 'supported_templates' => array(), ); /** @@ -137,6 +135,15 @@ public static function validate_options( $new_options ) { } } + // Validate supported templates. + $options['supported_templates'] = array(); + if ( isset( $new_options['supported_templates'] ) ) { + $options['supported_templates'] = array_intersect( + $new_options['supported_templates'], + array_keys( AMP_Theme_Support::get_template_conditional_options() ) + ); + } + // Validate analytics. if ( isset( $new_options['analytics'] ) ) { foreach ( $new_options['analytics'] as $id => $data ) { diff --git a/includes/options/class-amp-options-menu.php b/includes/options/class-amp-options-menu.php index 5664a06f01a..4865c76a316 100644 --- a/includes/options/class-amp-options-menu.php +++ b/includes/options/class-amp-options-menu.php @@ -322,7 +322,9 @@ public function render_supported_templates() { }

- +