2.5 )
add_action('admin_notices', 'version_warning');
}
function version_warning(){
echo "
".__('Register Plus is only compatible with WordPress v2.5 and up.')."
";
}
function AddPanel(){
add_options_page( 'Register Plus', 'Register Plus', 10, 'register-plus', array($this, 'RegPlusSettings') );
}
function DefaultSettings () {
$default = array(
'password' => '0',
'code' => '0',
'codepass' => array('0'),
'captcha' => '0',
'disclaimer' => '0',
'disclaimer_title' => 'Disclaimer',
'disclaimer_content' => '',
'disclaimer_agree' => 'Accept the Disclaimer',
'license' => '0',
'license_title' => 'License Agreement',
'license_content' => '',
'license_agree' => 'Accept the License Agreement',
'privacy' => '0',
'privacy_title' => 'Privacy Policy',
'privacy_content' => '',
'privacy_agree' => 'Accept the Privacy Policy',
'email_exists' => '0',
'firstname' => '0',
'lastname' => '0',
'website' => '0',
'aim' => '0',
'yahoo' => '0',
'jabber' => '0',
'about' => '0',
'profile_req' => array('0'),
'require_style' => 'border-color: red;',
'dash_widget' => '0',
'email_verify' => '0',
'email_delete_grace' => '7',
'html' => '0',
'adminhtml' => '0',
'from' => get_option('admin_email'),
'subject' => sprintf(__('[%s] Your username and password', 'regplus'), get_option('blogname')),
'custom_msg' => '0',
'msg' => " %blogname% Registration \r\n --------------------------- \r\n\r\n Here are your credentials: \r\n Username: %user_login% \r\n Password: %user_pass% \r\n Confirm Registration: %siteurl% \r\n\r\n Thank you for registering with %blogname%! \r\n",
'disable_admin' => '0',
'adminfrom' => get_option('admin_email'),
'adminsubject' => sprintf(__('[%s] New User Register', 'regplus'), get_option('blogname')),
'custom_adminmsg' => '0',
'adminmsg' => " New %blogname% Registration \r\n --------------------------- \r\n\r\n Username: %user_login% \r\n E-Mail: %user_email% \r\n",
'logo' => ''
);
# Get Previously Saved Items and put into new Settings
if( get_option("regplus_password") )
$default['password'] = get_option("regplus_password");
if( get_option("regplus_code") )
$default['code'] = get_option("regplus_code");
if( get_option("regplus_codepass") )
$default['codepass'] = get_option("regplus_codepass");
if( get_option("regplus_captcha") )
$default['captcha'] = get_option("regplus_captcha");
#Delete Previous Saved Items
delete_option('regplus_password');
delete_option('regplus_code');
delete_option('regplus_codepass');
delete_option('regplus_captcha');
#Set Default Settings
if( !get_option('register_plus') ){ #Set Defaults if no values exist
add_option( 'register_plus', $default );
}else{ #Set Defaults if new value does not exist
$regplus = get_option( 'register_plus' );
foreach( $default as $key => $val ){
if( !$regplus[$key] ){
$regplus[$key] = $val;
$new = true;
}
}
if( $new )
update_option( 'register_plus', $regplus );
}
}
function SaveSettings(){
check_admin_referer('regplus-update-options');
$update = get_option( 'register_plus' );
$update["password"] = $_POST['regplus_password'];
$update["code"] = $_POST['regplus_code'];
if( $_POST['regplus_code'] ) {
$update["codepass"] = $_POST['regplus_codepass'];
$update["code_req"] = $_POST['regplus_code_req'];
}
$update["captcha"] = $_POST['regplus_captcha'];
$update["disclaimer"] = $_POST['regplus_disclaimer'];
$update["disclaimer_title"] = $_POST['regplus_disclaimer_title'];
$update["disclaimer_content"] = $_POST['regplus_disclaimer_content'];
$update["disclaimer_agree"] = $_POST['regplus_disclaimer_agree'];
$update["license"] = $_POST['regplus_license'];
$update["license_title"] = $_POST['regplus_license_title'];
$update["license_content"] = $_POST['regplus_license_content'];
$update["license_agree"] = $_POST['regplus_license_agree'];
$update["privacy"] = $_POST['regplus_privacy'];
$update["privacy_title"] = $_POST['regplus_privacy_title'];
$update["privacy_content"] = $_POST['regplus_privacy_content'];
$update["privacy_agree"] = $_POST['regplus_privacy_agree'];
$update["email_exists"] = $_POST['regplus_email_exists'];
$update["firstname"] = $_POST['regplus_firstname'];
$update["lastname"] = $_POST['regplus_lastname'];
$update["website"] = $_POST['regplus_website'];
$update["aim"] = $_POST['regplus_aim'];
$update["yahoo"] = $_POST['regplus_yahoo'];
$update["jabber"] = $_POST['regplus_jabber'];
$update["about"] = $_POST['regplus_about'];
$update["profile_req"] = $_POST['regplus_profile_req'];
$update["require_style"] = $_POST['regplus_require_style'];
$update["dash_widget"] = $_POST['regplus_dash_widget'];
$update["email_verify"] = $_POST['regplus_email_verify'];
$update["email_verify_date"] = $_POST['regplus_email_verify_date'];
$update["email_delete_grace"] = $_POST['regplus_email_delete_grace'];
$update["reCAP_public_key"] = $_POST['regplus_reCAP_public_key'];
$update["reCAP_private_key"] = $_POST['regplus_reCAP_private_key'];
$update['html'] = $_POST['regplus_html'];
$update['from'] = $_POST['regplus_from'];
$update['subject'] = $_POST['regplus_subject'];
$update['custom_msg'] = $_POST['regplus_custom_msg'];
$update['msg'] = $_POST['regplus_msg'];
$update['disable_admin'] = $_POST['regplus_disable_admin'];
$update['adminhtml'] = $_POST['regplus_adminhtml'];
$update['adminfrom'] = $_POST['regplus_adminfrom'];
$update['adminsubject'] = $_POST['regplus_adminsubject'];
$update['custom_adminmsg'] = $_POST['regplus_custom_adminmsg'];
$update['adminmsg'] = $_POST['regplus_adminmsg'];
if( $_FILES['regplus_logo']['name'] ) $update['logo'] = $this->UploadLogo();
if( $_POST['label'] ){
foreach( $_POST['label'] as $k => $field ){
if( $field )
$custom[$k] = array( 'label' => $field, 'profile' => $_POST['profile'][$k], 'reg' => $_POST['reg'][$k], 'required' => $_POST['required'][$k] );
}
}
update_option( 'register_plus_custom', $custom );
update_option( 'register_plus', $update );
$_POST['notice'] = __('Settings Saved', 'regplus');
}
function UploadLogo(){
$upload_dir = ABSPATH . get_option('upload_path');
$upload_file = trailingslashit($upload_dir) . basename($_FILES['regplus_logo']['name']);
if( !is_dir($upload_dir) )
wp_upload_dir();
if( move_uploaded_file($_FILES['regplus_logo']['tmp_name'], $upload_file) ){
chmod($upload_file, 0777);
$logo = $_FILES['regplus_logo']['name'];
return trailingslashit( get_option('siteurl') ) . 'wp-content/uploads/' . $logo;
}else{
return false;
}
}
function SettingsHead(){
$regplus = get_option( 'register_plus' );
?>
' . $_POST['notice'] . '.
';
if( !is_array($regplus['profile_req']) )
$regplus['profile_req'] = array();
if( is_array($regplus['codepass']) ){
foreach( $regplus['codepass'] as $code ){
$codes .= '';
}
}
if( is_array($regplus_custom) ){
foreach( $regplus_custom as $k => $v ) {
$rows .= '
|
|
';
}
}
?>
errors['email_exists'] ){
unset($errors->errors['email_exists']);
}
}
if( $regplus['firstname'] && in_array('firstname', $regplus['profile_req']) ){
if(empty($_POST['firstname']) || $_POST['firstname'] == ''){
$errors->add('empty_firstname', __('ERROR: Please enter your First Name.', 'regplus'));
}
}
if( $regplus['lastname'] && in_array('lastname', $regplus['profile_req']) ){
if(empty($_POST['lastname']) || $_POST['lastname'] == ''){
$errors->add('empty_lastname', __('ERROR: Please enter your Last Name.', 'regplus'));
}
}
if( $regplus['website'] && in_array('website', $regplus['profile_req']) ){
if(empty($_POST['website']) || $_POST['website'] == ''){
$errors->add('empty_website', __('ERROR: Please enter your Website URL.', 'regplus'));
}
}
if( $regplus['aim'] && in_array('aim', $regplus['profile_req']) ){
if(empty($_POST['aim']) || $_POST['aim'] == ''){
$errors->add('empty_aim', __('ERROR: Please enter your AIM username.', 'regplus'));
}
}
if( $regplus['yahoo'] && in_array('yahoo', $regplus['profile_req']) ){
if(empty($_POST['yahoo']) || $_POST['yahoo'] == ''){
$errors->add('empty_yahoo', __('ERROR: Please enter your Yahoo IM username.', 'regplus'));
}
}
if( $regplus['jabber'] && in_array('jabber', $regplus['profile_req']) ){
if(empty($_POST['jabber']) || $_POST['jabber'] == ''){
$errors->add('empty_jabber', __('ERROR: Please enter your Jabber / Google Talk username.', 'regplus'));
}
}
if( $regplus['about'] && in_array('about', $regplus['profile_req']) ){
if(empty($_POST['about']) || $_POST['about'] == ''){
$errors->add('empty_about', __('ERROR: Please enter some information About Yourself.', 'regplus'));
}
}
foreach( $regplus_custom as $k=>$v ){
if( $v['required'] && $v['reg'] ){
$id = $this->Label_ID($v['label']);
if(empty($_POST[$id]) || $_POST[$id] == ''){
$errors->add('empty_' . $id, __('ERROR: Please enter your ' . $v['label'] . '.', 'regplus'));
}
}
}
if ( $regplus['password'] ){
if(empty($_POST['pass1']) || $_POST['pass1'] == '' || empty($_POST['pass2']) || $_POST['pass2'] == ''){
$errors->add('empty_password', __('ERROR: Please enter a Password.', 'regplus'));
}elseif($_POST['pass1'] !== $_POST['pass2']){
$errors->add('password_mismatch', __('ERROR: Your Password does not match.', 'regplus'));
}elseif(strlen($_POST['pass1'])<6){
$errors->add('password_length', __('ERROR: Your Password must be at least 6 characters in length.', 'regplus'));
}else{
$_POST['user_pw'] = $_POST['pass1'];
}
}
if ( $regplus['code'] && $regplus['code_req'] ){
if(empty($_POST['regcode']) || $_POST['regcode'] == ''){
$errors->add('empty_regcode', __('ERROR: Please enter the Invitation Code.', 'regplus'));
}elseif( !in_array($_POST['regcode'], $regplus['codepass']) ){
$errors->add('regcode_mismatch', __('ERROR: Your Invitation Code is incorrect.', 'regplus'));
}
}
if ( $regplus['captcha'] == 1 ){
$key = $_SESSION['1k2j48djh'];
$number = md5($_POST['captcha']);
if($number!=$key){
$errors->add('captcha_mismatch', __("ERROR: Image Validation does not match.", 'regplus'));
unset($_SESSION['1k2j48djh']);
}
} else if ( $regplus['captcha'] == 2){
require_once('recaptchalib.php');
$privatekey = $regplus['reCAP_private_key'];
$resp = rp_recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
$errors->add('recaptcha_mismatch', __("ERROR: The reCAPTCHA wasn't entered correctly.", 'regplus'));
//$errors->add('recaptcha_error', "(" . __("reCAPTCHA said: ", 'regplus') . $resp->error . ")");
}
}
if ( $regplus['disclaimer'] ){
if(!$_POST['disclaimer']){
$errors->add('disclaimer', __('ERROR: Please accept the ', 'regplus') . $regplus['disclaimer_title'] . '.');
}
}
if ( $regplus['license'] ){
if(!$_POST['license']){
$errors->add('license', __('ERROR: Please accept the ', 'regplus') . $regplus['license_title'] . '.');
}
}
if ( $regplus['privacy'] ){
if(!$_POST['privacy']){
$errors->add('privacy', __('ERROR: Please accept the ', 'regplus') . $regplus['privacy_title'] . '.');
}
}
return $errors;
}
function RegMsg($errors){
$regplus = get_option( 'register_plus' );
session_start();
if ( $errors->errors['registered'] ){
//unset($errors->errors['registered']);
}
if ( isset($_GET['checkemail']) && 'registered' == $_GET['checkemail'] ) $errors->add('registeredit', __('Registration complete. Please check your e-mail and click the verification link to activate your account.'), 'message');
return $errors;
}
# Add Fields to Register Form
function RegForm(){
$regplus = get_option( 'register_plus' );
$regplus_custom = get_option( 'register_plus_custom' );
if( !is_array( $regplus_custom ) ) $regplus_custom = array();
if ( $regplus['firstname'] ){
?>
$v){
if( $v['reg'] ){
$id = $this->Label_ID($v['label']);
?>
/>
/>
/>
';
echo rp_recaptcha_get_html($publickey);
echo '
';
}
}
function Label_ID($label){
$id = str_replace(' ', '_', $label);
$id = strtolower($id);
$id = sanitize_user($id, true);
return $id;
}
# Add Javascript & CSS needed
function PassHead(){
$regplus = get_option( 'register_plus' );
if ( $regplus['password'] ){
?>
0){
$top = '' . __('Additional Information', 'regplus') . '
';
}
echo $top;
foreach( $regplus_custom as $k=>$v ){
if( $v['profile'] ){
$id = $this->Label_ID($v['label']);
$value = get_usermeta( $user_ID, $id );
?>
| : |
|
$v ){
if( $v['profile'] ){
$key = $this->Label_ID($v['label']);
$value = $wpdb->prepare($_POST[$key]);
update_usermeta($user_ID ,$key ,$value);
}
}
}
function RanPass($len=7) {
$chars = "0123456789abcdefghijkl0123456789mnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQ0123456789RSTUVWXYZ0123456789";
srand((double)microtime()*1000000);
$i = 0;
$pass = '' ;
while ($i <= $len) {
$num = rand() % 33;
$tmp = substr($chars, $num, 1);
$pass = $pass . $tmp;
$i++;
}
return $pass;
}
function ValidateUser(){
global $wpdb;
$regplus = get_option( 'register_plus' );
if( $regplus['email_verify'] && isset( $_GET['checkemail'] ) ){
echo '' . __('Please activate your account using the verification link sent to your email address', 'regplus') . '
';
}
if( $regplus['email_verify'] && isset( $_GET['regplus_verification'] ) ){
$regplus = get_option( 'register_plus' );
$verify_key = $_GET['regplus_verification'];
$user_id = $wpdb->get_var( "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = 'email_verify' AND meta_value='$verify_key'");
$login = get_usermeta($user_id, 'email_verify_user');
$wpdb->query( "UPDATE $wpdb->users SET user_login = '$login' WHERE ID = '$user_id'" );
delete_usermeta($user_id, 'email_verify_user');
delete_usermeta($user_id, 'email_verify');
delete_usermeta($user_id, 'email_verify_date');
$msg = '' . sprintf(__('Thank you %s, your account has been verified, please login.', 'regplus'), $login ) . '
';
echo $msg;
}
}
function DeleteInvalidUsers(){
global $wpdb;
$regplus = get_option( 'register_plus' );
$grace = $regplus['email_delete_grace'];
$unverified = $wpdb->get_results( "SELECT user_id, meta_value FROM $wpdb->usermeta WHERE meta_key='email_verify_date'" );
$grace_date = date('Ymd', strtotime("-7 days"));
if( $unverified ){
foreach( $unverified as $bad ){
if( $grace_date > $bad->meta_value ){
include_once( ABSPATH . 'wp-admin/includes/user.php' );
wp_delete_user($bad->user_id);
}
}
}
}
}
}# END Class RegisterPlusPlugin
# Run The Plugin!
if( class_exists('RegisterPlusPlugin') ){
$register_plus = new RegisterPlusPlugin();
}
# Override set user password and send email to User #
if ( !function_exists('wp_new_user_notification') ) :
function wp_new_user_notification($user_id, $plaintext_pass = '') {
$user = new WP_User($user_id);
#-- REGPLUS --#
global $wpdb, $register_plus;
$regplus = get_option( 'register_plus' );
$regplus_custom = get_option( 'register_plus_custom' );
$ref = explode( '?', $_SERVER['HTTP_REFERER']);
$ref = $ref[0];
$admin = trailingslashit( get_option('siteurl') ) . 'wp-admin/users.php';
if( !is_array( $regplus_custom ) ) $regplus_custom = array();
if( $regplus['password'] && $_POST['user_pw'] )
$plaintext_pass = $wpdb->prepare($_POST['user_pw']);
else if( $ref == $admin && $_POST['pass1'] == $_POST['pass2'] )
$plaintext_pass = $wpdb->prepare($_POST['pass1']);
else
$plaintext_pass = $register_plus->RanPass(6);
if( $regplus['firstname'] && $_POST['firstname'] )
update_usermeta( $user_id, 'first_name', $wpdb->prepare($_POST['firstname']));
if( $regplus['lastname'] && $_POST['lastname'] )
update_usermeta( $user_id, 'last_name', $wpdb->prepare($_POST['lastname']));
if( $regplus['website'] && $_POST['website'] )
update_usermeta( $user_id, 'user_url', $wpdb->prepare($_POST['website']));
if( $regplus['aim'] && $_POST['aim'] )
update_usermeta( $user_id, 'aim', $wpdb->prepare($_POST['aim']));
if( $regplus['yahoo'] && $_POST['yahoo'] )
update_usermeta( $user_id, 'yim', $wpdb->prepare($_POST['yahoo']));
if( $regplus['jabber'] && $_POST['jabber'] )
update_usermeta( $user_id, 'jabber', $wpdb->prepare($_POST['jabber']));
if( $regplus['about'] && $_POST['about'] )
update_usermeta( $user_id, 'description', $wpdb->prepare($_POST['about']));
if( $regplus['code'] && $_POST['regcode'] )
update_usermeta( $user_id, 'invite_code', $wpdb->prepare($_POST['regcode']));
if( $ref != $admin && $regplus['email_verify'] ){
$code = $register_plus->RanPass(25);
update_usermeta( $user_id, 'email_verify', $code );
update_usermeta( $user_id, 'email_verify_date', date('Ymd') );
update_usermeta( $user_id, 'email_verify_user', $user->user_login );
$email_code = '?regplus_verification=' . $code;
$prelink = __('Verification URL: ', 'regplus');
$notice = __('Please use the link above to verify and activate your account', 'regplus') . "\r\n";
$temp_id = 'unverified__' . $register_plus->RanPass(7);
}
foreach( $regplus_custom as $k=>$v ){
$id = $register_plus->Label_ID($v['label']);
if( $v['reg'] && $_POST[$id] ){
update_usermeta( $user_id, $id, $wpdb->prepare($_POST[$id]));
}
}
#-- END REGPLUS --#
wp_set_password($plaintext_pass, $user_id);
$user_login = stripslashes($user->user_login);
$user_email = stripslashes($user->user_email);
#-- REGPLUS --#
if( !$regplus['custom_adminmsg'] && !$regplus['disable_admin'] ){
#-- END REGPLUS --#
$message = sprintf(__('New user Register on your blog %s:', 'regplus'), get_option('blogname')) . "\r\n\r\n";
$message .= sprintf(__('Username: %s', 'regplus'), $user_login) . "\r\n\r\n";
$message .= sprintf(__('E-mail: %s', 'regplus'), $user_email) . "\r\n";
@wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Register', 'regplus'), get_option('blogname')), $message);
#-- REGPLUS --#
}else if( !$regplus['disable_admin'] ){
if( $regplus['adminhtml'] ){
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
}
$headers .= 'From: ' . $regplus['adminfrom'] . "\r\n" . 'Reply-To: ' . $regplus['adminfrom'] . "\r\n";
$subject = $regplus['adminsubject'];
$message = str_replace('%user_login%', $user_login, $regplus['adminmsg']);
$message = str_replace('%user_email%', $user_email, $message);
$message = str_replace('%blogname%', get_option('blogname'), $message);
if( $regplus['email_verify'] )
$siteurl = get_option('siteurl') . "/wp-login.php" . $email_code;
else
$siteurl = get_option('siteurl') . "/wp-login.php";
$message = str_replace('%siteurl%', $siteurl, $message);
wp_mail($user_email, $subject, $message, $headers);
}
#-- END REGPLUS --#
if ( empty($plaintext_pass) )
return;
#-- REGPLUS --#
if( !$regplus['custom_msg'] ){
#-- END REGPLUS --#
$message = sprintf(__('Username: %s', 'regplus'), $user_login) . "\r\n";
$message .= sprintf(__('Password: %s', 'regplus'), $plaintext_pass) . "\r\n";
//$message .= get_option('siteurl') . "/wp-login.php";
#-- REGPLUS --#
$message .= $prelink . get_option('siteurl') . "/wp-login.php" . $email_code . "\r\n";
$message .= $notice;
#-- END REGPLUS --#
wp_mail($user_email, sprintf(__('[%s] Your username and password', 'regplus'), get_option('blogname')), $message);
#-- REGPLUS --#
}else{
if( $regplus['html'] ){
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
}
$headers .= 'From: ' . $regplus['from'] . "\r\n" . 'Reply-To: ' . $regplus['from'] . "\r\n";
$subject = $regplus['subject'];
$message = str_replace('%user_pass%', $plaintext_pass, $regplus['msg']);
$message = str_replace('%user_login%', $user_login, $message);
$message = str_replace('%user_email%', $user_email, $message);
$message = str_replace('%blogname%', get_option('blogname'), $message);
if( $regplus['email_verify'] )
$siteurl = get_option('siteurl') . "/wp-login.php" . $email_code;
else
$siteurl = get_option('siteurl') . "/wp-login.php";
$message = str_replace('%siteurl%', $siteurl, $message);
wp_mail($user_email, $subject, $message, $headers);
}
if( $ref != $admin && $regplus['email_verify'] ) #REGPLUS ADDED LINE
$temp_user = $wpdb->query( "UPDATE $wpdb->users SET user_login = '$temp_id' WHERE ID = '$user_id'" ); #REGPLUS ADDED LINE
#-- END REGPLUS --#
}
endif;
?>