Esempio n. 1
0
 private function add_new_user($post)
 {
     $new_user_id = wp_insert_user(array('user_login' => $post['username'], 'user_pass' => $post['password'], 'user_email' => $post['email'], 'first_name' => $post['first_name'], 'last_name' => $post['last_name'], 'user_url' => $post['website'], 'description' => $post['description'], 'user_registered' => date('Y-m-d H:i:s'), 'role' => $post['role']));
     if (!is_wp_error($new_user_id)) {
         global $wpdb;
         add_user_meta($new_user_id, 'company_name', $post['company_name']) or update_user_meta($new_user_id, 'company_name', $post['company_name']);
         add_user_meta($new_user_id, 'mobile', $post['mobile']) or update_user_meta($new_user_id, 'mobile', $post['mobile']);
         add_user_meta($new_user_id, 'phone', $post['phone']) or update_user_meta($new_user_id, 'phone', $post['phone']);
         $city = $_POST['city'];
         $group = $_POST['group'];
         $category = $_POST['category'];
         $company_name = $_POST['company_name'];
         $group_slug = sanitize_title($group);
         $category_slug = sanitize_title($category);
         $other_categories = (array) (!empty($_POST['categories']) ? $_POST['categories'] : array());
         $company_id = $wpdb->get_var("SELECT ID FROM wp_posts WHERE post_title = '" . $company_name . "'");
         if (!empty($company_name) && !$company_id) {
             $company_id = wp_insert_post(array('post_title' => $company_name, 'post_author' => $new_user_id, 'post_type' => sanitize_title($post['role']), 'post_status' => 'publish'));
             update_user_meta($new_user_id, 'company', $company_id);
         }
         $tax = $post['role'] == 'vendor' ? $city : 'venue-category';
         // Remove existing post and term relationships
         $old_tax = get_post_meta($company_id, $tax, true);
         wp_delete_object_term_relationships($company_id, $old_tax);
         if (count($other_categories) > 0) {
             $terms = array();
             foreach ($other_categories as $term_title) {
                 if (empty($term_title)) {
                     continue;
                 }
                 $term_slug = sanitize_title($term_title);
                 if (!($term = term_exists($term_title, $tax))) {
                     $term = wp_insert_term($term_title, $tax, array('slug' => $term_slug));
                 }
                 if (!is_wp_error($term)) {
                     $terms[] = $term['term_id'];
                 }
             }
             wp_set_post_terms($company_id, $terms, $tax, false);
         }
         // Update custom permalink
         update_post_meta($company_id, 'custom_permalink', $city . '/' . $group_slug . '/' . $category_slug . '/' . sanitize_title($company_name));
         // Update Post Meta
         update_post_meta($company_id, 'vendor', $new_user_id);
         update_post_meta($company_id, 'region', $group_slug);
         update_post_meta($company_id, 'city', $city);
         if ($post['role'] == 'vendor') {
             update_post_meta($company_id, 'category', $category_slug);
         } else {
             update_post_meta($company_id, 'main_category', $category_slug);
         }
         // Update user meta
         update_user_meta($new_user_id, 'city', $city);
         update_user_meta($new_user_id, 'group', $group_slug);
         update_user_meta($new_user_id, 'category', $category_slug);
         // Update registration code to inactive
         WEPN_Admin_Settings::set_used_reg_code($post['registration_code']);
         // Logged In user once registered
         wp_set_current_user($new_user_id, $post['username']);
         wp_set_auth_cookie($new_user_id);
         do_action('wp_login', $post['username']);
         exit(wp_redirect(home_url('/wp-admin/profile.php')));
     } else {
         WEPN_Notify::add($new_user_id->errors, 'error');
     }
 }
Esempio n. 2
0
 private function min($key, $min)
 {
     $val = $this->input[$key];
     if (strlen($val) < $min) {
         WEPN_Notify::add(ucfirst(str_replace('_', ' ', $key)) . ' minimum length is ' . $min, 'error');
     }
 }