Skip to content

Commit

Permalink
Avoid defining a new function
Browse files Browse the repository at this point in the history
It's less new code to simply define this inline
  • Loading branch information
danielbachhuber committed May 25, 2018
1 parent 98b0270 commit b59cd28
Showing 1 changed file with 9 additions and 29 deletions.
38 changes: 9 additions & 29 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit b59cd28

Please sign in to comment.