开发者

Add new user in user tables Wordpress

i have a custom table in theme to add a the user data to the database. then want to add the data through custom table to the database.

    <form action="" method="post">
    <table>
      <tr>
        <td>User Name:</td>
        <td><input type="text" name="user"/> </td>
      </tr>
      <tr>
        <td>Pass word:</td>
        <td><input type="password" name="pass"/></td>
      </tr>
      <tr>
        <td>Website:</td>
        <td><input type="text" name="url"/></td>
      </tr>
    </table>
        <input type="submit" name="scroll_submit" />
        </form>


<?php 
if(isset($_POST['scroll_submit'])){
  $username = $_POST['user'];
  $pass = $_POST['pass'];
  $url = $_POST['url'];

   wp_insert_user(array(
    'user_pass'  => $pass,
    'user_login' => $username,
    'user_url' => $url
   ));
   }

i can开发者_开发知识库 add 1 record in the user table , but not another... what is problem plz help me..


how about...

 if(isset($_POST['scroll_submit'])){

   $username = $_POST['user'];
   $pass = $_POST['pass'];
   $url = $_POST['url'];
   // YOU NEED AN EMAIL ADDRESS TO CREATE AN ACCOUNT
   $useremail = sanitize_user($_POST['email']); 

   if($pass==''){
      // Generate random 12 Character password
      $pass = wp_generate_password( 12, false );
   }

   // Check if that username is taken already
   if ( username_exists( $username ) ){
     die("Im sorry that Username Is in Use! please choose another");
   }else{
     echo "Username is available...";
   }

   // CREATES WP USER ACCOUNT
   $user_id = wp_create_user( $username, $pass, $useremail );

   // SENDS EMAIL NOTIFICATION
   wp_new_user_notification($user_id, $pass); 

   // Use 'update_user_meta()' to add or update the user information fields.
   update_user_meta($user_id, 'user_url', $url );
   echo "New User Created ID: ".$user_id;
 }

this will check for the password, if there is no password, then generate a 12 character random password, checks to see if that username is taken...

Create the new wp user account, send an email to the admin to let them know that a new user has been created, send an email to the user with the username and password,

Add the user information to the wp_user_meta table using the users new ID number.

the array for a generic user will return :

([ID] => 6
  [user_login] => MyUserName
  [user_pass] => $KJSHDFLUHWSEIFNPOSUDHVSJDN
  [user_nicename] => MyDisplayNicename
  [user_email] => Myemail@yourDomain.com
  [user_url] => 
  [user_registered] => 2011-09-20 10:00:00
  [user_activation_key] => 
  [user_status] => 0
  [display_name] => My Display Name
  [wp_capabilities] => Array
  (
    [subscriber] => 1
  )
  [jabber] => 
  [yim] => 
  [aim] => 
  [show_admin_bar_admin] => false
  [use_ssl] => 0
  [show_admin_bar_front] => true
  [admin_color] => fresh
  [comment_shortcuts] => false
  [rich_editing] => true
  [description] => 
  [nickname] => MyNickName
  [last_name] => 
  [first_name] => 
  [wp_user_level] => 0
  [user_level] => 0
  [user_firstname] => 
  [user_lastname] => 
  [user_description] => 
)

using the update_user_meta($user_id, 'WHATYOUWANTTOCHANGE', $url ); just replace WHATYOUWANTTOCHANGE with the array name ie: user_firstname will update/add a firstname for the user...

update_user_meta($user_id, 'user_firstname', $firstname);
update_user_meta($user_id, 'user_lastname', $lastname);
update_user_meta($user_id, 'user_description', $user_desc);

have a look through the wp reference

also remember to sanitize the user input; to avoid any SQL injections etc, never trust any user input....

always stripslashes, mysql_real_escape_string, htmlspecialchars,

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜