PluginProbe ʕ •ᴥ•ʔ
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress / 4.17.3
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress v4.17.3
4.17.3 4.17.2 4.17.1 4.17.0 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 / ShortcodeParser / FrontendProfileTag.php
wp-user-avatar / src / ShortcodeParser Last commit date
Builder 1 day ago MyAccount 3 months ago EditProfileTag.php 1 year ago FormProcessor.php 1 day ago FrontendProfileTag.php 1 day ago Init.php 4 years ago LoginFormTag.php 2 years ago MelangeTag.php 1 year ago MemberDirectoryTag.php 1 year ago MembershipShortcodes.php 1 year ago PasswordResetTag.php 3 months ago RegistrationFormTag.php 1 year ago index.php 5 years ago
FrontendProfileTag.php
220 lines
1 <?php
2
3 namespace ProfilePress\Core\ShortcodeParser;
4
5 use ProfilePress\Core\Classes\FormRepository as FR;
6 use ProfilePress\Core\ShortcodeParser\Builder\FrontendProfileBuilder;
7
8 /**
9 * Parse the individual profile shortcode of "Edit profile" builder
10 */
11 class FrontendProfileTag
12 {
13 public function __construct()
14 {
15 add_shortcode('profilepress-user-profile', array($this, 'user_profile_parser'));
16
17 add_action('wp', array($this, 'set_up_detected_profile'));
18
19 add_filter('pre_get_document_title', array($this, 'rewrite_profile_title'), 999999999, 1);
20 add_filter('wp_title', array($this, 'rewrite_profile_title'), 999999999, 1);
21 }
22
23 public function set_up_detected_profile()
24 {
25 global $ppress_frontend_profile_user_obj;
26
27 $who = get_query_var('who');
28
29 $user = '';
30
31 if (empty($who)) {
32 if (is_user_logged_in()) {
33 $user = wp_get_current_user();
34 } else {
35
36 if (strpos($_SERVER['REQUEST_URI'], '/' . ppress_get_profile_slug() . '/') !== false) {
37 nocache_headers();
38 wp_safe_redirect(home_url());
39 exit;
40 }
41 }
42 } else {
43
44 $username_or_nicename = apply_filters('ppress_frontend_user_profile_username', rawurldecode($who));
45
46 // attempt to check if the slug is a nice-name and then retrieve the username of the user.
47 $check = ppress_is_slug_nice_name($username_or_nicename);
48
49 if (is_string($check)) $username_or_nicename = $check;
50
51 $user = get_user_by('login', $username_or_nicename);
52
53 if ( ! $user) {
54 nocache_headers();
55 wp_safe_redirect(home_url());
56 exit;
57 }
58 }
59
60 $user = apply_filters('ppress_frontend_profile_wp_user_object', $user);
61
62 $ppress_frontend_profile_user_obj = $user;
63
64 FrontendProfileBuilder::get_instance($user);
65 }
66
67 /**
68 * Shortcode callback function to parse the shortcode.
69 *
70 * @param $atts
71 *
72 * @return string
73 */
74 public function user_profile_parser($atts)
75 {
76 global $ppress_frontend_profile_user_obj;
77
78 if ( ! is_user_logged_in() && ppress_get_setting('disable_guests_can_view_profiles') == 'on') {
79 return wpautop(sprintf(
80 __('This content is available to members only. Please <a href="%1$s">login</a> or <a href="%2$s">register</a> to view this area.', 'wp-user-avatar'),
81 ppress_login_url(),
82 ppress_registration_url()
83 ));
84 }
85
86 // Determine which user this shortcode instance will ultimately display, so the
87 // "members can't view other profiles" check below is enforced against the actual
88 // target user rather than the profile detected from the current URL/username.
89 $requested_user_id = ! empty($atts['user-id'])
90 ? absint($atts['user-id'])
91 : (int) ppress_var_obj($ppress_frontend_profile_user_obj, 'ID');
92
93 if (is_user_logged_in() && ppress_get_setting('disable_members_can_view_profiles') == 'on' && $requested_user_id !== get_current_user_id()) {
94 return wpautop(esc_html__('You are not authorized to access this area.', 'wp-user-avatar'));
95 }
96
97 $id = absint($atts['id']);
98
99 $user = '';
100
101 if ( ! empty($atts['user-id'])) {
102
103 $user = apply_filters('ppress_frontend_profile_wp_user_object', get_user_by('ID', $requested_user_id));
104
105 $ppress_frontend_profile_user_obj = $user;
106
107 // we are instantiating the class directly because it has already been called by set_up_detected_profile hooked into wp
108 // action. If we had used the singleton instance method, it would have returned the previous instance.
109 new FrontendProfileBuilder($user);
110 }
111
112 do_action('ppress_frond_end_profile_id', $id);
113
114 $attribution_start = apply_filters('ppress_hide_attribution', '<!-- This WordPress front-end profile is built and powered by ProfilePress WordPress plugin - https://profilepress.com -->' . "\r\n");
115 $attribution_end = apply_filters('ppress_hide_attribution', "\r\n" . '<!-- / ProfilePress WordPress plugin. -->' . "\r\n");
116 $css = self::get_user_profile_css($id);
117
118 // call the registration structure/design
119 return apply_filters('ppress_front_end_profile', $attribution_start . $css . $this->get_user_profile_structure($id) . $attribution_end, $user, $id);
120 }
121
122
123 /**
124 * Get the registration structure from the database
125 *
126 * @param int $id
127 *
128 * @return string
129 */
130 public static function get_user_profile_structure($id)
131 {
132 if (FR::is_drag_drop($id, FR::USER_PROFILE_TYPE)) {
133 $form_instance = FR::dnd_class_instance($id, FR::USER_PROFILE_TYPE);
134 if ( ! $form_instance) return esc_html__('Form class not found. Please check if this user profile actually exist in ProfilePress.', 'wp-user-avatar');
135 $user_profile_structure = $form_instance->form_structure();
136 } else {
137 $user_profile_structure = FR::get_form_meta($id, FR::USER_PROFILE_TYPE, FR::FORM_STRUCTURE);
138 }
139
140 return do_shortcode($user_profile_structure);
141 }
142
143
144 /**
145 * Get the CSS stylesheet for the ID registration
146 *
147 * @return mixed
148 */
149 public static function get_user_profile_css($id)
150 {
151 if (FR::is_drag_drop($id, FR::USER_PROFILE_TYPE)) {
152 $form_instance = FR::dnd_class_instance($id, FR::USER_PROFILE_TYPE);
153 if ( ! $form_instance) return '';
154 $user_profile_css = $form_instance->minified_form_css();
155 } else {
156 $user_profile_css = FR::get_form_meta($id, FR::USER_PROFILE_TYPE, FR::FORM_CSS);
157 }
158
159 return "<style type=\"text/css\">\r\n $user_profile_css \r\n</style>";
160 }
161
162 /** Rewrite the title of the profile */
163 public function rewrite_profile_title($title)
164 {
165 global $post, $ppress_frontend_profile_user_obj;
166
167 // if currently viewed page is the page with the front-end profile, rewrite the title accordingly.
168 if ((isset($post->ID) && !empty(ppress_get_setting('set_user_profile_shortcode')) && $post->ID == ppress_get_setting('set_user_profile_shortcode'))
169 || ppress_post_content_has_shortcode('profilepress-user-profile')
170 ) {
171
172 $user_object = $ppress_frontend_profile_user_obj;
173
174 if (isset($user_object) && is_object($user_object)) {
175
176 // if first and last name is set, use the combo as title
177 if ( ! empty($user_object->first_name) && ! empty($user_object->last_name)) {
178 $title = "$user_object->first_name {$user_object->last_name}";
179 } // if either first or last name is set, use either as title
180 elseif ( ! empty($user_object->first_name) || ! empty($user_object->last_name)) {
181 $title = "$user_object->first_name {$user_object->last_name}";
182 } // else use their username
183 else {
184 $title = $user_object->user_login;
185 }
186
187 $title = apply_filters('ppress_profile_username_title', self::title_possessiveness($title), $title);
188 }
189 }
190
191 return $title;
192 }
193
194 public static function title_possessiveness($string)
195 {
196 $string = trim($string);
197 $lastchar = substr($string, -1);
198
199 $profile_string = esc_html__('Profile', 'wp-user-avatar');
200
201 if ('s' == $lastchar) {
202 $title = ucwords($string) . "' $profile_string";
203 } else {
204 $title = ucwords($string) . "'s $profile_string";
205 }
206
207 return $title;
208 }
209
210 public static function get_instance()
211 {
212 static $instance = false;
213
214 if ( ! $instance) {
215 $instance = new self;
216 }
217
218 return $instance;
219 }
220 }