Site_Style_Sync_Controller
in package
Site Style Sync Controller
Manages the live synchronization of site styles to email templates. Converts site theme styles to email-compatible formats while maintaining visual consistency between the site and emails.
Table of Contents
- $email_safe_fonts : array<string|int, mixed>
- Email-safe fonts
- $site_theme : WP_Theme_JSON|null
- Current site theme data
- __construct() : mixed
- Constructor
- get_email_safe_fonts() : array<string|int, mixed>
- Get email-safe fonts
- get_theme() : WP_Theme_JSON|null
- Getter for site theme.
- initialize() : void
- Initialize the sync controller
- invalidate_site_theme_cache() : void
- Invalidate cached site theme data
- is_sync_enabled() : bool
- Check if site style sync is enabled
- sync_site_styles() : array<string|int, mixed>
- Sync site styles to email theme format
- convert_color_styles() : array<string|int, mixed>
- Convert site color styles to email format
- convert_element_style() : array<string|int, mixed>
- Convert individual element style to email format
- convert_element_styles() : array<string|int, mixed>
- Convert site element styles to email format
- convert_spacing_styles() : array<string|int, mixed>
- Convert site spacing styles to email format
- convert_spacing_values() : string|array<string|int, mixed>
- Convert spacing values to px format.
- convert_to_email_safe_font() : string
- Convert font family to email-safe alternative
- convert_to_px_size() : string
- Convert size value to px format.
- convert_typography_styles() : array<string|int, mixed>
- Convert site typography styles to email format
- get_site_theme() : WP_Theme_JSON
- Get site theme data
- resolve_and_assign() : bool
- Resolve and assign a single style property
- resolve_style_value() : mixed
- Styles may contain references to other styles.
- sync_settings_data() : array<string|int, mixed>
- Sync settings data from site theme to email-compatible format
- sync_styles_data() : array<string|int, mixed>
- Sync styles data from site theme to email-compatible format
Properties
$email_safe_fonts
Email-safe fonts
private
array<string|int, mixed>
$email_safe_fonts
= array()
$site_theme
Current site theme data
private
WP_Theme_JSON|null
$site_theme
= null
Methods
__construct()
Constructor
public
__construct() : mixed
Return values
mixed —get_email_safe_fonts()
Get email-safe fonts
public
get_email_safe_fonts() : array<string|int, mixed>
Return values
array<string|int, mixed> — Email-safe fonts.get_theme()
Getter for site theme.
public
get_theme() : WP_Theme_JSON|null
Return values
WP_Theme_JSON|null — Synced site theme.initialize()
Initialize the sync controller
public
initialize() : void
Hook into theme changes to trigger automatic sync
Return values
void —invalidate_site_theme_cache()
Invalidate cached site theme data
public
invalidate_site_theme_cache() : void
Return values
void —is_sync_enabled()
Check if site style sync is enabled
public
is_sync_enabled() : bool
Return values
bool —sync_site_styles()
Sync site styles to email theme format
public
sync_site_styles() : array<string|int, mixed>
Return values
array<string|int, mixed> — Email-compatible theme data.convert_color_styles()
Convert site color styles to email format
private
convert_color_styles(array<string|int, mixed> $color_styles) : array<string|int, mixed>
Parameters
- $color_styles : array<string|int, mixed>
-
Site color styles.
Return values
array<string|int, mixed> — Email-compatible color styles.convert_element_style()
Convert individual element style to email format
private
convert_element_style(array<string|int, mixed> $element_style) : array<string|int, mixed>
Parameters
- $element_style : array<string|int, mixed>
-
Site element style.
Return values
array<string|int, mixed> — Email-compatible element style.convert_element_styles()
Convert site element styles to email format
private
convert_element_styles(array<string|int, mixed> $element_styles) : array<string|int, mixed>
Parameters
- $element_styles : array<string|int, mixed>
-
Site element styles.
Return values
array<string|int, mixed> — Email-compatible element styles.convert_spacing_styles()
Convert site spacing styles to email format
private
convert_spacing_styles(array<string|int, mixed> $spacing_styles) : array<string|int, mixed>
Parameters
- $spacing_styles : array<string|int, mixed>
-
Site spacing styles.
Return values
array<string|int, mixed> — Email-compatible spacing styles.convert_spacing_values()
Convert spacing values to px format.
private
convert_spacing_values(string|array<string|int, mixed> $spacing_values) : string|array<string|int, mixed>
Parameters
- $spacing_values : string|array<string|int, mixed>
-
Original spacing values.
Return values
string|array<string|int, mixed> — Spacing values in px format.convert_to_email_safe_font()
Convert font family to email-safe alternative
private
convert_to_email_safe_font(string $font_family) : string
Parameters
- $font_family : string
-
Original font family.
Return values
string — Email-safe font family.convert_to_px_size()
Convert size value to px format.
private
convert_to_px_size(string $size) : string
Parameters
- $size : string
-
Original size value.
Return values
string — Size in px format.convert_typography_styles()
Convert site typography styles to email format
private
convert_typography_styles(array<string|int, mixed> $typography_styles) : array<string|int, mixed>
Parameters
- $typography_styles : array<string|int, mixed>
-
Site typography styles.
Return values
array<string|int, mixed> — Email-compatible typography styles.get_site_theme()
Get site theme data
private
get_site_theme() : WP_Theme_JSON
Return values
WP_Theme_JSON —resolve_and_assign()
Resolve and assign a single style property
private
resolve_and_assign(array<string|int, mixed> $styles, string $property, array<string|int, mixed> &$target[, callable|null $processor = null ]) : bool
Parameters
- $styles : array<string|int, mixed>
-
The source styles array.
- $property : string
-
The property key to resolve.
- $target : array<string|int, mixed>
-
The target array to assign the value to.
- $processor : callable|null = null
-
Optional processor function for the resolved value.
Return values
bool — True if the property was resolved and assigned, false otherwise.resolve_style_value()
Styles may contain references to other styles.
private
resolve_style_value(mixed $style_value) : mixed
This function resolves the reference to the actual value. https://make.wordpress.org/core/2022/10/11/reference-styles-values-in-theme-json/ It is not allowed to reference another reference so we don't need to check recursively.
Parameters
- $style_value : mixed
-
Style value that might contain a reference.
Return values
mixed — Resolved style value or null when the reference is not found.sync_settings_data()
Sync settings data from site theme to email-compatible format
private
sync_settings_data(array<string|int, mixed> $site_settings) : array<string|int, mixed>
Parameters
- $site_settings : array<string|int, mixed>
-
Site theme settings.
Return values
array<string|int, mixed> — Email-compatible settings.sync_styles_data()
Sync styles data from site theme to email-compatible format
private
sync_styles_data(array<string|int, mixed> $site_styles) : array<string|int, mixed>
Parameters
- $site_styles : array<string|int, mixed>
-
Site theme styles.
