PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.74
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.74
1.2.74 1.2.73 1.2.72 1.2.71 1.2.70 1.2.69 1.2.68 1.2.67 1.2.66 1.2.65 1.2.64 1.2.63 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 All 174 releases
← All changes | includes/class-templates.php +1309 -612 1.0.141.2.74 View file →
@@ -1,5 +1,6 @@
1 1 <?php
2 +
2 3 /**
3 4 * Template related functions
4 5 *
5 6 * This class defines all code necessary for UsersWP templates like login. register etc.
@@ -7,692 +8,1388 @@
7 8 * @since 1.0.0
8 9 * @author GeoDirectory Team <info@wpgeodirectory.com>
9 10 */
10 11 class UsersWP_Templates {
11 -
12 - /**
13 - * Locates UsersWP templates based on template type.
14 - *
15 - * @since 1.0.0
16 - * @package userswp
17 - * @param string $template Template type.
18 - * @return string The template filename if one is located.
19 - */
20 - public function uwp_locate_template( $template ) {
21 -
22 - switch ($template) {
23 - case 'register':
24 - return $this->uwp_generic_locate_template('register');
25 - break;
26 12
27 - case 'login':
28 - return $this->uwp_generic_locate_template('login');
29 - break;
13 + /**
14 + * The function is use for Retrieve the name of the highest
15 + * priority template file that exists.
16 + *
17 + * @param string $template_name Template files to search for, in order.
18 + * @param string $template_path Optional. Template path. Default null.
19 + * @param string $default_path Optional. Default path. Default null.
20 + *
21 + * @return string Template path.
22 + */
23 + public static function locate_template( $template_name, $template_path = '', $default_path = '' ) {
30 24
31 - case 'forgot':
32 - return $this->uwp_generic_locate_template('forgot');
33 - break;
25 + if ( ! $template_path ) {
26 + $template_path = uwp_get_theme_template_dir_name();
27 + }
34 28
35 - case 'change':
36 - return $this->uwp_generic_locate_template('change');
37 - break;
29 + if ( ! $default_path ) {
30 + $default_path = uwp_get_templates_dir();
31 + }
38 32
39 - case 'reset':
40 - return $this->uwp_generic_locate_template('reset');
41 - break;
33 + // Look within passed path within the theme - this is priority.
34 + $template = locate_template(
35 + array(
36 + untrailingslashit( $template_path ) . '/' . $template_name,
37 + $template_name,
38 + )
39 + );
42 40
43 - case 'account':
44 - return $this->uwp_generic_locate_template('account');
45 - break;
41 + // Get default template
42 + if ( ! $template ) {
43 + $template = untrailingslashit( $default_path ) . '/' . $template_name;
44 + }
46 45
47 - case 'profile':
48 - return $this->uwp_generic_locate_template('profile');
49 - break;
46 + // Return what we found.
47 + return apply_filters( 'uwp_locate_template', $template, $template_name, $template_path );
48 + }
50 49
51 - case 'users':
52 - return $this->uwp_generic_locate_template('users');
53 - break;
54 - }
50 + /**
51 + *
52 + * Displays default content for UWP pages
53 + *
54 + * @param $content
55 + *
56 + * @return string
57 + */
58 + public static function setup_singular_page_content( $content ) {
59 + global $post, $wp_query;
55 60
56 - return apply_filters('uwp_locate_template', false, $template);
57 - }
61 + if ( ! is_uwp_page() ) {
62 + return $content;
63 + }
58 64
59 - /**
60 - * Locates UsersWP templates based on template type.
61 - * Fallback to core templates when no custom templates found.
62 - *
63 - * @since 1.0.0
64 - * @package userswp
65 - * @param string $type Template type.
66 - * @return string The template filename if one is located.
67 - */
68 - public function uwp_generic_locate_template($type = 'register') {
69 -
70 - $plugin_path = dirname( dirname( __FILE__ ) );
71 -
72 - $template = locate_template(array("userswp/".$type.".php"));
73 - if (!$template) {
74 - $template = $plugin_path . '/templates/'.$type.'.php';
75 - }
76 - $template = apply_filters('uwp_template_'.$type, $template);
77 - return $template;
78 - }
65 + if ( ! ( ! empty( $wp_query ) && ! empty( $post ) && ( $post->ID == get_queried_object_id() ) ) ) {
66 + return $content;
67 + }
79 68
80 - /**
81 - * Doing some access checks for UsersWP related pages.
82 - *
83 - * @since 1.0.0
84 - * @package userswp
85 - * @return bool
86 - */
87 - public function access_checks() {
88 - global $post;
69 + /*
70 + * Some page builders need to be able to take control here so we add a filter to bypass it on the fly
71 + */
72 + if ( apply_filters( 'uwp_bypass_setup_singular_page', false ) ) {
73 + return $content;
74 + }
89 75
90 - if (!is_page()) {
91 - return false;
92 - }
76 + remove_filter( 'the_content', array( __CLASS__, 'setup_singular_page_content' ) );
93 77
94 - $current_page_id = $post->ID;
95 -
96 - $register_page = uwp_get_page_id('register_page', false);
97 - $login_page = uwp_get_page_id('login_page', false);
98 - $forgot_page = uwp_get_page_id('forgot_page', false);
99 - $reset_page = uwp_get_page_id('reset_page', false);
78 + if ( in_the_loop() ) {
100 79
101 - $change_page = uwp_get_page_id('change_page', false);
102 - $account_page = uwp_get_page_id('account_page', false);
103 -
104 - if (( $register_page && ((int) $register_page == $current_page_id )) ||
105 - ( $login_page && ((int) $login_page == $current_page_id ) ) ||
106 - ( $forgot_page && ((int) $forgot_page == $current_page_id ) ) ||
107 - ( $reset_page && ((int) $reset_page == $current_page_id ) )) {
108 - if (is_user_logged_in()) {
109 - $redirect_page_id = uwp_get_page_id('account_page', false);
110 - if (empty($redirect_page_id)) {
111 - $redirect_to = home_url('/');
112 - } else {
113 - $redirect_to = get_permalink($redirect_page_id);
80 + if ( $content == '' ) {
81 + if ( is_uwp_profile_page() ) {
82 + $content = '[uwp_profile]';
83 + } elseif ( is_uwp_register_page() ) {
84 + $content = '[uwp_register]';
85 + } elseif ( is_uwp_login_page() ) {
86 + $content = '[uwp_login]';
87 + } elseif ( is_uwp_forgot_page() ) {
88 + $content = '[uwp_forgot]';
89 + } elseif ( is_uwp_change_page() ) {
90 + $content = '[uwp_change]';
91 + } elseif ( is_uwp_reset_page() ) {
92 + $content = '[uwp_reset]';
93 + } elseif ( is_uwp_account_page() ) {
94 + $content = '[uwp_account]';
95 + } elseif ( is_uwp_users_page() ) {
96 + $content = '[uwp_users]';
97 + } elseif ( is_uwp_users_item_page() ) {
98 + $content = UsersWP_Defaults::page_user_list_item_content();
99 + } else {
100 + // do nothing
101 + }
102 +
103 + // run the shortcodes on the content
104 + $content = do_shortcode( $content );
105 +
106 + // run block content if its available
107 + if ( function_exists( 'do_blocks' ) ) {
108 + $content = do_blocks( $content );
109 + }
110 + }
111 +
112 + }
113 +
114 + // add our filter back
115 + add_filter( 'the_content', array( __CLASS__, 'setup_singular_page_content' ) );
116 +
117 +
118 + return $content;
119 + }
120 +
121 + /**
122 + *
123 + * Returns content for the users list item template
124 + *
125 + * @return string
126 + */
127 + public static function users_list_item_template_content() {
128 +
129 + $item_page_id = uwp_get_option( 'user_list_item_page', 0 );
130 + $content = get_post_field( 'post_content', $item_page_id );
131 +
132 + /*
133 + * Some page builders need to be able to take control here so we add a filter to bypass it on the fly
134 + */
135 + $bypass_content = apply_filters( 'uwp_bypass_users_list_item_template_content', '', $content, $item_page_id );
136 + if ( $bypass_content ) {
137 + return $bypass_content;
138 + }
139 +
140 + // if the content is blank then we grab the page defaults
141 + if ( $content == '' ) {
142 + $content = UsersWP_Defaults::page_user_list_item_content();
143 + }
144 +
145 + // run the shortcodes on the content
146 + $content = do_shortcode( $content );
147 +
148 + // run block content if its available
149 + if ( function_exists( 'do_blocks' ) ) {
150 + $content = do_blocks( $content );
151 + }
152 +
153 +
154 + return $content;
155 + }
156 +
157 + /**
158 + * Disable our sub templates access from frontend.
159 + *
160 + * @global object $post WordPress Post object.
161 + *
162 + * @since 1.2.1.2
163 + */
164 + public static function redirect_templates_sub_pages() {
165 + global $post;
166 + if ( isset( $post->ID ) && ! current_user_can( 'administrator' ) && (
167 + $post->ID == uwp_get_page_id( 'user_list_item_page' )
168 + ) ) {
169 + wp_redirect( home_url(), 301 );
170 + exit;
171 + }
172 + }
173 +
174 + /**
175 + * Doing some access checks for UsersWP related pages.
176 + *
177 + * @return bool
178 + * @package userswp
179 + * @since 1.0.0
180 + */
181 + public function access_checks() {
182 + global $post;
183 +
184 + if ( ! is_page() ) {
185 + return false;
186 + }
187 +
188 + if ( uwp_is_page_builder() ) {
189 + return false;
190 + }
191 +
192 + $current_page_id = $post->ID;
193 +
194 + $register_page = uwp_get_page_id( 'register_page', false );
195 + $login_page = uwp_get_page_id( 'login_page', false );
196 + $forgot_page = uwp_get_page_id( 'forgot_page', false );
197 + $reset_page = uwp_get_page_id( 'reset_page', false );
198 +
199 + $change_page = uwp_get_page_id( 'change_page', false );
200 + $account_page = uwp_get_page_id( 'account_page', false );
201 +
202 + if ( ( $register_page && ( (int) $register_page == $current_page_id ) ) ||
203 + ( $login_page && ( (int) $login_page == $current_page_id ) ) ||
204 + ( $forgot_page && ( (int) $forgot_page == $current_page_id ) ) ||
205 + ( $reset_page && ( (int) $reset_page == $current_page_id ) ) ) {
206 + if ( is_user_logged_in() ) {
207 + $redirect_page_id = uwp_get_page_id( 'account_page', false );
208 +
209 + if ( isset( $_REQUEST['redirect_to'] ) && ! empty( $_REQUEST['redirect_to'] ) ) {
210 + $redirect_to = esc_url_raw( $_REQUEST['redirect_to'] );
211 + } elseif ( isset( $redirect_page_id ) && (int) $redirect_page_id > 0 ) {
212 + $redirect_to = get_permalink( $redirect_page_id );
213 + } else {
214 + $redirect_to = home_url( '/' );
114 215 }
115 - $redirect_to = apply_filters('uwp_logged_in_redirect', $redirect_to);
116 - wp_redirect($redirect_to);
117 - exit();
118 - }
119 - } elseif ( $account_page && ((int) $account_page == $current_page_id ) ||
120 - ( $change_page && ((int) $change_page == $current_page_id ) )) {
121 - if (!is_user_logged_in()) {
122 - wp_redirect(get_permalink($login_page));
123 - exit();
124 - } else {
125 - $can_user_can_edit_account = apply_filters('uwp_user_can_edit_own_profile', true, get_current_user_id());
126 - if (!$can_user_can_edit_account && ((int) $account_page == $current_page_id )) {
127 - wp_redirect(home_url('/'));
128 - exit();
216 +
217 + $redirect_to = apply_filters( 'uwp_logged_in_redirect', $redirect_to );
218 + wp_safe_redirect( $redirect_to );
219 + exit();
220 + }
221 + } elseif ( $account_page && ( (int) $account_page == $current_page_id ) ||
222 + ( $change_page && ( (int) $change_page == $current_page_id ) ) ) {
223 + if ( ! is_user_logged_in() ) {
224 + if ( isset( $_REQUEST['redirect_to'] ) && ! empty( $_REQUEST['redirect_to'] ) ) {
225 + $redirect_to = esc_url( $_REQUEST['redirect_to'] );
226 + $login_page = add_query_arg(
227 + array(
228 + 'redirect_to' => $redirect_to,
229 + ),
230 + get_permalink($login_page)
231 + );
232 + } else {
233 + $login_page = get_permalink($login_page);
129 234 }
130 - }
131 - } else {
132 - return false;
133 - }
134 -
135 - return false;
136 - }
137 235
138 - /**
139 - * If auto generated password, redirects to change password page.
140 - *
141 - * @since 1.0.0
142 - * @package userswp
143 - * @return void
144 - */
145 - public function change_default_password_redirect() {
146 - if (!is_user_logged_in()) {
147 - return;
148 - }
149 - if(1 == uwp_get_option('change_disable_password_nag')) {
150 - return;
151 - }
152 - $change_page = uwp_get_page_id('change_page', false);
153 - $password_nag = get_user_option('default_password_nag', get_current_user_id());
154 -
155 - if ($password_nag) {
156 - if (is_page()) {
157 - global $post;
158 - $current_page_id = $post->ID;
159 - if ( $change_page && ((int) $change_page == $current_page_id ) ) {
160 - return;
161 - }
162 - }
163 - if ($change_page) {
164 - wp_redirect( get_permalink($change_page) );
165 - exit();
166 - }
167 - }
168 - }
236 + wp_safe_redirect( $login_page );
237 + exit();
238 + } else {
239 + $can_user_can_edit_account = apply_filters( 'uwp_user_can_edit_own_profile', true, get_current_user_id() );
240 + if ( ! $can_user_can_edit_account && ( (int) $account_page == $current_page_id ) ) {
241 + wp_safe_redirect( home_url( '/' ) );
242 + exit();
243 + }
244 + }
245 + } else {
246 + return false;
247 + }
169 248
170 - /**
171 - * Redirects /profile to /profile/{username} for loggedin users.
172 - *
173 - * @since 1.0.0
174 - * @package userswp
175 - * @return void
176 - */
177 - public function profile_redirect() {
178 - if (is_page()) {
179 - global $wp_query, $post;
180 - $current_page_id = $post->ID;
181 - $profile_page = uwp_get_page_id('profile_page', false);
182 - if ( $profile_page && ((int) $profile_page == $current_page_id ) ) {
249 + return false;
250 + }
183 251
184 - if (isset($wp_query->query_vars['uwp_profile'])) {
185 - //must be profile page
186 - $url_type = apply_filters('uwp_profile_url_type', 'slug');
187 - $author_slug = $wp_query->query_vars['uwp_profile'];
188 - if ($url_type == 'id') {
189 - $user = get_user_by('id', $author_slug);
190 - } else {
191 - $user = get_user_by('slug', $author_slug);
192 - }
252 + /**
253 + * If auto generated password, redirects to change password page.
254 + *
255 + * @return void
256 + * @package userswp
257 + * @since 1.0.0
258 + */
259 + public function change_default_password_redirect() {
260 + if ( ! is_user_logged_in() ) {
261 + return;
262 + }
263 + if ( 1 == uwp_get_option( 'change_disable_password_nag' ) ) {
264 + return;
265 + }
193 266
194 - if (!isset($user->ID)) {
195 - global $wp_query;
196 - $wp_query->set_404();
197 - status_header( 404 );
198 - get_template_part( 404 ); exit();
199 - }
267 + if ( uwp_is_page_builder() ) {
268 + return;
269 + }
200 270
201 - } else {
202 - if (is_user_logged_in()) {
203 - $user_id = get_current_user_id();
204 - $profile_url = uwp_build_profile_tab_url($user_id);
205 - wp_redirect( $profile_url );
206 - exit();
207 - } else {
208 - wp_redirect( home_url('/') );
209 - exit();
210 - }
271 + $change_page = uwp_get_page_id( 'change_page', false );
272 + $password_nag = get_user_option( 'default_password_nag', get_current_user_id() );
211 273
212 - }
274 + if ( $password_nag ) {
275 + if ( is_page() ) {
276 + global $post;
277 + $current_page_id = $post->ID;
278 + if ( $change_page && ( (int) $change_page == $current_page_id ) ) {
279 + return;
280 + }
281 + }
282 + if ( $change_page ) {
283 + wp_safe_redirect( get_permalink( $change_page ) );
284 + exit();
285 + }
286 + }
287 + }
213 288
214 - }
215 - }
216 - }
289 + /**
290 + * Redirects /profile to /profile/{username} for loggedin users.
291 + *
292 + * @return void
293 + * @package userswp
294 + * @since 1.0.0
295 + */
296 + public function profile_redirect() {
297 + if ( uwp_is_page_builder() ) {
298 + return;
299 + }
217 300
218 - /**
219 - * Redirects user to a predefined page after logging out.
220 - *
221 - * @since 1.0.0
222 - * @package userswp
223 - * @return void
224 - */
225 - public function logout_redirect() {
226 - $redirect_page_id = uwp_get_option('logout_redirect_to', '');
227 - if(isset( $_REQUEST['redirect_to'] )){
228 - $redirect_to = esc_url($_REQUEST['redirect_to']);
229 - } elseif ( isset($redirect_page_id) && (int)$redirect_page_id > 0) {
230 - $redirect_to = get_permalink($redirect_page_id);
231 - } else {
232 - $redirect_to = home_url('/');
233 - }
234 - $redirect_to = apply_filters('uwp_logout_redirect', $redirect_to);
235 - wp_redirect( $redirect_to );
236 - exit();
237 - }
301 + if ( is_page() ) {
302 + global $wp_query, $post;
303 + $current_page_id = $post->ID;
304 + $profile_page = uwp_get_page_id( 'profile_page', false );
305 + if ( $profile_page && ( (int) $profile_page == $current_page_id ) ) {
238 306
307 + if ( isset( $wp_query->query_vars['uwp_profile'] ) ) {
308 + //must be profile page
309 + $url_type = apply_filters( 'uwp_profile_url_type', 'slug' );
310 + $author_slug = $wp_query->query_vars['uwp_profile'];
311 + if ( $url_type == 'id' ) {
312 + $user = get_user_by( 'id', $author_slug );
313 + } else {
314 + $user = get_user_by( 'slug', $author_slug );
315 + }
239 316
240 - /**
241 - * Redirects wp-login.php to UsersWP login page.
242 - *
243 - * @since 1.0.0
244 - * @package userswp
245 - * @return void
246 - */
247 - public function wp_login_redirect() {
248 - $login_page_id = uwp_get_page_id('login_page', false);
249 - $block_wp_login = uwp_get_option('block_wp_login', '');
250 - if ($login_page_id && $block_wp_login == '1') {
251 - global $pagenow;
252 - if( 'wp-login.php' == $pagenow && !isset($_REQUEST['action']) ) {
253 - $redirect_to = get_permalink($login_page_id);
254 - wp_redirect( $redirect_to );
255 - exit();
256 - }
257 - }
258 - }
317 + if ( ! isset( $user->ID ) ) {
318 + global $wp_query;
319 + $wp_query->set_404();
320 + status_header( 404 );
321 + }
259 322
260 - /**
261 - * Changes the login url to the UWP login page.
262 - *
263 - * @param $login_url string The URL for login.
264 - * @param $redirect string The URL to redirect back to upon successful login.
265 - * @param $force_reauth bool Whether to force reauthorization, even if a cookie is present.
266 - * @since 1.0.12
267 - * @package userswp
268 - *
269 - * @return string The login url.
270 - */
271 - public function wp_login_url($login_url, $redirect, $force_reauth) {
272 - $login_page_id = uwp_get_page_id('login_page', false);
273 - $redirect_page_id = uwp_get_option('login_redirect_to', -1);
274 - if (!is_admin() && $login_page_id) {
275 - $login_page = get_permalink($login_page_id);
276 - if($redirect){
277 - $login_url = add_query_arg( 'redirect_to', $redirect, $login_page );
278 - }elseif(isset($redirect_page_id) && (int)$redirect_page_id == -1 && wp_get_referer()) {
279 - $redirect_to = esc_url(wp_get_referer());
280 - $login_url = add_query_arg( 'redirect_to', $redirect_to, $login_page );
281 - }elseif($redirect_page_id){
282 - $redirect_to = get_permalink($redirect_page_id);
283 - $login_url = add_query_arg( 'redirect_to', $redirect_to, $login_page );
284 - }else{
285 - $login_url = $login_page;
286 - }
287 - }
323 + } else {
324 + if ( is_user_logged_in() ) {
325 + $user_id = get_current_user_id();
326 + $obj = new UsersWP_Profile();
327 + $profile_url = $obj->get_profile_link( get_author_posts_url( $user_id ), $user_id );
328 + wp_safe_redirect( $profile_url );
329 + exit();
330 + } else {
331 + $redirect_to = apply_filters( 'uwp_no_login_profile_redirect', uwp_get_page_link('login') );
332 + $redirect_to = add_query_arg('redirect_to', urlencode(get_permalink($profile_page)), $redirect_to);
333 + wp_safe_redirect( $redirect_to );
334 + exit();
335 + }
288 336
289 - return $login_url;
290 - }
337 + }
291 338
292 - /**
293 - * Prints html for form fields of that particular form.
294 - *
295 - * @since 1.0.0
296 - * @package userswp
297 - * @param string $form_type Form type.
298 - * @return void
299 - */
300 - public function uwp_template_fields($form_type) {
339 + }
340 + }
341 + }
301 342
302 - global $wpdb;
303 - $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
304 - $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
343 + /**
344 + * Redirects user to a predefined page after logging out.
345 + *
346 + * @return void
347 + * @package userswp
348 + * @since 1.0.0
349 + */
350 + public function logout_redirect() {
351 + $redirect_page_id = uwp_get_page_id( 'logout_redirect_to' );
352 + if ( isset( $_REQUEST['redirect_to'] ) ) {
353 + $redirect_to = esc_url( $_REQUEST['redirect_to'] );
354 + } elseif ( isset( $redirect_page_id ) && (int) $redirect_page_id > 0 ) {
355 + $redirect_to = get_permalink( $redirect_page_id );
356 + } else {
357 + $redirect_to = home_url( '/' );
358 + }
359 + $redirect_to = apply_filters( 'uwp_logout_redirect', $redirect_to );
360 + wp_safe_redirect( $redirect_to );
361 + exit();
362 + }
305 363
306 - if ($form_type == 'register') {
307 - $fields = get_register_form_fields();
308 - } elseif ($form_type == 'account') {
309 - $fields = get_account_form_fields();
310 - } elseif ($form_type == 'change') {
311 - $fields = get_change_form_fields();
312 - } else {
313 - $fields = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $table_name . " WHERE form_type = %s AND is_active = '1' AND for_admin_use != '1' ORDER BY sort_order ASC", array($form_type)));
314 - }
315 -
316 - if (!empty($fields)) {
317 - foreach ($fields as $field) {
364 + /**
365 + * Redirects wp-login.php to UsersWP login page.
366 + *
367 + * @return void
368 + * @package userswp
369 + * @since 1.0.0
370 + */
371 + public function wp_login_redirect() {
372 + global $pagenow;
373 + if ( 'wp-login.php' == $pagenow && ! isset( $_REQUEST['action'] ) ) {
374 + $login_page_id = uwp_get_page_id( 'login_page', false );
375 + $block_wp_login = uwp_get_option( 'block_wp_login', '' );
376 + if ( $login_page_id && $block_wp_login == '1' ) {
377 + $redirect_to = get_permalink( $login_page_id );
378 + if ( $redirect_to ) {
379 + $redirect_to = add_query_arg( 'redirect_to', admin_url(), $redirect_to );
380 + }
381 + wp_safe_redirect( $redirect_to );
382 + exit();
383 + }
384 + }
385 + }
318 386
319 - if ($form_type == 'account') {
320 - if ($field->htmlvar_name == 'uwp_account_display_name') {
321 - if ($field->is_active != '1') {
322 - continue;
323 - }
324 - }
325 - if ($field->htmlvar_name == 'uwp_account_bio') {
326 - if ($field->is_active != '1') {
327 - continue;
328 - }
329 - }
387 + /**
388 + * Redirects wp-login.php?action=register to UsersWP registration page.
389 + *
390 + * @return void
391 + * @package userswp
392 + * @since 1.0.0
393 + */
394 + public function wp_register_redirect() {
395 +
396 + global $pagenow;
397 + if ( 'wp-login.php' == $pagenow && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'register' ) {
398 + $reg_page_id = uwp_get_page_id( 'register_page' );
399 + $block_wp_reg = uwp_get_option( 'wp_register_redirect' );
400 + if ( $reg_page_id && $block_wp_reg == '1' ) {
401 +
402 + $redirect = isset( $_REQUEST['redirect_to'] ) ? esc_url( $_REQUEST['redirect_to'] ) : '';
403 + $redirect_to = get_permalink( $reg_page_id );
404 + if ( $redirect ) {
405 + $redirect_to = add_query_arg( 'redirect_to', $redirect, $redirect_to );
406 + }
407 + wp_safe_redirect( $redirect_to );
408 + exit();
409 + }
410 + }
411 + }
412 +
413 + /**
414 + * Changes the login url to the UWP login page.
415 + *
416 + * @param $login_url string The URL for login.
417 + * @param $redirect string The URL to redirect back to upon successful login.
418 + * @param $force_reauth bool Whether to force reauthorization, even if a cookie is present.
419 + *
420 + * @return string The login url.
421 + * @package userswp
422 + *
423 + * @since 1.0.12
424 + */
425 + public function wp_login_url( $login_url, $redirect, $force_reauth ) {
426 + global $pagenow;
427 +
428 + if ( class_exists( 'Jetpack' ) && 'wp-login.php' == $pagenow && Jetpack::is_module_active( 'sso' ) ) {
429 + return $login_url; // Do not change the URL for Jetpack SSO
430 + }
431 +
432 + if( did_action('init') === 0 ){
433 + return $login_url; // Some plugin calls login link very early.
434 + }
435 +
436 + $login_page_id = uwp_get_page_id( 'login_page', false );
437 + $redirect_page_id = uwp_get_page_id( 'login_redirect_to' );
438 + if ( ( ! is_admin() || wp_doing_ajax() ) && $login_page_id ) {
439 + $login_page = get_permalink( $login_page_id );
440 + if ( $redirect ) {
441 + $login_url = add_query_arg( 'redirect_to', urlencode( $redirect ), $login_page );
442 + } elseif ( isset( $redirect_page_id ) && (int) $redirect_page_id == - 1 && wp_get_referer() ) {
443 + $redirect_to = esc_url( wp_get_referer() );
444 + $login_url = add_query_arg( 'redirect_to', $redirect_to, $login_page );
445 + } elseif ( isset( $redirect_page_id ) && $redirect_page_id > 0 ) {
446 + $redirect_to = get_permalink( $redirect_page_id );
447 + $login_url = add_query_arg( 'redirect_to', $redirect_to, $login_page );
448 + } else {
449 + $login_url = $login_page;
450 + }
451 + }
452 +
453 + return $login_url;
454 + }
455 +
456 + /**
457 + * Changes the register url with the UWP register page.
458 + *
459 + * @param $register_url string The URL for register.
460 + *
461 + * @return string The register url.
462 + * @since 1.0.22
463 + *
464 + */
465 + public function wp_register_url( $register_url ) {
466 + $register_page_id = uwp_get_page_id( 'register_page' );
467 + $redirect_page_id = uwp_get_page_id( 'register_redirect_to' );
468 +
469 + $redirect = isset( $_REQUEST['redirect_to'] ) ? esc_url( $_REQUEST['redirect_to'] ) : '';
470 + if ( isset( $register_page_id ) && $register_page_id > 0 ) {
471 + $register_page = get_permalink( $register_page_id );
472 + if ( $register_url && isset( $redirect ) && ! empty( $redirect ) ) {
473 + $register_url = add_query_arg( 'redirect_to', $redirect, $register_page );
474 + } elseif ( (int) $redirect_page_id > 0 ) {
475 + $redirect_to = get_permalink( $redirect_page_id );
476 + $register_url = add_query_arg( 'redirect_to', $redirect_to, $register_page );
477 + } else {
478 + $register_url = $register_page;
479 + }
480 + }
481 +
482 + return $register_url;
483 + }
484 +
485 + /**
486 + * Changes the lost password url with the UWP page.
487 + *
488 + * @param $lostpassword_url string The URL for lost password.
489 + *
490 + * @return string The lost password page url.
491 + */
492 + public function wp_lostpassword_url( $lostpassword_url ) {
493 + $forgot_page_url = uwp_get_forgot_page_url();
494 +
495 + if ( is_multisite() && isset( $_GET['redirect_to'] ) && false !== strpos( wp_unslash( $_GET['redirect_to'] ), network_admin_url() ) ) {
496 + return $lostpassword_url;
497 + }
498 +
499 + $redirect = isset( $_REQUEST['redirect_to'] ) ? esc_url( $_REQUEST['redirect_to'] ) : '';
500 + if ( $forgot_page_url ) {
501 + if ( $forgot_page_url && isset( $redirect ) && ! empty( $redirect ) ) {
502 + $lostpassword_url = add_query_arg( 'redirect_to', $redirect, $forgot_page_url );
503 + } else {
504 + $lostpassword_url = $forgot_page_url;
505 + }
506 + }
507 +
508 + return $lostpassword_url;
509 + }
510 +
511 + /**
512 + * Prints html for form fields of that particular form.
513 + *
514 + * @param string $form_type Form type.
515 + *
516 + * @return void
517 + * @since 1.0.0
518 + * @package userswp
519 + */
520 + public function template_fields( $form_type, $args = array() ) {
521 +
522 + global $wpdb, $aui_bs5;
523 + $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
524 + $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
525 +
526 + $form_id = ! empty( $args['id'] ) ? (int) $args['id'] : uwp_get_option('register_modal_form', 1);
527 + if ( $form_type == 'register' ) {
528 + $fields = get_register_form_fields($form_id);
529 + // Use limit from args, otherwise fall back to the register_modal_form setting.
530 + $form_limit = ! empty( $args['limit'] ) ? $args['limit'] : uwp_get_option('register_modal_form', '');
531 + if(isset($form_limit) && !is_array($form_limit)){
532 + $form_limit = explode(',', $form_limit);
533 + }
534 +
535 + if(isset($form_limit) && !empty($form_limit) && count($form_limit) > 1){
536 +
537 + $form_limit = array_map('uwp_clean', $form_limit);
538 + $form_limit = array_map('trim', $form_limit);
539 + $options = uwp_get_register_forms_dropdown_options($form_limit);
540 + $selector_id = wp_doing_ajax() ? "uwp-form-select-ajax" : 'uwp-form-select';
541 + $display_style = uwp_get_option('register_form_display_style', 'buttons');
542 +
543 + if ( $display_style === 'select' ) {
544 + // Render as select dropdown.
545 + $selector_label = apply_filters( 'uwp_account_type_selector_label', __('Account Type', 'userswp'), $form_type, $args );
546 + ?>
547 + <div class="form-group mb-3" id="<?php echo esc_attr( $selector_id ); ?>">
548 + <label for="uwp-form-type-select" class="form-label"><?php echo esc_html( $selector_label ); ?></label>
549 + <select id="uwp-form-type-select" class="form-select aui-select2 w-100" data-form-selector="select">
550 + <?php
551 + foreach ( $options as $option_id => $option_label ) {
552 + $selected = $form_id == $option_id ? 'selected' : '';
553 + ?>
554 + <option value="<?php echo esc_attr( $option_id ); ?>" <?php echo esc_attr( $selected ); ?> data-form_id="<?php echo esc_attr( $option_id ); ?>">
555 + <?php echo esc_html( $option_label ); ?>
556 + </option>
557 + <?php
558 + }
559 + ?>
560 + </select>
561 + </div>
562 + <?php
563 + } else {
564 + // Render as button groups (default)
565 + ?>
566 + <div class="btn-group btn-group-sm d-flex mb-3" role="group" id="<?php echo esc_attr( $selector_id ); ?>">
567 + <?php
568 + $options = array_chunk( $options, 5, true );
569 + $current_url = uwp_current_page_url();
570 + if ( isset( $options[0] ) && ! empty( $options[0] ) && count( $options[0] ) > 1 ) {
571 + foreach ( $options[0] as $id => $val ) {
572 + $active = $form_id == $id ? 'active' : '';
573 + $url = esc_url_raw( add_query_arg( array( 'uwp_form_id' => $id ), $current_url ) );
574 + echo aui()->button( array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
575 + 'type' => 'a',
576 + 'href' => '#',
577 + 'class' => 'btn btn-outline-primary '. esc_attr( $active ),
578 + 'content' => esc_attr( $val ),
579 + 'extra_attributes' => array('data-form_id'=> esc_attr( $id ) )
580 + ) );
581 + }
582 + }elseif(count( $options[0] ) == 1){
583 + $form_id = key($options[0]);
584 + }
585 +
586 + if ( isset( $options[1] ) && ! empty( $options[1] ) && count( $options[1] ) > 0 ) {
587 + foreach ( $options[1] as $id => $val ) {
588 + $active = $form_id == $id ? 'active' : '';
589 + $url = esc_url_raw( add_query_arg( array( 'uwp_form_id' => $id ), $current_url ) );
590 + ?>
591 + <div class="btn-group" role="group">
592 + <button id="uwp-form-select-dropdown" type="button" class="btn btn-secondary dropdown-toggle" data-<?php echo ( $aui_bs5 ? 'bs-' : '' ); ?>toggle="dropdown" aria-haspopup="true" aria-expanded="false">
593 + <?php esc_attr_e('More', 'userswp'); ?>
594 + </button>
595 + <div class="dropdown-menu mt-3" aria-labelledby="uwp-form-select">
596 + <?php
597 + echo aui()->button( array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
598 + 'type' => 'a',
599 + 'href' => esc_url( $url ),
600 + 'class' => 'dropdown-item ' . esc_attr( $active ),
601 + 'content' => esc_attr( $val ),
602 + 'extra_attributes' => array('data-form_id'=> esc_attr( $id ) )
603 + ) );
604 + ?>
605 + </div>
606 + </div>
607 + <?php
608 + }
609 + }
610 + ?>
611 + </div>
612 + <?php
613 + }
614 + }
615 + } elseif ( $form_type == 'account' ) {
616 + $fields = get_account_form_fields();
617 + } elseif ( $form_type == 'change' ) {
618 + $fields = get_change_form_fields();
619 + } else {
620 + $fields = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . $table_name . " WHERE form_type = %s AND is_active = '1' AND for_admin_use != '1' ORDER BY sort_order ASC", array( $form_type ) ) );
621 + }
622 +
623 + if ( ! empty( $fields ) ) {
624 + foreach ( $fields as $field ) {
625 +
626 + if ( $form_type == 'account' ) {
627 + if ( $field->htmlvar_name == 'display_name' ) {
628 + if ( $field->is_active != '1' ) {
629 + continue;
630 + }
631 + }
632 + if ( $field->htmlvar_name == 'bio' ) {
633 + if ( $field->is_active != '1' ) {
634 + continue;
635 + }
636 + }
637 + }
638 +
639 + if ( $form_type == 'register' ) {
640 + if ( $field->is_active != '1' ) {
641 + continue;
642 + }
643 + $count = $wpdb->get_var( $wpdb->prepare( "select count(*) from " . $extras_table_name . " where site_htmlvar_name=%s AND form_type = %s AND form_id=%d", array(
644 + $field->htmlvar_name,
645 + $form_type,
646 + $form_id
647 + ) ) );
648 + if ( $count == 1 ) {
649 + $this->template_fields_html( $field, $form_type );
650 + }
651 + } else {
652 + $this->template_fields_html( $field, $form_type );
653 + }
654 + }
655 + }
656 + }
657 +
658 + /**
659 + * Prints field html based on field type.
660 + *
661 + * @param object $field Field info.
662 + * @param string $form_type Form type.
663 + * @param int|bool $user_id User ID.
664 + *
665 + * @return void
666 + * @since 1.0.0
667 + * @package userswp
668 + */
669 + public function template_fields_html( $field, $form_type, $user_id = false ) {
670 + if ( ! $user_id ) {
671 + $user_id = get_current_user_id();
672 + }
673 +
674 + $value = $this->get_default_form_value( $field );
675 + if ( $form_type == 'account' ) {
676 + $user_data = get_userdata( $user_id );
677 +
678 + if ( $field->htmlvar_name == 'email' ) {
679 + if(!empty($user_data)) {
680 + $value = $user_data->user_email;
681 + }else{
682 + $value = '';
683 + }
684 + } elseif ( $field->htmlvar_name == 'password' ) {
685 + $value = '';
686 + $field->is_required = 0;
687 + } elseif ( $field->htmlvar_name == 'confirm_password' ) {
688 + $value = '';
689 + $field->is_required = 0;
690 + } else {
691 + $value = uwp_get_usermeta( $user_id, $field->htmlvar_name, false );
692 + if ( $value != '0' && ! $value ) {
693 + $value = $this->get_default_form_value( $field );
694 + }
695 + }
696 +
697 + }
698 +
699 + if ( ! isset( $value ) ) {
700 + $value = "";
701 + }
702 +
703 + if ( isset( $_POST[ $field->htmlvar_name ] ) && $field->field_type != 'password' ) {
704 + $value = isset( $_POST[ $field->htmlvar_name ] ) ? $_POST[ $field->htmlvar_name ] : ''; //@todo: Used to pre fill form when validation fails, need to find better solution
705 + }
706 +
707 + if ( 'checkbox' == $field->field_type ) {
708 + if ( in_array( $value, array( 'true', 'on', 1 ) ) ) {
709 + $value = 1;
710 + } else {
711 + $value = 0;
712 + }
713 + }
714 +
715 + $field = apply_filters( "uwp_form_input_field_{$field->field_type}", $field, $value, $form_type );
716 +
717 + $html = apply_filters( "uwp_form_input_html_{$field->field_type}", "", $field, $value, $form_type );
718 +
719 + if ( empty( $html ) ) {
720 +
721 + $design_style = uwp_get_option( "design_style", "bootstrap" );
722 + $bs_form_group = $design_style ? "form-group mb-3" : "";
723 + $bs_sr_only = $design_style ? "sr-only" : "";
724 + $bs_form_control = $design_style ? "form-control" : "";
725 +
726 + ?>
727 + <div id="<?php echo esc_attr( $field->htmlvar_name ); ?>_row"
728 + class="<?php if ( $field->is_required ) {
729 + echo 'required_field';
730 + } ?> uwp_form_row clearfix uwp_clear <?php echo esc_attr( $bs_form_group ); ?>">
731 + <?php
732 +
733 + $label = $site_title = uwp_get_form_label( $field );
734 + if ( ! is_admin() ) { ?>
735 + <label class="<?php echo esc_attr( $bs_sr_only ); ?>">
736 + <?php echo ( trim( $site_title ) ) ? esc_attr( $site_title ) : '&nbsp;'; ?>
737 + <?php if ( $field->is_required ) {
738 + echo '<span>*</span>';
739 + } ?>
740 + </label>
741 + <?php } ?>
742 +
743 + <input name="<?php echo esc_attr($field->htmlvar_name); ?>"
744 + class="<?php echo esc_attr($field->css_class); ?> <?php echo esc_attr( $bs_form_control ); ?>"
745 + placeholder="<?php echo esc_attr( uwp_get_field_placeholder( $field ) ); ?>"
746 + title="<?php echo esc_attr($label); ?>"
747 + <?php if ( $field->for_admin_use == 1 ) {
748 + echo 'readonly="readonly"';
749 + } ?>
750 + <?php if ( $field->is_required == 1 ) {
751 + echo 'required="required"';
752 + } ?>
753 + type="<?php echo esc_attr($field->field_type); ?>"
754 + value="<?php echo esc_html( $value ); ?>">
755 +
756 + </div>
757 + <?php
758 + } else {
759 + echo $html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
760 + }
761 + }
762 +
763 + /**
764 + * Returns default value based on field type.
765 + *
766 + * @param object $field Field info.
767 + *
768 + * @return string Field default value.
769 + * @since 1.0.0
770 + * @package userswp
771 + */
772 + public function get_default_form_value( $field ) {
773 + if ( $field->field_type == 'url' ) {
774 + if ( substr( $field->default_value, 0, 4 ) === "http" ) {
775 + $value = $field->default_value;
776 + } else {
777 + $value = "";
778 + }
779 + } else {
780 + $value = $field->default_value;
781 + }
782 +
783 + return $value;
784 + }
785 +
786 + /**
787 + * Display redirect to input of that particular form.
788 + *
789 + * @param string $form_type Form type.
790 + *
791 + * @return void
792 + * @since 1.0.21
793 + * @package userswp
794 + */
795 + public function template_extra_fields( $form_type, $args = array() ) {
796 + if ( $form_type == 'login' ) {
797 + $redirect_to = '';
798 + if ( isset( $args['redirect_to'] ) && ! empty( $args['redirect_to'] ) ) {
799 + $redirect_to = $args['redirect_to'];
800 + } elseif ( isset( $_REQUEST['redirect_to'] ) && ! empty( $_REQUEST['redirect_to'] ) ) {
801 + $redirect_to = esc_url( urldecode( $_REQUEST['redirect_to'] ) );
802 + } else {
803 + if ( - 1 == uwp_get_option( 'login_redirect_to', - 1 ) ) {
804 + $referer = wp_get_referer();
805 + if ( isset( $referer ) && ! empty( $referer ) ) {
806 + $redirect_to = $referer;
807 + } else {
808 + $redirect_to = home_url();
809 + }
810 + }
811 + }
812 +
813 + $redirect_to = apply_filters('uwp_login_redirect_to', $redirect_to, $args);
814 +
815 + if ( $redirect_to ) {
816 + echo '<input type="hidden" name="redirect_to" value="' . esc_url( $redirect_to ) . '"/>';
817 + }
818 +
819 + echo '<input type="hidden" name="uwp_login_nonce" value="' . esc_attr( wp_create_nonce( 'uwp-login-nonce' ) ) . '" />';
820 + } elseif ( $form_type == 'register' ) {
821 + $redirect_to = '';
822 + $form_id = ! empty( $args['id'] ) ? $args['id'] : 1;
823 + if ( isset( $args['redirect_to'] ) && ! empty( $args['redirect_to'] ) ) {
824 + $redirect_to = $args['redirect_to'];
825 + } else {
826 + $redirect_to_value = uwp_get_register_form_by( $form_id, 'redirect_to');
827 + if(!$redirect_to_value){
828 + $redirect_to_value = uwp_get_option( 'register_redirect_to', - 1 );
330 829 }
331 830
332 - if ($form_type == 'register') {
333 - if ($field->is_active != '1') {
334 - continue;
335 - }
336 - $count = $wpdb->get_var($wpdb->prepare("select count(*) from ".$extras_table_name." where site_htmlvar_name=%s AND form_type = %s", array($field->htmlvar_name, $form_type)));
337 - if ($count == 1) {
338 - $this->uwp_template_fields_html($field, $form_type);
339 - }
340 - } else {
341 - $this->uwp_template_fields_html($field, $form_type);
342 - }
343 - }
344 - }
345 - }
831 + if ( - 1 == $redirect_to_value) {
832 + $referer = wp_get_referer();
833 + if ( isset( $_REQUEST['redirect_to'] ) && ! empty( $_REQUEST['redirect_to'] ) ) {
834 + $redirect_to = esc_url( urldecode( $_REQUEST['redirect_to'] ) );
835 + } else if ( isset( $referer ) && ! empty( $referer ) ) {
836 + $redirect_to = $referer;
837 + } else {
838 + $redirect_to = home_url();
839 + }
840 + }
841 + }
346 842
347 - /**
348 - * Adds "Edit Account" form on account page.
349 - *
350 - * @since 1.0.0
351 - * @package userswp
352 - * @param string $type Template type.
353 - * @return void
354 - */
355 - public function uwp_account_edit_form_display($type) {
356 - if ($type == 'account') {
357 - ?>
358 - <form class="uwp-account-form uwp_form" method="post" enctype="multipart/form-data">
359 - <?php do_action('uwp_template_fields', 'account'); ?>
360 - <input type="hidden" name="uwp_account_nonce" value="<?php echo wp_create_nonce( 'uwp-account-nonce' ); ?>" />
361 - <input name="uwp_account_submit" value="<?php echo __( 'Update Account', 'userswp' ); ?>" type="submit">
362 - </form>
363 - <?php }
364 - }
843 + $redirect_to = apply_filters('uwp_register_redirect_to', $redirect_to, $args);
365 844
366 - /**
367 - * Prints field html based on field type.
368 - *
369 - * @since 1.0.0
370 - * @package userswp
371 - * @param object $field Field info.
372 - * @param string $form_type Form type.
373 - * @param int|bool $user_id User ID.
374 - * @return void
375 - */
376 - public function uwp_template_fields_html($field, $form_type, $user_id = false) {
377 - if (!$user_id) {
378 - $user_id = get_current_user_id();
379 - }
845 + if ( $redirect_to ) {
846 + echo '<input type="hidden" name="redirect_to" value="' . esc_url( $redirect_to ) . '"/>';
847 + }
380 848
381 - $value = $this->uwp_get_default_form_value($field);
382 - if ($form_type == 'account') {
383 - $user_data = get_userdata($user_id);
849 + $hash = substr( hash( 'SHA256', AUTH_KEY . site_url() ), 0, 25 );
850 + echo '<input type="hidden" name="uwp_register_hash" value="' . esc_html( $hash ) . '" style="display:none !important; visibility:hidden !important;" />';
851 + echo '<input type="hidden" name="uwp_register_hp" value="" style="display:none !important; visibility:hidden !important;" size="25" autocomplete="off" />';
852 + echo '<input type="hidden" name="uwp_register_nonce" value="' . esc_attr( wp_create_nonce( 'uwp-register-nonce-'. $form_id ) ) . '" />';
853 + echo '<input type="hidden" name="uwp_register_form_id" value="' . absint($form_id) . '">';
854 + } elseif ( $form_type == 'change' ) {
855 + echo '<input type="hidden" name="uwp_change_nonce" value="' . esc_attr( wp_create_nonce( 'uwp-change-nonce' ) ) . '" />';
856 + } elseif ( $form_type == 'forgot' ) {
857 + echo '<input type="hidden" name="uwp_forgot_nonce" value="' . esc_attr( wp_create_nonce( 'uwp-forgot-nonce' ) ) . '" />';
858 + } elseif ( $form_type == 'reset' ) {
859 + if ( isset( $_GET['key'] ) && isset( $_GET['login'] ) ) {
860 + echo '<input type="hidden" name="uwp_reset_username" value="' . esc_attr( $_GET['login'] ) . '" />';
861 + echo '<input type="hidden" name="uwp_reset_key" value="' . esc_attr( $_GET['key'] ) . '" />';
862 + }
863 + echo '<input type="hidden" name="uwp_reset_hp" value="" style="display:none !important; visibility:hidden !important;" size="25" autocomplete="off" />';
864 + echo '<input type="hidden" name="uwp_reset_nonce" value="' . esc_attr( wp_create_nonce( 'uwp-reset-nonce' ) ) . '" />';
865 + }
866 + }
384 867
385 - if ($field->htmlvar_name == 'uwp_account_email') {
386 - $value = $user_data->user_email;
387 - } elseif ($field->htmlvar_name == 'uwp_account_password') {
388 - $value = '';
389 - $field->is_required = 0;
390 - } elseif ($field->htmlvar_name == 'uwp_account_confirm_password') {
391 - $value = '';
392 - $field->is_required = 0;
393 - } else {
394 - $value = uwp_get_usermeta($user_id, $field->htmlvar_name, false);
395 - if ($value != '0' && !$value) {
396 - $value = $this->uwp_get_default_form_value($field);
397 - }
398 - }
868 + /**
869 + * Modifies the author page content with UsersWP profile content.
870 + *
871 + * @param string $content Original page content.
872 + *
873 + * @return string Modified page content.
874 + * @since 1.0.0
875 + * @package userswp
876 + */
877 + public function author_page_content( $content ) {
878 + if ( is_author() && 1 != uwp_get_option( 'uwp_disable_author_link' ) && apply_filters( 'uwp_use_author_page_content', true ) ) {
879 + return do_shortcode( '[uwp_profile]' );
880 + } else {
881 + return $content;
882 + }
399 883
400 - }
884 + }
401 885
402 - if (empty($value)) {
403 - $value = "";
404 - }
886 + /**
887 + * Modifies the menu item visibility based on UsersWP page type.
888 + *
889 + * @param object $menu_item Menu item info.
890 + *
891 + * @return object Modified menu item.
892 + * @since 1.0.0
893 + * @package userswp
894 + */
895 + public function setup_nav_menu_item( $menu_item ) {
405 896
406 - if (isset($_POST[$field->htmlvar_name]) && $field->field_type != 'password') {
407 - $value = $_POST[$field->htmlvar_name];
408 - }
897 + if ( is_admin() ) {
898 + return $menu_item;
899 + }
409 900
410 - $field = apply_filters("uwp_form_input_field_{$field->field_type}", $field, $value, $form_type);
411 -
412 - $html = apply_filters("uwp_form_input_html_{$field->field_type}", "", $field, $value, $form_type);
901 + // Prevent a notice error when using the customizer
902 + $menu_classes = $menu_item->classes;
413 903
414 - if (empty($html)) {
415 - $label = $site_title = uwp_get_form_label($field);
416 - if (!is_admin()) { ?>
417 - <label>
418 - <?php echo (trim($label)) ? $label : '&nbsp;'; ?>
419 - <?php if ($field->is_required == 1) echo '<span>*</span>';?>
420 - </label>
421 - <?php }
422 - ?>
423 - <input name="<?php echo $field->htmlvar_name; ?>"
424 - class="<?php echo $field->css_class; ?>"
425 - placeholder="<?php echo $label; ?>"
426 - title="<?php echo $label; ?>"
427 - <?php if ($field->for_admin_use == 1) { echo 'readonly="readonly"'; } ?>
428 - <?php if ($field->is_required == 1) { echo 'required="required"'; } ?>
429 - type="<?php echo $field->field_type; ?>"
430 - value="<?php echo esc_html($value); ?>">
431 - <?php
432 - } else {
433 - echo $html;
434 - }
435 - }
904 + if ( is_array( $menu_classes ) ) {
905 + $menu_classes = implode( ' ', $menu_item->classes );
906 + $str = 'users-wp-menu ';
907 + if ( strpos( $menu_classes, 'users-wp-menu ' ) !== false ) {
908 + $menu_classes = str_replace( $str, '', $menu_classes );
909 + }
436 910
437 - /**
438 - * Returns default value based on field type.
439 - *
440 - * @since 1.0.0
441 - * @package userswp
442 - * @param object $field Field info.
443 - * @return string Field default value.
444 - */
445 - public function uwp_get_default_form_value($field) {
446 - if ($field->field_type == 'url') {
447 - if (substr( $field->default_value, 0, 4 ) === "http") {
448 - $value = $field->default_value;
449 - } else {
450 - $value = "";
451 - }
452 - } else {
453 - $value = $field->default_value;
454 - }
911 + $menu_classes = explode( " ", $menu_classes );
912 + }
455 913
456 - return $value;
457 - }
914 + $register_slug = uwp_get_page_slug( 'register_page' );
915 + $login_slug = uwp_get_page_slug( 'login_page' );
916 + $change_slug = uwp_get_page_slug( 'change_page' );
917 + $account_slug = uwp_get_page_slug( 'account_page' );
918 + $profile_slug = uwp_get_page_slug( 'profile_page' );
919 + $forgot_slug = uwp_get_page_slug( 'forgot_page' );
920 + $logout_slug = "logout";
458 921
459 - /**
460 - * Modifies the author page content with UsersWP profile content.
461 - *
462 - * @since 1.0.0
463 - * @package userswp
464 - * @param string $content Original page content.
465 - * @return string Modified page content.
466 - */
467 - public function uwp_author_page_content($content) {
468 - if (is_author() && apply_filters( 'uwp_use_author_page_content', true ) ) {
469 - return do_shortcode('[uwp_profile]');
470 - } else {
471 - return $content;
472 - }
922 + $register_class = "users-wp-{$register_slug}-nav";
923 + $login_class = "users-wp-{$login_slug}-nav";
924 + $change_class = "users-wp-{$change_slug}-nav";
925 + $account_class = "users-wp-{$account_slug}-nav";
926 + $profile_class = "users-wp-{$profile_slug}-nav";
927 + $forgot_class = "users-wp-{$forgot_slug}-nav";
928 + $logout_class = "users-wp-{$logout_slug}-nav";
473 929
474 - }
930 + if ( ! empty( $menu_classes ) ) {
931 + foreach ( $menu_classes as $menu_class ) {
932 + switch ( $menu_class ) {
933 + case $register_class:
934 + if ( is_user_logged_in() ) {
935 + $menu_item->_invalid = true;
936 + } else {
937 + $menu_item->url = uwp_get_page_id( 'register_page', true );
938 + }
939 + break;
940 + case $login_class:
941 + if ( is_user_logged_in() ) {
942 + $menu_item->_invalid = true;
943 + } else {
944 + $menu_item->url = uwp_get_page_id( 'login_page', true );
945 + }
946 + break;
947 + case $account_class:
948 + if ( ! is_user_logged_in() ) {
949 + $menu_item->_invalid = true;
950 + } else {
951 + $menu_item->url = uwp_get_page_id( 'account_page', true );
952 + }
953 + break;
954 + case $profile_class:
955 + if ( ! is_user_logged_in() ) {
956 + $menu_item->_invalid = true;
957 + } else {
958 + $menu_item->url = uwp_get_page_id( 'profile_page', true );
959 + }
960 + break;
961 + case $change_class:
962 + if ( ! is_user_logged_in() ) {
963 + $menu_item->_invalid = true;
964 + } else {
965 + $menu_item->url = uwp_get_page_id( 'change_page', true );
966 + }
967 + break;
968 + case $forgot_class:
969 + if ( is_user_logged_in() ) {
970 + $menu_item->_invalid = true;
971 + } else {
972 + $menu_item->url = uwp_get_page_id( 'forgot_page', true );
973 + }
974 + break;
975 + case $logout_class:
976 + if ( ! is_user_logged_in() ) {
977 + $menu_item->_invalid = true;
978 + } else {
979 + $menu_item->url = $this->uwp_logout_url();
980 + }
981 + break;
982 + }
983 + }
984 + }
475 985
476 - /**
477 - * Modifies the menu item visibility based on UsersWP page type.
478 - *
479 - * @since 1.0.0
480 - * @package userswp
481 - * @param object $menu_item Menu item info.
482 - * @return object Modified menu item.
483 - */
484 - public function uwp_setup_nav_menu_item( $menu_item ) {
986 + $menu_item = apply_filters( 'uwp_setup_nav_menu_item', $menu_item, $menu_classes );
485 987
486 - if ( is_admin() ) {
487 - return $menu_item;
488 - }
988 + return $menu_item;
489 989
490 - // Prevent a notice error when using the customizer
491 - $menu_classes = $menu_item->classes;
990 + }
492 991
493 - if ( is_array( $menu_classes ) ) {
494 - $menu_classes = implode( ' ', $menu_item->classes );
495 - $str = 'users-wp-menu ';
496 - if (strpos($menu_classes, 'users-wp-menu ') !== false) {
497 - $menu_classes = str_replace($str, '', $menu_classes);
498 - }
499 - }
992 + /**
993 + * Returns the logout url by adding redirect page link.
994 + *
995 + * @param null $custom_redirect Redirect page link.
996 + *
997 + * @return string Logout url.
998 + * @since 1.0.0
999 + * @package userswp
1000 + */
1001 + public function uwp_logout_url( $custom_redirect = null ) {
500 1002
501 - $register_slug = uwp_get_page_slug('register_page');
502 - $login_slug = uwp_get_page_slug('login_page');
503 - $change_slug = uwp_get_page_slug('change_page');
504 - $account_slug = uwp_get_page_slug('account_page');
505 - $profile_slug = uwp_get_page_slug('profile_page');
506 - $forgot_slug = uwp_get_page_slug('forgot_page');
507 - $logout_slug = "logout";
1003 + $redirect = null;
508 1004
509 - $register_class = "users-wp-{$register_slug}-nav";
510 - $login_class = "users-wp-{$login_slug}-nav";
511 - $change_class = "users-wp-{$change_slug}-nav";
512 - $account_class = "users-wp-{$account_slug}-nav";
513 - $profile_class = "users-wp-{$profile_slug}-nav";
514 - $forgot_class = "users-wp-{$forgot_slug}-nav";
515 - $logout_class = "users-wp-{$logout_slug}-nav";
1005 + $user = get_userdata(get_current_user_id());
1006 + if($user && isset($user->roles[0])){
1007 + $user_role = $user->roles[0];
1008 + $redirect_page_id = uwp_get_option( 'logout_redirect_to_'.$user_role );
1009 + }
516 1010
517 - switch ( $menu_classes ) {
518 - case $register_class:
519 - if ( is_user_logged_in() ) {
520 - $menu_item->_invalid = true;
521 - } else {
522 - $menu_item->url = uwp_get_page_id('register_page', true);
523 - }
524 - break;
525 - case $login_class:
526 - if ( is_user_logged_in() ) {
527 - $menu_item->_invalid = true;
528 - } else {
529 - $menu_item->url = uwp_get_page_id('login_page', true);
530 - }
531 - break;
532 - case $account_class:
533 - if ( ! is_user_logged_in() ) {
534 - $menu_item->_invalid = true;
535 - } else {
536 - $menu_item->url = uwp_get_page_id('account_page', true);
537 - }
538 - break;
539 - case $profile_class:
540 - if ( ! is_user_logged_in() ) {
541 - $menu_item->_invalid = true;
542 - } else {
543 - $menu_item->url = uwp_get_page_id('profile_page', true);
544 - }
545 - break;
546 - case $change_class:
547 - if ( ! is_user_logged_in() ) {
548 - $menu_item->_invalid = true;
549 - } else {
550 - $menu_item->url = uwp_get_page_id('change_page', true);
551 - }
552 - break;
553 - case $forgot_class:
554 - if ( is_user_logged_in() ) {
555 - $menu_item->_invalid = true;
556 - } else {
557 - $menu_item->url = uwp_get_page_id('forgot_page', true);
558 - }
559 - break;
560 - case $logout_class:
561 - if ( ! is_user_logged_in() ) {
562 - $menu_item->_invalid = true;
563 - } else {
564 - $menu_item->url = $this->uwp_logout_url();
565 - }
566 - break;
1011 + if ( ! empty( $custom_redirect ) ) {
1012 + $redirect = esc_url( $custom_redirect );
1013 + } else if ( isset($redirect_page_id) && !empty($redirect_page_id) ) {
1014 + if ( uwp_is_wpml() ) {
1015 + $wpml_page_id = uwp_wpml_object_id( $redirect_page_id, 'page', true, ICL_LANGUAGE_CODE );
1016 + if ( ! empty( $wpml_page_id ) ) {
1017 + $redirect_page_id = $wpml_page_id;
1018 + }
1019 + }
1020 + $redirect = get_permalink( $redirect_page_id );
1021 + }
1022 +
1023 + return wp_logout_url( apply_filters( 'uwp_logout_url', $redirect, $custom_redirect ) );
1024 +
1025 + }
1026 +
1027 + /**
1028 + * Adds the UsersWP body class to body tag.
1029 + *
1030 + * @param array $classes Existing class array.
1031 + *
1032 + * @return array Modified class array.
1033 + * @since 1.0.0
1034 + * @package userswp
1035 + */
1036 + public function add_body_class( $classes ) {
1037 +
1038 + if ( is_uwp_page() ) {
1039 + $classes[] = 'uwp_page';
1040 +
1041 + if ( is_uwp_page( 'register_page' ) ) {
1042 + $classes[] = 'uwp_register_page';
1043 + } elseif ( is_uwp_page( 'login_page' ) ) {
1044 + $classes[] = 'uwp_login_page';
1045 + } elseif ( is_uwp_page( 'forgot_page' ) ) {
1046 + $classes[] = 'uwp_forgot_page';
1047 + } elseif ( is_uwp_page( 'change_page' ) ) {
1048 + $classes[] = 'uwp_change_page';
1049 + } elseif ( is_uwp_page( 'reset_page' ) ) {
1050 + $classes[] = 'uwp_reset_page';
1051 + } elseif ( is_uwp_page( 'account_page' ) ) {
1052 + $classes[] = 'uwp_account_page';
1053 + } elseif ( is_uwp_page( 'profile_page' ) ) {
1054 + $classes[] = 'uwp_profile_page';
1055 + } elseif ( is_uwp_page( 'users_page' ) ) {
1056 + $classes[] = 'uwp_users_page';
1057 + }
1058 + }
1059 +
1060 + if(is_user_logged_in()){
1061 + $classes[] = 'uwp-user-type-'.uwp_get_register_form_id( get_current_user_id() );
567 1062 }
568 1063
569 - $menu_item = apply_filters('uwp_setup_nav_menu_item', $menu_item, $menu_classes);
1064 + return $classes;
1065 + }
570 1066
571 - return $menu_item;
1067 + /**
1068 + *
1069 + * Returns content for author box
1070 + *
1071 + * @param $content
1072 + *
1073 + * @return string
1074 + */
1075 + public function author_box_page_content( $content ) {
572 1076
573 - }
1077 + global $post;
574 1078
575 - /**
576 - * Returns the logout url by adding redirect page link.
577 - *
578 - * @since 1.0.0
579 - * @package userswp
580 - * @param null $custom_redirect Redirect page link.
581 - * @return string Logout url.
582 - */
583 - public function uwp_logout_url( $custom_redirect = null ) {
1079 + if ( is_single() ) {
584 1080
585 - $redirect = null;
1081 + $author_box_enable_disable = uwp_get_option( 'author_box_enable_disable', 1 );
586 1082
587 - if ( !empty( $custom_redirect ) ) {
588 - $redirect = esc_url( $custom_redirect );
589 - } else if ( uwp_get_option('logout_redirect_to', false) ) {
590 - $redirect = esc_url( get_permalink( uwp_get_option('logout_redirect_to', 0) ) );
591 - }
1083 + if ( 1 == $author_box_enable_disable ) {
592 1084
593 - return wp_logout_url( apply_filters( 'uwp_logout_url', $redirect, $custom_redirect ) );
1085 + $author_box_display_post_types = uwp_get_option( 'author_box_display_post_types' );
594 1086
595 - }
1087 + if ( ! empty( $post->post_type ) && in_array( $post->post_type, (array) $author_box_display_post_types ) ) {
596 1088
597 - /**
598 - * Redirects to UsersWP info page after plugin activation.
599 - *
600 - * @since 1.0.0
601 - * @package userswp
602 - * @return void
603 - */
604 - public function uwp_activation_redirect() {
1089 + $author_box_display_content = uwp_get_option( 'author_box_display_content' );
605 1090
606 - if (get_option('uwp_activation_redirect', false)) {
607 - delete_option('uwp_activation_redirect');
608 - wp_redirect(admin_url('admin.php?page=userswp&tab=main&subtab=info'));
609 - exit;
1091 + if ( ! empty( $author_box_display_content ) && 'above_content' === $author_box_display_content ) {
1092 + $content = do_shortcode( '[uwp_author_box]' ) . $content;
1093 + } else {
1094 + $content = $content . do_shortcode( '[uwp_author_box]' );
1095 + }
610 1096
611 - }
1097 + // run block content if its available
1098 + if ( function_exists( 'do_blocks' ) ) {
1099 + $content = do_blocks( $content );
1100 + }
1101 + }
612 1102
613 - }
1103 + }
614 1104
615 - /**
616 - * Prints UsersWP fields in WP-Admin Users Edit page.
617 - *
618 - * @since 1.0.0
619 - * @package userswp
620 - * @param object $user User Object.
621 - */
622 - public function get_profile_extra_admin_edit($user) {
623 - echo $this->get_profile_extra_edit($user);
624 - }
1105 + }
625 1106
626 - /**
627 - * Gets UsersWP fields in WP-Admin Users Edit page.
628 - *
629 - * @since 1.0.0
630 - * @package userswp
631 - * @param object $user User Object.
632 - * @return string HTML string.
633 - */
634 - public function get_profile_extra_edit($user) {
635 - ob_start();
636 - global $wpdb;
637 - $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
638 - $excluded_fields = apply_filters('uwp_exclude_edit_profile_fields', array());
639 - $query = "SELECT * FROM " . $table_name . " WHERE form_type = 'account' AND is_default = '0'";
640 - if(is_array($excluded_fields) && count($excluded_fields) > 0){
641 - $query .= 'AND htmlvar_name NOT IN ('.implode(',', $excluded_fields).')';
642 - }
643 - $query .= ' ORDER BY sort_order ASC';
644 - $fields = $wpdb->get_results($query);
645 - if ($fields) {
646 - ?>
1107 + return $content;
1108 + }
1109 +
1110 + /**
1111 + * Adds form html for privacy fields in account page.
1112 + *
1113 + * @param string $type Form type.
1114 + *
1115 + * @return void
1116 + * @since 1.0.0
1117 + * @package userswp
1118 + *
1119 + */
1120 + public function privacy_edit_form_display( $type ) {
1121 + if ( $type == 'privacy' ) {
1122 + $make_profile_private = uwp_can_make_profile_private();
1123 + echo '<div class="uwp-account-form">';
1124 + $extra_where = "AND is_public='2'";
1125 + $fields = get_account_form_fields( $extra_where );
1126 + $fields = apply_filters( 'uwp_account_privacy_fields', $fields );
1127 + $user_id = get_current_user_id();
1128 + $form_id = uwp_get_register_form_id( $user_id );
1129 + $design_style = uwp_get_option( "design_style", "bootstrap" );
1130 + $bs_form_group = $design_style ? "form-group mb-3 row" : "";
1131 + $bs_form_control = $design_style ? "form-control" : "";
1132 + $bs_btn_class = $design_style ? "btn btn-primary btn-block text-uppercase" : "";
1133 + ?>
647 1134 <div class="uwp-profile-extra">
648 - <table class="uwp-profile-extra-table form-table">
649 - <?php
650 - foreach ($fields as $field) {
1135 + <div class="uwp-profile-extra-div form-table">
1136 + <form class="uwp-account-form uwp_form" method="post">
1137 + <?php if ( $fields ) { ?>
1138 + <div class="uwp-profile-extra-wrap <?php echo esc_attr( $bs_form_group ); ?>">
1139 + <div class="uwp-profile-extra-key col" style="font-weight: bold;">
1140 + <?php esc_attr_e( "Field", "userswp" ) ?>
1141 + </div>
1142 + <div class="uwp-profile-extra-value col" style="font-weight: bold;">
1143 + <?php esc_attr_e( "Is Public?", "userswp" ) ?>
1144 + </div>
1145 + </div>
1146 + <?php foreach ( $fields as $field ) { ?>
1147 + <div class="uwp-profile-extra-wrap <?php echo esc_attr( $bs_form_group ); ?>">
1148 + <div class="uwp-profile-extra-key col"><?php echo esc_attr( $field->site_title ); ?>
1149 + <span class="uwp-profile-extra-sep">:</span></div>
1150 + <div class="uwp-profile-extra-value col">
1151 + <?php
1152 + $field_name = $field->htmlvar_name . '_privacy';
1153 + $value = uwp_get_usermeta( $user_id, $field_name, false );
1154 + if ( $value === false ) {
1155 + $value = 'yes';
1156 + }
1157 + ?>
1158 + <select name="<?php echo esc_attr( $field_name ); ?>"
1159 + class="uwp_privacy_field aui-select2 <?php echo esc_attr( $bs_form_control ); ?>"
1160 + style="margin: 0;">
1161 + <option value="no" <?php selected( $value, "no" ); ?>><?php esc_attr_e( "No", "userswp" ) ?></option>
1162 + <option value="yes" <?php selected( $value, "yes" ); ?>><?php esc_attr_e( "Yes", "userswp" ) ?></option>
1163 + </select>
1164 + </div>
1165 + </div>
1166 + <?php }
1167 + }
651 1168
652 - // Icon
653 - $icon = uwp_get_field_icon( $field->field_icon );
1169 + global $wpdb;
1170 + $tabs_table_name = uwp_get_table_prefix() . 'uwp_profile_tabs';
1171 + $tabs = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . $tabs_table_name . " WHERE form_type = %s AND user_decided = 1 AND form_id = %s ORDER BY sort_order ASC", array('profile-tabs', $form_id) ) );
654 1172
655 - if ($field->field_type == 'fieldset') {
656 - ?>
657 - <tr style="margin: 0; padding: 0">
658 - <th class="uwp-profile-extra-key" style="margin: 0; padding: 0"><h3 style="margin: 10px 0;"><?php echo $icon.$field->site_title; ?></h3></th>
659 - <td></td>
660 - </tr>
661 - <?php
662 - } else { ?>
663 - <tr>
664 - <th class="uwp-profile-extra-key"><?php echo $icon.$field->site_title; ?></th>
665 - <td class="uwp-profile-extra-value">
666 - <?php $this->uwp_template_fields_html($field, 'account', $user->ID); ?>
667 - </td>
668 - </tr>
669 - <?php
670 - }
671 - }
672 - ?>
673 - </table>
1173 + if ( $tabs ) { ?>
1174 + <div class="uwp-profile-extra-wrap <?php echo esc_attr( $bs_form_group ); ?>">
1175 + <div class="uwp-profile-extra-key col" style="font-weight: bold;">
1176 + <?php esc_attr_e( "Tab Name", "userswp" ) ?>
1177 + </div>
1178 + <div class="uwp-profile-extra-value col" style="font-weight: bold;">
1179 + <?php esc_attr_e( "Privacy", "userswp" ) ?>
1180 + </div>
1181 + </div>
1182 + <?php }
1183 +
1184 + foreach ( $tabs as $tab ) { ?>
1185 + <div class="uwp-profile-extra-wrap <?php echo esc_attr( $bs_form_group ); ?>">
1186 + <div class="uwp-profile-extra-key col"><?php esc_attr_e( $tab->tab_name, 'userswp' ); ?>
1187 + <span class="uwp-profile-extra-sep">:</span></div>
1188 + <div class="uwp-profile-extra-value col">
1189 + <?php
1190 + $field_name = $tab->tab_key . '_tab_privacy';
1191 + $value = uwp_get_usermeta( $user_id, $field_name, '' );
1192 +
1193 + $privacy_options = array(
1194 + 0 => __( "Anyone", "userswp" ),
1195 + 1 => __( "Logged in", "userswp" ),
1196 + 2 => __( "Author only", "userswp" ),
1197 + );
1198 +
1199 + // Admin default
1200 + $admin_privacy = isset( $tab->tab_privacy ) ? absint( $tab->tab_privacy ) : 0;
1201 + $privacy_options = apply_filters( 'uwp_tab_privacy_options', $privacy_options, $tab );
1202 +
1203 + if ( empty( $value ) ) {
1204 + $value = $admin_privacy;
1205 + }
1206 + ?>
1207 + <select name="<?php echo esc_attr( $field_name ); ?>"
1208 + class="uwp_tab_privacy_field aui-select2 <?php echo esc_attr( $bs_form_control ); ?>"
1209 + style="margin: 0;">
1210 + <?php
1211 + foreach ( $privacy_options as $key => $val ) {
1212 +
1213 + $default = '';
1214 + if ( $admin_privacy == $key ) {
1215 + $default = __( ' (Default)', 'userswp' );
1216 + }
1217 + echo '<option value="' . esc_attr( $key ) . '"' . selected( $value, $key, false ) . '>' . esc_attr( $val . $default ) . '</option>';
1218 + }
1219 + ?>
1220 + </select>
1221 + </div>
1222 + </div>
1223 + <?php }
1224 +
1225 + $value = get_user_meta( $user_id, 'uwp_hide_from_listing', true ); ?>
1226 + <div class="uwp-profile-extra-wrap">
1227 + <div id="uwp_hide_from_listing" class="uwp_hide_from_listing">
1228 + <input name="uwp_hide_from_listing" class="" <?php checked( $value, "1", true ); ?>
1229 + type="checkbox"
1230 + value="1"><?php esc_attr_e( 'Hide profile from the users listing page.', 'userswp' ); ?>
1231 + </div>
1232 + </div>
1233 + <?php
1234 + do_action( 'uwp_after_privacy_form_fields', $fields );
1235 + if ( $make_profile_private ) {
1236 + $field_name = 'uwp_make_profile_private';
1237 + $value = get_user_meta( $user_id, $field_name, true );
1238 + if ( $value === false ) {
1239 + $value = '0';
1240 + }
1241 + ?>
1242 + <div id="uwp_make_profile_private" class=" uwp_make_profile_private_row">
1243 + <input type="hidden" name="uwp_make_profile_private" value="0">
1244 + <input name="uwp_make_profile_private" class="" <?php checked( $value, "1", true ); ?>
1245 + type="checkbox" value="1">
1246 + <?php esc_attr_e( 'Make the whole profile private', 'userswp' ); ?>
1247 + </div>
1248 + <?php
1249 + }
1250 + ?>
1251 + <input type="hidden" name="uwp_privacy_nonce"
1252 + value="<?php echo esc_attr( wp_create_nonce( 'uwp-privacy-nonce' ) ); ?>"/>
1253 + <input name="uwp_privacy_submit" class="<?php echo esc_attr( $bs_btn_class ); ?>"
1254 + value="<?php esc_attr_e( 'Submit', 'userswp' ); ?>" type="submit">
1255 + </form>
1256 + </div>
674 1257 </div>
675 - <?php
676 - }
677 - $output = ob_get_contents();
678 - ob_end_clean();
679 - return trim($output);
680 - }
1258 + <?php
1259 + echo '</div>';
1260 + }
1261 + }
681 1262
682 - /**
683 - * Adds the UsersWP body class to body tag.
684 - *
685 - * @since 1.0.0
686 - * @package userswp
687 - * @param array $classes Existing class array.
688 - * @return array Modified class array.
689 - */
690 - public function uwp_add_body_class( $classes ) {
1263 + /**
1264 + * Redirects the user to login page when email not confirmed.
1265 + *
1266 + * @param string $username Username.
1267 + * @param object $user User object.
1268 + *
1269 + * @return void
1270 + * @package userswp
1271 + *
1272 + * @since 1.0.0
1273 + */
1274 + public function unconfirmed_login_redirect( $username, $user ) {
1275 + if ( ! is_wp_error( $user ) ) {
1276 + $mod_value = get_user_meta( $user->ID, 'uwp_mod', true );
1277 + if ( $mod_value == 'email_unconfirmed' ) {
1278 + if ( ! in_array( 'administrator', $user->roles ) ) {
1279 + $login_page = uwp_get_page_id( 'login_page', false );
1280 + if ( $login_page ) {
1281 + $redirect_to = add_query_arg( array(
1282 + 'uwp_err' => 'act_pending',
1283 + 'user_id' => $user->ID
1284 + ), get_permalink( $login_page ) );
1285 + wp_destroy_current_session();
1286 + wp_clear_auth_cookie();
1287 + if ( wp_doing_ajax() ) {
1288 + global $userswp;
1289 + $message = $userswp->notices->form_notice_by_key( 'act_pending', false, $user->ID );
1290 + wp_send_json_error( $message );
1291 + } else {
1292 + wp_redirect( $redirect_to );
1293 + }
1294 + exit();
1295 + }
1296 + }
1297 + }
1298 + }
1299 + }
691 1300
692 - if ( is_uwp_page() ) {
693 - $classes[] = 'uwp_page';
694 - }
1301 + /**
1302 + * Oxygen override theme template.
1303 + *
1304 + * @since 1.2.2.15
1305 + *
1306 + * @param string $located Located template.
1307 + * @param string $template_name Template name.
1308 + * @param array $located Template args.
1309 + * @param string $template_path Template path.
1310 + * @param string $default_path Template default path.
1311 + * @return string Located template.
1312 + */
1313 + public function oxygen_override_template( $located, $template_name, $args, $template_path, $default_path ) {
1314 + if ( $_located = $this->oxygen_locate_template( $template_name ) ) {
1315 + $located = $_located;
1316 + }
695 1317
696 - return $classes;
697 - }
1318 + return $located;
1319 + }
1320 +
1321 + /**
1322 + * Oxygen locate theme template.
1323 + *
1324 + * @since 1.2.2.15
1325 + *
1326 + * @param string $template The template.
1327 + * @return string The theme template.
1328 + */
1329 + public function oxygen_locate_template( $template ) {
1330 + $located = '';
1331 +
1332 + if ( ! $template ) {
1333 + return $located;
1334 + }
1335 +
1336 + $has_filter = has_filter( 'template', 'ct_oxygen_template_name' );
1337 +
1338 + // Remove template filter
1339 + if ( $has_filter ) {
1340 + remove_filter( 'template', 'ct_oxygen_template_name' );
1341 + }
1342 +
1343 + $_located = $this->get_theme_template_path() . '/' . $template;
1344 +
1345 + if ( file_exists( $_located ) ) {
1346 + $located = $_located;
1347 + }
1348 +
1349 + // Add template filter
1350 + if ( $has_filter ) {
1351 + add_filter( 'template', 'ct_oxygen_template_name' );
1352 + }
1353 +
1354 + return $located;
1355 + }
1356 +
1357 + /**
1358 + * Get the UsersWP templates theme path.
1359 + *
1360 + * @since 1.2.2.15
1361 + *
1362 + * @return string Template path.
1363 + */
1364 + public static function get_theme_template_path() {
1365 + $template = get_template();
1366 + $theme_root = get_theme_root( $template );
1367 +
1368 + $theme_template_path = $theme_root . '/' . $template . '/' . untrailingslashit( uwp_get_theme_template_dir_name() );
1369 +
1370 + return $theme_template_path;
1371 + }
1372 +
1373 + /**
1374 + * Check & unset the_content hook.
1375 + *
1376 + * @since 1.2.13
1377 + *
1378 + * @param string $content The content.
1379 + * @return string The post content.
1380 + */
1381 + public function set_the_content_hook( $content ) {
1382 + global $wp_query, $post, $uwp_set_wpautop;
1383 +
1384 + // Prevent empty p tags on block theme.
1385 + if ( function_exists( 'wp_is_block_theme' ) && wp_is_block_theme() && ! empty( $wp_query ) && ! empty( $post ) && $post->ID == get_queried_object_id() && is_uwp_page() ) {
1386 + if ( $has_filter = has_filter( 'the_content', 'wpautop' ) ) {
1387 + $uwp_set_wpautop = $has_filter;
1388 +
1389 + remove_filter( 'the_content', 'wpautop' );
1390 + }
1391 + }
1392 +
1393 + return $content;
1394 + }
698 1395 }