| 1 |
<?php |
| 2 |
/* |
| 3 |
wp_update_user only attempts to clear and reset cookies if it's updating the password. |
| 4 |
The php function setcookie(), used in both the cookie-clearing and cookie-resetting functions, |
| 5 |
adds to the page headers and therefore must be called within the first php tag on the page, |
| 6 |
and before the WordPress get_header() function. Since wp_update_user needs this, it must be at the beginning of the page as well. |
| 7 |
*/ |
| 8 |
/* set action to login user after password changed in edit profile */ |
| 9 |
add_action( 'init', 'wppb_autologin_after_password_changed' ); |
| 10 |
function wppb_autologin_after_password_changed(){ |
| 11 |
if( isset( $_POST['action'] ) && $_POST['action'] == 'edit_profile' ){ |
| 12 |
if( isset( $_POST['passw1'] ) && !empty( $_POST['passw1'] ) && !empty( $_POST['form_name'] ) ){ |
| 13 |
|
| 14 |
/* all the error checking filters are defined in each field file so we need them here */ |
| 15 |
if ( file_exists ( WPPB_PLUGIN_DIR.'/front-end/default-fields/default-fields.php' ) ) |
| 16 |
require_once( WPPB_PLUGIN_DIR.'/front-end/default-fields/default-fields.php' ); |
| 17 |
if ( file_exists ( WPPB_PLUGIN_DIR.'/front-end/extra-fields/extra-fields.php' ) ) |
| 18 |
require_once( WPPB_PLUGIN_DIR.'/front-end/extra-fields/extra-fields.php' ); |
| 19 |
|
| 20 |
/* we get the form_name through $_POST so we can apply correctly the filter so we generate the correct fields in the current form */ |
| 21 |
$form_fields = apply_filters( 'wppb_change_form_fields', get_option( 'wppb_manage_fields' ), array( 'form_type'=> 'edit_profile', 'form_fields' => array(), 'form_name' => sanitize_text_field( $_POST['form_name'] ), 'role' => '', 'ID' => Profile_Builder_Form_Creator::wppb_get_form_id_from_form_name( sanitize_text_field( $_POST['form_name'] ), 'edit_profile' ), 'context' => 'edit_profile_auto_login_after_password_change' ) ); |
| 22 |
if( !empty( $form_fields ) ){ |
| 23 |
|
| 24 |
/* check for errors in the form through the filters */ |
| 25 |
$output_field_errors = array(); |
| 26 |
foreach( $form_fields as $field ){ |
| 27 |
$error_for_field = apply_filters( 'wppb_check_form_field_'.Wordpress_Creation_Kit_PB::wck_generate_slug( $field['field'] ), '', $field, $_POST, 'edit_profile' ); |
| 28 |
if( !empty( $error_for_field ) ) |
| 29 |
$output_field_errors[$field['id']] = '<span class="wppb-form-error">' . $error_for_field . '</span>'; |
| 30 |
} |
| 31 |
|
| 32 |
/* if we have no errors change the password */ |
| 33 |
if( empty( $output_field_errors ) ) { |
| 34 |
|
| 35 |
$user_id = get_current_user_id(); |
| 36 |
if( ( !is_multisite() && current_user_can( 'edit_users' ) ) || ( is_multisite() && current_user_can( 'manage_network' ) ) ) { |
| 37 |
if( isset( $_GET['edit_user'] ) && ! empty( $_GET['edit_user'] ) ){ |
| 38 |
$user_id = absint( $_GET['edit_user'] ); |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
if( !isset( $_GET['edit_user'] ) ) { |
| 43 |
wp_clear_auth_cookie(); |
| 44 |
/* set the new password for the user */ |
| 45 |
wp_set_password($_POST['passw1'], $user_id); |
| 46 |
// Here we calculate the expiration length of the current auth cookie and compare it to the default expiration. |
| 47 |
// If it's greater than this, then we know the user checked 'Remember Me' when they logged in. |
| 48 |
$logged_in_cookie = wp_parse_auth_cookie('', 'logged_in'); |
| 49 |
/** This filter is documented in wp-includes/pluggable.php */ |
| 50 |
$default_cookie_life = apply_filters('auth_cookie_expiration', (2 * DAY_IN_SECONDS), $user_id, false); |
| 51 |
$remember = (($logged_in_cookie['expiration'] - time()) > $default_cookie_life); |
| 52 |
|
| 53 |
wp_set_auth_cookie($user_id, $remember); |
| 54 |
} |
| 55 |
else{ |
| 56 |
wp_set_password($_POST['passw1'], $user_id); |
| 57 |
} |
| 58 |
} |
| 59 |
} |
| 60 |
} |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
function wppb_front_end_profile_info( $atts ){ |
| 66 |
// get value set in the shortcode as parameter, still need to default to something else than empty string |
| 67 |
extract( shortcode_atts( array( 'form_name' => 'unspecified', 'redirect_url' => '', 'redirect_priority' => 'normal' ), $atts, 'wppb-edit-profile' ) ); |
| 68 |
|
| 69 |
global ${$form_name}; |
| 70 |
|
| 71 |
$$form_name = new Profile_Builder_Form_Creator( array( 'form_type' => 'edit_profile', 'form_name' => $form_name, 'redirect_url' => $redirect_url, 'redirect_priority' => $redirect_priority ) ); |
| 72 |
|
| 73 |
return $$form_name; |
| 74 |
} |