| @@ -201,8 +201,9 @@ | ||
| 201 | 201 | $text_link_color = sanitize_text_field( $data['text_link_color'] ); |
| 202 | 202 | $content_background_color = sanitize_text_field( $data['content_background_color'] ); |
| 203 | 203 | $content_text_color = sanitize_text_field( $data['content_text_color'] ); |
| 204 | 204 | $title_color = sanitize_text_field( $data['title_color'] ); |
| 205 | + $preheader = sanitize_text_field( $data['preheader'] ); | |
| 205 | 206 | $global_header_settings = $data['global_header_settings'] ?? YayMailTemplate::DEFAULT_DATA['global_header_settings']; |
| 206 | 207 | $global_footer_settings = $data['global_footer_settings'] ?? YayMailTemplate::DEFAULT_DATA['global_footer_settings']; |
| 207 | 208 | $update_data = [ |
| 208 | 209 | 'elements' => $elements, |
| @@ -212,11 +213,17 @@ | ||
| 212 | 213 | 'content_text_color' => $content_text_color, |
| 213 | 214 | 'title_color' => $title_color, |
| 214 | 215 | 'global_header_settings' => $global_header_settings, |
| 215 | 216 | 'global_footer_settings' => $global_footer_settings, |
| 217 | + 'preheader' => $preheader, | |
| 216 | 218 | ]; |
| 217 | - $updated_data = $this->model::update( $id, $update_data, true ); | |
| 218 | - return $updated_data; | |
| 219 | + | |
| 220 | + if ( isset( $data['email_subject'] ) ) { | |
| 221 | + $template_name = get_post_meta( (int) $id, YayMailTemplate::META_KEYS['name'], true ); | |
| 222 | + $this->model::save_email_subject( $template_name, $data['email_subject'] ); | |
| 223 | + } | |
| 224 | + | |
| 225 | + return $this->model::update( $id, $update_data, true ); | |
| 219 | 226 | } |
| 220 | 227 | |
| 221 | 228 | public function exec_delete_template( \WP_REST_Request $request ) { |
| 222 | 229 | return $this->exec( [ $this, 'delete_template' ], $request ); |
| @@ -233,9 +240,15 @@ | ||
| 233 | 240 | } |
| 234 | 241 | |
| 235 | 242 | public function get_template_by_name( \WP_REST_Request $request ) { |
| 236 | 243 | $template_name = sanitize_text_field( $request->get_param( 'template_name' ) ); |
| 237 | - $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 | + } | |
| 238 | 251 | |
| 239 | 252 | if ( null === $template_data ) { |
| 240 | 253 | $all_emails = yaymail_get_emails(); |
| 241 | 254 | if ( in_array( |
| @@ -386,8 +399,11 @@ | ||
| 386 | 399 | return $this->exec( [ $this, 'change_global_header_footer_status' ], $request ); |
| 387 | 400 | } |
| 388 | 401 | |
| 389 | 402 | public function change_global_header_footer_status( \WP_REST_Request $request ) { |
| 390 | - $status = sanitize_text_field( $request->get_param( 'status' ) ); | |
| 391 | - return SettingModel::update( [ 'global_header_footer_enabled' => $status ] ); | |
| 403 | + $status = filter_var( $request->get_param( 'status' ), FILTER_VALIDATE_BOOLEAN ); | |
| 404 | + $platform = sanitize_text_field( $request->get_param( 'platform' ) ?? 'yaymail' ); | |
| 405 | + $platform_obj = \YayMail\Platform\PlatformRegistry::get( $platform ) ?? \YayMail\Platform\PlatformRegistry::get( 'yaymail' ); | |
| 406 | + $key = $platform_obj ? $platform_obj->ghf_option_key( 'enabled' ) : 'global_header_footer_enabled'; | |
| 407 | + return SettingModel::update( [ $key => $status ] ); | |
| 392 | 408 | } |
| 393 | -} | |
| 409 | +} | |