| @@ -2,8 +2,10 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace YayMail; |
| 4 | 4 | |
| 5 | 5 | use YayMail\Models\TemplateModel; |
| 6 | +use YayMail\Platform\PlatformRegistry; | |
| 7 | +use YayMail\Platform\YaymailPlatform; | |
| 6 | 8 | use YayMail\Utils\Helpers; |
| 7 | 9 | |
| 8 | 10 | /** |
| 9 | 11 | * GlobalHeaderFooter Class |
| @@ -30,9 +32,11 @@ | ||
| 30 | 32 | 'global_header_elements' => [], |
| 31 | 33 | 'global_footer_elements' => [], |
| 32 | 34 | ]; |
| 33 | 35 | |
| 34 | - if ( ! self::is_global_header_footer_enabled() ) { | |
| 36 | + $template_name = $template->get_name(); | |
| 37 | + | |
| 38 | + if ( ! self::is_global_header_footer_enabled( $template_name ) ) { | |
| 35 | 39 | return $fallback_result; |
| 36 | 40 | } |
| 37 | 41 | |
| 38 | 42 | $template = self::get_template_from_input( $template ); |
| @@ -40,10 +44,12 @@ | ||
| 40 | 44 | if ( empty( $template ) ) { |
| 41 | 45 | return $fallback_result; |
| 42 | 46 | } |
| 43 | 47 | |
| 44 | - $global_header_footer_elements = TemplateModel::get_instance()->get_global_header_and_footer( $template->get_language() ); | |
| 48 | + $ghf_template_name = self::resolve_platform( $template_name )->ghf_option_key(); | |
| 45 | 49 | |
| 50 | + $global_header_footer_elements = TemplateModel::get_instance()->get_global_header_and_footer( $template->get_language(), $ghf_template_name ); | |
| 51 | + | |
| 46 | 52 | if ( empty( $global_header_footer_elements ) ) { |
| 47 | 53 | return $fallback_result; |
| 48 | 54 | } |
| 49 | 55 | |
| @@ -58,8 +64,26 @@ | ||
| 58 | 64 | return $global_header_footer_elements; |
| 59 | 65 | } |
| 60 | 66 | |
| 61 | 67 | /** |
| 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 | + /** | |
| 62 | 86 | * Get template from input |
| 63 | 87 | * |
| 64 | 88 | * @param string|YayMailTemplate $template |
| 65 | 89 | * |
| @@ -132,9 +156,10 @@ | ||
| 132 | 156 | * @return string|null |
| 133 | 157 | */ |
| 134 | 158 | public static function get_global_header_override_heading_content( $template ) { |
| 135 | 159 | |
| 136 | - if ( ! self::is_global_header_footer_enabled() ) { | |
| 160 | + $template_name = $template->get_name(); | |
| 161 | + if ( ! self::is_global_header_footer_enabled( $template_name ) ) { | |
| 137 | 162 | return null; |
| 138 | 163 | } |
| 139 | 164 | |
| 140 | 165 | $template = self::get_template_from_input( $template ); |
| @@ -148,9 +173,12 @@ | ||
| 148 | 173 | if ( ! Helpers::is_true( $global_header_settings['content_override'] ) ) { |
| 149 | 174 | return null; |
| 150 | 175 | } |
| 151 | 176 | |
| 152 | - return $global_header_settings['heading_content'] ?? YayMailTemplate::DEFAULT_DATA['global_header_settings']['heading_content']; | |
| 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 ); | |
| 153 | 181 | } |
| 154 | 182 | |
| 155 | 183 | /** |
| 156 | 184 | * Get global footer override content |
| @@ -160,9 +188,10 @@ | ||
| 160 | 188 | * @return string|null |
| 161 | 189 | */ |
| 162 | 190 | public static function get_global_footer_override_content( $template ) { |
| 163 | 191 | |
| 164 | - if ( ! self::is_global_header_footer_enabled() ) { | |
| 192 | + $template_name = $template->get_name(); | |
| 193 | + if ( ! self::is_global_header_footer_enabled( $template_name ) ) { | |
| 165 | 194 | return null; |
| 166 | 195 | } |
| 167 | 196 | |
| 168 | 197 | $template = self::get_template_from_input( $template ); |
| @@ -176,9 +205,12 @@ | ||
| 176 | 205 | if ( ! Helpers::is_true( $global_footer_settings['content_override'] ) ) { |
| 177 | 206 | return null; |
| 178 | 207 | } |
| 179 | 208 | |
| 180 | - return $global_footer_settings['footer_content'] ?? YayMailTemplate::DEFAULT_DATA['global_footer_settings']['footer_content']; | |
| 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 ); | |
| 181 | 213 | } |
| 182 | 214 | |
| 183 | 215 | /** |
| 184 | 216 | * Check if element is in global header |
| @@ -229,8 +261,14 @@ | ||
| 229 | 261 | ) |
| 230 | 262 | ) > 0; |
| 231 | 263 | } |
| 232 | 264 | |
| 233 | - public static function is_global_header_footer_enabled() { | |
| 234 | - return yaymail_settings()['global_header_footer_enabled'] ?? false; | |
| 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 ); | |
| 235 | 273 | } |
| 236 | 274 | } |