/** * Imports a talent into the site based on their WordPress.org username. * @return int|WP_Error Post ID on success, WP_Error object otherwise. */ public function import() { if (!post_type_exists($this->type)) { return new WP_Error('invalid_post_type', sprintf(__('Invalid post type "%s"!', 'wptalents'), $this->type)); } $query = new WP_Query(array('post_type' => $this->type, 'post_status' => 'any', 'meta_key' => 'wordpress-username', 'meta_value' => $this->username, 'posts_per_page' => 1)); if ($query->have_posts()) { return new WP_Error('already_exists', sprintf(__('Talent already exists! (ID: %d)', 'wptalents'), $query->posts[0]->ID)); } $post_id = wp_insert_post(array('post_title' => $this->name, 'post_type' => $this->type)); if (0 === $post_id || is_wp_error($post_id)) { return new WP_Error('insert_failed', sprintf(__('Importing %s failed!', 'wptalents'), $this->name)); } update_post_meta($post_id, 'wordpress-username', $this->username); $collector = new Profile_Collector(get_post($post_id)); $collector->_retrieve_data(); $collector = new Gravatar_Collector(get_post($post_id)); $collector->_retrieve_data(); return $post_id; }