PluginProbe ʕ •ᴥ•ʔ
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress / 4.16.19
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress v4.16.19
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 / Themes / DragDrop / UserProfile / DefaultTemplate.php
wp-user-avatar / src / Themes / DragDrop / UserProfile Last commit date
DefaultTemplate.php 3 years ago Dixon.php 1 year ago
DefaultTemplate.php
544 lines
1 <?php
2
3 namespace ProfilePress\Core\Themes\DragDrop\UserProfile;
4
5 use ProfilePress\Core\Admin\SettingsPages\DragDropBuilder\DragDropBuilder;
6 use ProfilePress\Core\Classes\ExtensionManager as EM;
7 use ProfilePress\Core\ShortcodeParser\Builder\FrontendProfileBuilder;
8 use ProfilePress\Core\Themes\DragDrop\AbstractTheme;
9 use ProfilePress\Core\Admin\SettingsPages\DragDropBuilder\Fields;
10
11 class DefaultTemplate extends AbstractTheme
12 {
13
14 public function __construct($form_id, $form_type)
15 {
16 parent::__construct($form_id, $form_type);
17
18 add_action('ppress_profile_tab_content_main', [$this, 'profile_content_main']);
19 add_action('ppress_profile_tab_content_posts', [$this, 'profile_content_posts']);
20 add_action('ppress_profile_tab_content_comments', [$this, 'profile_content_comments']);
21 }
22
23 public static function default_field_listing()
24 {
25 Fields\Init::init();
26 $standard_fields = DragDropBuilder::get_instance()->standard_fields();
27
28 return [
29 $standard_fields['profile-username'],
30 $standard_fields['profile-email'],
31 $standard_fields['profile-first-name'],
32 $standard_fields['profile-last-name'],
33 $standard_fields['profile-website'],
34 $standard_fields['profile-bio'],
35 ];
36 }
37
38 public function default_metabox_settings()
39 {
40 $data = parent::default_metabox_settings();
41 $data['ppress_dpf_max_width'] = '1000px';
42 $data['ppress_dpf_area_max_width'] = '600px';
43 $data['ppress_dpf_profile_cover_enabled'] = 'true';
44 $data['ppress_dpf_profile_show_bio'] = 'true';
45 $data['ppress_dpf_profile_cover_ratio'] = '2.7';
46 $data['ppress_dpf_profile_header_display_name'] = 'first_last_names';
47 $data['ppress_dpf_profile_user_meta'] = [];
48 $data['ppress_dpf_profile_menu_tabs'] = ['main', 'posts', 'comments'];
49
50 $data['ppress_dpf_profile_header_name_color'] = '#555555';
51 $data['ppress_dpf_profile_body_text_color'] = '#666666';
52 $data['ppress_dpf_profile_menu_background_color'] = '#444444';
53 $data['ppress_dpf_profile_menu_tab_text_color'] = '#ffffff';
54 $data['ppress_dpf_profile_active_menu_tab_bg_color'] = '#007bff';
55
56 return $data;
57 }
58
59 public function appearance_settings($settings)
60 {
61 $profile_tabs = $this->profile_tabs();
62
63 $settings[] = [
64 'id' => 'ppress_dpf_max_width',
65 'type' => 'text',
66 'label' => esc_html__('Profile Maximum Width', 'wp-user-avatar'),
67 'description' => esc_html__('The maximum width of the profile template.', 'wp-user-avatar'),
68 'priority' => 10
69 ];
70
71 $settings[] = [
72 'id' => 'ppress_dpf_area_max_width',
73 'type' => 'text',
74 'label' => esc_html__('Profile Area Maximum Width', 'wp-user-avatar'),
75 'description' => esc_html__('The maximum width of the profile area inside profile below the header.', 'wp-user-avatar'),
76 'priority' => 20
77 ];
78
79 $settings[] = [
80 'id' => 'ppress_dpf_profile_cover_enabled',
81 'type' => 'checkbox',
82 'label' => esc_html__('Enable Cover Photo', 'wp-user-avatar'),
83 'priority' => 40
84 ];
85
86 $settings[] = [
87 'id' => 'ppress_dpf_profile_cover_ratio',
88 'type' => 'select',
89 'label' => esc_html__('Profile Cover Ratio', 'wp-user-avatar'),
90 'options' => [
91 '1.6' => '1.6:1',
92 '2.7' => '2.7:1',
93 '3.2' => '3.2:1',
94 ],
95 'description' => esc_html__('Choose an aspect ratio of the profile cover photo.', 'wp-user-avatar'),
96 'priority' => 50
97 ];
98
99 $settings[] = [
100 'id' => 'ppress_dpf_profile_header_display_name',
101 'type' => 'select',
102 'label' => esc_html__('Header Text', 'wp-user-avatar'),
103 'options' => [
104 'hide' => esc_html__('Hide', 'wp-user-avatar'),
105 'username' => esc_html__('Username', 'wp-user-avatar'),
106 'display-name' => esc_html__('Display Name', 'wp-user-avatar'),
107 'nickname' => esc_html__('Nickname', 'wp-user-avatar'),
108 'first_last_names' => esc_html__('First & Last Name', 'wp-user-avatar'),
109 'last_first_names' => esc_html__('Last & First Name', 'wp-user-avatar'),
110 'first-name' => esc_html__('First Name Only', 'wp-user-avatar')
111 ],
112 'description' => esc_html__('What to use as display name in profile header. Select "Hide" to hide it from showing.', 'wp-user-avatar'),
113 'priority' => 60
114 ];
115
116 if (EM::is_enabled(EM::CUSTOM_FIELDS)) {
117
118 $settings[] = [
119 'id' => 'ppress_dpf_profile_show_social_links',
120 'type' => 'checkbox',
121 'label' => esc_html__('Show Social Links in Header', 'wp-user-avatar'),
122 'priority' => 70
123 ];
124 } else {
125
126 $upgrade_url = 'https://profilepress.com/pricing/?utm_source=wp_dashboard&utm_medium=upgrade&utm_campaign=default_profile_social_link';
127 $settings[] = [
128 'id' => 'ppress_dpf_profile_social_link_upsell',
129 'label' => '',
130 'type' => 'custom',
131 'content' => sprintf(
132 esc_html__('%sUpgrade to ProfilePress premium%s if you don\'t have the custom field addon to display users social profiles.', 'wp-user-avatar'),
133 '<a href="' . $upgrade_url . '" target="_blank">', '</a>'
134 ),
135 ];
136 }
137
138 $settings[] = [
139 'id' => 'ppress_dpf_profile_show_bio',
140 'type' => 'checkbox',
141 'label' => esc_html__('Show Bio in Header', 'wp-user-avatar'),
142 'priority' => 80
143 ];
144
145 $settings[] = [
146 'id' => 'ppress_dpf_profile_user_meta',
147 'type' => 'select2',
148 'label' => esc_html__('Fields to Show in User Meta', 'wp-user-avatar'),
149 'options' => ppress_standard_custom_fields_key_value_pair(true),
150 'priority' => 90
151 ];
152
153 $settings[] = [
154 'id' => 'ppress_dpf_profile_menu_tabs',
155 'type' => 'select2',
156 'label' => esc_html__('Profile Menu Tabs', 'wp-user-avatar'),
157 'options' => array_reduce(array_keys($profile_tabs), function ($carry, $item) use ($profile_tabs) {
158 $carry[$item] = $profile_tabs[$item]['title'];
159
160 return $carry;
161 }),
162 'priority' => 100
163 ];
164
165 return $settings;
166 }
167
168 public function color_settings($settings)
169 {
170 $settings2 = [
171 [
172 'id' => 'ppress_dpf_profile_header_name_color',
173 'type' => 'color',
174 'label' => esc_html__('Header Name', 'wp-user-avatar')
175 ],
176 [
177 'id' => 'ppress_dpf_profile_body_text_color',
178 'type' => 'color',
179 'label' => esc_html__('Body Text', 'wp-user-avatar')
180 ],
181 [
182 'id' => 'ppress_dpf_profile_menu_background_color',
183 'type' => 'color',
184 'label' => esc_html__('Menu Background', 'wp-user-avatar')
185 ],
186 [
187 'id' => 'ppress_dpf_profile_menu_tab_text_color',
188 'type' => 'color',
189 'label' => esc_html__('Menu Tab Text', 'wp-user-avatar')
190 ],
191 [
192 'id' => 'ppress_dpf_profile_active_menu_tab_bg_color',
193 'type' => 'color',
194 'label' => esc_html__('Active Menu Tab Background', 'wp-user-avatar')
195 ]
196 ];
197
198 return array_merge($settings, $settings2);
199 }
200
201 private function cover_image_structure()
202 {
203 $cover_ratio = $this->get_meta('ppress_dpf_profile_cover_ratio');
204 if (empty($cover_ratio)) $cover_ratio = '2.7';
205 ?>
206 <div class="ppress-default-profile-cover" data-ratio="<?php echo esc_attr($cover_ratio); ?>">
207 <div class="ppress-default-profile-cover-e" data-ratio="<?php echo esc_attr($cover_ratio); ?>">
208 <img src="[profile-cover-image-url]">
209 </div>
210 </div>
211 <?php
212 }
213
214 private function is_profile_cover_enabled()
215 {
216 return $this->get_meta('ppress_dpf_profile_cover_enabled') == 'true';
217 }
218
219 private function header_social_links()
220 {
221 if ($this->get_meta('ppress_dpf_profile_show_social_links') !== 'true') return;
222
223 echo $this->social_profile_icons();
224 }
225
226 public function profile_tabs()
227 {
228 return apply_filters('ppress_profile_tabs', [
229 'main' => [
230 'icon' => 'person',
231 'title' => esc_html__('About', 'wp-user-avatar')
232 ],
233 'posts' => [
234 'icon' => 'create',
235 'title' => esc_html__('Posts', 'wp-user-avatar')
236 ],
237 'comments' => [
238 'icon' => 'comment',
239 'title' => esc_html__('Comments', 'wp-user-avatar')
240 ]
241 ], $this);
242 }
243
244 private function active_tab()
245 {
246 $active = apply_filters('ppress_dpf_default_tab', 'main', $this);
247
248 if ( ! empty($_GET['tab'])) {
249
250 $sanitized_tab = sanitize_text_field($_GET['tab']);
251
252 if (in_array($sanitized_tab, array_keys($this->profile_tabs()))) {
253 $active = sanitize_text_field($_GET['tab']);
254 }
255 }
256
257 return $active;
258 }
259
260 public function profile_tabs_section()
261 {
262 $saved_tabs = array_filter($this->get_meta('ppress_dpf_profile_menu_tabs'), function ($item) {
263 return ! empty($item);
264 });
265
266 if (empty($saved_tabs)) $saved_tabs = ['main', 'posts', 'comments'];
267
268 $saved_tabs = apply_filters('ppress_dpf_saved_tabs', $saved_tabs, $this);
269
270 $profile_tabs = $this->profile_tabs();
271
272 if ( ! empty($saved_tabs)) {
273
274 echo '<div class="ppress-dpf-profile-nav">';
275
276 foreach ($saved_tabs as $tab_id) :
277 $url = $profile_tabs[$tab_id]['url'] ?? esc_url(remove_query_arg('pfpage', add_query_arg('tab', $tab_id)));
278 ?>
279 <div class="ppress-dpf-profile-nav-item ppress-dpf-nav-<?= $tab_id ?><?= $this->active_tab() == $tab_id ? ' ppress-dpf-active' : ''; ?>">
280 <a href="<?= $url ?>">
281 <span class="ppress-material-icons"><?= $profile_tabs[$tab_id]['icon'] ?></span>
282 <span class="ppress-dpf-nav-title"><?= $profile_tabs[$tab_id]['title'] ?></span>
283 </a>
284 </div>
285 <?php endforeach;
286 echo '<div class="ppress-dpf-clear"></div>';
287 echo '</div>';
288 }
289 }
290
291 public function profile_content_main()
292 {
293 $profile_listing = $this->profile_listing()
294 ->item_wrap_start_tag('<div class="ppress-dpf-profile-body-item">')
295 ->item_wrap_end_tag('</div>')
296 ->title_start_tag('<div class="ppress-dpf-item-label">')
297 ->title_end_tag('</div>')
298 ->info_start_tag('<div class="ppress-dpf-item-value">')
299 ->info_end_tag('</div>')
300 ->forge();
301
302 $has_field_data = $profile_listing->has_field_data();
303
304 $profile_listing = $profile_listing->output();
305
306 if ($has_field_data === false) : ?>
307 <p class="ppress-dpf-profile-note">
308 <span class="ppress-material-icons">sentiment_dissatisfied</span>
309 <span>
310
311 <?php if (ppress_is_my_own_profile()) :
312 printf(
313 __('Your profile is looking a little empty. Why not <a href="%s">add some information</a>?', 'wp-user-avatar'),
314 ppress_edit_profile_url()
315 );
316 else :
317 esc_html_e("This user hasn't added any information to their profile yet. Check back later.", 'wp-user-avatar');
318 endif; ?>
319 </span>
320 </p>
321 <?php endif;
322
323 if ($has_field_data === true) { ?>
324 <div class="ppress-dpf-profile-body-items">
325 <?php echo $profile_listing; ?>
326 </div>
327 <?php
328 }
329 }
330
331 public function profile_content_posts()
332 {
333 /** @var \WP_User */
334 global $ppress_frontend_profile_user_obj;
335
336 $current_page = absint(ppressGET_var('pfpage', 1));
337 $pagination_args = apply_filters('ppress_profile_posts_pagination_args', ['limit' => 10], $this);
338 $limit = absint($pagination_args['limit']);
339
340 $offset = $current_page > 1 ? ($current_page - 1) * $limit : 0;
341
342 $posts = FrontendProfileBuilder::author_posts_query(
343 $ppress_frontend_profile_user_obj->ID,
344 ['limit' => $limit, 'offset' => $offset]
345 );
346
347 echo $posts['structure'];
348
349 if (ppress_settings_by_key('author_slug_to_profile') != 'on' && $posts['total_post_count'] >= $limit) {
350
351 printf(
352 '<div class="ppress-dpf-more-post-wrap"><a href="%s" class="ppress-dpf-more-post-btn">%s</a></div>',
353 esc_url(add_query_arg('pfpage', ++$current_page)),
354 apply_filters(
355 'ppress_profile_posts_pagination_button',
356 esc_html__('See More Posts', 'wp-user-avatar'),
357 $this
358 )
359 );
360 }
361 }
362
363 public function profile_content_comments()
364 {
365 /** @var \WP_User */
366 global $ppress_frontend_profile_user_obj;
367
368 $current_page = absint(ppressGET_var('pfpage', 1));
369 $pagination_args = apply_filters('ppress_profile_comments_pagination_args', ['limit' => 10], $this);
370 $limit = absint($pagination_args['limit']);
371
372 $offset = $current_page > 1 ? ($current_page - 1) * $limit : 0;
373
374 $comments = FrontendProfileBuilder::author_comment_query(
375 $ppress_frontend_profile_user_obj->ID,
376 ['limit' => $limit, 'offset' => $offset]
377 );
378
379 echo $comments['structure'];
380
381 if ($comments['comment_count'] >= $limit) {
382 printf(
383 '<div class="ppress-dpf-more-post-wrap"><a href="%s" class="ppress-dpf-more-post-btn">%s</a></div>',
384 esc_url(add_query_arg('pfpage', ++$current_page)),
385 apply_filters(
386 'ppress_profile_comments_pagination_button',
387 esc_html__('See More Comments', 'wp-user-avatar'),
388 $this
389 )
390 );
391 }
392 }
393
394 public function form_structure()
395 {
396 $active_tab = $this->active_tab();
397
398 $max_width = esc_html($this->get_meta('ppress_dpf_max_width'));
399 $profile_area_max_width = esc_html($this->get_meta('ppress_dpf_area_max_width'));
400 $header_display_name = esc_html($this->get_meta('ppress_dpf_profile_header_display_name'));
401
402 /** @see https://stackoverflow.com/a/20373067/2648410 using array_values to reindex array numeric keys */
403 $profile_user_meta = array_values(
404 array_filter(
405 array_map(function ($meta_key) {
406
407 if (empty($meta_key)) return false;
408
409 $value = $this->get_profile_field($meta_key, true);
410
411 return empty($value) ? false : $value;
412
413 }, $this->get_meta('ppress_dpf_profile_user_meta'))
414 )
415 );
416
417 $classes = 'ppress-default-profile';
418
419 if ( ! $this->is_profile_cover_enabled()) {
420 $classes .= ' ppdf-nocover';
421 }
422 ob_start();
423 ?>
424 [pp-form-wrapper class="<?= $classes ?>" style="max-width:<?= $max_width ?>"]
425
426 <?php if ($this->is_profile_cover_enabled()) $this->cover_image_structure(); ?>
427
428 <div class="ppress-dpf-header">
429 <?php if (ppress_is_my_own_profile()) : ?>
430 <div class="ppress-dpf-headericon">
431 <a href="<?= ppress_my_account_url(); ?>" class="ppress-dpf-edit-a ppress-hint-wrap hint--bottom" aria-label="<?= esc_html__('Edit your profile') ?>">
432 <span class="ppress-material-icons">settings</span>
433 </a>
434 </div>
435 <?php endif; ?>
436
437 <div class="ppress-dpf-profile-photo">
438 <img src="[profile-avatar-url]" width="190" height="190">
439 </div>
440
441 <div class="ppress-dpf-profile-meta">
442 <div class="ppress-dpf-main-meta">
443
444 <?php if ('hide' !== $header_display_name) : ?>
445 <div class="ppress-dpf-name"><?= $this->get_profile_field($header_display_name) ?></div>
446 <?php endif; ?>
447
448 <?php $this->header_social_links(); ?>
449 </div>
450
451 <?php if (is_array($profile_user_meta) && ! empty($profile_user_meta)) : $count = count($profile_user_meta) - 1; ?>
452 <div class="ppress-dpf-meta">
453 <?php foreach ($profile_user_meta as $index => $meta_data) : ?>
454 <?= $meta_data ?>
455 <?php if ($index !== $count): ?>
456 <span class="b">&bull;</span>
457 <?php endif; ?>
458 <?php endforeach; ?>
459 </div>
460 <?php endif; ?>
461
462 <?php if ($this->get_meta('ppress_dpf_profile_show_bio') == 'true') : ?>
463 <div class="ppress-dpf-meta-text">
464 [profile-bio]
465 </div>
466 <?php endif; ?>
467
468 </div>
469
470 <div class="ppress-dpf-clear"></div>
471
472 </div>
473
474 <?php $this->profile_tabs_section(); ?>
475
476 <div class="ppress-dpf-profile-body ppdf-<?= $active_tab ?>"<?= ! empty($profile_area_max_width) ? ' style="max-width:' . $profile_area_max_width . '"' : '' ?>>
477 <?php do_action(sprintf('ppress_profile_tab_content_%s', $active_tab)); ?>
478 </div>
479 [/pp-form-wrapper]
480
481 <?php
482 return ob_get_clean();
483 }
484
485 public function form_css()
486 {
487 $form_id = $this->form_id;
488 $form_type = $this->form_type;
489
490 $photo_size = 190;
491
492 $meta_padding = ($photo_size + 60) . 'px';
493
494 $photosize_up = ($photo_size / 2) + 5;
495
496 $profile_photo_style = [
497 "width:{$photo_size}px",
498 "height:{$photo_size}px"
499 ];
500
501 if ($this->is_profile_cover_enabled()) {
502 $profile_photo_style[] = "top:-" . $photosize_up . "px";
503 }
504
505 $profile_photo_style = implode(';', $profile_photo_style);
506
507 $header_name_color = esc_html($this->get_meta('ppress_dpf_profile_header_name_color'));
508 $body_text_color = esc_html($this->get_meta('ppress_dpf_profile_body_text_color'));
509 $menu_background_color = esc_html($this->get_meta('ppress_dpf_profile_menu_background_color'));
510 $menu_tab_text_color = esc_html($this->get_meta('ppress_dpf_profile_menu_tab_text_color'));
511 $active_menu_tab_bg_color = esc_html($this->get_meta('ppress_dpf_profile_active_menu_tab_bg_color'));
512
513 return <<<CSS
514 div#pp-$form_type-$form_id.ppress-default-profile .ppress-dpf-profile-photo {
515 $profile_photo_style
516 }
517
518 div#pp-$form_type-$form_id.ppress-default-profile {
519 color: $body_text_color;
520 }
521
522 div#pp-$form_type-$form_id.ppress-default-profile .ppress-dpf-profile-nav {
523 background: $menu_background_color;
524 }
525
526 div#pp-$form_type-$form_id.ppress-default-profile .ppress-dpf-profile-nav-item a {
527 color: $menu_tab_text_color;
528 }
529
530 div#pp-$form_type-$form_id.ppress-default-profile .ppress-dpf-name {
531 color: $header_name_color;
532 }
533
534 div#pp-$form_type-$form_id.ppress-default-profile .ppress-dpf-profile-meta {
535 padding-left: $meta_padding;
536 }
537
538 div#pp-$form_type-$form_id.ppress-default-profile .ppress-dpf-profile-nav-item.ppress-dpf-active a {
539 background: $active_menu_tab_bg_color;
540 }
541 CSS;
542
543 }
544 }