| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Template related functions |
| 5 |
* |
| 6 |
* This class defines all code necessary for UsersWP templates like login. register etc. |
| 7 |
* |
| 8 |
* @since 1.0.0 |
| 9 |
* @author GeoDirectory Team <info@wpgeodirectory.com> |
| 10 |
*/ |
| 11 |
class UsersWP_Templates { |
| 12 |
|
| 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 = '' ) { |
| 24 |
|
| 25 |
if ( ! $template_path ) { |
| 26 |
$template_path = uwp_get_theme_template_dir_name(); |
| 27 |
} |
| 28 |
|
| 29 |
if ( ! $default_path ) { |
| 30 |
$default_path = uwp_get_templates_dir(); |
| 31 |
} |
| 32 |
|
| 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 |
); |
| 40 |
|
| 41 |
// Get default template |
| 42 |
if ( ! $template ) { |
| 43 |
$template = untrailingslashit( $default_path ) . '/' . $template_name; |
| 44 |
} |
| 45 |
|
| 46 |
// Return what we found. |
| 47 |
return apply_filters( 'uwp_locate_template', $template, $template_name, $template_path ); |
| 48 |
} |
| 49 |
|
| 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; |
| 60 |
|
| 61 |
if ( ! is_uwp_page() ) { |
| 62 |
return $content; |
| 63 |
} |
| 64 |
|
| 65 |
if ( ! ( ! empty( $wp_query ) && ! empty( $post ) && ( $post->ID == get_queried_object_id() ) ) ) { |
| 66 |
return $content; |
| 67 |
} |
| 68 |
|
| 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 |
} |
| 75 |
|
| 76 |
remove_filter( 'the_content', array( __CLASS__, 'setup_singular_page_content' ) ); |
| 77 |
|
| 78 |
if ( in_the_loop() ) { |
| 79 |
|
| 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( '/' ); |
| 215 |
} |
| 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); |
| 234 |
} |
| 235 |
|
| 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 |
} |
| 248 |
|
| 249 |
return false; |
| 250 |
} |
| 251 |
|
| 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 |
} |
| 266 |
|
| 267 |
if ( uwp_is_page_builder() ) { |
| 268 |
return; |
| 269 |
} |
| 270 |
|
| 271 |
$change_page = uwp_get_page_id( 'change_page', false ); |
| 272 |
$password_nag = get_user_option( 'default_password_nag', get_current_user_id() ); |
| 273 |
|
| 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 |
} |
| 288 |
|
| 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 |
} |
| 300 |
|
| 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 ) ) { |
| 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 |
} |
| 316 |
|
| 317 |
if ( ! isset( $user->ID ) ) { |
| 318 |
global $wp_query; |
| 319 |
$wp_query->set_404(); |
| 320 |
status_header( 404 ); |
| 321 |
} |
| 322 |
|
| 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', home_url( '/' ) ); |
| 332 |
wp_safe_redirect( $redirect_to ); |
| 333 |
exit(); |
| 334 |
} |
| 335 |
|
| 336 |
} |
| 337 |
|
| 338 |
} |
| 339 |
} |
| 340 |
} |
| 341 |
|
| 342 |
/** |
| 343 |
* Redirects user to a predefined page after logging out. |
| 344 |
* |
| 345 |
* @return void |
| 346 |
* @package userswp |
| 347 |
* @since 1.0.0 |
| 348 |
*/ |
| 349 |
public function logout_redirect() { |
| 350 |
$redirect_page_id = uwp_get_page_id( 'logout_redirect_to' ); |
| 351 |
if ( isset( $_REQUEST['redirect_to'] ) ) { |
| 352 |
$redirect_to = esc_url( $_REQUEST['redirect_to'] ); |
| 353 |
} elseif ( isset( $redirect_page_id ) && (int) $redirect_page_id > 0 ) { |
| 354 |
$redirect_to = get_permalink( $redirect_page_id ); |
| 355 |
} else { |
| 356 |
$redirect_to = home_url( '/' ); |
| 357 |
} |
| 358 |
$redirect_to = apply_filters( 'uwp_logout_redirect', $redirect_to ); |
| 359 |
wp_safe_redirect( $redirect_to ); |
| 360 |
exit(); |
| 361 |
} |
| 362 |
|
| 363 |
/** |
| 364 |
* Redirects wp-login.php to UsersWP login page. |
| 365 |
* |
| 366 |
* @return void |
| 367 |
* @package userswp |
| 368 |
* @since 1.0.0 |
| 369 |
*/ |
| 370 |
public function wp_login_redirect() { |
| 371 |
global $pagenow; |
| 372 |
if ( 'wp-login.php' == $pagenow && ! isset( $_REQUEST['action'] ) ) { |
| 373 |
$login_page_id = uwp_get_page_id( 'login_page', false ); |
| 374 |
$block_wp_login = uwp_get_option( 'block_wp_login', '' ); |
| 375 |
if ( $login_page_id && $block_wp_login == '1' ) { |
| 376 |
$redirect_to = get_permalink( $login_page_id ); |
| 377 |
if ( $redirect_to ) { |
| 378 |
$redirect_to = add_query_arg( 'redirect_to', admin_url(), $redirect_to ); |
| 379 |
} |
| 380 |
wp_safe_redirect( $redirect_to ); |
| 381 |
exit(); |
| 382 |
} |
| 383 |
} |
| 384 |
} |
| 385 |
|
| 386 |
/** |
| 387 |
* Redirects wp-login.php?action=register to UsersWP registration page. |
| 388 |
* |
| 389 |
* @return void |
| 390 |
* @package userswp |
| 391 |
* @since 1.0.0 |
| 392 |
*/ |
| 393 |
public function wp_register_redirect() { |
| 394 |
|
| 395 |
global $pagenow; |
| 396 |
if ( 'wp-login.php' == $pagenow && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'register' ) { |
| 397 |
$reg_page_id = uwp_get_page_id( 'register_page' ); |
| 398 |
$block_wp_reg = uwp_get_option( 'wp_register_redirect' ); |
| 399 |
if ( $reg_page_id && $block_wp_reg == '1' ) { |
| 400 |
|
| 401 |
$redirect = isset( $_REQUEST['redirect_to'] ) ? esc_url( $_REQUEST['redirect_to'] ) : ''; |
| 402 |
$redirect_to = get_permalink( $reg_page_id ); |
| 403 |
if ( $redirect ) { |
| 404 |
$redirect_to = add_query_arg( 'redirect_to', $redirect, $redirect_to ); |
| 405 |
} |
| 406 |
wp_safe_redirect( $redirect_to ); |
| 407 |
exit(); |
| 408 |
} |
| 409 |
} |
| 410 |
} |
| 411 |
|
| 412 |
/** |
| 413 |
* Changes the login url to the UWP login page. |
| 414 |
* |
| 415 |
* @param $login_url string The URL for login. |
| 416 |
* @param $redirect string The URL to redirect back to upon successful login. |
| 417 |
* @param $force_reauth bool Whether to force reauthorization, even if a cookie is present. |
| 418 |
* |
| 419 |
* @return string The login url. |
| 420 |
* @package userswp |
| 421 |
* |
| 422 |
* @since 1.0.12 |
| 423 |
*/ |
| 424 |
public function wp_login_url( $login_url, $redirect, $force_reauth ) { |
| 425 |
global $pagenow; |
| 426 |
|
| 427 |
if ( class_exists( 'Jetpack' ) && 'wp-login.php' == $pagenow && Jetpack::is_module_active( 'sso' ) ) { |
| 428 |
return $login_url; // Do not change the URL for Jetpack SSO |
| 429 |
} |
| 430 |
|
| 431 |
if( did_action('init') === 0 ){ |
| 432 |
return $login_url; // Some plugin calls login link very early. |
| 433 |
} |
| 434 |
|
| 435 |
$login_page_id = uwp_get_page_id( 'login_page', false ); |
| 436 |
$redirect_page_id = uwp_get_page_id( 'login_redirect_to' ); |
| 437 |
if ( ( ! is_admin() || wp_doing_ajax() ) && $login_page_id ) { |
| 438 |
$login_page = get_permalink( $login_page_id ); |
| 439 |
if ( $redirect ) { |
| 440 |
$login_url = add_query_arg( 'redirect_to', urlencode( $redirect ), $login_page ); |
| 441 |
} elseif ( isset( $redirect_page_id ) && (int) $redirect_page_id == - 1 && wp_get_referer() ) { |
| 442 |
$redirect_to = esc_url( wp_get_referer() ); |
| 443 |
$login_url = add_query_arg( 'redirect_to', $redirect_to, $login_page ); |
| 444 |
} elseif ( isset( $redirect_page_id ) && $redirect_page_id > 0 ) { |
| 445 |
$redirect_to = get_permalink( $redirect_page_id ); |
| 446 |
$login_url = add_query_arg( 'redirect_to', $redirect_to, $login_page ); |
| 447 |
} else { |
| 448 |
$login_url = $login_page; |
| 449 |
} |
| 450 |
} |
| 451 |
|
| 452 |
return $login_url; |
| 453 |
} |
| 454 |
|
| 455 |
/** |
| 456 |
* Changes the register url with the UWP register page. |
| 457 |
* |
| 458 |
* @param $register_url string The URL for register. |
| 459 |
* |
| 460 |
* @return string The register url. |
| 461 |
* @since 1.0.22 |
| 462 |
* |
| 463 |
*/ |
| 464 |
public function wp_register_url( $register_url ) { |
| 465 |
$register_page_id = uwp_get_page_id( 'register_page' ); |
| 466 |
$redirect_page_id = uwp_get_page_id( 'register_redirect_to' ); |
| 467 |
|
| 468 |
$redirect = isset( $_REQUEST['redirect_to'] ) ? esc_url( $_REQUEST['redirect_to'] ) : ''; |
| 469 |
if ( isset( $register_page_id ) && $register_page_id > 0 ) { |
| 470 |
$register_page = get_permalink( $register_page_id ); |
| 471 |
if ( $register_url && isset( $redirect ) && ! empty( $redirect ) ) { |
| 472 |
$register_url = add_query_arg( 'redirect_to', $redirect, $register_page ); |
| 473 |
} elseif ( (int) $redirect_page_id > 0 ) { |
| 474 |
$redirect_to = get_permalink( $redirect_page_id ); |
| 475 |
$register_url = add_query_arg( 'redirect_to', $redirect_to, $register_page ); |
| 476 |
} else { |
| 477 |
$register_url = $register_page; |
| 478 |
} |
| 479 |
} |
| 480 |
|
| 481 |
return $register_url; |
| 482 |
} |
| 483 |
|
| 484 |
/** |
| 485 |
* Changes the lost password url with the UWP page. |
| 486 |
* |
| 487 |
* @param $lostpassword_url string The URL for lost password. |
| 488 |
* |
| 489 |
* @return string The lost password page url. |
| 490 |
*/ |
| 491 |
public function wp_lostpassword_url( $lostpassword_url ) { |
| 492 |
$forgot_page_url = uwp_get_forgot_page_url(); |
| 493 |
|
| 494 |
if ( is_multisite() && isset( $_GET['redirect_to'] ) && false !== strpos( wp_unslash( $_GET['redirect_to'] ), network_admin_url() ) ) { |
| 495 |
return $lostpassword_url; |
| 496 |
} |
| 497 |
|
| 498 |
$redirect = isset( $_REQUEST['redirect_to'] ) ? esc_url( $_REQUEST['redirect_to'] ) : ''; |
| 499 |
if ( $forgot_page_url ) { |
| 500 |
if ( $forgot_page_url && isset( $redirect ) && ! empty( $redirect ) ) { |
| 501 |
$lostpassword_url = add_query_arg( 'redirect_to', $redirect, $forgot_page_url ); |
| 502 |
} else { |
| 503 |
$lostpassword_url = $forgot_page_url; |
| 504 |
} |
| 505 |
} |
| 506 |
|
| 507 |
return $lostpassword_url; |
| 508 |
} |
| 509 |
|
| 510 |
/** |
| 511 |
* Prints html for form fields of that particular form. |
| 512 |
* |
| 513 |
* @param string $form_type Form type. |
| 514 |
* |
| 515 |
* @return void |
| 516 |
* @since 1.0.0 |
| 517 |
* @package userswp |
| 518 |
*/ |
| 519 |
public function template_fields( $form_type, $args = array() ) { |
| 520 |
|
| 521 |
global $wpdb, $aui_bs5; |
| 522 |
$table_name = uwp_get_table_prefix() . 'uwp_form_fields'; |
| 523 |
$extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras'; |
| 524 |
|
| 525 |
$form_id = ! empty( $args['id'] ) ? (int) $args['id'] : uwp_get_option('register_modal_form', 1); |
| 526 |
if ( $form_type == 'register' ) { |
| 527 |
$fields = get_register_form_fields($form_id); |
| 528 |
// Use limit from args, otherwise fall back to the register_modal_form setting. |
| 529 |
$form_limit = ! empty( $args['limit'] ) ? $args['limit'] : uwp_get_option('register_modal_form', ''); |
| 530 |
if(isset($form_limit) && !is_array($form_limit)){ |
| 531 |
$form_limit = explode(',', $form_limit); |
| 532 |
} |
| 533 |
|
| 534 |
if(isset($form_limit) && !empty($form_limit) && count($form_limit) > 1){ |
| 535 |
|
| 536 |
$form_limit = array_map('uwp_clean', $form_limit); |
| 537 |
$form_limit = array_map('trim', $form_limit); |
| 538 |
$options = uwp_get_register_forms_dropdown_options($form_limit); |
| 539 |
$selector_id = wp_doing_ajax() ? "uwp-form-select-ajax" : 'uwp-form-select'; |
| 540 |
$display_style = uwp_get_option('register_form_display_style', 'buttons'); |
| 541 |
|
| 542 |
if ( $display_style === 'select' ) { |
| 543 |
// Render as select dropdown. |
| 544 |
$selector_label = apply_filters( 'uwp_account_type_selector_label', __('Account Type', 'userswp'), $form_type, $args ); |
| 545 |
?> |
| 546 |
<div class="form-group mb-3" id="<?php echo esc_attr( $selector_id ); ?>"> |
| 547 |
<label for="uwp-form-type-select" class="form-label"><?php echo esc_html( $selector_label ); ?></label> |
| 548 |
<select id="uwp-form-type-select" class="form-select aui-select2 w-100" data-form-selector="select"> |
| 549 |
<?php |
| 550 |
foreach ( $options as $option_id => $option_label ) { |
| 551 |
$selected = $form_id == $option_id ? 'selected' : ''; |
| 552 |
?> |
| 553 |
<option value="<?php echo esc_attr( $option_id ); ?>" <?php echo esc_attr( $selected ); ?> data-form_id="<?php echo esc_attr( $option_id ); ?>"> |
| 554 |
<?php echo esc_html( $option_label ); ?> |
| 555 |
</option> |
| 556 |
<?php |
| 557 |
} |
| 558 |
?> |
| 559 |
</select> |
| 560 |
</div> |
| 561 |
<?php |
| 562 |
} else { |
| 563 |
// Render as button groups (default) |
| 564 |
?> |
| 565 |
<div class="btn-group btn-group-sm d-flex mb-3" role="group" id="<?php echo esc_attr( $selector_id ); ?>"> |
| 566 |
<?php |
| 567 |
$options = array_chunk( $options, 5, true ); |
| 568 |
$current_url = uwp_current_page_url(); |
| 569 |
if ( isset( $options[0] ) && ! empty( $options[0] ) && count( $options[0] ) > 1 ) { |
| 570 |
foreach ( $options[0] as $id => $val ) { |
| 571 |
$active = $form_id == $id ? 'active' : ''; |
| 572 |
$url = esc_url_raw( add_query_arg( array( 'uwp_form_id' => $id ), $current_url ) ); |
| 573 |
echo aui()->button( array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 574 |
'type' => 'a', |
| 575 |
'href' => '#', |
| 576 |
'class' => 'btn btn-outline-primary '. esc_attr( $active ), |
| 577 |
'content' => esc_attr( $val ), |
| 578 |
'extra_attributes' => array('data-form_id'=> esc_attr( $id ) ) |
| 579 |
) ); |
| 580 |
} |
| 581 |
}elseif(count( $options[0] ) == 1){ |
| 582 |
$form_id = key($options[0]); |
| 583 |
} |
| 584 |
|
| 585 |
if ( isset( $options[1] ) && ! empty( $options[1] ) && count( $options[1] ) > 0 ) { |
| 586 |
foreach ( $options[1] as $id => $val ) { |
| 587 |
$active = $form_id == $id ? 'active' : ''; |
| 588 |
$url = esc_url_raw( add_query_arg( array( 'uwp_form_id' => $id ), $current_url ) ); |
| 589 |
?> |
| 590 |
<div class="btn-group" role="group"> |
| 591 |
<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"> |
| 592 |
<?php esc_attr_e('More', 'userswp'); ?> |
| 593 |
</button> |
| 594 |
<div class="dropdown-menu mt-3" aria-labelledby="uwp-form-select"> |
| 595 |
<?php |
| 596 |
echo aui()->button( array( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 597 |
'type' => 'a', |
| 598 |
'href' => esc_url( $url ), |
| 599 |
'class' => 'dropdown-item ' . esc_attr( $active ), |
| 600 |
'content' => esc_attr( $val ), |
| 601 |
'extra_attributes' => array('data-form_id'=> esc_attr( $id ) ) |
| 602 |
) ); |
| 603 |
?> |
| 604 |
</div> |
| 605 |
</div> |
| 606 |
<?php |
| 607 |
} |
| 608 |
} |
| 609 |
?> |
| 610 |
</div> |
| 611 |
<?php |
| 612 |
} |
| 613 |
} |
| 614 |
} elseif ( $form_type == 'account' ) { |
| 615 |
$fields = get_account_form_fields(); |
| 616 |
} elseif ( $form_type == 'change' ) { |
| 617 |
$fields = get_change_form_fields(); |
| 618 |
} else { |
| 619 |
$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 ) ) ); |
| 620 |
} |
| 621 |
|
| 622 |
if ( ! empty( $fields ) ) { |
| 623 |
foreach ( $fields as $field ) { |
| 624 |
|
| 625 |
if ( $form_type == 'account' ) { |
| 626 |
if ( $field->htmlvar_name == 'display_name' ) { |
| 627 |
if ( $field->is_active != '1' ) { |
| 628 |
continue; |
| 629 |
} |
| 630 |
} |
| 631 |
if ( $field->htmlvar_name == 'bio' ) { |
| 632 |
if ( $field->is_active != '1' ) { |
| 633 |
continue; |
| 634 |
} |
| 635 |
} |
| 636 |
} |
| 637 |
|
| 638 |
if ( $form_type == 'register' ) { |
| 639 |
if ( $field->is_active != '1' ) { |
| 640 |
continue; |
| 641 |
} |
| 642 |
$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( |
| 643 |
$field->htmlvar_name, |
| 644 |
$form_type, |
| 645 |
$form_id |
| 646 |
) ) ); |
| 647 |
if ( $count == 1 ) { |
| 648 |
$this->template_fields_html( $field, $form_type ); |
| 649 |
} |
| 650 |
} else { |
| 651 |
$this->template_fields_html( $field, $form_type ); |
| 652 |
} |
| 653 |
} |
| 654 |
} |
| 655 |
} |
| 656 |
|
| 657 |
/** |
| 658 |
* Prints field html based on field type. |
| 659 |
* |
| 660 |
* @param object $field Field info. |
| 661 |
* @param string $form_type Form type. |
| 662 |
* @param int|bool $user_id User ID. |
| 663 |
* |
| 664 |
* @return void |
| 665 |
* @since 1.0.0 |
| 666 |
* @package userswp |
| 667 |
*/ |
| 668 |
public function template_fields_html( $field, $form_type, $user_id = false ) { |
| 669 |
if ( ! $user_id ) { |
| 670 |
$user_id = get_current_user_id(); |
| 671 |
} |
| 672 |
|
| 673 |
$value = $this->get_default_form_value( $field ); |
| 674 |
if ( $form_type == 'account' ) { |
| 675 |
$user_data = get_userdata( $user_id ); |
| 676 |
|
| 677 |
if ( $field->htmlvar_name == 'email' ) { |
| 678 |
if(!empty($user_data)) { |
| 679 |
$value = $user_data->user_email; |
| 680 |
}else{ |
| 681 |
$value = ''; |
| 682 |
} |
| 683 |
} elseif ( $field->htmlvar_name == 'password' ) { |
| 684 |
$value = ''; |
| 685 |
$field->is_required = 0; |
| 686 |
} elseif ( $field->htmlvar_name == 'confirm_password' ) { |
| 687 |
$value = ''; |
| 688 |
$field->is_required = 0; |
| 689 |
} else { |
| 690 |
$value = uwp_get_usermeta( $user_id, $field->htmlvar_name, false ); |
| 691 |
if ( $value != '0' && ! $value ) { |
| 692 |
$value = $this->get_default_form_value( $field ); |
| 693 |
} |
| 694 |
} |
| 695 |
|
| 696 |
} |
| 697 |
|
| 698 |
if ( ! isset( $value ) ) { |
| 699 |
$value = ""; |
| 700 |
} |
| 701 |
|
| 702 |
if ( isset( $_POST[ $field->htmlvar_name ] ) && $field->field_type != 'password' ) { |
| 703 |
$value = isset( $_POST[ $field->htmlvar_name ] ) ? $_POST[ $field->htmlvar_name ] : ''; //@todo: Used to pre fill form when validation fails, need to find better solution |
| 704 |
} |
| 705 |
|
| 706 |
if ( 'checkbox' == $field->field_type ) { |
| 707 |
if ( in_array( $value, array( 'true', 'on', 1 ) ) ) { |
| 708 |
$value = 1; |
| 709 |
} else { |
| 710 |
$value = 0; |
| 711 |
} |
| 712 |
} |
| 713 |
|
| 714 |
$field = apply_filters( "uwp_form_input_field_{$field->field_type}", $field, $value, $form_type ); |
| 715 |
|
| 716 |
$html = apply_filters( "uwp_form_input_html_{$field->field_type}", "", $field, $value, $form_type ); |
| 717 |
|
| 718 |
if ( empty( $html ) ) { |
| 719 |
|
| 720 |
$design_style = uwp_get_option( "design_style", "bootstrap" ); |
| 721 |
$bs_form_group = $design_style ? "form-group mb-3" : ""; |
| 722 |
$bs_sr_only = $design_style ? "sr-only" : ""; |
| 723 |
$bs_form_control = $design_style ? "form-control" : ""; |
| 724 |
|
| 725 |
?> |
| 726 |
<div id="<?php echo esc_attr( $field->htmlvar_name ); ?>_row" |
| 727 |
class="<?php if ( $field->is_required ) { |
| 728 |
echo 'required_field'; |
| 729 |
} ?> uwp_form_row clearfix uwp_clear <?php echo esc_attr( $bs_form_group ); ?>"> |
| 730 |
<?php |
| 731 |
|
| 732 |
$label = $site_title = uwp_get_form_label( $field ); |
| 733 |
if ( ! is_admin() ) { ?> |
| 734 |
<label class="<?php echo esc_attr( $bs_sr_only ); ?>"> |
| 735 |
<?php echo ( trim( $site_title ) ) ? esc_attr( $site_title ) : ' '; ?> |
| 736 |
<?php if ( $field->is_required ) { |
| 737 |
echo '<span>*</span>'; |
| 738 |
} ?> |
| 739 |
</label> |
| 740 |
<?php } ?> |
| 741 |
|
| 742 |
<input name="<?php echo esc_attr($field->htmlvar_name); ?>" |
| 743 |
class="<?php echo esc_attr($field->css_class); ?> <?php echo esc_attr( $bs_form_control ); ?>" |
| 744 |
placeholder="<?php echo esc_attr( uwp_get_field_placeholder( $field ) ); ?>" |
| 745 |
title="<?php echo esc_attr($label); ?>" |
| 746 |
<?php if ( $field->for_admin_use == 1 ) { |
| 747 |
echo 'readonly="readonly"'; |
| 748 |
} ?> |
| 749 |
<?php if ( $field->is_required == 1 ) { |
| 750 |
echo 'required="required"'; |
| 751 |
} ?> |
| 752 |
type="<?php echo esc_attr($field->field_type); ?>" |
| 753 |
value="<?php echo esc_html( $value ); ?>"> |
| 754 |
|
| 755 |
</div> |
| 756 |
<?php |
| 757 |
} else { |
| 758 |
echo $html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 759 |
} |
| 760 |
} |
| 761 |
|
| 762 |
/** |
| 763 |
* Returns default value based on field type. |
| 764 |
* |
| 765 |
* @param object $field Field info. |
| 766 |
* |
| 767 |
* @return string Field default value. |
| 768 |
* @since 1.0.0 |
| 769 |
* @package userswp |
| 770 |
*/ |
| 771 |
public function get_default_form_value( $field ) { |
| 772 |
if ( $field->field_type == 'url' ) { |
| 773 |
if ( substr( $field->default_value, 0, 4 ) === "http" ) { |
| 774 |
$value = $field->default_value; |
| 775 |
} else { |
| 776 |
$value = ""; |
| 777 |
} |
| 778 |
} else { |
| 779 |
$value = $field->default_value; |
| 780 |
} |
| 781 |
|
| 782 |
return $value; |
| 783 |
} |
| 784 |
|
| 785 |
/** |
| 786 |
* Display redirect to input of that particular form. |
| 787 |
* |
| 788 |
* @param string $form_type Form type. |
| 789 |
* |
| 790 |
* @return void |
| 791 |
* @since 1.0.21 |
| 792 |
* @package userswp |
| 793 |
*/ |
| 794 |
public function template_extra_fields( $form_type, $args = array() ) { |
| 795 |
if ( $form_type == 'login' ) { |
| 796 |
$redirect_to = ''; |
| 797 |
if ( isset( $args['redirect_to'] ) && ! empty( $args['redirect_to'] ) ) { |
| 798 |
$redirect_to = $args['redirect_to']; |
| 799 |
} elseif ( isset( $_REQUEST['redirect_to'] ) && ! empty( $_REQUEST['redirect_to'] ) ) { |
| 800 |
$redirect_to = esc_url( urldecode( $_REQUEST['redirect_to'] ) ); |
| 801 |
} else { |
| 802 |
if ( - 1 == uwp_get_option( 'login_redirect_to', - 1 ) ) { |
| 803 |
$referer = wp_get_referer(); |
| 804 |
if ( isset( $referer ) && ! empty( $referer ) ) { |
| 805 |
$redirect_to = $referer; |
| 806 |
} else { |
| 807 |
$redirect_to = home_url(); |
| 808 |
} |
| 809 |
} |
| 810 |
} |
| 811 |
|
| 812 |
$redirect_to = apply_filters('uwp_login_redirect_to', $redirect_to, $args); |
| 813 |
|
| 814 |
if ( $redirect_to ) { |
| 815 |
echo '<input type="hidden" name="redirect_to" value="' . esc_url( $redirect_to ) . '"/>'; |
| 816 |
} |
| 817 |
|
| 818 |
echo '<input type="hidden" name="uwp_login_nonce" value="' . esc_attr( wp_create_nonce( 'uwp-login-nonce' ) ) . '" />'; |
| 819 |
} elseif ( $form_type == 'register' ) { |
| 820 |
$redirect_to = ''; |
| 821 |
$form_id = ! empty( $args['id'] ) ? $args['id'] : 1; |
| 822 |
if ( isset( $args['redirect_to'] ) && ! empty( $args['redirect_to'] ) ) { |
| 823 |
$redirect_to = $args['redirect_to']; |
| 824 |
} else { |
| 825 |
$redirect_to_value = uwp_get_register_form_by( $form_id, 'redirect_to'); |
| 826 |
if(!$redirect_to_value){ |
| 827 |
$redirect_to_value = uwp_get_option( 'register_redirect_to', - 1 ); |
| 828 |
} |
| 829 |
|
| 830 |
if ( - 1 == $redirect_to_value) { |
| 831 |
$referer = wp_get_referer(); |
| 832 |
if ( isset( $_REQUEST['redirect_to'] ) && ! empty( $_REQUEST['redirect_to'] ) ) { |
| 833 |
$redirect_to = esc_url( urldecode( $_REQUEST['redirect_to'] ) ); |
| 834 |
} else if ( isset( $referer ) && ! empty( $referer ) ) { |
| 835 |
$redirect_to = $referer; |
| 836 |
} else { |
| 837 |
$redirect_to = home_url(); |
| 838 |
} |
| 839 |
} |
| 840 |
} |
| 841 |
|
| 842 |
$redirect_to = apply_filters('uwp_register_redirect_to', $redirect_to, $args); |
| 843 |
|
| 844 |
if ( $redirect_to ) { |
| 845 |
echo '<input type="hidden" name="redirect_to" value="' . esc_url( $redirect_to ) . '"/>'; |
| 846 |
} |
| 847 |
|
| 848 |
$hash = substr( hash( 'SHA256', AUTH_KEY . site_url() ), 0, 25 ); |
| 849 |
echo '<input type="hidden" name="uwp_register_hash" value="' . esc_html( $hash ) . '" style="display:none !important; visibility:hidden !important;" />'; |
| 850 |
echo '<input type="hidden" name="uwp_register_hp" value="" style="display:none !important; visibility:hidden !important;" size="25" autocomplete="off" />'; |
| 851 |
echo '<input type="hidden" name="uwp_register_nonce" value="' . esc_attr( wp_create_nonce( 'uwp-register-nonce' ) ) . '" />'; |
| 852 |
echo '<input type="hidden" name="uwp_register_form_id" value="' . absint($form_id) . '">'; |
| 853 |
} elseif ( $form_type == 'change' ) { |
| 854 |
echo '<input type="hidden" name="uwp_change_nonce" value="' . esc_attr( wp_create_nonce( 'uwp-change-nonce' ) ) . '" />'; |
| 855 |
} elseif ( $form_type == 'forgot' ) { |
| 856 |
echo '<input type="hidden" name="uwp_forgot_nonce" value="' . esc_attr( wp_create_nonce( 'uwp-forgot-nonce' ) ) . '" />'; |
| 857 |
} elseif ( $form_type == 'reset' ) { |
| 858 |
if ( isset( $_GET['key'] ) && isset( $_GET['login'] ) ) { |
| 859 |
echo '<input type="hidden" name="uwp_reset_username" value="' . esc_attr( $_GET['login'] ) . '" />'; |
| 860 |
echo '<input type="hidden" name="uwp_reset_key" value="' . esc_attr( $_GET['key'] ) . '" />'; |
| 861 |
} |
| 862 |
echo '<input type="hidden" name="uwp_reset_hp" value="" style="display:none !important; visibility:hidden !important;" size="25" autocomplete="off" />'; |
| 863 |
echo '<input type="hidden" name="uwp_reset_nonce" value="' . esc_attr( wp_create_nonce( 'uwp-reset-nonce' ) ) . '" />'; |
| 864 |
} |
| 865 |
} |
| 866 |
|
| 867 |
/** |
| 868 |
* Modifies the author page content with UsersWP profile content. |
| 869 |
* |
| 870 |
* @param string $content Original page content. |
| 871 |
* |
| 872 |
* @return string Modified page content. |
| 873 |
* @since 1.0.0 |
| 874 |
* @package userswp |
| 875 |
*/ |
| 876 |
public function author_page_content( $content ) { |
| 877 |
if ( is_author() && 1 != uwp_get_option( 'uwp_disable_author_link' ) && apply_filters( 'uwp_use_author_page_content', true ) ) { |
| 878 |
return do_shortcode( '[uwp_profile]' ); |
| 879 |
} else { |
| 880 |
return $content; |
| 881 |
} |
| 882 |
|
| 883 |
} |
| 884 |
|
| 885 |
/** |
| 886 |
* Modifies the menu item visibility based on UsersWP page type. |
| 887 |
* |
| 888 |
* @param object $menu_item Menu item info. |
| 889 |
* |
| 890 |
* @return object Modified menu item. |
| 891 |
* @since 1.0.0 |
| 892 |
* @package userswp |
| 893 |
*/ |
| 894 |
public function setup_nav_menu_item( $menu_item ) { |
| 895 |
|
| 896 |
if ( is_admin() ) { |
| 897 |
return $menu_item; |
| 898 |
} |
| 899 |
|
| 900 |
// Prevent a notice error when using the customizer |
| 901 |
$menu_classes = $menu_item->classes; |
| 902 |
|
| 903 |
if ( is_array( $menu_classes ) ) { |
| 904 |
$menu_classes = implode( ' ', $menu_item->classes ); |
| 905 |
$str = 'users-wp-menu '; |
| 906 |
if ( strpos( $menu_classes, 'users-wp-menu ' ) !== false ) { |
| 907 |
$menu_classes = str_replace( $str, '', $menu_classes ); |
| 908 |
} |
| 909 |
|
| 910 |
$menu_classes = explode( " ", $menu_classes ); |
| 911 |
} |
| 912 |
|
| 913 |
$register_slug = uwp_get_page_slug( 'register_page' ); |
| 914 |
$login_slug = uwp_get_page_slug( 'login_page' ); |
| 915 |
$change_slug = uwp_get_page_slug( 'change_page' ); |
| 916 |
$account_slug = uwp_get_page_slug( 'account_page' ); |
| 917 |
$profile_slug = uwp_get_page_slug( 'profile_page' ); |
| 918 |
$forgot_slug = uwp_get_page_slug( 'forgot_page' ); |
| 919 |
$logout_slug = "logout"; |
| 920 |
|
| 921 |
$register_class = "users-wp-{$register_slug}-nav"; |
| 922 |
$login_class = "users-wp-{$login_slug}-nav"; |
| 923 |
$change_class = "users-wp-{$change_slug}-nav"; |
| 924 |
$account_class = "users-wp-{$account_slug}-nav"; |
| 925 |
$profile_class = "users-wp-{$profile_slug}-nav"; |
| 926 |
$forgot_class = "users-wp-{$forgot_slug}-nav"; |
| 927 |
$logout_class = "users-wp-{$logout_slug}-nav"; |
| 928 |
|
| 929 |
if ( ! empty( $menu_classes ) ) { |
| 930 |
foreach ( $menu_classes as $menu_class ) { |
| 931 |
switch ( $menu_class ) { |
| 932 |
case $register_class: |
| 933 |
if ( is_user_logged_in() ) { |
| 934 |
$menu_item->_invalid = true; |
| 935 |
} else { |
| 936 |
$menu_item->url = uwp_get_page_id( 'register_page', true ); |
| 937 |
} |
| 938 |
break; |
| 939 |
case $login_class: |
| 940 |
if ( is_user_logged_in() ) { |
| 941 |
$menu_item->_invalid = true; |
| 942 |
} else { |
| 943 |
$menu_item->url = uwp_get_page_id( 'login_page', true ); |
| 944 |
} |
| 945 |
break; |
| 946 |
case $account_class: |
| 947 |
if ( ! is_user_logged_in() ) { |
| 948 |
$menu_item->_invalid = true; |
| 949 |
} else { |
| 950 |
$menu_item->url = uwp_get_page_id( 'account_page', true ); |
| 951 |
} |
| 952 |
break; |
| 953 |
case $profile_class: |
| 954 |
if ( ! is_user_logged_in() ) { |
| 955 |
$menu_item->_invalid = true; |
| 956 |
} else { |
| 957 |
$menu_item->url = uwp_get_page_id( 'profile_page', true ); |
| 958 |
} |
| 959 |
break; |
| 960 |
case $change_class: |
| 961 |
if ( ! is_user_logged_in() ) { |
| 962 |
$menu_item->_invalid = true; |
| 963 |
} else { |
| 964 |
$menu_item->url = uwp_get_page_id( 'change_page', true ); |
| 965 |
} |
| 966 |
break; |
| 967 |
case $forgot_class: |
| 968 |
if ( is_user_logged_in() ) { |
| 969 |
$menu_item->_invalid = true; |
| 970 |
} else { |
| 971 |
$menu_item->url = uwp_get_page_id( 'forgot_page', true ); |
| 972 |
} |
| 973 |
break; |
| 974 |
case $logout_class: |
| 975 |
if ( ! is_user_logged_in() ) { |
| 976 |
$menu_item->_invalid = true; |
| 977 |
} else { |
| 978 |
$menu_item->url = $this->uwp_logout_url(); |
| 979 |
} |
| 980 |
break; |
| 981 |
} |
| 982 |
} |
| 983 |
} |
| 984 |
|
| 985 |
$menu_item = apply_filters( 'uwp_setup_nav_menu_item', $menu_item, $menu_classes ); |
| 986 |
|
| 987 |
return $menu_item; |
| 988 |
|
| 989 |
} |
| 990 |
|
| 991 |
/** |
| 992 |
* Returns the logout url by adding redirect page link. |
| 993 |
* |
| 994 |
* @param null $custom_redirect Redirect page link. |
| 995 |
* |
| 996 |
* @return string Logout url. |
| 997 |
* @since 1.0.0 |
| 998 |
* @package userswp |
| 999 |
*/ |
| 1000 |
public function uwp_logout_url( $custom_redirect = null ) { |
| 1001 |
|
| 1002 |
$redirect = null; |
| 1003 |
|
| 1004 |
$user = get_userdata(get_current_user_id()); |
| 1005 |
if($user && isset($user->roles[0])){ |
| 1006 |
$user_role = $user->roles[0]; |
| 1007 |
$redirect_page_id = uwp_get_option( 'logout_redirect_to_'.$user_role ); |
| 1008 |
} |
| 1009 |
|
| 1010 |
if ( ! empty( $custom_redirect ) ) { |
| 1011 |
$redirect = esc_url( $custom_redirect ); |
| 1012 |
} else if ( isset($redirect_page_id) && !empty($redirect_page_id) ) { |
| 1013 |
if ( uwp_is_wpml() ) { |
| 1014 |
$wpml_page_id = uwp_wpml_object_id( $redirect_page_id, 'page', true, ICL_LANGUAGE_CODE ); |
| 1015 |
if ( ! empty( $wpml_page_id ) ) { |
| 1016 |
$redirect_page_id = $wpml_page_id; |
| 1017 |
} |
| 1018 |
} |
| 1019 |
$redirect = get_permalink( $redirect_page_id ); |
| 1020 |
} |
| 1021 |
|
| 1022 |
return wp_logout_url( apply_filters( 'uwp_logout_url', $redirect, $custom_redirect ) ); |
| 1023 |
|
| 1024 |
} |
| 1025 |
|
| 1026 |
/** |
| 1027 |
* Adds the UsersWP body class to body tag. |
| 1028 |
* |
| 1029 |
* @param array $classes Existing class array. |
| 1030 |
* |
| 1031 |
* @return array Modified class array. |
| 1032 |
* @since 1.0.0 |
| 1033 |
* @package userswp |
| 1034 |
*/ |
| 1035 |
public function add_body_class( $classes ) { |
| 1036 |
|
| 1037 |
if ( is_uwp_page() ) { |
| 1038 |
$classes[] = 'uwp_page'; |
| 1039 |
|
| 1040 |
if ( is_uwp_page( 'register_page' ) ) { |
| 1041 |
$classes[] = 'uwp_register_page'; |
| 1042 |
} elseif ( is_uwp_page( 'login_page' ) ) { |
| 1043 |
$classes[] = 'uwp_login_page'; |
| 1044 |
} elseif ( is_uwp_page( 'forgot_page' ) ) { |
| 1045 |
$classes[] = 'uwp_forgot_page'; |
| 1046 |
} elseif ( is_uwp_page( 'change_page' ) ) { |
| 1047 |
$classes[] = 'uwp_change_page'; |
| 1048 |
} elseif ( is_uwp_page( 'reset_page' ) ) { |
| 1049 |
$classes[] = 'uwp_reset_page'; |
| 1050 |
} elseif ( is_uwp_page( 'account_page' ) ) { |
| 1051 |
$classes[] = 'uwp_account_page'; |
| 1052 |
} elseif ( is_uwp_page( 'profile_page' ) ) { |
| 1053 |
$classes[] = 'uwp_profile_page'; |
| 1054 |
} elseif ( is_uwp_page( 'users_page' ) ) { |
| 1055 |
$classes[] = 'uwp_users_page'; |
| 1056 |
} |
| 1057 |
} |
| 1058 |
|
| 1059 |
if(is_user_logged_in()){ |
| 1060 |
$classes[] = 'uwp-user-type-'.uwp_get_register_form_id( get_current_user_id() ); |
| 1061 |
} |
| 1062 |
|
| 1063 |
return $classes; |
| 1064 |
} |
| 1065 |
|
| 1066 |
/** |
| 1067 |
* |
| 1068 |
* Returns content for author box |
| 1069 |
* |
| 1070 |
* @param $content |
| 1071 |
* |
| 1072 |
* @return string |
| 1073 |
*/ |
| 1074 |
public function author_box_page_content( $content ) { |
| 1075 |
|
| 1076 |
global $post; |
| 1077 |
|
| 1078 |
if ( is_single() ) { |
| 1079 |
|
| 1080 |
$author_box_enable_disable = uwp_get_option( 'author_box_enable_disable', 1 ); |
| 1081 |
|
| 1082 |
if ( 1 == $author_box_enable_disable ) { |
| 1083 |
|
| 1084 |
$author_box_display_post_types = uwp_get_option( 'author_box_display_post_types' ); |
| 1085 |
|
| 1086 |
if ( ! empty( $post->post_type ) && in_array( $post->post_type, (array) $author_box_display_post_types ) ) { |
| 1087 |
|
| 1088 |
$author_box_display_content = uwp_get_option( 'author_box_display_content' ); |
| 1089 |
|
| 1090 |
if ( ! empty( $author_box_display_content ) && 'above_content' === $author_box_display_content ) { |
| 1091 |
$content = do_shortcode( '[uwp_author_box]' ) . $content; |
| 1092 |
} else { |
| 1093 |
$content = $content . do_shortcode( '[uwp_author_box]' ); |
| 1094 |
} |
| 1095 |
|
| 1096 |
// run block content if its available |
| 1097 |
if ( function_exists( 'do_blocks' ) ) { |
| 1098 |
$content = do_blocks( $content ); |
| 1099 |
} |
| 1100 |
} |
| 1101 |
|
| 1102 |
} |
| 1103 |
|
| 1104 |
} |
| 1105 |
|
| 1106 |
return $content; |
| 1107 |
} |
| 1108 |
|
| 1109 |
/** |
| 1110 |
* Adds form html for privacy fields in account page. |
| 1111 |
* |
| 1112 |
* @param string $type Form type. |
| 1113 |
* |
| 1114 |
* @return void |
| 1115 |
* @since 1.0.0 |
| 1116 |
* @package userswp |
| 1117 |
* |
| 1118 |
*/ |
| 1119 |
public function privacy_edit_form_display( $type ) { |
| 1120 |
if ( $type == 'privacy' ) { |
| 1121 |
$make_profile_private = uwp_can_make_profile_private(); |
| 1122 |
echo '<div class="uwp-account-form">'; |
| 1123 |
$extra_where = "AND is_public='2'"; |
| 1124 |
$fields = get_account_form_fields( $extra_where ); |
| 1125 |
$fields = apply_filters( 'uwp_account_privacy_fields', $fields ); |
| 1126 |
$user_id = get_current_user_id(); |
| 1127 |
$form_id = uwp_get_register_form_id( $user_id ); |
| 1128 |
$design_style = uwp_get_option( "design_style", "bootstrap" ); |
| 1129 |
$bs_form_group = $design_style ? "form-group mb-3 row" : ""; |
| 1130 |
$bs_form_control = $design_style ? "form-control" : ""; |
| 1131 |
$bs_btn_class = $design_style ? "btn btn-primary btn-block text-uppercase" : ""; |
| 1132 |
?> |
| 1133 |
<div class="uwp-profile-extra"> |
| 1134 |
<div class="uwp-profile-extra-div form-table"> |
| 1135 |
<form class="uwp-account-form uwp_form" method="post"> |
| 1136 |
<?php if ( $fields ) { ?> |
| 1137 |
<div class="uwp-profile-extra-wrap <?php echo esc_attr( $bs_form_group ); ?>"> |
| 1138 |
<div class="uwp-profile-extra-key col" style="font-weight: bold;"> |
| 1139 |
<?php esc_attr_e( "Field", "userswp" ) ?> |
| 1140 |
</div> |
| 1141 |
<div class="uwp-profile-extra-value col" style="font-weight: bold;"> |
| 1142 |
<?php esc_attr_e( "Is Public?", "userswp" ) ?> |
| 1143 |
</div> |
| 1144 |
</div> |
| 1145 |
<?php foreach ( $fields as $field ) { ?> |
| 1146 |
<div class="uwp-profile-extra-wrap <?php echo esc_attr( $bs_form_group ); ?>"> |
| 1147 |
<div class="uwp-profile-extra-key col"><?php echo esc_attr( $field->site_title ); ?> |
| 1148 |
<span class="uwp-profile-extra-sep">:</span></div> |
| 1149 |
<div class="uwp-profile-extra-value col"> |
| 1150 |
<?php |
| 1151 |
$field_name = $field->htmlvar_name . '_privacy'; |
| 1152 |
$value = uwp_get_usermeta( $user_id, $field_name, false ); |
| 1153 |
if ( $value === false ) { |
| 1154 |
$value = 'yes'; |
| 1155 |
} |
| 1156 |
?> |
| 1157 |
<select name="<?php echo esc_attr( $field_name ); ?>" |
| 1158 |
class="uwp_privacy_field aui-select2 <?php echo esc_attr( $bs_form_control ); ?>" |
| 1159 |
style="margin: 0;"> |
| 1160 |
<option value="no" <?php selected( $value, "no" ); ?>><?php esc_attr_e( "No", "userswp" ) ?></option> |
| 1161 |
<option value="yes" <?php selected( $value, "yes" ); ?>><?php esc_attr_e( "Yes", "userswp" ) ?></option> |
| 1162 |
</select> |
| 1163 |
</div> |
| 1164 |
</div> |
| 1165 |
<?php } |
| 1166 |
} |
| 1167 |
|
| 1168 |
global $wpdb; |
| 1169 |
$tabs_table_name = uwp_get_table_prefix() . 'uwp_profile_tabs'; |
| 1170 |
$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) ) ); |
| 1171 |
|
| 1172 |
if ( $tabs ) { ?> |
| 1173 |
<div class="uwp-profile-extra-wrap <?php echo esc_attr( $bs_form_group ); ?>"> |
| 1174 |
<div class="uwp-profile-extra-key col" style="font-weight: bold;"> |
| 1175 |
<?php esc_attr_e( "Tab Name", "userswp" ) ?> |
| 1176 |
</div> |
| 1177 |
<div class="uwp-profile-extra-value col" style="font-weight: bold;"> |
| 1178 |
<?php esc_attr_e( "Privacy", "userswp" ) ?> |
| 1179 |
</div> |
| 1180 |
</div> |
| 1181 |
<?php } |
| 1182 |
|
| 1183 |
foreach ( $tabs as $tab ) { ?> |
| 1184 |
<div class="uwp-profile-extra-wrap <?php echo esc_attr( $bs_form_group ); ?>"> |
| 1185 |
<div class="uwp-profile-extra-key col"><?php esc_attr_e( $tab->tab_name, 'userswp' ); ?> |
| 1186 |
<span class="uwp-profile-extra-sep">:</span></div> |
| 1187 |
<div class="uwp-profile-extra-value col"> |
| 1188 |
<?php |
| 1189 |
$field_name = $tab->tab_key . '_tab_privacy'; |
| 1190 |
$value = uwp_get_usermeta( $user_id, $field_name, '' ); |
| 1191 |
|
| 1192 |
$privacy_options = array( |
| 1193 |
0 => __( "Anyone", "userswp" ), |
| 1194 |
1 => __( "Logged in", "userswp" ), |
| 1195 |
2 => __( "Author only", "userswp" ), |
| 1196 |
); |
| 1197 |
|
| 1198 |
// Admin default |
| 1199 |
$admin_privacy = isset( $tab->tab_privacy ) ? absint( $tab->tab_privacy ) : 0; |
| 1200 |
$privacy_options = apply_filters( 'uwp_tab_privacy_options', $privacy_options, $tab ); |
| 1201 |
|
| 1202 |
if ( empty( $value ) ) { |
| 1203 |
$value = $admin_privacy; |
| 1204 |
} |
| 1205 |
?> |
| 1206 |
<select name="<?php echo esc_attr( $field_name ); ?>" |
| 1207 |
class="uwp_tab_privacy_field aui-select2 <?php echo esc_attr( $bs_form_control ); ?>" |
| 1208 |
style="margin: 0;"> |
| 1209 |
<?php |
| 1210 |
foreach ( $privacy_options as $key => $val ) { |
| 1211 |
|
| 1212 |
$default = ''; |
| 1213 |
if ( $admin_privacy == $key ) { |
| 1214 |
$default = __( ' (Default)', 'userswp' ); |
| 1215 |
} |
| 1216 |
echo '<option value="' . esc_attr( $key ) . '"' . selected( $value, $key, false ) . '>' . esc_attr( $val . $default ) . '</option>'; |
| 1217 |
} |
| 1218 |
?> |
| 1219 |
</select> |
| 1220 |
</div> |
| 1221 |
</div> |
| 1222 |
<?php } |
| 1223 |
|
| 1224 |
$value = get_user_meta( $user_id, 'uwp_hide_from_listing', true ); ?> |
| 1225 |
<div class="uwp-profile-extra-wrap"> |
| 1226 |
<div id="uwp_hide_from_listing" class="uwp_hide_from_listing"> |
| 1227 |
<input name="uwp_hide_from_listing" class="" <?php checked( $value, "1", true ); ?> |
| 1228 |
type="checkbox" |
| 1229 |
value="1"><?php esc_attr_e( 'Hide profile from the users listing page.', 'userswp' ); ?> |
| 1230 |
</div> |
| 1231 |
</div> |
| 1232 |
<?php |
| 1233 |
do_action( 'uwp_after_privacy_form_fields', $fields ); |
| 1234 |
if ( $make_profile_private ) { |
| 1235 |
$field_name = 'uwp_make_profile_private'; |
| 1236 |
$value = get_user_meta( $user_id, $field_name, true ); |
| 1237 |
if ( $value === false ) { |
| 1238 |
$value = '0'; |
| 1239 |
} |
| 1240 |
?> |
| 1241 |
<div id="uwp_make_profile_private" class=" uwp_make_profile_private_row"> |
| 1242 |
<input type="hidden" name="uwp_make_profile_private" value="0"> |
| 1243 |
<input name="uwp_make_profile_private" class="" <?php checked( $value, "1", true ); ?> |
| 1244 |
type="checkbox" value="1"> |
| 1245 |
<?php esc_attr_e( 'Make the whole profile private', 'userswp' ); ?> |
| 1246 |
</div> |
| 1247 |
<?php |
| 1248 |
} |
| 1249 |
?> |
| 1250 |
<input type="hidden" name="uwp_privacy_nonce" |
| 1251 |
value="<?php echo esc_attr( wp_create_nonce( 'uwp-privacy-nonce' ) ); ?>"/> |
| 1252 |
<input name="uwp_privacy_submit" class="<?php echo esc_attr( $bs_btn_class ); ?>" |
| 1253 |
value="<?php esc_attr_e( 'Submit', 'userswp' ); ?>" type="submit"> |
| 1254 |
</form> |
| 1255 |
</div> |
| 1256 |
</div> |
| 1257 |
<?php |
| 1258 |
echo '</div>'; |
| 1259 |
} |
| 1260 |
} |
| 1261 |
|
| 1262 |
/** |
| 1263 |
* Redirects the user to login page when email not confirmed. |
| 1264 |
* |
| 1265 |
* @param string $username Username. |
| 1266 |
* @param object $user User object. |
| 1267 |
* |
| 1268 |
* @return void |
| 1269 |
* @package userswp |
| 1270 |
* |
| 1271 |
* @since 1.0.0 |
| 1272 |
*/ |
| 1273 |
public function unconfirmed_login_redirect( $username, $user ) { |
| 1274 |
if ( ! is_wp_error( $user ) ) { |
| 1275 |
$mod_value = get_user_meta( $user->ID, 'uwp_mod', true ); |
| 1276 |
if ( $mod_value == 'email_unconfirmed' ) { |
| 1277 |
if ( ! in_array( 'administrator', $user->roles ) ) { |
| 1278 |
$login_page = uwp_get_page_id( 'login_page', false ); |
| 1279 |
if ( $login_page ) { |
| 1280 |
$redirect_to = add_query_arg( array( |
| 1281 |
'uwp_err' => 'act_pending', |
| 1282 |
'user_id' => $user->ID |
| 1283 |
), get_permalink( $login_page ) ); |
| 1284 |
wp_destroy_current_session(); |
| 1285 |
wp_clear_auth_cookie(); |
| 1286 |
if ( wp_doing_ajax() ) { |
| 1287 |
global $userswp; |
| 1288 |
$message = $userswp->notices->form_notice_by_key( 'act_pending', false, $user->ID ); |
| 1289 |
wp_send_json_error( $message ); |
| 1290 |
} else { |
| 1291 |
wp_redirect( $redirect_to ); |
| 1292 |
} |
| 1293 |
exit(); |
| 1294 |
} |
| 1295 |
} |
| 1296 |
} |
| 1297 |
} |
| 1298 |
} |
| 1299 |
|
| 1300 |
/** |
| 1301 |
* Oxygen override theme template. |
| 1302 |
* |
| 1303 |
* @since 1.2.2.15 |
| 1304 |
* |
| 1305 |
* @param string $located Located template. |
| 1306 |
* @param string $template_name Template name. |
| 1307 |
* @param array $located Template args. |
| 1308 |
* @param string $template_path Template path. |
| 1309 |
* @param string $default_path Template default path. |
| 1310 |
* @return string Located template. |
| 1311 |
*/ |
| 1312 |
public function oxygen_override_template( $located, $template_name, $args, $template_path, $default_path ) { |
| 1313 |
if ( $_located = $this->oxygen_locate_template( $template_name ) ) { |
| 1314 |
$located = $_located; |
| 1315 |
} |
| 1316 |
|
| 1317 |
return $located; |
| 1318 |
} |
| 1319 |
|
| 1320 |
/** |
| 1321 |
* Oxygen locate theme template. |
| 1322 |
* |
| 1323 |
* @since 1.2.2.15 |
| 1324 |
* |
| 1325 |
* @param string $template The template. |
| 1326 |
* @return string The theme template. |
| 1327 |
*/ |
| 1328 |
public function oxygen_locate_template( $template ) { |
| 1329 |
$located = ''; |
| 1330 |
|
| 1331 |
if ( ! $template ) { |
| 1332 |
return $located; |
| 1333 |
} |
| 1334 |
|
| 1335 |
$has_filter = has_filter( 'template', 'ct_oxygen_template_name' ); |
| 1336 |
|
| 1337 |
// Remove template filter |
| 1338 |
if ( $has_filter ) { |
| 1339 |
remove_filter( 'template', 'ct_oxygen_template_name' ); |
| 1340 |
} |
| 1341 |
|
| 1342 |
$_located = $this->get_theme_template_path() . '/' . $template; |
| 1343 |
|
| 1344 |
if ( file_exists( $_located ) ) { |
| 1345 |
$located = $_located; |
| 1346 |
} |
| 1347 |
|
| 1348 |
// Add template filter |
| 1349 |
if ( $has_filter ) { |
| 1350 |
add_filter( 'template', 'ct_oxygen_template_name' ); |
| 1351 |
} |
| 1352 |
|
| 1353 |
return $located; |
| 1354 |
} |
| 1355 |
|
| 1356 |
/** |
| 1357 |
* Get the UsersWP templates theme path. |
| 1358 |
* |
| 1359 |
* @since 1.2.2.15 |
| 1360 |
* |
| 1361 |
* @return string Template path. |
| 1362 |
*/ |
| 1363 |
public static function get_theme_template_path() { |
| 1364 |
$template = get_template(); |
| 1365 |
$theme_root = get_theme_root( $template ); |
| 1366 |
|
| 1367 |
$theme_template_path = $theme_root . '/' . $template . '/' . untrailingslashit( uwp_get_theme_template_dir_name() ); |
| 1368 |
|
| 1369 |
return $theme_template_path; |
| 1370 |
} |
| 1371 |
|
| 1372 |
/** |
| 1373 |
* Check & unset the_content hook. |
| 1374 |
* |
| 1375 |
* @since 1.2.13 |
| 1376 |
* |
| 1377 |
* @param string $content The content. |
| 1378 |
* @return string The post content. |
| 1379 |
*/ |
| 1380 |
public function set_the_content_hook( $content ) { |
| 1381 |
global $wp_query, $post, $uwp_set_wpautop; |
| 1382 |
|
| 1383 |
// Prevent empty p tags on block theme. |
| 1384 |
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() ) { |
| 1385 |
if ( $has_filter = has_filter( 'the_content', 'wpautop' ) ) { |
| 1386 |
$uwp_set_wpautop = $has_filter; |
| 1387 |
|
| 1388 |
remove_filter( 'the_content', 'wpautop' ); |
| 1389 |
} |
| 1390 |
} |
| 1391 |
|
| 1392 |
return $content; |
| 1393 |
} |
| 1394 |
} |