From 856cc50975303b55e9418f05907cb368cfee2f1e Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Sat, 29 Jul 2017 12:07:51 -0700 Subject: [PATCH 1/2] Extend page resource in REST API with available_page_templates field --- gutenberg.php | 1 + lib/rest-api.php | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 lib/rest-api.php diff --git a/gutenberg.php b/gutenberg.php index 01cd4899f2b40..1156be80b3857 100644 --- a/gutenberg.php +++ b/gutenberg.php @@ -24,6 +24,7 @@ require_once dirname( __FILE__ ) . '/lib/i18n.php'; require_once dirname( __FILE__ ) . '/lib/parser.php'; require_once dirname( __FILE__ ) . '/lib/register.php'; + require_once dirname( __FILE__ ) . '/lib/rest-api.php'; // Register server-side code for individual blocks. require_once dirname( __FILE__ ) . '/lib/blocks/latest-posts.php'; diff --git a/lib/rest-api.php b/lib/rest-api.php new file mode 100644 index 0000000000000..c5b24e2f7edd0 --- /dev/null +++ b/lib/rest-api.php @@ -0,0 +1,67 @@ + 'gutenberg_get_available_page_templates', + 'schema' => array( + 'description' => __( 'Available templates for a given page.', 'gutenberg' ), + 'type' => 'array', + 'items' => array( + 'type' => 'object', + 'properties' => array( + 'name' => array( + 'type' => 'string', + 'description' => __( 'Template name', 'gutenberg' ), + ), + 'template' => array( + 'type' => 'string', + 'description' => __( 'Template slug', 'gutenberg' ), + ), + ), + ), + 'readonly' => true, + 'context' => array( 'edit' ), + ), + ) ); +} +add_action( 'rest_api_init', 'gutenberg_register_available_page_templates_field' ); + +/** + * Returns available page templates for a requested page.. + * + * @since 0.7.0 + * @see gutenberg_register_available_page_templates_field() + * + * @param array $page Page data. + * @return array Available page templates. + */ +function gutenberg_get_available_page_templates( $page ) { + $available_templates = array(); + + // No page templates are available if the post is the page on front. See page_attributes_meta_box(). + if ( intval( get_option( 'page_for_posts' ) ) === $page['id'] ) { + return array(); + } + + $page_templates = wp_get_theme()->get_page_templates( $page['id'] ); + foreach ( $page_templates as $template => $name ) { + $available_templates[] = compact( 'name', 'template' ); + } + return $available_templates; +} From 29d0d922db98ae4a4a4ebaa9b2f95d4ae6a7705a Mon Sep 17 00:00:00 2001 From: James Nylen Date: Sun, 30 Jul 2017 18:22:30 +0100 Subject: [PATCH 2/2] Try: configure codecov.io to ignore PRs that do not change coverage --- codecov.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 codecov.yml diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000000000..ba6f0b2b6e5ea --- /dev/null +++ b/codecov.yml @@ -0,0 +1,2 @@ +comment: + require_changes: true