Created
November 16, 2015 17:59
-
-
Save cartpauj/384d3582f8eb301cc049 to your computer and use it in GitHub Desktop.
Adds display name settings to MemberPress
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
<?php | |
/* | |
Plugin Name: MemberPress Display Name | |
Plugin URI: https://memberpress.com | |
Description: Adds a Display Name field to MemberPress signup and account pages | |
Version: 1.0 | |
Author: Caseproof, LLC | |
Author URI: http://caseproof.com/ | |
Copyright: 2004-2014, Caseproof, LLC | |
*/ | |
function mpdn_show_on_registration() { | |
?> | |
<div class="mp-form-row"> | |
<div class="mp-form-label"> | |
<label>Display Name Publically As:*<br/><small>Must be different than your username and email address</small></label> | |
</div> | |
<input type="text" name="mepr_user_display_name" id="mepr_user_display_name" class="mepr-form-input mepr-display-name" value="<?php echo (isset($_POST['mepr_user_display_name']) && !empty($_POST['mepr_user_display_name']))?stripslashes($_POST['mepr_user_display_name']):''; ?>" /> | |
</div> | |
<?php | |
} | |
add_action('mepr-after-password-fields', 'mpdn_show_on_registration', 9); | |
function mpdn_validate_registration($errors) { | |
$mepr_options = MeprOptions::fetch(); | |
//Ignore logged in users | |
if(MeprUtils::is_user_logged_in()) { return $errors; } | |
if(empty($_POST['mepr_user_display_name'])) { | |
$errors[] = "You must enter a Public Display Name"; | |
return $errors; | |
} | |
if($mepr_options->username_is_email) { | |
if(stripslashes($_POST['user_email']) == stripslashes($_POST['mepr_user_display_name'])) { | |
$errors[] = "Your Public Display Name must be different than your Email Address"; | |
} | |
} | |
else { | |
if(stripslashes($_POST['user_email']) == stripslashes($_POST['mepr_user_display_name'])) { | |
$errors[] = "Your Public Display Name must be different than your Email Address"; | |
} | |
if(stripslashes($_POST['user_login']) == stripslashes($_POST['mepr_user_display_name'])) { | |
$errors[] = "Your Public Display Name must be different than your Username"; | |
} | |
} | |
return $errors; | |
} | |
add_filter('mepr-validate-signup', 'mpdn_validate_registration'); | |
function mpdn_save_registration($txn) { | |
//If it's not set, let's bail - something's wrong or the user is already logged in | |
if(!isset($_POST['mepr_user_display_name'])) { return; } | |
$display_name = stripslashes($_POST['mepr_user_display_name']); | |
$user = new MeprUser($txn->user_id); | |
if(isset($user->ID) && (int)$user->ID > 0) { | |
$user->display_name = $display_name; | |
$user->store(); | |
//Set the nickname to the display name also, why not? | |
update_user_meta($user->ID, 'nickname', $display_name); | |
} | |
} | |
add_action('mepr-signup', 'mpdn_save_registration'); | |
function mpdn_show_on_account($user) { | |
?> | |
<div class="mp-form-row"> | |
<div class="mp-form-label"> | |
<label>Display Name Publically As:*<br/><small>Must be different than your username and email address</small></label> | |
</div> | |
<input type="text" name="mepr_user_display_name" id="mepr_user_display_name" class="mepr-form-input mepr-display-name" value="<?php echo $user->display_name; ?>" /> | |
</div> | |
<?php | |
} | |
add_action('mepr-account-home-fields', 'mpdn_show_on_account'); | |
function mpdn_validate_on_account($errors, $user) { | |
if(!isset($_POST['mepr_user_display_name']) || empty($_POST['mepr_user_display_name'])) { | |
$errors[] = "You must enter a Public Display Name"; | |
return $errors; | |
} | |
$display_name = stripslashes($_POST['mepr_user_display_name']); | |
$new_email = stripslashes($_POST['user_email']); | |
$old_email = $user->user_email; | |
$username = $user->user_login; | |
if($display_name == $new_email || $display_name == $old_email) { | |
$errors[] = "Your Public Display Name cannot be the same as your Email Address"; | |
} | |
if($display_name == $username) { | |
$errors[] = "Your Public Display Name cannot be the same as your Username"; | |
} | |
return $errors; | |
} | |
add_filter('mepr-validate-account', 'mpdn_validate_on_account', 11, 2); | |
function mpdn_save_account($user) { | |
$display_name = stripslashes($_POST['mepr_user_display_name']); | |
$user->display_name = $display_name; | |
$user->store(); | |
//Set the nickname to the display name also, why not? | |
update_user_meta($user->ID, 'nickname', $display_name); | |
} | |
add_action('mepr-save-account', 'mpdn_save_account'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, where I can add this php file? thankypu