| 1 |
<?php |
| 2 |
/** |
| 3 |
* Template related functions |
| 4 |
* |
| 5 |
* This class defines all code necessary for UsersWP templates like login. register etc. |
| 6 |
* |
| 7 |
* @since 1.0.0 |
| 8 |
* @author GeoDirectory Team <info@wpgeodirectory.com> |
| 9 |
*/ |
| 10 |
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 |
|
| 27 |
case 'login': |
| 28 |
return $this->uwp_generic_locate_template('login'); |
| 29 |
break; |
| 30 |
|
| 31 |
case 'forgot': |
| 32 |
return $this->uwp_generic_locate_template('forgot'); |
| 33 |
break; |
| 34 |
|
| 35 |
case 'change': |
| 36 |
return $this->uwp_generic_locate_template('change'); |
| 37 |
break; |
| 38 |
|
| 39 |
case 'reset': |
| 40 |
return $this->uwp_generic_locate_template('reset'); |
| 41 |
break; |
| 42 |
|
| 43 |
case 'account': |
| 44 |
return $this->uwp_generic_locate_template('account'); |
| 45 |
break; |
| 46 |
|
| 47 |
case 'profile': |
| 48 |
return $this->uwp_generic_locate_template('profile'); |
| 49 |
break; |
| 50 |
|
| 51 |
case 'users': |
| 52 |
return $this->uwp_generic_locate_template('users'); |
| 53 |
break; |
| 54 |
} |
| 55 |
|
| 56 |
return apply_filters('uwp_locate_template', false, $template); |
| 57 |
} |
| 58 |
|
| 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 |
} |
| 79 |
|
| 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; |
| 89 |
|
| 90 |
if (!is_page()) { |
| 91 |
return false; |
| 92 |
} |
| 93 |
|
| 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); |
| 100 |
|
| 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); |
| 114 |
} |
| 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(); |
| 129 |
} |
| 130 |
} |
| 131 |
} else { |
| 132 |
return false; |
| 133 |
} |
| 134 |
|
| 135 |
return false; |
| 136 |
} |
| 137 |
|
| 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 |
} |
| 166 |
|
| 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 ) ) { |
| 180 |
|
| 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 |
} |
| 190 |
|
| 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 |
} |
| 197 |
|
| 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 |
} |
| 208 |
|
| 209 |
} |
| 210 |
|
| 211 |
} |
| 212 |
} |
| 213 |
} |
| 214 |
|
| 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 |
} |
| 233 |
|
| 234 |
|
| 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 |
} |
| 254 |
|
| 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) { |
| 264 |
|
| 265 |
global $wpdb; |
| 266 |
$table_name = uwp_get_table_prefix() . 'uwp_form_fields'; |
| 267 |
$extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras'; |
| 268 |
|
| 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) { |
| 281 |
|
| 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 |
} |
| 293 |
} |
| 294 |
|
| 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 |
} |
| 309 |
|
| 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 |
} |
| 328 |
|
| 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 |
} |
| 343 |
|
| 344 |
$value = $this->uwp_get_default_form_value($field); |
| 345 |
if ($form_type == 'account') { |
| 346 |
$user_data = get_userdata($user_id); |
| 347 |
|
| 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 |
} |
| 362 |
|
| 363 |
} |
| 364 |
|
| 365 |
if (empty($value)) { |
| 366 |
$value = ""; |
| 367 |
} |
| 368 |
|
| 369 |
if (isset($_POST[$field->htmlvar_name]) && $field->field_type != 'password') { |
| 370 |
$value = $_POST[$field->htmlvar_name]; |
| 371 |
} |
| 372 |
|
| 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); |
| 376 |
|
| 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 |
} |
| 393 |
|
| 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 |
} |
| 412 |
|
| 413 |
return $value; |
| 414 |
} |
| 415 |
|
| 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 |
} |
| 430 |
|
| 431 |
} |
| 432 |
|
| 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 ) { |
| 442 |
|
| 443 |
if ( is_admin() ) { |
| 444 |
return $menu_item; |
| 445 |
} |
| 446 |
|
| 447 |
// Prevent a notice error when using the customizer |
| 448 |
$menu_classes = $menu_item->classes; |
| 449 |
|
| 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 |
} |
| 457 |
|
| 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"; |
| 465 |
|
| 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"; |
| 473 |
|
| 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; |
| 524 |
} |
| 525 |
|
| 526 |
$menu_item = apply_filters('uwp_setup_nav_menu_item', $menu_item, $menu_classes); |
| 527 |
|
| 528 |
return $menu_item; |
| 529 |
|
| 530 |
} |
| 531 |
|
| 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 ) { |
| 541 |
|
| 542 |
$redirect = null; |
| 543 |
|
| 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 |
} |
| 549 |
|
| 550 |
return wp_logout_url( apply_filters( 'uwp_logout_url', $redirect, $custom_redirect ) ); |
| 551 |
|
| 552 |
} |
| 553 |
|
| 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() { |
| 562 |
|
| 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; |
| 567 |
|
| 568 |
} |
| 569 |
|
| 570 |
} |
| 571 |
|
| 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 |
} |
| 582 |
|
| 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 |
?> |
| 598 |
<div class="uwp-profile-extra"> |
| 599 |
<table class="uwp-profile-extra-table form-table"> |
| 600 |
<?php |
| 601 |
foreach ($fields as $field) { |
| 602 |
|
| 603 |
// Icon |
| 604 |
if ($field->field_icon) { |
| 605 |
$icon = '<i class="uwp_field_icon '.$field->field_icon.'"></i>'; |
| 606 |
} else { |
| 607 |
$icon = ''; |
| 608 |
} |
| 609 |
|
| 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> |
| 629 |
</div> |
| 630 |
<?php |
| 631 |
} |
| 632 |
$output = ob_get_contents(); |
| 633 |
ob_end_clean(); |
| 634 |
return trim($output); |
| 635 |
} |
| 636 |
|
| 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 |
} |
| 650 |
|
| 651 |
return $classes; |
| 652 |
} |
| 653 |
} |