| @@ -2,10 +2,8 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace YayMail; |
| 4 | 4 | |
| 5 | 5 | use YayMail\Models\TemplateModel; |
| 6 | -use YayMail\Platform\PlatformRegistry; | |
| 7 | -use YayMail\Platform\YaymailPlatform; | |
| 8 | 6 | use YayMail\Utils\Helpers; |
| 9 | 7 | |
| 10 | 8 | /** |
| 11 | 9 | * GlobalHeaderFooter Class |
| @@ -32,11 +30,9 @@ | ||
| 32 | 30 | 'global_header_elements' => [], |
| 33 | 31 | 'global_footer_elements' => [], |
| 34 | 32 | ]; |
| 35 | 33 | |
| 36 | - $template_name = $template->get_name(); | |
| 37 | - | |
| 38 | - if ( ! self::is_global_header_footer_enabled( $template_name ) ) { | |
| 34 | + if ( ! self::is_global_header_footer_enabled() ) { | |
| 39 | 35 | return $fallback_result; |
| 40 | 36 | } |
| 41 | 37 | |
| 42 | 38 | $template = self::get_template_from_input( $template ); |
| @@ -44,12 +40,10 @@ | ||
| 44 | 40 | if ( empty( $template ) ) { |
| 45 | 41 | return $fallback_result; |
| 46 | 42 | } |
| 47 | 43 | |
| 48 | - $ghf_template_name = self::resolve_platform( $template_name )->ghf_option_key(); | |
| 44 | + $global_header_footer_elements = TemplateModel::get_instance()->get_global_header_and_footer( $template->get_language() ); | |
| 49 | 45 | |
| 50 | - $global_header_footer_elements = TemplateModel::get_instance()->get_global_header_and_footer( $template->get_language(), $ghf_template_name ); | |
| 51 | - | |
| 52 | 46 | if ( empty( $global_header_footer_elements ) ) { |
| 53 | 47 | return $fallback_result; |
| 54 | 48 | } |
| 55 | 49 | |
| @@ -64,26 +58,8 @@ | ||
| 64 | 58 | return $global_header_footer_elements; |
| 65 | 59 | } |
| 66 | 60 | |
| 67 | 61 | /** |
| 68 | - * Resolve the platform that owns a given global-header-footer template name. | |
| 69 | - * | |
| 70 | - * Template naming is the only signal available at this call depth ('wp-core*' | |
| 71 | - * belongs to the yaymagic-email-builder product, everything else to yaymail), so this | |
| 72 | - * is the single place that maps it to a registered platform instead of each | |
| 73 | - * caller re-deriving option keys inline. | |
| 74 | - * | |
| 75 | - * @param string $template_name | |
| 76 | - * | |
| 77 | - * @return \YayMail\Platform\PlatformInterface | |
| 78 | - */ | |
| 79 | - private static function resolve_platform( $template_name ) { | |
| 80 | - $platform_key = str_starts_with( $template_name, 'wp-core' ) ? 'yaymagic-email-builder' : 'yaymail'; | |
| 81 | - | |
| 82 | - return PlatformRegistry::get( $platform_key ) ?? PlatformRegistry::get( 'yaymail' ) ?? new YaymailPlatform(); | |
| 83 | - } | |
| 84 | - | |
| 85 | - /** | |
| 86 | 62 | * Get template from input |
| 87 | 63 | * |
| 88 | 64 | * @param string|YayMailTemplate $template |
| 89 | 65 | * |
| @@ -156,10 +132,9 @@ | ||
| 156 | 132 | * @return string|null |
| 157 | 133 | */ |
| 158 | 134 | public static function get_global_header_override_heading_content( $template ) { |
| 159 | 135 | |
| 160 | - $template_name = $template->get_name(); | |
| 161 | - if ( ! self::is_global_header_footer_enabled( $template_name ) ) { | |
| 136 | + if ( ! self::is_global_header_footer_enabled() ) { | |
| 162 | 137 | return null; |
| 163 | 138 | } |
| 164 | 139 | |
| 165 | 140 | $template = self::get_template_from_input( $template ); |
| @@ -173,12 +148,9 @@ | ||
| 173 | 148 | if ( ! Helpers::is_true( $global_header_settings['content_override'] ) ) { |
| 174 | 149 | return null; |
| 175 | 150 | } |
| 176 | 151 | |
| 177 | - $default_heading = self::resolve_platform( $template_name )->is_woo_product() | |
| 178 | - ? YayMailTemplate::DEFAULT_DATA['global_header_settings']['heading_content'] | |
| 179 | - : '<h1 style="font-size: 30px; font-weight: 300; line-height: normal; margin: 0px; color: inherit;">[yaymail_site_name]</h1>'; | |
| 180 | - return $global_header_settings['heading_content'] ?? apply_filters( 'yaymail_default_global_header_override_content', $default_heading ); | |
| 152 | + return $global_header_settings['heading_content'] ?? YayMailTemplate::DEFAULT_DATA['global_header_settings']['heading_content']; | |
| 181 | 153 | } |
| 182 | 154 | |
| 183 | 155 | /** |
| 184 | 156 | * Get global footer override content |
| @@ -188,10 +160,9 @@ | ||
| 188 | 160 | * @return string|null |
| 189 | 161 | */ |
| 190 | 162 | public static function get_global_footer_override_content( $template ) { |
| 191 | 163 | |
| 192 | - $template_name = $template->get_name(); | |
| 193 | - if ( ! self::is_global_header_footer_enabled( $template_name ) ) { | |
| 164 | + if ( ! self::is_global_header_footer_enabled() ) { | |
| 194 | 165 | return null; |
| 195 | 166 | } |
| 196 | 167 | |
| 197 | 168 | $template = self::get_template_from_input( $template ); |
| @@ -205,12 +176,9 @@ | ||
| 205 | 176 | if ( ! Helpers::is_true( $global_footer_settings['content_override'] ) ) { |
| 206 | 177 | return null; |
| 207 | 178 | } |
| 208 | 179 | |
| 209 | - $default_footer = self::resolve_platform( $template_name )->is_woo_product() | |
| 210 | - ? YayMailTemplate::DEFAULT_DATA['global_footer_settings']['footer_content'] | |
| 211 | - : '<p style="font-size: 14px;margin: 0px 0px 16px; text-align: center;">[yaymail_site_name]</p>'; | |
| 212 | - return $global_footer_settings['footer_content'] ?? apply_filters( 'yaymail_default_global_footer_override_content', $default_footer ); | |
| 180 | + return $global_footer_settings['footer_content'] ?? YayMailTemplate::DEFAULT_DATA['global_footer_settings']['footer_content']; | |
| 213 | 181 | } |
| 214 | 182 | |
| 215 | 183 | /** |
| 216 | 184 | * Check if element is in global header |
| @@ -261,14 +229,8 @@ | ||
| 261 | 229 | ) |
| 262 | 230 | ) > 0; |
| 263 | 231 | } |
| 264 | 232 | |
| 265 | - public static function is_global_header_footer_enabled( $template_name = '' ) { | |
| 266 | - if ( empty( $template_name ) ) { | |
| 267 | - return false; | |
| 268 | - } | |
| 269 | - | |
| 270 | - $key = self::resolve_platform( $template_name )->ghf_option_key( 'enabled' ); | |
| 271 | - | |
| 272 | - return (bool) ( yaymail_settings()[ $key ] ?? false ); | |
| 233 | + public static function is_global_header_footer_enabled() { | |
| 234 | + return yaymail_settings()['global_header_footer_enabled'] ?? false; | |
| 273 | 235 | } |
| 274 | 236 | } |