| @@ -240,9 +240,15 @@ | ||
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | public function get_template_by_name( \WP_REST_Request $request ) { |
| 243 | 243 | $template_name = sanitize_text_field( $request->get_param( 'template_name' ) ); |
| 244 | - $template_data = $this->model::find_by_name( $template_name ); | |
| 244 | + $variant = yaymail_sanitize_template_variant( $request->get_param( 'variant' ) ); | |
| 245 | + $template_data = $this->model::find_by_name( $template_name, '', $variant ); | |
| 246 | + if ( '' !== $variant && empty( $template_data['id'] ) ) { | |
| 247 | + // Variant posts are created on first open, seeded from the default design. | |
| 248 | + new YayMailTemplate( $template_name, '', $variant ); | |
| 249 | + $template_data = $this->model::find_by_name( $template_name, '', $variant ); | |
| 250 | + } | |
| 245 | 251 | |
| 246 | 252 | if ( null === $template_data ) { |
| 247 | 253 | $all_emails = yaymail_get_emails(); |
| 248 | 254 | if ( in_array( |