SHARE
TWEET

Untitled

a guest Oct 4th, 2017 99 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /**
  3. * Template Name: New Parent
  4. */
  5.  
  6. function specs_parent_register() {
  7.   if( $_SERVER['REQUEST_METHOD'] == 'POST' && !empty( $_POST['action'] ) &&  $_POST['action'] == "new_parent_post") {
  8.  
  9.     if (!isset($_POST['first-name'] ) ) {
  10.       $firstNameErr = "Your First Name is required.";
  11.     } else {
  12.       $first_name = sanitize_text_field($_POST['first-name']);
  13.     }
  14.  
  15.     if (!isset($_POST['last-name'] ) ) {
  16.       $lastNameErr = "Your Last Name is required.";
  17.     } else {
  18.       $last_name = sanitize_text_field($_POST['last-name']);
  19.     }
  20.  
  21.     if (!isset($_POST['parent-username'] ) ) {
  22.       $usernameErr = "A username is required.";
  23.     } else {
  24.       $parent_username = sanitize_text_field($_POST['parent-username']);
  25.     }
  26.  
  27.     if (!isset($_POST['parent-pass'] ) ) {
  28.       $passwordErr = "A password is required.";
  29.     } else {
  30.       $parent_pass = sanitize_text_field($_POST['parent-pass']);
  31.     }
  32.  
  33.     if (!isset($_POST['parent-email'] ) ) {
  34.       $emailErr = "An email address is required.";
  35.     } else {
  36.       $parent_email = sanitize_email($_POST['parent-email']);
  37.     }
  38.  
  39.     $parent_name = $first_name . ' ' . $last_name;
  40.  
  41.     $new_parent_post = array(
  42.       'post_title' => $parent_name,
  43.       'post_name' => $parent_username,
  44.       'post_content' => '',
  45.       'post_status' => 'publish',
  46.       'post_type' => 'parent'
  47.     );
  48.  
  49.     $pid = wp_insert_post($new_parent_post);
  50.  
  51.     $parent_data = array (
  52.       'first_name' => $first_name,
  53.       'last_name' => $last_name,
  54.       'user_login' => $parent_username,
  55.       'user_pass' => $parent_pass,
  56.       'user_email' => $parent_email,
  57.       'display_name' => $parent_name,
  58.       'role' => 'parent'
  59.     );
  60.  
  61.     $parent_user_id = wp_insert_user( $parent_data );
  62.   }
  63.  
  64.     ?>
  65.           <div>
  66.             <form id="new-parent-post" name="new-parent-post" method="post" action="">
  67.               <p><label for="first-name">First Name <span class="form-error">* <?php echo $firstNameErr; ?> </span></label>
  68.                 <input type="text" id="first-name" name="first-name" size="20" />
  69.               </p>
  70.  
  71.               <p><label for="last-name">Last Name <span class="form-error">* <?php echo $lastNameErr; ?> </span></label>
  72.                 <input type="text" id="last-name" name="last-name" size="20" />
  73.               </p>
  74.  
  75.               <p><label for="parent-username">Username <span class="form-error">* <?php echo $usernameErr; ?> </span></label>
  76.                 <input type="text" id="parent-username" name="parent-username" size="20" />
  77.               </p>
  78.  
  79.               <p><label for="parent-pass">Password <span class="form-error">* <?php echo $passwordErr; ?> </span></label>
  80.                 <input type="password"  id="parent-pass" name="parent-pass" size="20" />
  81.               </p>
  82.  
  83.               <p><label for="parent-email">Email <span class="form-error">* <?php echo $emailErr; ?> </span></label>
  84.                 <input type="email" id="parent-email" name="parent-email" size="20" />
  85.               </p>
  86.  
  87.               <p align="right"><input type="submit" value="Create User" id="submit" name="submit" /></p>
  88.               <input type="hidden" name="action" value="new_parent_post" />
  89.               <?php wp_nonce_field( 'new-parent-nonce' ); ?>
  90.             </form>
  91.           </div>
  92.   <?php
  93. }
  94. add_action( 'genesis_entry_content', 'specs_parent_register');
  95.  
  96. // Run Genesis loop
  97. genesis();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top