From b59cd284cafc21a1f452e26eb838c763aa6e244a Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Fri, 25 May 2018 04:50:24 -0700 Subject: [PATCH] Avoid defining a new function It's less new code to simply define this inline --- lib/client-assets.php | 38 +++++++++----------------------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/lib/client-assets.php b/lib/client-assets.php index a967998a41429..7dff270fcb77e 100644 --- a/lib/client-assets.php +++ b/lib/client-assets.php @@ -1033,9 +1033,17 @@ function gutenberg_editor_scripts_and_styles( $hook ) { */ $allowed_block_types = apply_filters( 'allowed_block_types', true, $post ); + $available_templates = wp_get_theme()->get_page_templates( $post_to_edit['id'] ); + $available_templates = array_merge( + array( + '' => apply_filters( 'default_page_template_title', __( 'Default template', 'gutenberg' ), 'rest-api' ), + ), + $available_templates + ); + $editor_settings = array( 'alignWide' => $align_wide || ! empty( $gutenberg_theme_support[0]['wide-images'] ), // Backcompat. Use `align-wide` outside of `gutenberg` array. - 'availableTemplates' => gutenberg_get_available_page_attributes_templates( $post_to_edit['id'] ), + 'availableTemplates' => $available_templates, 'allowedBlockTypes' => $allowed_block_types, 'disableCustomColors' => get_theme_support( 'disable-custom-colors' ), 'disablePostFormats' => ! current_theme_supports( 'post-formats' ), @@ -1094,34 +1102,6 @@ function gutenberg_editor_scripts_and_styles( $hook ) { do_action( 'enqueue_block_editor_assets' ); } -/** - * Get available templates for a post. - * - * We wrap the WP_Theme::get_page_templates() method since we wish to support the - * `default_page_template_title` filter to change the name of the default template. - * - * @since TBD - * - * @param int $post_id The ID of the post being edited. - * @return array - * - * @see WP_Theme::get_page_templates() - */ -function gutenberg_get_available_page_attributes_templates( $post_id ) { - // We only want to add the default template to the array if there are other - // templates since an array with only the default template will trigger the - // template select input in the meta box. - $templates = wp_get_theme()->get_page_templates( get_post( $post_id ) ); - if ( is_array( $templates ) && ! empty( $templates ) ) { - return array_merge( - array( '' => apply_filters( 'default_page_template_title', __( 'Default template' ), 'gutenberg' ), ), - $templates - ); - } else { - return array(); - } -} - /** * Ensure the editor module is loaded before third party plugins. *