| @@ -38,14 +38,12 @@ | ||
| 38 | 38 | 'content_background_color' => '_yaymail_email_content_background_color', |
| 39 | 39 | 'content_text_color' => '_yaymail_email_content_text_color', |
| 40 | 40 | 'title_color' => '_yaymail_email_title_color', |
| 41 | 41 | 'language' => '_yaymail_template_language', |
| 42 | - 'variant' => '_yaymail_template_variant', | |
| 43 | 42 | 'modified_by' => '_yaymail_modified_by', |
| 44 | 43 | 'is_v4_supported' => '_yaymail_is_v4_supported', |
| 45 | 44 | 'global_header_settings' => '_yaymail_global_header_settings', |
| 46 | 45 | 'global_footer_settings' => '_yaymail_global_footer_settings', |
| 47 | - 'preheader' => '_yaymail_preheader', | |
| 48 | 46 | ]; |
| 49 | 47 | |
| 50 | 48 | public const DEFAULT_DATA = [ |
| 51 | 49 | 'name' => '', |
| @@ -56,13 +54,10 @@ | ||
| 56 | 54 | 'content_background_color' => '', |
| 57 | 55 | 'content_text_color' => '', |
| 58 | 56 | 'title_color' => '', |
| 59 | 57 | 'language' => '', |
| 60 | - 'variant' => '', | |
| 61 | 58 | 'modified_by' => '', |
| 62 | 59 | 'is_v4_supported' => false, |
| 63 | - 'attachments' => [], | |
| 64 | - 'preheader' => '', | |
| 65 | 60 | 'global_header_settings' => [ |
| 66 | 61 | 'content_override' => false, |
| 67 | 62 | 'heading_content' => '<h1 style="font-size: 30px; font-weight: 300; line-height: normal; margin: 0px; color: inherit;">Hello YayMail</h1>', |
| 68 | 63 | 'hidden' => false, |
| @@ -83,27 +78,19 @@ | ||
| 83 | 78 | 'status' => self::DEFAULT_DATA['status'], |
| 84 | 79 | 'background_color' => self::DEFAULT_DATA['background_color'], |
| 85 | 80 | 'text_link_color' => self::DEFAULT_DATA['text_link_color'], |
| 86 | 81 | 'language' => self::DEFAULT_DATA['language'], |
| 87 | - 'variant' => self::DEFAULT_DATA['variant'], | |
| 88 | 82 | 'title_color' => self::DEFAULT_DATA['title_color'], |
| 89 | - 'attachments' => self::DEFAULT_DATA['attachments'], | |
| 90 | - 'preheader' => self::DEFAULT_DATA['preheader'], | |
| 91 | 83 | 'global_header_settings' => self::DEFAULT_DATA['global_header_settings'], |
| 92 | 84 | 'global_footer_settings' => self::DEFAULT_DATA['global_footer_settings'], |
| 93 | 85 | ]; |
| 94 | 86 | |
| 95 | - /** | |
| 96 | - * @param string $template_name Email id. | |
| 97 | - * @param string $language Unused in Lite; kept so callers match the Pro signature. | |
| 98 | - * @param string $variant Variant slug, '' for the default design. | |
| 99 | - */ | |
| 100 | - public function __construct( $template_name = '', $language = '', $variant = '' ) { | |
| 87 | + public function __construct( $template_name = '', $language = '' ) { | |
| 101 | 88 | |
| 102 | 89 | $this->model = TemplateModel::get_instance(); |
| 103 | 90 | |
| 104 | - if ( is_string( $template_name ) && ! empty( $template_name ) ) { | |
| 105 | - $template_data = $this->model::find_by_name( $template_name, $language, $variant ); | |
| 91 | + if ( is_string( $template_name ) && ! empty( $template_name ) && Helpers::is_yaymail_email( $template_name ) ) { | |
| 92 | + $template_data = $this->model::find_by_name( $template_name, $language ); | |
| 106 | 93 | if ( empty( $template_data['id'] ) && SupportedPlugins::get_instance()->get_support_info( $template_name )['status'] === 'already_supported' ) { |
| 107 | 94 | /** Insert new template when not exists */ |
| 108 | 95 | $template_data = $this->model::insert( |
| 109 | 96 | [ |
| @@ -109,9 +96,8 @@ | ||
| 109 | 96 | [ |
| 110 | 97 | 'name' => $template_name, |
| 111 | 98 | 'elements' => yaymail_get_default_elements( $template_name ), |
| 112 | 99 | 'language' => $language, |
| 113 | - 'variant' => $variant, | |
| 114 | 100 | 'background_color' => self::DEFAULT_DATA['background_color'], |
| 115 | 101 | 'text_link_color' => self::DEFAULT_DATA['text_link_color'], |
| 116 | 102 | 'content_background_color' => self::DEFAULT_DATA['content_background_color'], |
| 117 | 103 | 'content_text_color' => self::DEFAULT_DATA['content_text_color'], |
| @@ -119,16 +105,10 @@ | ||
| 119 | 105 | 'global_header_settings' => self::DEFAULT_DATA['global_header_settings'], |
| 120 | 106 | 'global_footer_settings' => self::DEFAULT_DATA['global_footer_settings'], |
| 121 | 107 | ] |
| 122 | 108 | ); |
| 123 | - // A new variant post starts from the default design instead of the stock elements. | |
| 124 | - $seed = '' !== $variant ? $this->get_variant_seed( $template_name ) : []; | |
| 125 | - if ( ! empty( $seed ) && ! empty( $template_data['id'] ) ) { | |
| 126 | - $template_data = $this->model::update( $template_data['id'], $seed ); | |
| 127 | - } | |
| 128 | 109 | } |
| 129 | - // Missing, not-yet-supported templates come back without an id; 0 keeps is_exists() false | |
| 130 | - $this->set_id( $template_data['id'] ?? 0 ); | |
| 110 | + $this->set_id( $template_data['id'] ); | |
| 131 | 111 | $this->set_props( $template_data ); |
| 132 | 112 | // TODO: Consider filter available elements before pass to props |
| 133 | 113 | $this->renderer = new TemplateRenderer( $this ); |
| 134 | 114 | }//end if |
| @@ -133,22 +113,8 @@ | ||
| 133 | 113 | $this->renderer = new TemplateRenderer( $this ); |
| 134 | 114 | }//end if |
| 135 | 115 | } |
| 136 | 116 | |
| 137 | - /** | |
| 138 | - * Design to copy into a freshly created variant post: the default design of the same email. | |
| 139 | - * | |
| 140 | - * @return array Subset of template data accepted by TemplateModel::update(), or [] when nothing to copy. | |
| 141 | - */ | |
| 142 | - private function get_variant_seed( $template_name ) { | |
| 143 | - $source = $this->model::find_by_name( $template_name ); | |
| 144 | - if ( empty( $source['id'] ) ) { | |
| 145 | - return []; | |
| 146 | - } | |
| 147 | - $seed_keys = [ 'elements', 'background_color', 'text_link_color', 'content_background_color', 'content_text_color', 'title_color', 'global_header_settings', 'global_footer_settings', 'preheader' ]; | |
| 148 | - return array_intersect_key( $source, array_flip( $seed_keys ) ); | |
| 149 | - } | |
| 150 | - | |
| 151 | 117 | public function is_exists() { |
| 152 | 118 | return is_numeric( $this->id ) && $this->id > 0; |
| 153 | 119 | } |
| 154 | 120 | |
| @@ -154,11 +120,8 @@ | ||
| 154 | 120 | |
| 155 | 121 | public function is_enabled() { |
| 156 | 122 | // Check if YayMail core is migrated |
| 157 | 123 | // If not, consider template is not activated |
| 158 | - if ( ! defined( 'YAYMAIL_VERSION' ) ) { | |
| 159 | - return $this->get_status() === 'active'; | |
| 160 | - } | |
| 161 | 124 | $old_version = get_option( 'yaymail_version' ); |
| 162 | 125 | if ( $old_version && version_compare( $old_version, '4.0.0', '<' ) ) { |
| 163 | 126 | return false; |
| 164 | 127 | } |
| @@ -228,24 +191,12 @@ | ||
| 228 | 191 | public function get_language( $context = 'view' ) { |
| 229 | 192 | return $this->get_prop( 'language', $context ); |
| 230 | 193 | } |
| 231 | 194 | |
| 232 | - public function get_variant( $context = 'view' ) { | |
| 233 | - return $this->get_prop( 'variant', $context ); | |
| 234 | - } | |
| 235 | - | |
| 236 | 195 | public function get_title_color( $context = 'view' ) { |
| 237 | 196 | return $this->get_prop( 'title_color', $context ); |
| 238 | 197 | } |
| 239 | 198 | |
| 240 | - public function get_attachments( $context = 'view' ) { | |
| 241 | - return $this->get_prop( 'attachments', $context ); | |
| 242 | - } | |
| 243 | - | |
| 244 | - public function get_preheader( $context = 'view' ) { | |
| 245 | - return $this->get_prop( 'preheader', $context ); | |
| 246 | - } | |
| 247 | - | |
| 248 | 199 | /** |
| 249 | 200 | * Get global header |
| 250 | 201 | * |
| 251 | 202 | * @since 4.1.0 |
| @@ -334,20 +285,8 @@ | ||
| 334 | 285 | $this->set_prop( 'language', $value ); |
| 335 | 286 | } |
| 336 | 287 | } |
| 337 | 288 | |
| 338 | - public function set_variant( $value ) { | |
| 339 | - if ( is_string( $value ) ) { | |
| 340 | - $this->set_prop( 'variant', $value ); | |
| 341 | - } | |
| 342 | - } | |
| 343 | - | |
| 344 | - public function set_preheader( $value ) { | |
| 345 | - if ( is_string( $value ) ) { | |
| 346 | - $this->set_prop( 'preheader', $value ); | |
| 347 | - } | |
| 348 | - } | |
| 349 | - | |
| 350 | 289 | public function set_title_color( $value ) { |
| 351 | 290 | if ( ! is_null( $value ) && is_string( $value ) ) { |
| 352 | 291 | $this->set_prop( 'title_color', $value ); |
| 353 | 292 | } |
| @@ -408,12 +347,8 @@ | ||
| 408 | 347 | } |
| 409 | 348 | |
| 410 | 349 | public function get_content( $data ) { |
| 411 | 350 | try { |
| 412 | - if ( strpos( $this->get_name(), 'wp-core-' ) === 0 && ! empty( $this->renderer ) ) { | |
| 413 | - return $this->renderer->generate_content( $data ); | |
| 414 | - } | |
| 415 | - | |
| 416 | 351 | if ( ! empty( $this->renderer ) ) { |
| 417 | 352 | return StyleInline::get_instance()->convert_style_inline( $this->renderer->generate_content( $data ) ); |
| 418 | 353 | } |
| 419 | 354 | } catch ( \Exception $e ) { |
| @@ -419,8 +354,8 @@ | ||
| 419 | 354 | } catch ( \Exception $e ) { |
| 420 | 355 | yaymail_get_logger( $e->getMessage() ); |
| 421 | 356 | } catch ( \Error $e ) { |
| 422 | 357 | yaymail_get_logger( $e->getMessage() ); |
| 423 | - }//end try | |
| 358 | + } | |
| 424 | 359 | return ''; |
| 425 | 360 | } |
| 426 | 361 | } |