Templates
in package
Templates class.
Table of Contents
- $post_types : array<string|int, mixed>
- The post type.
- $template_directory : string
- The template directory.
- $template_prefix : string
- The plugin slug.
- $templates_registry : Templates_Registry
- The templates registry.
- __construct() : mixed
- Constructor of the class.
- add_theme_templates() : array<string|int, mixed>
- This is need to enable saving post – template association.
- get_block_template() : WP_Block_Template|null
- Get a block template by ID.
- get_post_types() : array<string|int, mixed>
- This is a callback function for adding post_types property to templates rest api response.
- initialize() : void
- Initializes the class.
- register_post_types_to_api() : void
- Register post_types property to the templates rest api response.
- register_templates() : Templates_Registry
- Register the templates via register_block_template
Properties
$post_types
The post type.
private
array<string|int, mixed>
$post_types
= array()
$template_directory
The template directory.
private
string
$template_directory
= __DIR__ . DIRECTORY_SEPARATOR
$template_prefix
The plugin slug.
private
string
$template_prefix
= 'mailpoet'
$templates_registry
The templates registry.
private
Templates_Registry
$templates_registry
Methods
__construct()
Constructor of the class.
public
__construct(Templates_Registry $templates_registry) : mixed
Parameters
- $templates_registry : Templates_Registry
-
The templates registry.
Return values
mixed —add_theme_templates()
This is need to enable saving post – template association.
public
add_theme_templates(array<string|int, mixed> $templates, string $theme, WP_Post $post, string $post_type) : array<string|int, mixed>
When a theme doesn't support block_templates feature the association is not saved, because templates registered via register_block_template are not added to the list of available templates. https://github.com/WordPress/wordpress-develop/blob/cdc2f255acce57372b849d6278c4156e1056c749/src/wp-includes/class-wp-theme.php#L1355
This function ensures that the email templates are in the list which is used for checking if the template can be saved in the association. See https://github.com/WordPress/wordpress-develop/blob/cdc2f255acce57372b849d6278c4156e1056c749/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php#L1595-L1599
Parameters
- $templates : array<string|int, mixed>
-
The templates.
- $theme : string
-
The theme.
- $post : WP_Post
-
The post.
- $post_type : string
-
The post type.
Return values
array<string|int, mixed> —get_block_template()
Get a block template by ID.
public
get_block_template(string $template_slug) : WP_Block_Template|null
Parameters
- $template_slug : string
-
The template slug.
Return values
WP_Block_Template|null —get_post_types()
This is a callback function for adding post_types property to templates rest api response.
public
get_post_types(array<string|int, mixed> $response_object) : array<string|int, mixed>
Parameters
- $response_object : array<string|int, mixed>
-
The rest API response object.
Return values
array<string|int, mixed> —initialize()
Initializes the class.
public
initialize(array<string|int, string> $post_types) : void
Parameters
- $post_types : array<string|int, string>
-
The list of post types registered for usage with email editor.
Return values
void —register_post_types_to_api()
Register post_types property to the templates rest api response.
public
register_post_types_to_api() : void
There is a PR that adds the property into the core https://github.com/WordPress/wordpress-develop/pull/7530 Until it is merged, we need to add it manually.
Return values
void —register_templates()
Register the templates via register_block_template
public
register_templates(Templates_Registry $templates_registry) : Templates_Registry
Parameters
- $templates_registry : Templates_Registry
-
The templates registry.