PluginProbe ʕ •ᴥ•ʔ
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress / trunk
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress vtrunk
4.16.18 4.16.17 4.16.16 trunk 1.0 1.0.1 1.0.2 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5a 1.1.6 1.1.7 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.4 1.4.1 1.4.2 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.7 1.7.1 1.7.2 1.8 1.8.1 1.8.10 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.1.9 2.2.10 2.2.11 2.2.12 2.2.13 2.2.14 2.2.15 2.2.16 2.2.2 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 3.0 3.1 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 3.1.19 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.10 3.2.11 3.2.12 3.2.13 3.2.14 3.2.15 3.2.16 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 4.0.0 4.0.1 4.0.2 4.0.3 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.10.0 4.10.1 4.10.2 4.10.3 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.13.3 4.13.4 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.15.0 4.15.1 4.15.10 4.15.11 4.15.12 4.15.13 4.15.14 4.15.15 4.15.16 4.15.17 4.15.18 4.15.19 4.15.2 4.15.20 4.15.20.1 4.15.21 4.15.22 4.15.23 4.15.24 4.15.25 4.15.3 4.15.4 4.15.5 4.15.6 4.15.7 4.15.8 4.15.9 4.16.0 4.16.1 4.16.10 4.16.11 4.16.12 4.16.13 4.16.14 4.16.15 4.16.2 4.16.3 4.16.4 4.16.5 4.16.6 4.16.7 4.16.8 4.16.9 4.2.0 4.3.0 4.3.1 4.3.2 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.5.3 4.5.4 4.5.5 4.6.0 4.7.0 4.8.0 4.9.0
wp-user-avatar / src / Admin / SettingsPages / EmailSettings / DefaultTemplateCustomizer.php
wp-user-avatar / src / Admin / SettingsPages / EmailSettings Last commit date
CustomizerTrait.php 5 years ago DefaultTemplateCustomizer.php 3 years ago EmailSettingsPage.php 1 year ago WPListTable.php 4 years ago email-template-preview.php 5 years ago
DefaultTemplateCustomizer.php
337 lines
1 <?php
2
3 namespace ProfilePress\Core\Admin\SettingsPages\EmailSettings;
4
5 class DefaultTemplateCustomizer
6 {
7 use CustomizerTrait;
8
9 const DBPREFIX = 'ppress_email';
10
11 const body_section = 'ppress_email_template_body';
12 const header_section = 'ppress_email_template_header';
13 const footer_section = 'ppress_email_template_footer';
14
15 protected static $site_title;
16
17 public function __construct()
18 {
19 if ( ! empty($_REQUEST['ppress-preview-template'])) {
20
21 $this->clean_up_customizer();
22 $this->modify_customizer_publish_button();
23
24 add_action('customize_controls_enqueue_scripts', [$this, 'monkey_patch_customizer_payload']);
25
26 self::$site_title = ppress_site_title();
27
28 add_action('customize_register', [$this, 'customizer_register'], -1);
29
30 add_action('parse_request', [$this, 'include_customizer_template'], 1);
31
32 add_action('customize_controls_init', [$this, 'set_customizer_urls']);
33
34 add_action('customize_section_active', array($this, 'remove_sections'), 999999999, 2);
35
36 // Remove all customizer panels.
37 add_action('customize_panel_active', '__return_false');
38
39 add_filter('gettext', array($this, 'rewrite_customizer_panel_description'), 10, 3);
40
41 // rewrite panel name from blog name to PP email template.
42 add_filter('pre_option_blogname', function () {
43 return esc_html__('ProfilePress Email Template', 'wp-user-avatar');
44 });
45 }
46 }
47
48 public static function get_customizer_value($setting)
49 {
50 $settings = get_option(self::DBPREFIX, []);
51
52 $default = self::defaults($setting);
53
54 if ($setting == 'header_text' && empty($default)) $default = ppress_site_title();
55
56 $default = str_replace('{{siteTitle}}', ppress_site_title(), $default);
57
58 return ! empty($settings[$setting]) ? $settings[$setting] : $default;
59 }
60
61 public function monkey_patch_customizer_payload()
62 {
63 wp_add_inline_script('customize-controls', '(function ( api ) {
64 api.bind( "ready", function () {
65 var _query = api.previewer.query;
66 api.previewer.query = function () {
67 var query = _query.call( this );
68 query["ppress-preview-template"] = "true";
69 return query;
70 };
71 // needed to ensure save button is publising changes and not saving draft.
72 // esp for wp.com business hosting with save button set to draft by default.
73 api.state("selectedChangesetStatus").set("publish");
74 });
75 })( wp.customize );'
76 );
77
78 wp_add_inline_style(
79 'customize-controls',
80 'button#publish-settings {display: none !important;}#customize-save-button-wrapper .save.has-next-sibling {border-radius: 3px;}');
81 }
82
83 public function include_customizer_template()
84 {
85 if (is_customize_preview() && ! empty($_GET['ppress-preview-template']) && wp_verify_nonce($_REQUEST['_wpnonce'], 'ppress-preview-template')) {
86 include(dirname(__FILE__) . '/email-template-preview.php');
87 exit;
88 }
89
90 wp_safe_redirect(PPRESS_SETTINGS_EMAIL_SETTING_PAGE);
91 exit;
92 }
93
94 public function set_customizer_urls()
95 {
96 global $wp_customize;
97
98 $preview_url = add_query_arg(
99 '_wpnonce',
100 wp_create_nonce('ppress-preview-template'),
101 sprintf(home_url('/?ppress-preview-template=true'))
102 );
103
104 $return_url = PPRESS_SETTINGS_EMAIL_SETTING_PAGE;
105
106 $wp_customize->set_preview_url($preview_url);
107 $wp_customize->set_return_url($return_url);
108 }
109
110 public static function get_prefixed_id($setting)
111 {
112 return self::DBPREFIX . "[" . $setting . "]";
113 }
114
115 public function remove_sections($active, $section)
116 {
117 $sections_ids = [self::header_section, self::footer_section, self::body_section];
118
119 return in_array($section->id, $sections_ids);
120 }
121
122 public function rewrite_customizer_panel_description($translations, $text, $domain)
123 {
124 if (strpos($text, 'Customizer allows you to preview changes to your site')) {
125 $translations = __(
126 'The customizer allows you to design and preview ProfilePress default email template.',
127 'wp-user-avatar'
128 );
129 }
130
131 return $translations;
132 }
133
134 public function customizer_register($wp_customize)
135 {
136 remove_all_actions('customize_register'); // improve compatibility with hestia, generatepress themes etc
137 $this->sections($wp_customize);
138 $this->settings($wp_customize);
139 $this->controls($wp_customize);
140 }
141
142 /**
143 * @param \WP_Customize_Manager $wp_customize
144 */
145 public function sections($wp_customize)
146 {
147 $wp_customize->add_section(self::body_section, array(
148 'title' => esc_html__('Body', 'wp-user-avatar'),
149 'priority' => 10,
150 )
151 );
152
153 $wp_customize->add_section(self::header_section, array(
154 'title' => esc_html__('Header', 'wp-user-avatar'),
155 'priority' => 10,
156 )
157 );
158
159 $wp_customize->add_section(self::footer_section, array(
160 'title' => esc_html__('Footer', 'wp-user-avatar'),
161 'priority' => 20,
162 )
163 );
164 }
165
166 public static function defaults($setting)
167 {
168 $defaults = [
169 'background_color' => '#f2f4f6',
170 'background_text_color' => '#a8aaaf',
171 'content_background_color' => '#ffffff',
172 'content_header_color' => '#333333',
173 'content_text_color' => '#51545e',
174 'header_text' => self::$site_title,
175 'footer_text' => sprintf(esc_html__('© %s %s. All rights reserved.'), date('Y'), '{{siteTitle}}')
176 ];
177
178 return isset($defaults[$setting]) ? $defaults[$setting] : '';
179 }
180
181 /**
182 * @param \WP_Customize_Manager $wp_customize
183 */
184 public function settings($wp_customize)
185 {
186 $wp_customize->add_setting(self::get_prefixed_id('background_color'), [
187 'type' => 'option',
188 'default' => self::defaults('background_color')
189 ]);
190
191 $wp_customize->add_setting(self::get_prefixed_id('background_text_color'), [
192 'type' => 'option',
193 'default' => self::defaults('background_text_color')
194 ]);
195
196 $wp_customize->add_setting(self::get_prefixed_id('content_background_color'), [
197 'type' => 'option',
198 'default' => self::defaults('content_background_color')
199 ]);
200
201 $wp_customize->add_setting(self::get_prefixed_id('content_header_color'), [
202 'type' => 'option',
203 'default' => self::defaults('content_header_color')
204 ]);
205
206 $wp_customize->add_setting(self::get_prefixed_id('content_text_color'), [
207 'type' => 'option',
208 'default' => self::defaults('content_text_color')
209 ]);
210
211 $wp_customize->add_setting(self::get_prefixed_id('header_logo'), [
212 'type' => 'option'
213 ]);
214
215 $wp_customize->add_setting(self::get_prefixed_id('header_text'), [
216 'default' => self::defaults('header_text'),
217 'type' => 'option'
218 ]);
219
220 $wp_customize->add_setting(self::get_prefixed_id('footer_text'), [
221 'default' => sprintf(esc_html__('© %s %s. All rights reserved.'), date('Y'), self::$site_title),
222 'type' => 'option'
223 ]);
224 }
225
226 /**
227 * @param \WP_Customize_Manager $wp_customize
228 */
229 public function controls($wp_customize)
230 {
231 $wp_customize->add_control(new \WP_Customize_Color_Control(
232 $wp_customize,
233 self::get_prefixed_id('background_color'),
234 array(
235 'label' => __('Background Color', 'wp-user-avatar'),
236 'section' => self::body_section,
237 'settings' => self::get_prefixed_id('background_color'),
238 'priority' => 10
239 )
240 ));
241
242 $wp_customize->add_control(new \WP_Customize_Color_Control(
243 $wp_customize,
244 self::get_prefixed_id('background_text_color'),
245 array(
246 'label' => __('Background Text Color', 'wp-user-avatar'),
247 'section' => self::body_section,
248 'settings' => self::get_prefixed_id('background_text_color'),
249 'priority' => 20
250 )
251 ));
252 $wp_customize->add_control(new \WP_Customize_Color_Control(
253 $wp_customize,
254 self::get_prefixed_id('content_background_color'),
255 array(
256 'label' => __('Content Background Color', 'wp-user-avatar'),
257 'section' => self::body_section,
258 'settings' => self::get_prefixed_id('content_background_color'),
259 'priority' => 30
260 )
261 ));
262
263 $wp_customize->add_control(new \WP_Customize_Color_Control(
264 $wp_customize,
265 self::get_prefixed_id('content_header_color'),
266 array(
267 'label' => __('Content Header Color', 'wp-user-avatar'),
268 'section' => self::body_section,
269 'settings' => self::get_prefixed_id('content_header_color'),
270 'priority' => 40
271 )
272 ));
273
274 $wp_customize->add_control(new \WP_Customize_Color_Control(
275 $wp_customize,
276 self::get_prefixed_id('content_text_color'),
277 array(
278 'label' => __('Content Text Color', 'wp-user-avatar'),
279 'section' => self::body_section,
280 'settings' => self::get_prefixed_id('content_text_color'),
281 'priority' => 40
282 )
283 ));
284
285 $wp_customize->add_control(new \WP_Customize_Cropped_Image_Control(
286 $wp_customize,
287 self::get_prefixed_id('header_logo'),
288 array(
289 'label' => __('Logo', 'wp-user-avatar'),
290 'section' => self::header_section,
291 'settings' => self::get_prefixed_id('header_logo'),
292 'flex_width' => true,
293 'flex_height' => true,
294 'width' => 308,
295 'height' => 48,
296 'button_labels' => array(
297 'select' => __('Select Logo', 'wp-user-avatar'),
298 'change' => __('Change Logo', 'wp-user-avatar'),
299 'default' => __('Default', 'wp-user-avatar'),
300 'remove' => __('Remove', 'wp-user-avatar'),
301 'placeholder' => __('No logo selected', 'wp-user-avatar'),
302 'frame_title' => __('Select Logo', 'wp-user-avatar'),
303 'frame_button' => __('Choose Logo', 'wp-user-avatar'),
304 ),
305 'priority' => 50
306 )
307 ));
308
309 $wp_customize->add_control(self::get_prefixed_id('header_text'), array(
310 'label' => __('Header Text', 'wp-user-avatar'),
311 'description' => __('This is used when template logo is not set.', 'wp-user-avatar'),
312 'section' => self::header_section,
313 'type' => 'text',
314 'settings' => self::get_prefixed_id('header_text'),
315 'priority' => 60
316 ));
317
318 $wp_customize->add_control(self::get_prefixed_id('footer_text'), array(
319 'label' => __('Footer Text', 'wp-user-avatar'),
320 'section' => self::footer_section,
321 'type' => 'textarea',
322 'settings' => self::get_prefixed_id('footer_text'),
323 'priority' => 70
324 ));
325 }
326
327 public static function get_instance()
328 {
329 static $instance = null;
330
331 if (is_null($instance)) {
332 $instance = new self();
333 }
334
335 return $instance;
336 }
337 }