0

I am building a music eCommerce website, which sells some audios. I have built a sign up form with 5 text boxes of Name, Email, Password, Username, Phone number. I am saving this data in a wp-registration table.

How can I link this sign up form with the website in such a way that if a user registers, then only he is able to see all the music content, otherwise just the normal text.

Here is the sign up code.

      <?php
      /* Template Name: Sign Up */
      get_header();
      $fNameErr  = $familyNameErr = $phoneErr = $emailErr = $passwordErr = "";
      $error_css = $fName = $familyName = $phone = $email = $password =  "";

      if (isset($_POST['submit'])) {
      if (empty($_POST["fName"])) {
      $fNameErr = 'background-color:#ff4338';

      } else {
      $fName = test_input($_POST["fName"]);
      // check if name only contains letters and whitespace
      if (!preg_match("/^[a-zA-Z ]*$/", $fName)) {
        $fNameErr = "*";
      }
     } 



     if (empty($_POST["familyName"])) {
     $error_css = 'background-color:#ff4338';
   } else {
     $familyName = test_input($_POST["familyName"]);
     // check if name only contains letters and whitespace
     if (!preg_match("/^[a-zA-Z ]*$/", $familyName)) {
        $familyNameErr = "*";
      }
    }


    if (empty($_POST["email"])) {
    $error_css = 'background-color:#ff4338';
    } else {
    $email = test_input($_POST["email"]);
    // check if e-mail address is well-formed
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        $emailErr = "Invalid email format";
    }
}



if (empty($_POST["phone"])) {
    $error_css = 'background-color:#ff4338';
} else {
    $phone = test_input($_POST["phone"]);
    // check if e-mail address is well-formed
    if (!preg_match("/^[0-9]{3}-[0-9]{3}-[0-9]{4}$/", $phone)) {
        $phoneErr = "*";
    }
}



if (empty($_POST["password"])) {
    $error_css = 'background-color:#ff4338';
} else {
    $password = test_input($_POST["password"]);
    // check if e-mail address is well-formed
}



global $wpdb;


$wpdb->insert('wp_registration', array(
    'First_Name' => $_POST['fName'],
    'Last_Name' => $_POST['familyName'],
    'Phone' => $_POST['phone'],
    'Email' => $_POST['email'],
    'Password' => $_POST['password']
), array(
    '%s',
    '%s'
));

}
?>


<form action="index.php" class="modal-content animate" method="post">
    <div class="container">
        <input id="fName" name="fName" onblur="this.placeholder = 'Prénom nom'" onfocus="this.placeholder=''" placeholder="Prénom nom" required="" style="<?php echo $fNameErr; ?>" type="text"> 
        <input name="familyName" onblur="this.placeholder = 'Nom de famille'" onfocus="this.placeholder=''" placeholder="Nom de famille" required="" style="<?php echo $error_css; ?>" type="text"> 
        <input name="phone" onblur="this.placeholder = 'Numéro de téléphone'" onfocus="this.placeholder=''" placeholder="Numéro de téléphone" required="" style="<?php echo $error_css; ?>" type="number"> 
        <input name="email" onblur="this.placeholder = 'Courriel'" onfocus="this.placeholder=''" placeholder="Courriel" required="" style="<?php echo $error_css; ?>" type="text">
        <input name="password" onblur="this.placeholder = 'Mot de passe'" onfocus="this.placeholder=''" placeholder="Mot de passe" required="" style="<?php echo $error_css; ?>" type="password"><br>

        <div class="buttons">
            <input class="btn btn-primary custom-button red-btn" name="submit" type="submit" value="Inscription">
        </div>
    </div>
</form>
  • how are you dealing with the audio files - are they already restricted from downloads somehow? – alexwc_ Aug 17 '17 at 15:07
  • Right now, they are on the downloads page and everybody can download them. I want to restrict this only for the login users. But I don't seem to link the sign up form with the sign form and the wordpress website. – Jon_Snow Aug 17 '17 at 15:08
  • well, it might be a bit more complicate than that to code. Check some plugins like Restrict Content Pro. Or check Easy Digital Downloads – alexwc_ Aug 17 '17 at 15:11
0

Maybe this plugins can help you
https://wordpress.org/plugins/pagerestrict/
https://wordpress.org/plugins/wordpress-access-control/

Update

if ( is_user_logged_in() ) {
    // you content
}
else {
    // you text
}

UPDATE 2

When the user is authorized, him ID was write in global array. This ID you can take from this array.

$current_user = wp_get_current_user();

I don't know structure your table, but you need to have user ID field like in wp_users table. Make a request to the database.

global $wpdb

$value = $wpdb->get_result("SELECT `user_name_in_your_table`
                            FROM `wp_registration`
                            WHERE `user_id` = '$current_user->ID'");

if($value[0]->user_name_in_your_table !== ''){
    //access
} else{
    //denied
}
  • Would these plugins work for the custom sign up and custom sign in forms ? And I don't want to hide the full page. I Just want to hide the audio files. – Jon_Snow Aug 17 '17 at 15:09
  • @Jon_Snow view my update answer – Nikita Dudarev Aug 17 '17 at 15:12
  • but that if ( is_user_logged_in() ), won't that just check if a wordpress user is logged in or not. if ( is_user_logged_in() ) is using the wp-users table I guess and I am storing the data in a custom table wp-registration – Jon_Snow Aug 17 '17 at 15:16
  • @Jon_Snow It's your custom table? – Nikita Dudarev Aug 17 '17 at 15:33
  • Yes it is. I just don't know how to integrate that with the the content of the website – Jon_Snow Aug 17 '17 at 16:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.