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 +1312 -570 1.0.101.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,647 +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_option('register_page', false);
97 - $login_page = uwp_get_option('login_page', false);
98 - $forgot_page = uwp_get_option('forgot_page', false);
99 - $reset_page = uwp_get_option('reset_page', false);
78 + if ( in_the_loop() ) {
100 79
101 - $change_page = uwp_get_option('change_page', false);
102 - $account_page = uwp_get_option('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_option('account_page', '');
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 - $change_page = uwp_get_option('change_page', false);
150 - $password_nag = get_user_option('default_password_nag', get_current_user_id());
151 -
152 - if ($password_nag) {
153 - if (is_page()) {
154 - global $post;
155 - $current_page_id = $post->ID;
156 - if ( $change_page && ((int) $change_page == $current_page_id ) ) {
157 - return;
158 - }
159 - }
160 - if ($change_page) {
161 - wp_redirect( get_permalink($change_page) );
162 - exit();
163 - }
164 - }
165 - }
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 + }
166 248
167 - /**
168 - * Redirects /profile to /profile/{username} for loggedin users.
169 - *
170 - * @since 1.0.0
171 - * @package userswp
172 - * @return void
173 - */
174 - public function profile_redirect() {
175 - if (is_page()) {
176 - global $wp_query, $post;
177 - $current_page_id = $post->ID;
178 - $profile_page = uwp_get_option('profile_page', false);
179 - if ( $profile_page && ((int) $profile_page == $current_page_id ) ) {
249 + return false;
250 + }
180 251
181 - if (isset($wp_query->query_vars['uwp_profile'])) {
182 - //must be profile page
183 - $url_type = apply_filters('uwp_profile_url_type', 'slug');
184 - $author_slug = $wp_query->query_vars['uwp_profile'];
185 - if ($url_type == 'id') {
186 - $user = get_user_by('id', $author_slug);
187 - } else {
188 - $user = get_user_by('slug', $author_slug);
189 - }
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 + }
190 266
191 - if (!isset($user->ID)) {
192 - global $wp_query;
193 - $wp_query->set_404();
194 - status_header( 404 );
195 - get_template_part( 404 ); exit();
196 - }
267 + if ( uwp_is_page_builder() ) {
268 + return;
269 + }
197 270
198 - } else {
199 - if (is_user_logged_in()) {
200 - $user_id = get_current_user_id();
201 - $profile_url = uwp_build_profile_tab_url($user_id);
202 - wp_redirect( $profile_url );
203 - exit();
204 - } else {
205 - wp_redirect( home_url('/') );
206 - exit();
207 - }
271 + $change_page = uwp_get_page_id( 'change_page', false );
272 + $password_nag = get_user_option( 'default_password_nag', get_current_user_id() );
208 273
209 - }
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 + }
210 288
211 - }
212 - }
213 - }
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 + }
214 300
215 - /**
216 - * Redirects user to a predefined page after logging out.
217 - *
218 - * @since 1.0.0
219 - * @package userswp
220 - * @return void
221 - */
222 - public function logout_redirect() {
223 - $redirect_page_id = uwp_get_option('logout_redirect_to', '');
224 - if (empty($redirect_page_id)) {
225 - $redirect_to = home_url('/');
226 - } else {
227 - $redirect_to = get_permalink($redirect_page_id);
228 - }
229 - $redirect_to = apply_filters('uwp_logout_redirect', $redirect_to);
230 - wp_redirect( $redirect_to );
231 - exit();
232 - }
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 ) ) {
233 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 + }
234 316
235 - /**
236 - * Redirects wp-login.php to UsersWP login page.
237 - *
238 - * @since 1.0.0
239 - * @package userswp
240 - * @return void
241 - */
242 - public function wp_login_redirect() {
243 - $login_page_id = uwp_get_option('login_page', false);
244 - $block_wp_login = uwp_get_option('block_wp_login', '');
245 - if ($login_page_id && $block_wp_login == '1') {
246 - global $pagenow;
247 - if( 'wp-login.php' == $pagenow && !isset($_REQUEST['action']) ) {
248 - $redirect_to = get_permalink($login_page_id);
249 - wp_redirect( $redirect_to );
250 - exit();
251 - }
252 - }
253 - }
317 + if ( ! isset( $user->ID ) ) {
318 + global $wp_query;
319 + $wp_query->set_404();
320 + status_header( 404 );
321 + }
254 322
255 - /**
256 - * Prints html for form fields of that particular form.
257 - *
258 - * @since 1.0.0
259 - * @package userswp
260 - * @param string $form_type Form type.
261 - * @return void
262 - */
263 - public function uwp_template_fields($form_type) {
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 + }
264 336
265 - global $wpdb;
266 - $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
267 - $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
337 + }
268 338
269 - if ($form_type == 'register') {
270 - $fields = get_register_form_fields();
271 - } elseif ($form_type == 'account') {
272 - $fields = get_account_form_fields();
273 - } elseif ($form_type == 'change') {
274 - $fields = get_change_form_fields();
275 - } else {
276 - $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)));
277 - }
278 -
279 - if (!empty($fields)) {
280 - foreach ($fields as $field) {
339 + }
340 + }
341 + }
281 342
282 - if ($form_type == 'account') {
283 - if ($field->htmlvar_name == 'uwp_account_display_name') {
284 - if ($field->is_active != '1') {
285 - continue;
286 - }
287 - }
288 - if ($field->htmlvar_name == 'uwp_account_bio') {
289 - if ($field->is_active != '1') {
290 - continue;
291 - }
292 - }
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 + }
363 +
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 + }
386 +
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 );
293 829 }
294 830
295 - if ($form_type == 'register') {
296 - if ($field->is_active != '1') {
297 - continue;
298 - }
299 - $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)));
300 - if ($count == 1) {
301 - $this->uwp_template_fields_html($field, $form_type);
302 - }
303 - } else {
304 - $this->uwp_template_fields_html($field, $form_type);
305 - }
306 - }
307 - }
308 - }
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 + }
309 842
310 - /**
311 - * Adds "Edit Account" form on account page.
312 - *
313 - * @since 1.0.0
314 - * @package userswp
315 - * @param string $type Template type.
316 - * @return void
317 - */
318 - public function uwp_account_edit_form_display($type) {
319 - if ($type == 'account') {
320 - ?>
321 - <form class="uwp-account-form uwp_form" method="post" enctype="multipart/form-data">
322 - <?php do_action('uwp_template_fields', 'account'); ?>
323 - <input type="hidden" name="uwp_account_nonce" value="<?php echo wp_create_nonce( 'uwp-account-nonce' ); ?>" />
324 - <input name="uwp_account_submit" value="<?php echo __( 'Update Account', 'userswp' ); ?>" type="submit">
325 - </form>
326 - <?php }
327 - }
843 + $redirect_to = apply_filters('uwp_register_redirect_to', $redirect_to, $args);
328 844
329 - /**
330 - * Prints field html based on field type.
331 - *
332 - * @since 1.0.0
333 - * @package userswp
334 - * @param object $field Field info.
335 - * @param string $form_type Form type.
336 - * @param int|bool $user_id User ID.
337 - * @return void
338 - */
339 - public function uwp_template_fields_html($field, $form_type, $user_id = false) {
340 - if (!$user_id) {
341 - $user_id = get_current_user_id();
342 - }
845 + if ( $redirect_to ) {
846 + echo '<input type="hidden" name="redirect_to" value="' . esc_url( $redirect_to ) . '"/>';
847 + }
343 848
344 - $value = $this->uwp_get_default_form_value($field);
345 - if ($form_type == 'account') {
346 - $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 + }
347 867
348 - if ($field->htmlvar_name == 'uwp_account_email') {
349 - $value = $user_data->user_email;
350 - } elseif ($field->htmlvar_name == 'uwp_account_password') {
351 - $value = '';
352 - $field->is_required = 0;
353 - } elseif ($field->htmlvar_name == 'uwp_account_confirm_password') {
354 - $value = '';
355 - $field->is_required = 0;
356 - } else {
357 - $value = uwp_get_usermeta($user_id, $field->htmlvar_name, false);
358 - if ($value != '0' && !$value) {
359 - $value = $this->uwp_get_default_form_value($field);
360 - }
361 - }
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 + }
362 883
363 - }
884 + }
364 885
365 - if (empty($value)) {
366 - $value = "";
367 - }
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 ) {
368 896
369 - if (isset($_POST[$field->htmlvar_name]) && $field->field_type != 'password') {
370 - $value = $_POST[$field->htmlvar_name];
371 - }
897 + if ( is_admin() ) {
898 + return $menu_item;
899 + }
372 900
373 - $field = apply_filters("uwp_form_input_field_{$field->field_type}", $field, $value, $form_type);
374 -
375 - $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;
376 903
377 - if (empty($html)) {
378 - $label = $site_title = uwp_get_form_label($field);
379 - ?>
380 - <input name="<?php echo $field->htmlvar_name; ?>"
381 - class="<?php echo $field->css_class; ?>"
382 - placeholder="<?php echo $label; ?>"
383 - title="<?php echo $label; ?>"
384 - <?php if ($field->for_admin_use == 1) { echo 'readonly="readonly"'; } ?>
385 - <?php if ($field->is_required == 1) { echo 'required="required"'; } ?>
386 - type="<?php echo $field->field_type; ?>"
387 - value="<?php echo esc_html($value); ?>">
388 - <?php
389 - } else {
390 - echo $html;
391 - }
392 - }
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 + }
393 910
394 - /**
395 - * Returns default value based on field type.
396 - *
397 - * @since 1.0.0
398 - * @package userswp
399 - * @param object $field Field info.
400 - * @return string Field default value.
401 - */
402 - public function uwp_get_default_form_value($field) {
403 - if ($field->field_type == 'url') {
404 - if (substr( $field->default_value, 0, 4 ) === "http") {
405 - $value = $field->default_value;
406 - } else {
407 - $value = "";
408 - }
409 - } else {
410 - $value = $field->default_value;
411 - }
911 + $menu_classes = explode( " ", $menu_classes );
912 + }
412 913
413 - return $value;
414 - }
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";
415 921
416 - /**
417 - * Modifies the author page content with UsersWP profile content.
418 - *
419 - * @since 1.0.0
420 - * @package userswp
421 - * @param string $content Original page content.
422 - * @return string Modified page content.
423 - */
424 - public function uwp_author_page_content($content) {
425 - if (is_author()) {
426 - return do_shortcode('[uwp_profile]');
427 - } else {
428 - return $content;
429 - }
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";
430 929
431 - }
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 + }
432 985
433 - /**
434 - * Modifies the menu item visibility based on UsersWP page type.
435 - *
436 - * @since 1.0.0
437 - * @package userswp
438 - * @param object $menu_item Menu item info.
439 - * @return object Modified menu item.
440 - */
441 - public function uwp_setup_nav_menu_item( $menu_item ) {
986 + $menu_item = apply_filters( 'uwp_setup_nav_menu_item', $menu_item, $menu_classes );
442 987
443 - if ( is_admin() ) {
444 - return $menu_item;
445 - }
988 + return $menu_item;
446 989
447 - // Prevent a notice error when using the customizer
448 - $menu_classes = $menu_item->classes;
990 + }
449 991
450 - if ( is_array( $menu_classes ) ) {
451 - $menu_classes = implode( ' ', $menu_item->classes );
452 - $str = 'users-wp-menu ';
453 - if (strpos($menu_classes, 'users-wp-menu ') !== false) {
454 - $menu_classes = str_replace($str, '', $menu_classes);
455 - }
456 - }
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 ) {
457 1002
458 - $register_slug = uwp_get_page_slug('register_page');
459 - $login_slug = uwp_get_page_slug('login_page');
460 - $change_slug = uwp_get_page_slug('change_page');
461 - $account_slug = uwp_get_page_slug('account_page');
462 - $profile_slug = uwp_get_page_slug('profile_page');
463 - $forgot_slug = uwp_get_page_slug('forgot_page');
464 - $logout_slug = "logout";
1003 + $redirect = null;
465 1004
466 - $register_class = "users-wp-{$register_slug}-nav";
467 - $login_class = "users-wp-{$login_slug}-nav";
468 - $change_class = "users-wp-{$change_slug}-nav";
469 - $account_class = "users-wp-{$account_slug}-nav";
470 - $profile_class = "users-wp-{$profile_slug}-nav";
471 - $forgot_class = "users-wp-{$forgot_slug}-nav";
472 - $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 + }
473 1010
474 - switch ( $menu_classes ) {
475 - case $register_class:
476 - if ( is_user_logged_in() ) {
477 - $menu_item->_invalid = true;
478 - } else {
479 - $menu_item->url = get_permalink(uwp_get_option('register_page', 0));
480 - }
481 - break;
482 - case $login_class:
483 - if ( is_user_logged_in() ) {
484 - $menu_item->_invalid = true;
485 - } else {
486 - $menu_item->url = get_permalink(uwp_get_option('login_page', 0));
487 - }
488 - break;
489 - case $account_class:
490 - if ( ! is_user_logged_in() ) {
491 - $menu_item->_invalid = true;
492 - } else {
493 - $menu_item->url = get_permalink(uwp_get_option('account_page', 0));
494 - }
495 - break;
496 - case $profile_class:
497 - if ( ! is_user_logged_in() ) {
498 - $menu_item->_invalid = true;
499 - } else {
500 - $menu_item->url = get_permalink(uwp_get_option('profile_page', 0));
501 - }
502 - break;
503 - case $change_class:
504 - if ( ! is_user_logged_in() ) {
505 - $menu_item->_invalid = true;
506 - } else {
507 - $menu_item->url = get_permalink(uwp_get_option('change_page', 0));
508 - }
509 - break;
510 - case $forgot_class:
511 - if ( is_user_logged_in() ) {
512 - $menu_item->_invalid = true;
513 - } else {
514 - $menu_item->url = get_permalink(uwp_get_option('forgot_page', 0));
515 - }
516 - break;
517 - case $logout_class:
518 - if ( ! is_user_logged_in() ) {
519 - $menu_item->_invalid = true;
520 - } else {
521 - $menu_item->url = $this->uwp_logout_url();
522 - }
523 - 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() );
524 1062 }
525 1063
526 - $menu_item = apply_filters('uwp_setup_nav_menu_item', $menu_item, $menu_classes);
1064 + return $classes;
1065 + }
527 1066
528 - 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 ) {
529 1076
530 - }
1077 + global $post;
531 1078
532 - /**
533 - * Returns the logout url by adding redirect page link.
534 - *
535 - * @since 1.0.0
536 - * @package userswp
537 - * @param null $custom_redirect Redirect page link.
538 - * @return string Logout url.
539 - */
540 - public function uwp_logout_url( $custom_redirect = null ) {
1079 + if ( is_single() ) {
541 1080
542 - $redirect = null;
1081 + $author_box_enable_disable = uwp_get_option( 'author_box_enable_disable', 1 );
543 1082
544 - if ( !empty( $custom_redirect ) ) {
545 - $redirect = esc_url( $custom_redirect );
546 - } else if ( uwp_get_option('logout_redirect_to', false) ) {
547 - $redirect = esc_url( get_permalink( uwp_get_option('logout_redirect_to', 0) ) );
548 - }
1083 + if ( 1 == $author_box_enable_disable ) {
549 1084
550 - 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' );
551 1086
552 - }
1087 + if ( ! empty( $post->post_type ) && in_array( $post->post_type, (array) $author_box_display_post_types ) ) {
553 1088
554 - /**
555 - * Redirects to UsersWP info page after plugin activation.
556 - *
557 - * @since 1.0.0
558 - * @package userswp
559 - * @return void
560 - */
561 - public function uwp_activation_redirect() {
1089 + $author_box_display_content = uwp_get_option( 'author_box_display_content' );
562 1090
563 - if (get_option('uwp_activation_redirect', false)) {
564 - delete_option('uwp_activation_redirect');
565 - wp_redirect(admin_url('admin.php?page=userswp&tab=main&subtab=info'));
566 - 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 + }
567 1096
568 - }
1097 + // run block content if its available
1098 + if ( function_exists( 'do_blocks' ) ) {
1099 + $content = do_blocks( $content );
1100 + }
1101 + }
569 1102
570 - }
1103 + }
571 1104
572 - /**
573 - * Prints UsersWP fields in WP-Admin Users Edit page.
574 - *
575 - * @since 1.0.0
576 - * @package userswp
577 - * @param object $user User Object.
578 - */
579 - public function get_profile_extra_admin_edit($user) {
580 - echo $this->get_profile_extra_edit($user);
581 - }
1105 + }
582 1106
583 - /**
584 - * Gets UsersWP fields in WP-Admin Users Edit page.
585 - *
586 - * @since 1.0.0
587 - * @package userswp
588 - * @param object $user User Object.
589 - * @return string HTML string.
590 - */
591 - public function get_profile_extra_edit($user) {
592 - ob_start();
593 - global $wpdb;
594 - $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
595 - $fields = $wpdb->get_results("SELECT * FROM " . $table_name . " WHERE form_type = 'account' AND is_default = '0' ORDER BY sort_order ASC");
596 - if ($fields) {
597 - ?>
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 + ?>
598 1134 <div class="uwp-profile-extra">
599 - <table class="uwp-profile-extra-table form-table">
600 - <?php
601 - 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 + }
602 1168
603 - // Icon
604 - if ($field->field_icon) {
605 - $icon = '<i class="uwp_field_icon '.$field->field_icon.'"></i>';
606 - } else {
607 - $icon = '';
608 - }
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) ) );
609 1172
610 - if ($field->field_type == 'fieldset') {
611 - ?>
612 - <tr style="margin: 0; padding: 0">
613 - <th class="uwp-profile-extra-key" style="margin: 0; padding: 0"><h3 style="margin: 10px 0;"><?php echo $icon.$field->site_title; ?></h3></th>
614 - <td></td>
615 - </tr>
616 - <?php
617 - } else { ?>
618 - <tr>
619 - <th class="uwp-profile-extra-key"><?php echo $icon.$field->site_title; ?></th>
620 - <td class="uwp-profile-extra-value">
621 - <?php $this->uwp_template_fields_html($field, 'account', $user->ID); ?>
622 - </td>
623 - </tr>
624 - <?php
625 - }
626 - }
627 - ?>
628 - </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>
629 1257 </div>
630 - <?php
631 - }
632 - $output = ob_get_contents();
633 - ob_end_clean();
634 - return trim($output);
635 - }
1258 + <?php
1259 + echo '</div>';
1260 + }
1261 + }
636 1262
637 - /**
638 - * Adds the UsersWP body class to body tag.
639 - *
640 - * @since 1.0.0
641 - * @package userswp
642 - * @param array $classes Existing class array.
643 - * @return array Modified class array.
644 - */
645 - public function uwp_add_body_class( $classes ) {
646 -
647 - if ( is_uwp_page() ) {
648 - $classes[] = 'uwp_page';
649 - }
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 + }
650 1300
651 - return $classes;
652 - }
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 + }
1317 +
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 + }
653 1395 }