';
}
}
}
if($type){
$uwp_notices[] = array($type => ob_get_contents());
}else{
$uwp_notices[] = ob_get_contents();
}
ob_end_clean();
}
/**
* Displays UsersWP notices in forms.
*
* @since 1.0.0
* @package userswp
*
* @param string $type Form type
*
* @return void
*/
public function display_notices($type) {
global $uwp_notices;
if (is_array($uwp_notices)) {
foreach ($uwp_notices as $notice) {
// If the notification is type specific then only output on that type
if(is_array($notice)){
foreach($notice as $key => $val){
if( $key == $type ){ echo $val; }
}
}else{
if (!empty($notice)) {
echo $notice;
}
}
}
}
if ($type == 'change') {
$user_id = get_current_user_id();
$password_nag = get_user_option('default_password_nag', $user_id);
if ($password_nag) {
$change_page = uwp_get_page_id('change_page', false);
$remove_nag_url = add_query_arg('uwp_remove_nag', 'yes', get_permalink($change_page));
if (isset($_GET['uwp_remove_nag']) && $_GET['uwp_remove_nag'] == 'yes') {
delete_user_meta( $user_id, 'default_password_nag' );
$message = sprintf(__('We have removed the system generated password warning for you. From this point forward you can continue to access our site as usual. To go to home page, click here.', 'userswp'), home_url('/'));
echo '
';
echo $message;
echo '
';
} else {
$message = sprintf(__('Warning: You seems like you are using a system generated password. Please change the password in this page. If this is not a problem for you, you can remove this warning by clicking here.', 'userswp'), $remove_nag_url);
echo '
';
echo $message;
echo '
';
}
}
}
}
/**
* Processes register form submission.
*
* @since 1.0.0
* @package userswp
*
* @param array $data Submitted $_POST data
* @param array $files Submitted $_FILES data
*
* @return bool|WP_Error|string
*/
public function process_register($data = array(), $files = array()) {
$errors = new WP_Error();
$file_obj = new UsersWP_Files();
if( ! isset( $data['uwp_register_nonce'] ) || ! wp_verify_nonce( $data['uwp_register_nonce'], 'uwp-register-nonce' ) ) {
return false;
}
if (!get_option('users_can_register')) {
$errors->add('register_disabled', __('ERROR: User registration is currently not allowed.', 'userswp'));
return $errors;
}
$reg_terms_page_id = uwp_get_option('register_terms_page', '');
$reg_terms_page_id = apply_filters('uwp_reg_terms_page_id', $reg_terms_page_id);
if (!empty($reg_terms_page_id)) {
if (!isset($data['agree_terms']) || $data['agree_terms'] != 'yes') {
$errors->add('accept_tos', __('ERROR: You must accept our terms and conditions.', 'userswp'));
return $errors;
}
}
do_action('uwp_before_validate', 'register');
$result = uwp_validate_fields($data, 'register');
$result = apply_filters('uwp_validate_result', $result, 'register', $data);
if (is_wp_error($result)) {
return $result;
}
$uploads_result = $file_obj->uwp_validate_uploads($files, 'register');
if (is_wp_error($uploads_result)) {
return $uploads_result;
}
do_action('uwp_after_validate', 'register');
$result = array_merge( $result, $uploads_result );
$error_code = $errors->get_error_code();
if (!empty($error_code)) {
return $errors;
}
if (isset($result['password']) && !empty($result['password'])) {
$password = $result['password'];
$generated_password = false;
} else {
$password = wp_generate_password();
$this->generated_password = $password;
$generated_password = true;
}
$first_name = "";
if (isset($result['uwp_account_first_name']) && !empty($result['uwp_account_first_name'])) {
$first_name = $result['uwp_account_first_name'];
}
$last_name = "";
if (isset($result['uwp_account_last_name']) && !empty($result['uwp_account_last_name'])) {
$last_name = $result['uwp_account_last_name'];
}
if (isset($result['uwp_account_display_name']) && !empty($result['uwp_account_display_name'])) {
$display_name = $result['uwp_account_display_name'];
} else {
if (!empty($first_name) || !empty($last_name)) {
$display_name = $first_name . ' ' . $last_name;
} else {
$display_name = $result['uwp_account_username'];
}
}
$description = "";
if (isset($result['uwp_account_bio']) && !empty($result['uwp_account_bio'])) {
$description = $result['uwp_account_bio'];
}
$args = array(
'user_login' => $result['uwp_account_username'],
'user_email' => $result['uwp_account_email'],
'user_pass' => $password,
'display_name' => $display_name,
'first_name' => $first_name,
'last_name' => $last_name,
'description' => $description
);
$user_id = wp_insert_user( $args );
if (!$user_id) {
$errors->add('registerfail', sprintf(__('Error: Something went wrong.', 'userswp'), get_option('admin_email')));
return $errors;
}
$result = apply_filters('uwp_before_extra_fields_save', $result, 'register', $user_id);
$save_result = $this->uwp_save_user_extra_fields($user_id, $result, 'register');
$save_result = apply_filters('uwp_after_extra_fields_save', $save_result, $result, 'register', $user_id);
if (is_wp_error($save_result)) {
return $save_result;
}
if (!$save_result) {
$errors->add('something_wrong', __('Error: Something went wrong. Please contact site admin.', 'userswp'));
}
$error_code = $errors->get_error_code();
if (!empty($error_code)) {
return $errors;
}
do_action('uwp_after_custom_fields_save', 'register', $data, $result, $user_id);
$reg_action = uwp_get_option('uwp_registration_action', false);
if ($reg_action == 'require_email_activation' && !$generated_password) {
$email = new UsersWP_Mails();
$send_result = $email->send( 'activate', $user_id );
if (!$send_result) {
$errors->add('something_wrong', __('Error: Something went wrong when sending email. Please contact site admin.', 'userswp'));
}
} else {
$email = new UsersWP_Mails();
$send_result = $email->send( 'register', $user_id );
if (!$send_result) {
$errors->add('something_wrong', __('Error: Something went wrong when sending email. Please contact site admin.', 'userswp'));
}
}
if ($reg_action != 'require_admin_review') {
$register_admin_notify = uwp_get_option('register_admin_notify', '');
if ($register_admin_notify == '1') {
$admin_register_send_result = $email->send_admin_email('register_admin', $user_id);
if (is_wp_error($admin_register_send_result)) {
return $admin_register_send_result;
}
}
}
$error_code = $errors->get_error_code();
if (!empty($error_code)) {
return $errors;
}
if ($reg_action == 'auto_approve_login') {
$res = wp_signon(
array(
'user_login' => $result['uwp_account_username'],
'user_password' => $password,
'remember' => false
)
);
if (is_wp_error($res)) {
$errors->add('invalid_userorpass', __('Error: Invalid username or Password.', 'userswp'));
return $errors;
} else {
$reg_redirect_page_id = uwp_get_option('register_redirect_to', '');
if(isset( $_REQUEST['redirect_to'] )) {
$reg_redirect_to = esc_url($_REQUEST['redirect_to']);
} elseif (empty($reg_redirect_page_id)) {
$reg_redirect_to = home_url('/');
} else {
$reg_redirect_to = get_permalink($reg_redirect_page_id);
}
$redirect = apply_filters('uwp_register_redirect', $reg_redirect_to);
wp_redirect($redirect);
exit();
}
} else {
if ($reg_action == 'require_email_activation') {
global $wp;
$resend_link = uwp_current_page_url();
$resend_link = add_query_arg(
array(
'user_id' => $user_id,
'action' => 'uwp_resend',
'_nonce' => wp_create_nonce('uwp_resend'),
),
$resend_link
);
return sprintf(__('An email has been sent to your registered email address. Please click the activation link to proceed. Resend.', 'userswp'), $resend_link);
} elseif ($reg_action == 'require_admin_review' && defined('UWP_MOD_VERSION')) {
update_user_meta( $user_id, 'uwp_mod', '1' );
$email = new UsersWP_Mails();
$send_result = $email->send( 'mod_pending', $user_id );
$user_data = get_user_by('id', $user_id);
$send_result = apply_filters('uwp_forms_check_for_send_mail_errors', $send_result, $user_data, $errors);
if (is_wp_error($send_result)) {
return $send_result;
}
$admin_send_result = $email->send_admin_email('mod_admin', $user_id);
if (is_wp_error($admin_send_result)) {
return $admin_send_result;
}
return __('Your account is under moderation. We will email you once its approved.', 'userswp');
} else {
$login_page_url = wp_login_url();
if ($generated_password) {
return sprintf(__('Account registered successfully. A password has been generated and mailed to your registered Email ID. Please login here.', 'userswp'), $login_page_url);
} else {
return sprintf(__('Account registered successfully. Please login here', 'userswp'), $login_page_url);
}
}
}
}
/**
* Processes login form submission.
*
* @since 1.0.0
* @package userswp
*
* @param array $data Submitted $_POST data
*
* @return bool|WP_Error|string
*/
public function process_login($data) {
$errors = new WP_Error();
if( ! isset( $data['uwp_login_nonce'] ) || ! wp_verify_nonce( $data['uwp_login_nonce'], 'uwp-login-nonce' ) ) {
return false;
}
do_action('uwp_before_validate', 'login');
$result = uwp_validate_fields($data, 'login');
$result = apply_filters('uwp_validate_result', $result, 'login', $data);
if (is_wp_error($result)) {
return $result;
}
do_action('uwp_after_validate', 'login');
if (isset($data['remember_me']) && $data['remember_me'] == 'forever') {
$remember_me = true;
} else {
$remember_me = false;
}
remove_action( 'authenticate', 'gglcptch_login_check', 21, 1 );
$res = wp_signon(
array(
'user_login' => $result['uwp_login_username'],
'user_password' => $result['password'],
'remember' => $remember_me
)
);
add_action( 'authenticate', 'gglcptch_login_check', 21, 1 );
if (is_wp_error($res)) {
$errors->add('invalid_userorpass', __('Error: Invalid username or Password.', 'userswp'));
return $errors;
} else {
$redirect_page_id = uwp_get_option('login_redirect_to', -1);
if (isset($_REQUEST['redirect_to']) && !empty($_REQUEST['redirect_to'])) {
$redirect_to = esc_url($_REQUEST['redirect_to']);
} elseif (isset($data['redirect_to']) && !empty($data['redirect_to'])) {
$redirect_to = esc_url($data['redirect_to']);
} elseif (isset($redirect_page_id) && (int)$redirect_page_id > 0) {
$redirect_to = get_permalink($redirect_page_id);
} else {
if ( current_user_can('manage_options') ) {
$redirect_to = admin_url();
} else {
$redirect_to = home_url('/');
}
}
$redirect_to = apply_filters('uwp_login_redirect', $redirect_to);
wp_redirect($redirect_to);
exit();
}
}
/**
* Processes forgot password form submission.
*
* @since 1.0.0
* @package userswp
*
* @param array $data Submitted $_POST data
*
* @return bool|WP_Error|string
*/
public function process_forgot($data) {
$errors = new WP_Error();
if( ! isset( $data['uwp_forgot_nonce'] ) || ! wp_verify_nonce( $data['uwp_forgot_nonce'], 'uwp-forgot-nonce' ) ) {
return false;
}
do_action('uwp_before_validate', 'forgot');
$result = uwp_validate_fields($data, 'forgot');
$result = apply_filters('uwp_validate_result', $result, 'forgot', $data);
if (is_wp_error($result)) {
return $result;
}
do_action('uwp_after_validate', 'forgot');
$user_data = get_user_by('email', $data['uwp_forgot_email']);
// make sure user account is active before account reset
$mod_value = get_user_meta( $user_data->ID, 'uwp_mod', true );
if ($mod_value == 'email_unconfirmed') {
$errors->add('activate_account', __('Error: Your account is not activated yet. Please activate your account first.', 'userswp'));
}
$error_code = $errors->get_error_code();
if (!empty($error_code)) {
return $errors;
}
$email = new UsersWP_Mails();
$send_result = $email->send( 'forgot', $user_data->ID );
$send_result = apply_filters('uwp_forms_check_for_send_mail_errors', $send_result, $user_data, $errors);
if (is_wp_error($send_result)) {
return $send_result;
}
return true;
}
/**
* Processes change password form submission.
*
* @since 1.0.0
* @package userswp
*
* @param array $data Submitted $_POST data
*
* @return bool|WP_Error|string
*/
public function process_change($data) {
$errors = new WP_Error();
if( ! isset( $data['uwp_change_nonce'] ) || ! wp_verify_nonce( $data['uwp_change_nonce'], 'uwp-change-nonce' ) ) {
return false;
}
do_action('uwp_before_validate', 'change');
$result = uwp_validate_fields($data, 'change');
$result = apply_filters('uwp_validate_result', $result, 'change', $data);
if (is_wp_error($result)) {
return $result;
}
do_action('uwp_after_validate', 'change');
$user_data = get_user_by('id', get_current_user_id());
if (is_wp_error($user_data)) {
return $user_data;
}
$email = new UsersWP_Mails();
$send_result = $email->send( 'change', $user_data->ID );
$send_result = apply_filters('uwp_forms_check_for_send_mail_errors', $send_result, $user_data, $errors);
if (is_wp_error($send_result)) {
return $send_result;
}
wp_set_password( $data['uwp_change_password'], $user_data->ID );
wp_set_auth_cookie( $user_data->ID, false);
return true;
}
/**
* Processes reset password form submission.
*
* @since 1.0.0
* @package userswp
*
* @param array $data Submitted $_POST data
*
* @return bool|WP_Error|string
*/
public function process_reset($data) {
$errors = new WP_Error();
if( ! isset( $data['uwp_reset_nonce'] ) || ! wp_verify_nonce( $data['uwp_reset_nonce'], 'uwp-reset-nonce' ) ) {
return false;
}
do_action('uwp_before_validate', 'reset');
$result = uwp_validate_fields($data, 'reset');
$result = apply_filters('uwp_validate_result', $result, 'reset', $data);
if (is_wp_error($result)) {
return $result;
}
do_action('uwp_after_validate', 'reset');
$login = $data['uwp_reset_username'];
$key = $data['uwp_reset_key'];
$user_data = check_password_reset_key( $key, $login );
if (is_wp_error($user_data)) {
return $user_data;
}
$email = new UsersWP_Mails();
$send_result = $email->send( 'reset', $user_data->ID );
$send_result = apply_filters('uwp_forms_check_for_send_mail_errors', $send_result, $user_data, $errors);
if (is_wp_error($send_result)) {
return $send_result;
}
wp_set_password( $data['uwp_reset_password'], $user_data->ID );
return true;
}
/**
* Modifies the mail subject based on the admin notification type.
*
* @since 1.0.0
* @package userswp
* @subpackage userswp/includes
* @param string $subject Unmodified mail subject.
* @param string $type Notification type.
* @return string Modified mail subject.
*/
public function init_mail_subject($subject, $type) {
switch ($type) {
case "register":
$subject = uwp_get_option('registration_success_email_subject', '');
break;
case "activate":
$subject = uwp_get_option('registration_activate_email_subject', '');
break;
case "forgot":
$subject = uwp_get_option('forgot_password_email_subject', '');
break;
case "reset":
$subject = uwp_get_option('reset_password_email_subject', '');
break;
case "change":
$subject = uwp_get_option('change_password_email_subject', '');
break;
case "account":
$subject = uwp_get_option('account_update_email_subject', '');
break;
}
return $subject;
}
/**
* Modifies the mail content based on the admin notification type.
*
* @since 1.0.0
* @package userswp
* @subpackage userswp/includes
* @param string $content Unmodified mail content.
* @param string $type Notification type.
* @return string Modified mail content.
*/
public function init_mail_content($content, $type) {
switch ($type) {
case "register":
$content = uwp_get_option('registration_success_email_content', '');
break;
case "activate":
$content = uwp_get_option('registration_activate_email_content', '');
break;
case "forgot":
$content = uwp_get_option('forgot_password_email_content', '');
break;
case "reset":
$content = uwp_get_option('reset_password_email_content', '');
break;
case "change":
$content = uwp_get_option('change_password_email_content', '');
break;
case "account":
$content = uwp_get_option('account_update_email_content', '');
break;
}
return $content;
}
/**
* Modifies the mail extras based on the notification type.
*
* @since 1.0.0
* @package userswp
* @subpackage userswp/includes
* @param string $extras Unmodified mail extras.
* @param string $type Notification type.
* @return string Modified mail extras.
*/
public function init_mail_extras($extras, $type, $user_id) {
switch ($type) {
case "activate":
$extras = $this->generate_activate_message($user_id);
break;
case "register":
$extras = $this->generate_register_message($user_id);
break;
case "forgot":
$extras = $this->generate_forgot_message($user_id);
}
return $extras;
}
/**
* Modifies the admin mail subject based on the admin notification type.
*
* @since 1.0.0
* @package userswp
* @subpackage userswp/includes
* @param string $subject Unmodified admin mail subject.
* @param string $type Admin notification type.
* @return string Modified admin mail subject.
*/
public function init_admin_mail_subject($subject, $type) {
switch ($type) {
case "register_admin":
$subject = uwp_get_option('registration_success_email_subject_admin', '');
break;
}
return $subject;
}
/**
* Modifies the admin mail content based on the admin notification type.
*
* @since 1.0.0
* @package userswp
* @subpackage userswp/includes
* @param string $content Unmodified admin mail content.
* @param string $type Admin notification type.
* @return string Modified admin mail content.
*/
public function init_admin_mail_content($content, $type) {
switch ($type) {
case "register_admin":
$content = uwp_get_option('registration_success_email_content_admin', '');
break;
}
return $content;
}
/**
* Modifies the admin mail extras based on the notification type.
*
* @since 1.0.0
* @package userswp
* @subpackage userswp/includes
* @param string $extras Unmodified mail extras.
* @param string $type Notification type.
* @return string Modified mail extras.
*/
public function init_admin_mail_extras($extras, $type, $user_id) {
switch ($type) {
case "register_admin":
$user_data = get_userdata($user_id);
$extras = __('
htmlvar_name}")){
$html = apply_filters("uwp_form_input_html_time_{$field->htmlvar_name}",$html, $field, $value, $form_type);
}
// If no html then we run the standard output.
if(empty($html)) {
ob_start(); // Start buffering;
if ($value != '')
$value = date('H:i', strtotime($value));
?>
htmlvar_name}")){
$html = apply_filters("uwp_form_input_html_select_{$field->htmlvar_name}", $html, $field, $value, $form_type);
}
// Check if there is a field type specific filter.
if(has_filter("uwp_form_input_html_select_{$field->field_type_key}")){
$html = apply_filters("uwp_form_input_html_select_{$field->field_type_key}", $html, $field, $value, $form_type);
}
// If no html then we run the standard output.
if(empty($html)) {
ob_start(); // Start buffering;
?>
htmlvar_name}")){
$html = apply_filters("uwp_form_input_html_file_{$field->htmlvar_name}", $html, $field, $value, $form_type);
}
// If no html then we run the standard output.
if(empty($html)) {
ob_start(); // Start buffering;
?>
htmlvar_name}")){
$html = apply_filters("uwp_form_input_html_checkbox_{$field->htmlvar_name}", $html, $field, $value, $form_type);
}
// If no html then we run the standard output.
if(empty($html)) {
ob_start(); // Start buffering;
$site_title = uwp_get_form_label($field);
?>
htmlvar_name}")){
$html = apply_filters("uwp_form_input_html_radio_{$field->htmlvar_name}", $html, $field, $value, $form_type);
}
// If no html then we run the standard output.
if(empty($html)) {
ob_start(); // Start buffering;
?>
htmlvar_name}")){
$html = apply_filters("uwp_form_input_textarea_{$field->htmlvar_name}", $html, $field, $value, $form_type);
}
// If no html then we run the standard output.
if(empty($html)) {
ob_start(); // Start buffering;
?>
htmlvar_name}")){
$html = apply_filters("uwp_form_input_fieldset_{$field->htmlvar_name}",$html, $field, $value, $form_type);
}
// If no html then we run the standard output.
if(empty($html)) {
ob_start(); // Start buffering;
?>
htmlvar_name}")){
$html = apply_filters("uwp_form_input_url_{$field->htmlvar_name}",$html, $field, $value, $form_type);
}
// If no html then we run the standard output.
if(empty($html)) {
ob_start(); // Start buffering;
?>
htmlvar_name}")){
$html = apply_filters("uwp_form_input_email_{$field->htmlvar_name}",$html, $field, $value, $form_type);
}
// If no html then we run the standard output.
if(empty($html)) {
ob_start(); // Start buffering;
?>
htmlvar_name}_after")){
$html = apply_filters("uwp_form_input_email_{$field->htmlvar_name}_after",$html, $field, $value, $form_type);
}
return $html;
}
/**
* Form field template for password field type.
*
* @since 1.0.0
* @package userswp
*
* @param string $html Form field html
* @param object $field Field info.
* @param string $value Form field default value.
* @param string $form_type Form type
*
* @return string Modified form field html.
*/
public function uwp_form_input_password($html, $field, $value, $form_type){
// Check if there is a custom field specific filter.
if(has_filter("uwp_form_input_password_{$field->htmlvar_name}")){
$html = apply_filters("uwp_form_input_password_{$field->htmlvar_name}",$html, $field, $value, $form_type);
}
// If no html then we run the standard output.
if(empty($html)) {
ob_start(); // Start buffering;
?>