-
Notifications
You must be signed in to change notification settings - Fork 341
Expand file tree
/
Copy pathContent_Map.php
More file actions
167 lines (153 loc) · 7.06 KB
/
Content_Map.php
File metadata and controls
167 lines (153 loc) · 7.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
/**
* Class Google\Site_Kit\Core\Email_Reporting\Content_Map
*
* @package Google\Site_Kit\Core\Email_Reporting
* @copyright 2026 Google LLC
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link https://sitekit.withgoogle.com
*/
namespace Google\Site_Kit\Core\Email_Reporting;
/**
* Class for mapping email template content (titles and body).
*
* Provides centralized content for simple email templates,
* used by both HTML and plain text renderers. Body paragraphs may
* contain safe inline HTML (e.g. strong tags) which the HTML
* renderer preserves via wp_kses() and the plain text renderer
* strips via wp_strip_all_tags().
*
* @since 1.173.0
*/
class Content_Map {
/**
* Gets the title for a template.
*
* @since 1.174.0
*
* @param string $template_name The template name.
* @return string The title string (may contain sprintf placeholders).
*/
public static function get_title( $template_name ) {
$titles = self::get_all_titles();
return $titles[ $template_name ] ?? '';
}
/**
* Gets title with format arguments applied.
*
* @since 1.174.0
*
* @param string $template_name The template name.
* @param array $args Format arguments for sprintf substitution.
* @return string The resolved title string.
*/
public static function get_title_with_args( $template_name, $args = array() ) {
$title = self::get_title( $template_name );
if ( empty( $args ) || empty( $title ) ) {
return $title;
}
return vsprintf( $title, $args );
}
/**
* Gets the body content for a template.
*
* @since 1.173.0
*
* @param string $template_name The template name.
* @return array Array of body paragraphs (may contain HTML).
*/
public static function get_body( $template_name ) {
$bodies = self::get_all_bodies();
return $bodies[ $template_name ] ?? array();
}
/**
* Gets body content with format arguments applied.
*
* Retrieves paragraphs for the given template and substitutes
* any sprintf-style placeholders with the provided arguments.
*
* @since 1.173.0
*
* @param string $template_name The template name.
* @param array $args Format arguments for vsprintf substitution.
* @return array Array of resolved body paragraphs (may contain HTML).
*/
public static function get_body_with_args( $template_name, $args = array() ) {
$body = self::get_body( $template_name );
if ( empty( $args ) ) {
return $body;
}
return array_map(
function ( $paragraph ) use ( $args ) {
return vsprintf( $paragraph, $args );
},
$body
);
}
/**
* Gets all template title mappings.
*
* @since 1.174.0
*
* @return array Mapping of template names to title strings.
*/
protected static function get_all_titles() {
return array(
/* translators: 1: opening anchor tag with mailto link, 2: inviter email address, 3: closing anchor tag */
'invitation-email' => __( '%1$s%2$s%3$s invited you to receive periodic performance reports', 'google-site-kit' ),
'subscription-confirmation' => __( 'Success! You’re subscribed to Site Kit reports', 'google-site-kit' ),
'error-email' => __( 'Action needed: your Site Kit report couldn’t be generated', 'google-site-kit' ),
'error-email-cron-scheduler' => __( 'Email reports are failing to send', 'google-site-kit' ),
);
}
/**
* Gets all template body content mappings.
*
* @since 1.173.0
*
* @return array Mapping of template names to body paragraph arrays.
*/
protected static function get_all_bodies() {
return array(
'invitation-email' => array(
__( 'Receive the most important insights about your site’s performance, key trends, and tailored metrics, powered by Site Kit, directly in your inbox.', 'google-site-kit' ),
__( 'You can unsubscribe or change how often emails are sent anytime from your Site Kit dashboard.', 'google-site-kit' ),
),
'subscription-confirmation' => array(
__( 'You’re all set to receive your site performance reports.', 'google-site-kit' ),
/* translators: %1$s: frequency (e.g., "monthly") wrapped in strong tags, %2$s: first report date wrapped in strong tags */
__( 'You’ve successfully set your frequency to <strong>%1$s</strong>, and you can expect to receive your first report on <strong>%2$s</strong>.', 'google-site-kit' ),
__( 'You can manage your subscription settings or change the report frequency anytime in your Site Kit dashboard.', 'google-site-kit' ),
),
'error-email' => array(
__( 'We were unable to generate your report due to a server error. To fix this, contact your host. Report delivery will automatically resume once the issue is resolved.', 'google-site-kit' ),
),
'error-email-cron-scheduler' => array(
__( "We were unable to deliver your report, likely due to a WP-Cron configuration error in your WordPress site's system settings. To fix this, contact your administrator or get help. Report delivery will automatically resume once the issue is resolved.", 'google-site-kit' ),
),
// Opening/closing tag placeholders keep inline styles and HTML
// out of translation strings. Inline color styles are required
// because many email clients strip or ignore CSS classes.
'error-email-permissions-search-console' => array(
/* translators: 1: opening anchor tag for help link, 2: closing anchor tag */
__( 'We were unable to generate your reports due to insufficient permissions in Search Console. To fix this, contact your administrator or %1$sget help%2$s.', 'google-site-kit' ),
__( 'Report delivery will automatically resume once the issue is resolved.', 'google-site-kit' ),
),
'error-email-permissions-analytics-4' => array(
/* translators: 1: opening anchor tag for help link, 2: closing anchor tag */
__( 'We were unable to generate your reports due to insufficient permissions in Analytics. To fix this, contact your administrator or %1$sget help%2$s.', 'google-site-kit' ),
__( 'Report delivery will automatically resume once the issue is resolved.', 'google-site-kit' ),
),
'error-email-report-search-console' => array(
/* translators: 1: opening anchor tag for settings link, 2: closing anchor tag, 3: opening anchor tag for help link, 4: closing anchor tag */
__( 'We were unable to generate your report because data loading failed for Search Console. To fix this, go to %1$sSearch Console settings%2$s in Site Kit or %3$sget help%4$s.', 'google-site-kit' ),
__( 'Report delivery will automatically resume once the issue is resolved.', 'google-site-kit' ),
),
'error-email-report-analytics-4' => array(
/* translators: 1: opening anchor tag for settings link, 2: closing anchor tag, 3: opening anchor tag for help link, 4: closing anchor tag */
__( 'We were unable to generate your report because data loading failed for Analytics. To fix this, go to %1$sAnalytics settings%2$s in Site Kit or %3$sget help%4$s.', 'google-site-kit' ),
__( 'Report delivery will automatically resume once the issue is resolved.', 'google-site-kit' ),
),
);
}
}