Do not display registration form to logged in users
<p>I'm trying to figure out a way to add if condition to the registration form. Presently logged in users can access the registration form, which isn't right. Below is the piece of code.</p>

<p>Note, my CMS is wordpress.</p>

<p>I've tried using the:</p>

<pre><code>if (is_user_logged_in()) 

/* MAIN CODE HERE */

    else
        return "You are already logged in!";
</code></pre>

<p>But it only ends up displaying the 'if (is_user...' above the registration form.</p>

<p>Here's the code:</p>

<pre><code>&lt;?php
if ('wwm-register.php' == basename($_SERVER['SCRIPT_FILENAME']))
     die ('&lt;h2&gt;Direct File Access Prohibited&lt;/h2&gt;');


function wwm_register_page() {
global $wpdb, $user_ID;
FUNCTION TO DISPLAY PLANS&lt;/div&gt;
&lt;?php
return;
exit;
}

        if (get_option('wwm_form_validator')) {
?&gt;
            FORM VALIDATION SCRIPT
&lt;?php
        }

    $main_fields=get_option('wwm_main_fields');

    $use_plugin_as=get_option('use_plugin_as');

    if ($use_plugin_as!=='all')  {
        if($use_plugin_as=='membership') {
            $type='membership';
            $main_fields[0][show]='1'; //show username and pass and mail
        }elseif($use_plugin_as=='order'){
            $type='order';
            $main_fields[0][show]='0'; //don't show username and pass and mail
        }else{
            $type='membership';
        }
    }


    if (isset($_GET['type'])) {
        if($_GET['type']=='membership') {
            $type='membership';
            $main_fields[0][show]='1'; //show username and pass and mail
        }elseif($_GET['type']=='order'){
            $type='order';
            $main_fields[0][show]='0'; //don't show username and pass and mail
        }
    }



    if ($type)
        $planlist = $wpdb-&gt;get_results("SELECT id,title,price,description FROM ".WWM_PLANS_TABLE." WHERE display='1' AND plantype='".$type."'");
    else
        $planlist = $wpdb-&gt;get_results("SELECT id,title,price,description FROM ".WWM_PLANS_TABLE." WHERE display='1'");

    if (isset($_POST['preview'])) $preview=$_POST['preview']; else $preview=0;

    if (isset($_POST['username'])) $username=attribute_escape(strip_tags(stripslashes(strtolower(trim($_POST['username'])))));elseif (isset($_GET['username'])) $username=attribute_escape(strip_tags(stripslashes(strtolower(trim($_GET['username'])))));

    if (isset($_POST['pass'])) $pass=attribute_escape(strip_tags(stripslashes((trim($_POST['pass'])))));
    if (isset($_POST['pass2'])) $pass2=attribute_escape(strip_tags(stripslashes((trim($_POST['pass2'])))));

    if (isset($_POST['email'])) $email=attribute_escape(strip_tags(stripslashes((trim($_POST['email'])))));elseif (isset($_GET['email'])) $email=attribute_escape(strip_tags(stripslashes(strtolower(trim($_GET['email'])))));

    if (isset($_POST['companyname'])) $companyname=attribute_escape(strip_tags(stripslashes((trim($_POST['companyname'])))));

    if (isset($_POST['fname'])) $fname=attribute_escape(strip_tags(stripslashes((trim($_POST['fname'])))));elseif (isset($_GET['fname'])) $fname=attribute_escape(strip_tags(stripslashes(strtolower(trim($_GET['fname'])))));

    if (isset($_POST['lname'])) $lname=attribute_escape(strip_tags(stripslashes((trim($_POST['lname'])))));elseif (isset($_GET['lname'])) $lname=attribute_escape(strip_tags(stripslashes(strtolower(trim($_GET['lname'])))));

    if (isset($_POST['nname'])) $nname=attribute_escape(strip_tags(stripslashes((trim($_POST['nname'])))));
    if (isset($_POST['url'])) $url=attribute_escape(strip_tags(stripslashes((trim($_POST['url'])))));elseif (isset($_GET['url'])) $url=attribute_escape(strip_tags(stripslashes(strtolower(trim($_GET['url'])))));

    if (isset($_POST['desc'])) $desc=attribute_escape(strip_tags(stripslashes((trim($_POST['desc'])))));elseif (isset($_GET['desc'])) $desc=attribute_escape(strip_tags(stripslashes(strtolower(trim($_GET['desc'])))));

    if (isset($_POST['yahooim'])) $yahooim=attribute_escape(strip_tags(stripslashes((trim($_POST['yahooim'])))));
    if (isset($_POST['aolim'])) $aolim=attribute_escape(strip_tags(stripslashes((trim($_POST['aolim'])))));
    if (isset($_POST['jabberim'])) $jabberim=attribute_escape(strip_tags(stripslashes((trim($_POST['jabberim'])))));

    if (isset($_POST['countryname'])) $countryname=attribute_escape(strip_tags(stripslashes((trim($_POST['countryname'])))));elseif (isset($_GET['countryname'])) $countryname=attribute_escape(strip_tags(stripslashes(strtolower(trim($_GET['countryname'])))));

    if (isset($_POST['statename'])) $statename=attribute_escape(strip_tags(stripslashes((trim($_POST['statename'])))));
    elseif (isset($_GET['statename'])) $statename=attribute_escape(strip_tags(stripslashes(strtolower(trim($_GET['statename'])))));

    if (isset($_POST['cityname'])) $cityname=attribute_escape(strip_tags(stripslashes((trim($_POST['cityname'])))));
    elseif (isset($_GET['cityname'])) $cityname=attribute_escape(strip_tags(stripslashes(strtolower(trim($_GET['cityname'])))));

    if (isset($_POST['adrs'])) $adrs=attribute_escape(strip_tags(stripslashes((trim($_POST['adrs'])))));
    elseif (isset($_GET['adrs'])) $adrs=attribute_escape(strip_tags(stripslashes(strtolower(trim($_GET['adrs'])))));

    if (isset($_POST['adrs2'])) $adrs2=attribute_escape(strip_tags(stripslashes((trim($_POST['adrs2'])))));
    elseif (isset($_GET['adrs2'])) $adrs2=attribute_escape(strip_tags(stripslashes(strtolower(trim($_GET['adrs2'])))));


    if (isset($_POST['zipcode'])) $zipcode=attribute_escape(strip_tags(stripslashes((trim($_POST['zipcode'])))));
    elseif (isset($_GET['zipcode'])) $zipcode=attribute_escape(strip_tags(stripslashes(strtolower(trim($_GET['zipcode'])))));

    if (isset($_POST['telephone'])) $telephone=attribute_escape(strip_tags(stripslashes((trim($_POST['telephone'])))));
    elseif (isset($_GET['telephone'])) $telephone=attribute_escape(strip_tags(stripslashes(strtolower(trim($_GET['telephone'])))));

    if (isset($_POST['birthday'])) $birthday=attribute_escape(strip_tags(stripslashes((trim($_POST['birthday'])))));
    if (isset($_POST['birthmonth'])) $birthmonth=attribute_escape(strip_tags(stripslashes((trim($_POST['birthmonth'])))));
    if (isset($_POST['birthyear'])) $birthyear=attribute_escape(strip_tags(stripslashes((trim($_POST['birthyear'])))));
    if (isset($_POST['gender'])) $gender=attribute_escape(strip_tags(stripslashes((trim($_POST['gender'])))));
    if (isset($_POST['terms'])) $terms=attribute_escape(strip_tags(stripslashes((trim($_POST['terms'])))));
    if (isset($_POST['avatar'])) $avatar=attribute_escape(strip_tags(stripslashes((trim($_POST['avatar'])))));

    if (isset($_POST['plan'])) $plan=attribute_escape(strip_tags(stripslashes((trim($_POST['plan'])))));elseif (isset($_GET['plan'])) $plan=attribute_escape(strip_tags(stripslashes(strtolower(trim($_GET['plan'])))));

    if (isset($_POST['captcha'])) $captcha=attribute_escape(strip_tags(stripslashes((trim($_POST['captcha'])))));

    if (isset($_POST['promocode'])) $promocode=attribute_escape(strip_tags(stripslashes((trim($_POST['promocode'])))));elseif (isset($_GET['promocode'])) $promocode=attribute_escape(strip_tags(stripslashes(strtolower(trim($_GET['promocode'])))));

    if (isset($_POST['payment_method'])) $payment_method=attribute_escape(strip_tags(stripslashes((trim($_POST['payment_method'])))));elseif (isset($_GET['payment_method'])) $payment_method=attribute_escape(strip_tags(stripslashes(strtolower(trim($_GET['payment_method'])))));

    if (isset($_POST['blog_title'])) $blog_title=attribute_escape(strip_tags(stripslashes((trim($_POST['blog_title'])))));elseif (isset($_GET['blog_title'])) $blog_title=attribute_escape(strip_tags(stripslashes(strtolower(trim($_GET['blog_title'])))));

    if (isset($_POST['blog_domain'])) $blog_domain=attribute_escape(strip_tags(stripslashes((trim($_POST['blog_domain'])))));elseif (isset($_GET['blog_domain'])) $blog_domain=attribute_escape(strip_tags(stripslashes(strtolower(trim($_GET['blog_domain'])))));

    $last_id=wwm_get_fields_last_id('registration');

    for ($i=1;$i&lt;=$last_id;$i++){

        $list=$wpdb-&gt;get_row("SELECT label,regex,req FROM ".WWM_FIELDS_TABLE." WHERE id={$i};");
        if ($list) {

            if (isset($_POST['custom-'.$i])) $custom_value[$i]=attribute_escape(stripslashes(strip_tags(trim($_POST['custom-'.$i]))));
            elseif (isset($_GET['custom-'.$i])) $custom_value[$i]=attribute_escape(strip_tags(stripslashes(trim($_GET['custom-'.$i]))));                $custom_regex[$i]=$list-&gt;regex;
                    $custom_req[$i]=$list-&gt;req;
                    $custom_label[$i]=$list-&gt;label; 
                    $custom[$i][label]=$list-&gt;label;
                    $custom[$i][value]=$custom_value[$i];

                    if (isset($_POST['file-'.$i])) {
                    $file_custom_fields[]=$_POST['file-'.$i];
                    }

            }

    }

    if (!get_option('wwm_users_can_register')) {
        echo '&lt;div class="wwm-errormessage" &gt;'.__('Registration has been disabled.','wwm').'&lt;/div&gt;';
        $hidden=true;   

    }elseif((isset($_GET['action']))){
        $hidden=true;

        if (isset($_GET['method']) &amp;&amp; 'twoco'==$_GET['method'])
            include('include/payment_2co.php');
        else
            include('include/payment.php');

    }elseif ( (isset($_GET['mail'])) &amp;&amp; (isset($_GET['activate_key'])) ) {
        $hidden=true;
        $user_data = get_user_by_email($_GET['mail']);


        if ( (get_usermeta($user_data-&gt;ID,'activate_key')==$_GET['activate_key']) &amp;&amp; (get_usermeta($user_data-&gt;ID,'status')=='incomplete') ){
            update_usermeta($user_data-&gt;ID,'status','0');   
            delete_usermeta($user_data-&gt;ID,'activate_key');
            $thanksmsg=__('Your account has been successfully activated.','wwm') . ' &lt;a href="'.wp_login_url().'"&gt; '.__('Log In').'&lt;/a&gt;';

            if (get_option('free_members_welcome_mail')) {
                $to=$_GET['mail'];

                $username=$user_data-&gt;user_login;
                $fname=$user_data-&gt;first_name;
                $lname=$user_data-&gt;last_name;
                $expiredate=get_usermeta($user_data-&gt;ID,'expire');
                $plan=get_usermeta($user_data-&gt;ID,'plan_id');
                    $planinfo=get_plan_info($plan);
                $plantitle=$planinfo-&gt;title;


                $blogname=get_option('blogname');
                $subject='Welcome to '.$blogname.'!';

                $body=get_option('free_members_welcome_mail_body');
                $tags=array('{plantitle}','{expiredate}','{firstname}','{lastname}','{username}','{password}','{planid}');
                $replace=array($plantitle,$expiredate,$fname,$lname,$username,$pass,$plan);
                $body=str_replace($tags,$replace,$body);
                $body.='&lt;p&gt;';


                wwm_mail_actions('html'); //set actions

                if ( !wp_mail($to, $subject, $body, $header) ) 
                        $msg= __('The e-mail could not be sent.') . "&lt;br /&gt;\n" . __('Possible reason: your host may have disabled the mail() function...') ;
            } //free members welcome

            echo '&lt;div class="wwm-thanksmessage"&gt;'.$thanksmsg.'&lt;/div&gt;';
        }elseif($user_data-&gt;ID &amp;&amp; get_usermeta($user_data-&gt;ID,'status')!=='incomplete'){
            $errormsg=__('We think you did it before!','wwm');
        echo '&lt;div class="wwm-errormessage" &gt;'.$errormsg.'&lt;/div&gt;';
        }elseif((!$user_data-&gt;ID) ||get_usermeta($user_data-&gt;ID,'activate_key')!==$_GET['activate_key']){
            $errormsg=__('Your activation key is not valid for the plan!','wwm');
            echo '&lt;div class="wwm-errormessage" &gt;'.$errormsg.'&lt;/div&gt;';
        }

    }
    elseif ( (isset($_POST['submit'])) || (isset($_POST['submit-upload'])) ) {

        if ( !wp_verify_nonce( $_POST['wwm_form_noncename'], plugin_basename(__FILE__) )) 
            return "Invalid nonce. Try agian.";

        require_once(ABSPATH.'/wp-includes/registration.php');
        //require_once(ABSPATH.'/wp-includes/pluggable.php');

        if (isset($_POST['submit-upload'])) { //avatar


        $override['test_form']=false;
        $allowed=array(jpg,jpeg,jpe,gif,png);

        $result=wwm_handle_upload($_FILES['avatarfile'],$override,100,$allowed); //100Kb means max upload size for avatars!

        if (!$result['error']) {
            require_once(ABSPATH.'/wp-admin/includes/image.php');
            $site=get_option(siteurl);
            $path=ABSPATH.'/wp-content/avatar/';
            $urlpath=$site."/wp-content/avatar/";
            if (!is_dir($path))  {
                mkdir($path);//chmod($path,777);
            }
            $avatar_size=get_option('wwm_avatar_width');
            $avatar=wwm_image_resize( $result['file'],$avatar_size, $avatar_size, $crop=false, $suffix=$username.'avatar', $dest_path= $path, $jpeg_quality=75) ;

            if (basename($avatar))
            $avatar=$urlpath.basename($avatar);
            else
            $uploaderror.=$main_fields[20][name].': '.__('Image is very little.','wwm').'.&lt;br/&gt;';

        }else{
            $uploaderror.=$main_fields[20][name].': '.$result['error'].'.&lt;br/&gt;';

        }
    }

    if ($file_custom_fields) {

        foreach($file_custom_fields as $field_id) {

                $override['test_form']=false;
                $allowed=unserialize($wpdb-&gt;get_var($wpdb-&gt;prepare("SELECT options FROM ".WWM_FIELDS_TABLE." WHERE id=%s;",$field_id)));
                $max_upload_size=get_site_option( 'fileupload_maxk', 1500 );
                $result=wwm_handle_upload($_FILES['custom-'.$field_id ],$override,$max_upload_size,$allowed);

                if (!$result['error']) {
                    $custom_value[$field_id]=$result['url'];

                }else{
                    if (!$_FILES['custom-'.$field_id ][error]=='4') { //error[4] means empty file
                        $msgerror.=$custom_label[$field_id].': '.$result['error'].'.&lt;br/&gt;';
                        $custom_value[$field_id]='error';
                    }
                }

        }
    }


    for ($i=1;$i&lt;=$last_id;$i++){
                    if ( ((empty($custom_value[$i])) || ($custom_value[$i]==__('-Select-','wwm'))) &amp;&amp; ($custom_req[$i]) ) 
                    $msgerror.= sprintf(__('Please enter %s.', 'wwm'), $custom_label[$i])."&lt;br/&gt;";

    }


    if ( ($planlist) &amp;&amp; (strlen($plan)&lt;1) ) $msgerror.=__('Please choose a plan.','wwm').'&lt;br/&gt;';

    if ($main_fields[0][show]) {
        if ((strlen($username)&gt;20) || (strlen($username)&lt;4) ) $msgerror.=__('Please enter a username(at least 4 characters).','wwm').'&lt;br/&gt;';  
        if (username_exists($username)) $msgerror.=sprintf(__('%s already exists.', 'wwm'), $username)."&lt;br/&gt;";
        if (!validate_username($username)) $msgerror.=sprintf(__('%s is not allowed.', 'wwm'), $username)."&lt;br/&gt;";

        if ( (strlen($pass)&gt;30) || (strlen($pass)&lt;6) ) $msgerror.=__('Please enter a password(at least 6 characters).', 'wwm')."&lt;br/&gt;";
        if ( (empty($pass2)) || (strlen($pass2)&gt;30) || ($pass!==$pass2) ) $msgerror.=__('Please re-type password to confirm.', 'wwm')."&lt;br/&gt;";
    }
    if ( ($main_fields[1][show]) || ($main_fields[0][show]) ) {
        if ( ($main_fields[1][req]) &amp;&amp; (strlen($email)&lt;6) ) $msgerror.=__('Please enter a correct email address.', 'wwm')."&lt;br/&gt;";

        if ( ($main_fields[1][req]) &amp;&amp; (email_exists($email)) &amp;&amp; ($type!=='order') ) $msgerror.=__('That email already exists.', 'wwm')."&lt;br/&gt;";
        if ( (!wwm_validate_email($email)) &amp;&amp; (!strlen($email)&lt;6) ) $msgerror.=__('Please enter a correct email address.', 'wwm')."&lt;br/&gt;";
    }

        if ( ($main_fields[2][req]) &amp;&amp; (strlen($fname)&lt;1) ) $msgerror.=sprintf(__('Please enter %s.', 'wwm'), $main_fields[2][name])."&lt;br/&gt;";
        if ( ($main_fields[3][req]) &amp;&amp; (strlen($lname)&lt;1) ) $msgerror.=sprintf(__('Please enter %s.', 'wwm'), $main_fields[3][name])."&lt;br/&gt;";
        if ( (($main_fields[6][req]) &amp;&amp; (strlen($url)&lt;10)) || ( (strlen($url)&gt;1) &amp;&amp;
        (!ereg('^(http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&amp;amp;%\$#\=~])*$',$url) ))) 
        $msgerror.=__('Please enter a correct URL.', 'wwm')."&lt;br/&gt;";
        if ( ($main_fields[4][req]) &amp;&amp; (strlen($nname)&lt;5) ) $msgerror.=sprintf(__('Please enter %s.', 'wwm'), $main_fields[4][name])."&lt;br/&gt;";
        if ( ($main_fields[18][req]) &amp;&amp; (strlen($desc)&lt;5) ) $msgerror.=sprintf(__('Please enter %s.', 'wwm'), $main_fields[18][name])."&lt;br/&gt;";
        if ( ($main_fields[7][req]) &amp;&amp; (strlen($yahooim)&lt;5) ) $msgerror.=sprintf(__('Please enter %s.', 'wwm'), $main_fields[7][name])."&lt;br/&gt;";
        if ( ($main_fields[8][req]) &amp;&amp; (strlen($aolim)&lt;5) ) $msgerror.=sprintf(__('Please enter %s.', 'wwm'), $main_fields[8][name])."&lt;br/&gt;";
        if ( ($main_fields[9][req]) &amp;&amp; (strlen($jabberim)&lt;5) ) $msgerror.=sprintf(__('Please enter %s.', 'wwm'), $main_fields[9][name])."&lt;br/&gt;";

        if ( ($main_fields[5][req]) &amp;&amp; (strlen($companyname)&lt;2) ) $msgerror.=sprintf(__('Please enter %s.', 'wwm'), $main_fields[5][name])."&lt;br/&gt;";

        if ( ($main_fields[12][req]) &amp;&amp; (strlen($countryname)&lt;1) ) $msgerror.=__('Please choose your country.', 'wwm')."&lt;br/&gt;";
        if ( ($main_fields[13][req]) &amp;&amp; (strlen($statename)&lt;1) ) $msgerror.=sprintf(__('Please enter %s.', 'wwm'), $main_fields[13][name])."&lt;br/&gt;";
        if ( ($main_fields[14][req]) &amp;&amp; (strlen($cityname)&lt;1) ) $msgerror.=sprintf(__('Please enter %s.', 'wwm'), $main_fields[14][name])."&lt;br/&gt;";
        if ( ($main_fields[15][req]) &amp;&amp; (strlen($adrs)&lt;1) ) $msgerror.=sprintf(__('Please enter %s.', 'wwm'), $main_fields[15][name])."&lt;br/&gt;";
        if ( ($main_fields[16][req]) &amp;&amp; (strlen($zipcode)&lt;1)  ) $msgerror.=sprintf(__('Please enter %s.', 'wwm'), $main_fields[16][name])."&lt;br/&gt;";
        if ( ($main_fields[17][req]) &amp;&amp; (strlen($telephone)&lt;1) ) $msgerror.=sprintf(__('Please enter %s.', 'wwm'), $main_fields[17][name])."&lt;br/&gt;";
        if ( (($main_fields[10][req]) &amp;&amp; (strlen($birthday)&lt;1)) || (($main_fields[10][req]) &amp;&amp; (strlen($birthmonth)&lt;1)) || (($main_fields[10][req]) &amp;&amp; (strlen($birthyear)&lt;1)) ) $msgerror.=__('Please choose your birthdate.', 'wwm')."&lt;br/&gt;";

        if ( ($main_fields[11][req]) &amp;&amp; (strlen($gender)&lt;1) ) $msgerror.=__('Please choose your gender.', 'wwm')."&lt;br/&gt;";
        if ( ($main_fields[19][show]) &amp;&amp; (strlen($terms)&lt;1) &amp;&amp; ( (!get_option('wwm_show_preview'))||($preview) &amp;&amp; (get_option('wwm_show_preview')) ) ) $msgerror.=sprintf(__('Please accept %s.', 'wwm'), $main_fields[19][name])."&lt;br/&gt;";
        if ( ($main_fields[20][req]) &amp;&amp; (strlen($avatar)&lt;1) ) $msgerror.=sprintf(__('Please upload a photo as %s.', 'wwm'), $main_fields[20][name])."&lt;br/&gt;";
        if ( ($main_fields[22][req]) &amp;&amp; (strlen($promocode)&lt;1) ) $msgerror.=sprintf(__('Please enter %s.', 'wwm'), $main_fields[22][name])."&lt;br/&gt;";

        //if ( ($main_fields[100][show]) &amp;&amp; (strlen($blog_domain)&lt;4) ) $msgerror.=sprintf(__('Please enter %s.', 'wwm'), $main_fields[100][name]) . ' '.__('(at least 4 characters)','wwm')." &lt;br/&gt;";
        //if ( ($main_fields[100][show]) &amp;&amp; (strlen($blog_title)&lt;4) ) $msgerror.=sprintf(__('Please enter %s.', 'wwm'), $main_fields[101][name]). ' '.__('(at least 4 characters)','wwm')." &lt;br/&gt;";



        if (!get_option('wwm_users_can_register')) $msgerror.=__('Registration has been disabled.', 'wwm')."&lt;br/&gt;";


    if (($main_fields[21][show]) &amp;&amp; ( (!get_option('wwm_show_preview'))||($preview) &amp;&amp; (get_option('wwm_show_preview')) ) )  {
        $type=get_option('wwm_cap_type');
        if ( $type == 'simple' ){
            if (!class_exists(tam_captcha)) include('captcha/captcha.php');

            $tam_captcha=new tam_captcha;
            $check=$tam_captcha-&gt;check(attribute_escape($_POST['captcha-id']), $captcha);

            $tam_captcha-&gt;remove(attribute_escape($_POST['captcha-id']));   

            if(!$check){
                $msgerror.=sprintf(__('Please enter a correct %s.', 'wwm'), $main_fields[21][name])."&lt;br/&gt;";

            }   
        } else if ( $type == 'recap'){
            require_once('captcha/recaptchalib.php');
            $privatekey = get_option('wwm_recap_private');
            $recap = rp_recaptcha_check_answer ($privatekey,

                $_SERVER["REMOTE_ADDR"],
                $_POST["recaptcha_challenge_field"],
                $_POST["recaptcha_response_field"]);

            if (!$recap-&gt;is_valid) {
                $msgerror.=sprintf(__('Please enter a correct %s.', 'wwm'), $main_fields[21][name])."&lt;br/&gt;";

            }
        }
    } //end if requires 



    } //end first if


        if ($_POST['submit']) {
            if ($planlist) {
                $theplan = $wpdb-&gt;get_row($wpdb-&gt;prepare("SELECT title,price,duration,plantype FROM ".WWM_PLANS_TABLE." WHERE display='1' AND id=%s",$plan) );
                $planprice=$theplan-&gt;price;
                $plantitle=$theplan-&gt;title;
                $planduration=$theplan-&gt;duration;
                $plantype=$theplan-&gt;plantype;
            }


            if ( (strstr(basename($_SERVER['SCRIPT_FILENAME']),'admin.php')) &amp;&amp; (is_admin()) ){
                $planprice=0;
                $admin=true; //free for backend page
            }

            if ($promocode) {
                $promocode=strtolower($promocode);
                $codes=get_option('wwm_discount_code');
                $valid=false;
                if ($codes) {
                    for ($id=1;$id&lt;=MAX_DISCOUNT_NUM;$id++ ) {
                        if ($codes[$id][code]==$promocode) {
                            if ( ($codes[$id][plans][0]) &amp;&amp; ($codes[$id][plans][0]!==',')) {

                                foreach($codes[$id][plans] as $codeid=&gt;$codeplan) {
                                    if($codeplan==$plan) { 
                                        $planprice=$planprice*((100-$codes[$id][percent])*(1/100));
                                        $valid=true;
                                    }
                                }
                            }else{
                                $valid=true;
                                $planprice=$planprice*((100-$codes[$id][percent])*(1/100));
                            }
                        }
                    }
                }

                if (!$valid) 
                $msgerror.=sprintf(__('%s is not valid.', 'wwm'), $main_fields[22][name])."&lt;br/&gt;";  
            }

        }   



    if (empty($msgerror) &amp;&amp; ($_POST['submit']) ) {

        $user_login = $username;
        $user_email = $email;
        $user_pass = $pass;
        $user_nicename=$nname;
        $user_url=$url;
        $display_name=$user_nicename;
        $first_name=$fname;
        $last_name=$lname;
        $description=$desc;
        //$role=''; leave to default userrole
        //$rich_editing=true;
        $yim=$yahooim;
        $aim=$aolim;
        $jabber=$jabberim;


        if (  ($planprice&lt;=0)&amp;&amp; ($type!='order') &amp;&amp; ($plantype!='order') ) {
            $userdata = compact('user_login', 'user_email', 'user_pass','user_nicename','user_url','display_name','first_name','last_name','description','yim','aim','jabber');

            $id=wp_insert_user($userdata);

            update_usermeta($id,'company',$companyname);
            update_usermeta($id,'country',$countryname);
            update_usermeta($id,'state',$statename);
            update_usermeta($id,'city',$cityname);
            update_usermeta($id,'address',$adrs);
            update_usermeta($id,'address2',$adrs2);
            update_usermeta($id,'zip',$zipcode);
            update_usermeta($id,'phone',$telephone);
            if (($birthyear)&amp;&amp;($birthmonth)&amp;&amp;($birthday) ) $birthdate=$birthyear.'-'.$birthmonth.'-'.$birthday.' 00:00:00';
                update_usermeta($id,'birthday',$birthdate);
            update_usermeta($id,'gender',$gender);
            update_usermeta($id,'last_ip', $_SERVER['REMOTE_ADDR']);
            update_usermeta($id,'status','');
            update_usermeta($id,'plan_id',$plan);
            update_usermeta($id,'avatar',$avatar);
            update_usermeta($id,'promocode',$promocode);

                if ($planduration)
                $expiredate = date("Y-m-d H:i:s",strtotime('+'.$planduration.'day')); else $expiredate=0;

            update_usermeta($id,'expire',$expiredate);

            for ($i=1;$i&lt;=$last_id;$i++) {
                if  ( ($custom_label[$i]) &amp;&amp; ($custom_value[$i]) )
                update_usermeta($id,'customfield_'.$i,$custom_value[$i]);
            }

            do_action('wwm_free_member_registered',$id);
</code></pre>

<p>SEND EMAIL</p>

<pre><code>                wwm_mail_actions('html'); //set actions

                if ( !wp_mail($to, $subject, $body, $header) ) 
                        $msg= __('The e-mail could not be sent.') . "&lt;br /&gt;\n" . __('Possible reason: your host may have disabled the mail() function...') ;

            } //end verify mail


            $thanksmsg=__('Thank you for your registration.','wwm')."&lt;br/&gt;";
</code></pre>

<p>/* NOTIFY MEMBERS ON SIGN UP */
                }
            }
        }else{ //else if there is error </p>

<pre><code>         if ( ($msgerror)&amp;&amp;(isset($_POST['submit'])) ) echo '&lt;div class="wwm-errormessage" &gt;'.$msgerror.'&lt;/div&gt;';   


    if ($uploaderror) echo '&lt;div class="wwm-errormessage" &gt;'.$uploaderror.'&lt;/div&gt;'; 

if (!$hidden) { 

    do_action('wwm_register_header');

    ?&gt;

    &lt;div class="wwm_register_page"&gt;
</code></pre>

<p>/<em>REGISTRATION FORM</em>/</p>

<pre><code>    &lt;?php   

    }//end if
}//end of hidden
}
?&gt;
</code></pre>
