Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Custom Registration
- Plugin URI: https://www.corewaysolution.com/
- Description: Custom Registration
- Version: 1.0
- Author: Sehjad Ansari
- Author URI: Custom Registration
- */
- add_action('wp_enqueue_scripts','ava_test_init');
- function ava_test_init() {
- wp_enqueue_script( 'plugin_reg', plugins_url( 'plugin_reg.js', __FILE__ ));
- wp_enqueue_script( 'validate_reg', plugins_url( 'validate_reg.js', __FILE__ ));
- }
- function registration_form( $username, $password, $email) {
- echo '
- <style>
- div {
- margin-bottom:2px;
- }
- input{
- margin-bottom:4px;
- }
- </style>
- ';
- echo '<div id="loadingimage" class="loadingimage" style="display: none;">
- <div id="loadingimage1" class="loadingimage1"> <img src="http://192.168.1.53/stockfocus/wp-content/themes/strokefocus/images/loading.gif"> </div>
- </div>';
- echo '
- <form action="' . $_SERVER['REQUEST_URI'] . '" method="post" name="custome_ragistrion">
- <div>
- <input type="text" name="username" value="' . ( isset( $_POST['username'] ) ? $username : null ) . '" placeholder="*username">
- </div>
- <div>
- <input type="password" name="password" value="' . ( isset( $_POST['password'] ) ? $password : null ) . '" placeholder="*Password">
- </div>
- <div>
- <input type="text" name="email" value="' . ( isset( $_POST['email']) ? $email : null ) . '" placeholder="*Email">
- </div>
- <input type="submit" name="submit" value="Register" class="custome_submit"/>
- </form>
- ';
- }
- function registration_validation( $username, $password, $email/*, $website, $first_name, $last_name, $nickname, $bio*/ ) {
- global $reg_errors;
- $reg_errors = new WP_Error;
- if ( empty( $username ) || empty( $password ) || empty( $email ) ) {
- $reg_errors->add('field', 'Required form field is missing');
- }
- if ( 4 > strlen( $username ) ) {
- $reg_errors->add( 'username_length', 'Username too short. At least 4 characters is required' );
- }
- if ( username_exists( $username ) )
- $reg_errors->add('user_name', 'Sorry, that username already exists!');
- if ( ! validate_username( $username ) ) {
- $reg_errors->add( 'username_invalid', 'Sorry, the username you entered is not valid' );
- }
- if ( 5 > strlen( $password ) ) {
- $reg_errors->add( 'password', 'Password length must be greater than 5' );
- }
- if ( !is_email( $email ) ) {
- $reg_errors->add( 'email_invalid', 'Email is not valid' );
- }
- if ( email_exists( $email ) ) {
- $reg_errors->add( 'email', 'Email Already in use' );
- }
- /*if ( ! empty( $website ) ) {
- if ( ! filter_var( $website, FILTER_VALIDATE_URL ) ) {
- $reg_errors->add( 'website', 'Website is not a valid URL' );
- }
- }
- */
- if ( is_wp_error( $reg_errors ) ) {
- foreach ( $reg_errors->get_error_messages() as $error ) {
- echo '<div>';
- echo '<strong>ERROR</strong>:';
- echo $error . '<br/>';
- echo '</div>';
- }
- }
- }
- function complete_registration() {
- global $wpdb;
- global $reg_errors, $username, $password, $email/*, $website, $first_name, $last_name, $nickname, $bio*/;
- if ( 1 > count( $reg_errors->get_error_messages() ) ) {
- $userdata = array(
- 'user_login' => $username,
- 'user_email' => $email,
- 'user_pass' => $password
- );
- $user = wp_insert_user( $userdata );
- /*$from = "d.developer001@gmail.com";
- $to = "d.developer001@gmail.com";
- $subject = "PHP Mail Test script";
- $message = "This is a test to check the PHP Mail functionality";
- $headers = "From:" . $from;
- mail($to,$subject,$message, $headers);
- echo "Test email sent";*/
- wp_update_user( array ('ID' => $user, 'role' => 'pending_user') ) ;
- update_user_meta( $user, 'ihc_user_levels ', 4);
- $table_name = $wpdb->prefix . "ihc_user_levels";
- $wpdb->insert($table_name, array(
- "user_id" => $user,
- "level_id" => 4,
- ));
- $admin_email =get_option('admin_email');
- $to = $admin_email;
- $subject = 'surveyor Ragistration';
- $body = 'username=<b>'.$username.'</b><br>
- email=<b>'.$email.'</b><br>
- password=<b>'.$password.'</b><br>';
- $headers = array('Content-Type: text/html; charset=UTF-8');
- wp_mail( $to, $subject, $body, $headers );
- // echo 'Registration complete. Goto <a href="' . get_site_url() . '/wp-login.php">login page</a>.';
- echo 'Registration complete. Goto ';
- }
- }
- function custom_registration_function() {
- if ( isset($_POST['submit'] ) ) {
- registration_validation(
- $_POST['username'],
- $_POST['password'],
- $_POST['email']
- );
- // sanitize user form input
- global $username, $password, $email/*, $website, $first_name, $last_name, $nickname, $bio*/;
- $username = sanitize_user( $_POST['username'] );
- $password = esc_attr( $_POST['password'] );
- $email = sanitize_email( $_POST['email'] );
- // call @function complete_registration to create the user
- // only when no WP_error is found
- complete_registration(
- $username,
- $password,
- $email
- );
- }
- registration_form(
- $username,
- $password,
- $email
- );
- }
- // Register a new shortcode: [cr_custom_registration]
- add_shortcode( 'cr_custom_registration', 'custom_registration_shortcode' );
- // The callback function that will replace [book]
- function custom_registration_shortcode() {
- ob_start();
- custom_registration_function();
- return ob_get_clean();
- }
Add Comment
Please, Sign In to add comment