-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- New module : Delete account. - New helper for HTML of error messages. - Hook for Email validation rule.
- Loading branch information
Showing
11 changed files
with
302 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
defined('ABSPATH') || die; | ||
|
||
function wpuextranet_get_html_errors($errors = array(), $args = array()) { | ||
/* Do not */ | ||
if (empty($errors)) { | ||
return ''; | ||
} | ||
$defaults = array( | ||
'type' => 'error', | ||
'form_id' => '' | ||
); | ||
$args = array_merge($defaults, $args); | ||
$classname = 'extranet-message extranet-message--' . $args['type'] . ' form-' . $args['form_id'] . '-' . $args['type'] . ''; | ||
$html_return = ''; | ||
/* Display errors */ | ||
if (count($errors) > 1) { | ||
$html_return .= '<ul class="' . $classname . '">'; | ||
foreach ($errors as $error) { | ||
$html_return .= '<li>'; | ||
if ($args['type'] == 'error') { | ||
$html_return .= '<strong class="error">' . __('Error:', 'wpu_extranet') . '</strong> '; | ||
} | ||
$html_return .= $error; | ||
$html_return .= '</li>'; | ||
} | ||
$html_return .= '</ul>'; | ||
} else { | ||
$html_return .= '<p class="' . $classname . '">'; | ||
$html_return .= implode('<br />', $errors); | ||
$html_return .= '</p>'; | ||
} | ||
|
||
return $html_return; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
<?php | ||
defined('ABSPATH') || die; | ||
|
||
/* ---------------------------------------------------------- | ||
Delete account | ||
---------------------------------------------------------- */ | ||
|
||
/* Test | ||
-------------------------- */ | ||
|
||
function wpu_extranet_user_can_delete_account($errors, $user_id) { | ||
if (current_user_can('edit_users', $user_id)) { | ||
$errors[] = __('You can not delete this type of account.', 'wpu_extranet'); | ||
} | ||
|
||
$errors = apply_filters('wpu_extranet_user_can_delete_account', $errors, $user_id); | ||
|
||
return $errors; | ||
} | ||
|
||
/* Form action | ||
-------------------------- */ | ||
|
||
function wpu_extranet_delete_account__action() { | ||
if (empty($_POST)) { | ||
return ''; | ||
} | ||
if (!is_user_logged_in()) { | ||
return ''; | ||
} | ||
if (!isset($_POST['current_password'])) { | ||
return ''; | ||
} | ||
|
||
if (!isset($_POST['wpuextranet_delete_account']) || !wp_verify_nonce($_POST['wpuextranet_delete_account'], 'wpuextranet_delete_account_action')) { | ||
return ''; | ||
} | ||
|
||
$password = trim($_POST['current_password']); | ||
|
||
$user_id = get_current_user_id(); | ||
$current_user = get_user_by('id', $user_id); | ||
if (!$current_user) { | ||
return; | ||
} | ||
|
||
/* Check errors */ | ||
$errors = array(); | ||
|
||
/* Empty fields */ | ||
if (empty($password)) { | ||
$errors[] = __('All fields are required.', 'wpu_extranet'); | ||
} | ||
|
||
/* Invalid password */ | ||
if (!wp_check_password($password, $current_user->data->user_pass, $current_user->ID)) { | ||
$errors[] = __('Invalid password.', 'wpu_extranet'); | ||
} | ||
|
||
/* User can edit other users : prevent deletion */ | ||
$errors = wpu_extranet_user_can_delete_account($errors, $user_id); | ||
|
||
if (empty($errors)) { | ||
/* Delete user and redirect to home */ | ||
require_once ABSPATH . 'wp-admin/includes/user.php'; | ||
wp_delete_user($user_id); | ||
wp_redirect(home_url() . '#'); | ||
die; | ||
} | ||
|
||
/* Display errors */ | ||
return wpuextranet_get_html_errors($errors, array( | ||
'form_id' => 'delete_account', | ||
'type' => 'error' | ||
)); | ||
|
||
} | ||
|
||
/* HTML Form | ||
-------------------------- */ | ||
|
||
function wpu_extranet_delete_account__form($args = array()) { | ||
if (!is_array($args)) { | ||
$args = array(); | ||
} | ||
if (!isset($args['before_fields'])) { | ||
$args['before_fields'] = ''; | ||
} | ||
$html = ''; | ||
|
||
$user_id = get_current_user_id(); | ||
$userdata = get_userdata($user_id); | ||
|
||
$errors = wpu_extranet_user_can_delete_account(array(), $user_id); | ||
$user_can_delete_account = empty($errors); | ||
if (!empty($errors)) { | ||
$args['before_fields'] .= wpuextranet_get_html_errors($errors, array( | ||
'form_id' => 'delete_account', | ||
'type' => 'error' | ||
)); | ||
} | ||
|
||
$settings = wpu_extranet_get_skin_settings(); | ||
$html .= '<div class="' . $settings['form_wrapper_classname'] . ' form-delete_account-wrapper">'; | ||
$html .= '<h3>' . __('Delete your account', 'wpu_extranet') . '</h3>'; | ||
$html .= '<form name="delete_accountform" id="delete_accountform" action="' . get_permalink() . '#delete_accountform" method="post">'; | ||
$html .= $args['before_fields']; | ||
if ($user_can_delete_account) { | ||
$html .= '<ul class="' . $settings['form_items_classname'] . '">'; | ||
$html .= wpu_extranet__display_field('current_password', array( | ||
'type' => 'password', | ||
'attributes' => 'minlength="6" autocomplete="off" required="required"', | ||
'label' => __('Enter your current password', 'wpu_extranet') | ||
)); | ||
$html .= '<li class="' . $settings['form_box_submit_classname'] . '">'; | ||
$html .= wp_nonce_field('wpuextranet_delete_account_action', 'wpuextranet_delete_account', true, false); | ||
$html .= '<button class="' . $settings['form_submit_button_classname'] . '" type="submit"><span>' . __('Delete your account', 'wpu_extranet') . '</span></button>'; | ||
} | ||
$html .= '</li>'; | ||
$html .= '</ul>'; | ||
$html .= '</form>'; | ||
$html .= '</div>'; | ||
return $html; | ||
} | ||
|
||
/* ---------------------------------------------------------- | ||
Example code | ||
---------------------------------------------------------- */ | ||
|
||
/* | ||
$html_return_delete_account = wpu_extranet_delete_account__action(); | ||
get_header(); | ||
echo '<h1>' . get_the_title() . '</h1>'; | ||
echo wpu_extranet_delete_account__form(array( | ||
'before_fields' => $html_return_delete_account | ||
)); | ||
get_footer(); | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
<?php | ||
return ['domain'=>NULL,'plural-forms'=>NULL,'messages'=>['All fields are required.'=>'Tous les champs sont requis.','Invalid email.'=>'E-mail invalide.','New email is the same as the current email.'=>'Le nouvel e-mail est le même que l’e-mail actuel.','Emails do not match.'=>'Les e-mails ne sont pas identiques.','Email is already in use.'=>'L’e-mail est déjà utilisé.','Email successfully updated!'=>'L’e-mail a été mis à jour avec succès !','Change email'=>'Changer d\'adresse e-mail','Your current email'=>'Votre adresse e-mail actuelle','New email'=>'Nouvel e-mail','Confirm new email'=>'Confirmez votre nouvel e-mail','Current password is incorrect.'=>'Le mot de passe actuel est incorrect.','Passwords do not match.'=>'Les mots de passe ne correspondent pas.','Password is too short, minimum of 6 characters.'=>'Le mot de passe est trop court, minimum de 6 caractères.','Password successfully changed!'=>'Mot de passe changé avec succès !','Error:'=>'Erreur :','Change password'=>'Changer le mot de passe','Enter your current password'=>'Veuillez saisir votre mot de passe actuel','New password'=>'Nouveau mot de passe','Confirm new password'=>'Confirmer le nouveau mot de passe','Profile successfully updated!'=>'Profil mis à jour avec succès!','Infos'=>'Infos','The current avatar is generated by %s.'=>'L’avatar actuel est généré par %s.','Delete this avatar'=>'Supprimer cet avatar','Avatar'=>'Avatar','Username'=>'Nom d\'utilisateur','Email'=>'E-mail','Edit my infos'=>'Modifier mes infos','Check your email for the confirmation link.'=>'Vérifiez vos courriels pour y trouver le lien de confirmation.','Your account could not be found.'=>'Votre compte est introuvable.','Reset password failed.'=>'Échec de la réinitialisation du mot de passe.','Username or Email Address'=>'Identifiant ou adresse email','Get New Password'=>'Obtenir un nouveau mot de passe','Registration confirmation will be emailed to you.'=>'La confirmation d’inscription vous sera envoyée par courriel.','This username already exists.'=>'Ce nom d’utilisateur existe déjà.','This email is already registered.'=>'Cet e-mail est déjà enregistré.','This username contains invalid characters.'=>'Ce nom d’utilisateur contient des caractères non valides.','Registration failed.'=>'Échec de l’inscription.','Password'=>'Mot de passe','Register'=>'S\'inscrire','Log out'=>'Se déconnecter','First name'=>'Prénom','Last name'=>'Nom'],'language'=>'fr_FR','x-generator'=>'Poedit 3.4.4']; | ||
return ['domain'=>NULL,'plural-forms'=>NULL,'messages'=>['Error:'=>'Erreur :','All fields are required.'=>'Tous les champs sont requis.','Invalid email.'=>'E-mail invalide.','New email is the same as the current email.'=>'Le nouvel e-mail est le même que l’e-mail actuel.','Emails do not match.'=>'Les e-mails ne sont pas identiques.','Email is already in use.'=>'L’e-mail est déjà utilisé.','Email successfully updated!'=>'L’e-mail a été mis à jour avec succès !','Change email'=>'Changer d\'adresse e-mail','Your current email'=>'Votre adresse e-mail actuelle','New email'=>'Nouvel e-mail','Confirm new email'=>'Confirmez votre nouvel e-mail','Current password is incorrect.'=>'Le mot de passe actuel est incorrect.','Passwords do not match.'=>'Les mots de passe ne correspondent pas.','Password is too short, minimum of 6 characters.'=>'Le mot de passe est trop court, minimum de 6 caractères.','Password successfully changed!'=>'Mot de passe changé avec succès !','Change password'=>'Changer le mot de passe','Enter your current password'=>'Veuillez saisir votre mot de passe actuel','New password'=>'Nouveau mot de passe','Confirm new password'=>'Confirmer le nouveau mot de passe','You can not delete this type of account.'=>'Vous ne pouvez pas supprimer ce type de compte.','Invalid password.'=>'Mot de passe invalide.','Delete your account'=>'Supprimer votre compte','Profile successfully updated!'=>'Profil mis à jour avec succès!','Infos'=>'Infos','The current avatar is generated by %s.'=>'L’avatar actuel est généré par %s.','Delete this avatar'=>'Supprimer cet avatar','Avatar'=>'Avatar','Username'=>'Nom d\'utilisateur','Email'=>'E-mail','Edit my infos'=>'Modifier mes infos','Check your email for the confirmation link.'=>'Vérifiez vos courriels pour y trouver le lien de confirmation.','Your account could not be found.'=>'Votre compte est introuvable.','Reset password failed.'=>'Échec de la réinitialisation du mot de passe.','Username or Email Address'=>'Identifiant ou adresse email','Get New Password'=>'Obtenir un nouveau mot de passe','Registration confirmation will be emailed to you.'=>'La confirmation d’inscription vous sera envoyée par courriel.','This username already exists.'=>'Ce nom d’utilisateur existe déjà.','This email is already registered.'=>'Cet e-mail est déjà enregistré.','This username contains invalid characters.'=>'Ce nom d’utilisateur contient des caractères non valides.','Registration failed.'=>'Échec de l’inscription.','Password'=>'Mot de passe','Register'=>'S\'inscrire','Log out'=>'Se déconnecter','First name'=>'Prénom','Last name'=>'Nom','Simple toolbox to create an extranet or a customer account'=>'Boîte à outils simple pour créer un extranet ou un compte client'],'language'=>'fr_FR','x-generator'=>'Poedit 3.4.4']; |
Binary file not shown.
Oops, something went wrong.