Template: Make it possible to both ''add'' and ''remove'' items from the page templates list using the theme_page_templates filter.

The `theme_page_templates` hook was originally added in [27297] as `page_templates`, and later renamed in [27470]. Previously, it was only possible to remove or rename page templates via this hook.

Fixes #13265. Fixes #25879.


git-svn-id: https://develop.svn.wordpress.org/trunk@34995 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Drew Jaynes 2015-10-09 21:50:05 +00:00
parent b374a081a9
commit 1758d36a88

View File

@ -1021,18 +1021,15 @@ final class WP_Theme implements ArrayAccess {
/**
* Filter list of page templates for a theme.
*
* This filter does not currently allow for page templates to be added.
*
* @since 3.9.0
* @since 4.4.0 Converted to allow complete control over the `$page_templates` array.
*
* @param array $page_templates Array of page templates. Keys are filenames,
* values are translated names.
* @param WP_Theme $this The theme object.
* @param WP_Post|null $post The post being edited, provided for context, or null.
*/
$return = apply_filters( 'theme_page_templates', $page_templates, $this, $post );
return array_intersect_assoc( $return, $page_templates );
return (array) apply_filters( 'theme_page_templates', $page_templates, $this, $post );
}
/**