Skip to content

Commit

Permalink
Add support for the default_page_template_title filter in page-attr…
Browse files Browse the repository at this point in the history
…ibutes meta-box. (#6948)

* Add support for default_page_template_title filter

* Allow an empty array if there are no templates

* Avoid defining a new function

It's less new code to simply define this inline
  • Loading branch information
kallehauge authored and danielbachhuber committed May 25, 2018
1 parent 4366d9b commit b627478
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion editor/components/page-attributes/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function PageTemplate( { availableTemplates, selectedTemplate, instanceId
onBlur={ onEventUpdate }
onChange={ onEventUpdate }
>
{ map( { '': __( 'Default template' ), ...availableTemplates }, ( templateName, templateSlug ) => (
{ map( availableTemplates, ( templateName, templateSlug ) => (
<option key={ templateSlug } value={ templateSlug }>{ templateName }</option>
) ) }
</select>
Expand Down
10 changes: 9 additions & 1 deletion 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' => wp_get_theme()->get_page_templates( get_post( $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

0 comments on commit b627478

Please sign in to comment.