PluginProbe ʕ •ᴥ•ʔ
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress / 3.1
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress v3.1
4.16.19 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 5 years ago EmailSettingsPage.php 5 years ago WPListTable.php 5 years ago email-template-preview.php 5 years ago
DefaultTemplateCustomizer.php
320 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_text_color' => '#51545e',
173 'header_text' => self::$site_title,
174 'footer_text' => sprintf(esc_html__('© %s %s. All rights reserved.'), date('Y'), '{{siteTitle}}')
175 ];
176
177 return isset($defaults[$setting]) ? $defaults[$setting] : '';
178 }
179
180 /**
181 * @param \WP_Customize_Manager $wp_customize
182 */
183 public function settings($wp_customize)
184 {
185 $wp_customize->add_setting(self::get_prefixed_id('background_color'), [
186 'type' => 'option',
187 'default' => self::defaults('background_color')
188 ]);
189
190 $wp_customize->add_setting(self::get_prefixed_id('background_text_color'), [
191 'type' => 'option',
192 'default' => self::defaults('background_text_color')
193 ]);
194
195 $wp_customize->add_setting(self::get_prefixed_id('content_background_color'), [
196 'type' => 'option',
197 'default' => self::defaults('content_background_color')
198 ]);
199
200 $wp_customize->add_setting(self::get_prefixed_id('content_text_color'), [
201 'type' => 'option',
202 'default' => self::defaults('content_text_color')
203 ]);
204
205 $wp_customize->add_setting(self::get_prefixed_id('header_logo'), [
206 'type' => 'option'
207 ]);
208
209 $wp_customize->add_setting(self::get_prefixed_id('header_text'), [
210 'default' => self::defaults('header_text'),
211 'type' => 'option'
212 ]);
213
214 $wp_customize->add_setting(self::get_prefixed_id('footer_text'), [
215 'default' => sprintf(esc_html__('© %s %s. All rights reserved.'), date('Y'), self::$site_title),
216 'type' => 'option'
217 ]);
218 }
219
220 /**
221 * @param \WP_Customize_Manager $wp_customize
222 */
223 public function controls($wp_customize)
224 {
225 $wp_customize->add_control(new \WP_Customize_Color_Control(
226 $wp_customize,
227 self::get_prefixed_id('background_color'),
228 array(
229 'label' => __('Background Color', 'wp-user-avatar'),
230 'section' => self::body_section,
231 'settings' => self::get_prefixed_id('background_color'),
232 'priority' => 10
233 )
234 ));
235
236 $wp_customize->add_control(new \WP_Customize_Color_Control(
237 $wp_customize,
238 self::get_prefixed_id('background_text_color'),
239 array(
240 'label' => __('Background Text Color', 'wp-user-avatar'),
241 'section' => self::body_section,
242 'settings' => self::get_prefixed_id('background_text_color'),
243 'priority' => 20
244 )
245 ));
246 $wp_customize->add_control(new \WP_Customize_Color_Control(
247 $wp_customize,
248 self::get_prefixed_id('content_background_color'),
249 array(
250 'label' => __('Content Background Color', 'wp-user-avatar'),
251 'section' => self::body_section,
252 'settings' => self::get_prefixed_id('content_background_color'),
253 'priority' => 30
254 )
255 ));
256
257 $wp_customize->add_control(new \WP_Customize_Color_Control(
258 $wp_customize,
259 self::get_prefixed_id('content_text_color'),
260 array(
261 'label' => __('Content Text Color', 'wp-user-avatar'),
262 'section' => self::body_section,
263 'settings' => self::get_prefixed_id('content_text_color'),
264 'priority' => 40
265 )
266 ));
267
268 $wp_customize->add_control(new \WP_Customize_Cropped_Image_Control(
269 $wp_customize,
270 self::get_prefixed_id('header_logo'),
271 array(
272 'label' => __('Logo', 'wp-user-avatar'),
273 'section' => self::header_section,
274 'settings' => self::get_prefixed_id('header_logo'),
275 'flex_width' => true,
276 'flex_height' => true,
277 'width' => 308,
278 'height' => 48,
279 'button_labels' => array(
280 'select' => __('Select Logo', 'wp-user-avatar'),
281 'change' => __('Change Logo', 'wp-user-avatar'),
282 'default' => __('Default', 'wp-user-avatar'),
283 'remove' => __('Remove', 'wp-user-avatar'),
284 'placeholder' => __('No logo selected', 'wp-user-avatar'),
285 'frame_title' => __('Select Logo', 'wp-user-avatar'),
286 'frame_button' => __('Choose Logo', 'wp-user-avatar'),
287 ),
288 'priority' => 50
289 )
290 ));
291
292 $wp_customize->add_control(self::get_prefixed_id('header_text'), array(
293 'label' => __('Header Text', 'wp-user-avatar'),
294 'description' => __('This is used when template logo is not set.', 'wp-user-avatar'),
295 'section' => self::header_section,
296 'type' => 'text',
297 'settings' => self::get_prefixed_id('header_text'),
298 'priority' => 60
299 ));
300
301 $wp_customize->add_control(self::get_prefixed_id('footer_text'), array(
302 'label' => __('Footer Text', 'wp-user-avatar'),
303 'section' => self::footer_section,
304 'type' => 'textarea',
305 'settings' => self::get_prefixed_id('footer_text'),
306 'priority' => 70
307 ));
308 }
309
310 public static function get_instance()
311 {
312 static $instance = null;
313
314 if (is_null($instance)) {
315 $instance = new self();
316 }
317
318 return $instance;
319 }
320 }