Skip to content

Commit

Permalink
Framework: Add post types template filters during init hook
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed Jan 25, 2018
1 parent f920ba2 commit 864df38
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lib/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,17 @@ function gutenberg_templates( $templates, $theme, $post, $post_type ) {
return $templates;
}

/*
* TODO: This needs to be dynamically generated for all post types, either
* queried here or a new filter made available for generic templates filter.
*
* - add_filter( 'theme_{$post_type}_templates', 'gutenberg_templates' );
/**
* Adds filters to override available templates for all post types.
*/

add_filter( 'theme_post_templates', 'gutenberg_templates', 10, 4 );
add_filter( 'theme_page_templates', 'gutenberg_templates', 10, 4 );
function gutenberg_filter_post_type_templates() {
$post_types = get_post_types();
foreach ( $post_types as $post_type ) {
$filter_tag = sprintf( 'theme_%s_templates', $post_type );
add_filter( $filter_tag, 'gutenberg_templates', 10, 4 );
}
}
add_action( 'init', 'gutenberg_filter_post_type_templates', 20 );

/**
* Registers post tyes and taxonomies for dynamic templates.
Expand Down

0 comments on commit 864df38

Please sign in to comment.