Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- global $wp;
- global $bp;
- function makeEmpAvatar($url, $user_id)
- {
- $site_url = site_url();
- $upload_dir = wp_upload_dir();
- $jobavatars_dirname = $upload_dir['basedir'] . "/wp-jobhunt-users";
- wp_mkdir_p($jobavatars_dirname);
- $ar_filename = explode("/", $url);
- $tmp_filename = array_pop($ar_filename);
- $filename_dir = $ar_filename[count($ar_filename) - 1];
- $hshd_name = stp_filename_hash($tmp_filename, $filename_dir);
- $source = $url;
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $source);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- $data = curl_exec($ch);
- $error = curl_error($ch);
- curl_close($ch);
- echo $error;
- $destination = $jobavatars_dirname . '/' . $hshd_name;
- $file = fopen($destination, "w+");
- fputs($file, $data);
- fclose($file);
- $file_url = $upload_dir['baseurl'] . "/wp-jobhunt-users/" . $hshd_name;
- /*INSERTING INTO MEDIALIBRARY*/
- // $filename should be the path to a file in the upload directory.
- $filename = $destination;
- // Check the type of file. We'll use this as the 'post_mime_type'.
- $filetype = wp_check_filetype(basename($filename), null);
- // Get the path to the upload directory.
- $wp_upload_dir = wp_upload_dir();
- // Prepare an array of post data for the attachment.
- $attachment = array(
- 'guid' => $file_url,
- 'post_mime_type' => $filetype['type'],
- 'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)),
- 'post_content' => '',
- //'post_author' => $user_id,
- 'post_status' => 'inherit',
- );
- // Insert the attachment.
- $attach_id = wp_insert_attachment($attachment, $filename, 0);
- // Make sure that this file is included, as wp_generate_attachment_metadata() depends on it.
- require_once ABSPATH . 'wp-admin/includes/image.php';
- // Generate the metadata for the attachment, and update the database record.
- $attach_data = wp_generate_attachment_metadata($attach_id, $filename);
- wp_update_attachment_metadata($attach_id, $attach_data);
- /*END INSERTING INTO MEDIALIBRARY*/
- $info = pathinfo($hshd_name);
- $avatar_filename = basename($hshd_name, '.' . $info['extension']);
- $ava_thumb = $avatar_filename . "-270x203." . $info['extension'];
- update_user_meta($user_id, 'user_img', $ava_thumb);
- return $ava_thumb;
- }
- function get_remote_employers()
- {
- $url = "https://api.utmn.ru/prof/companies/";
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_URL, $url);
- $result = curl_exec($ch);
- curl_close($ch);
- $res = json_decode($result);
- //create_success_category();
- $cntr = 0;
- foreach ($res as $key => $user) {
- $random_password = wp_generate_password(12, false);
- //$login = substr(trnslt($user->name), 0, 1) . "." . trnslt($user->last_name);
- $tmp_login = trnslt($user->work_company);
- $ar_tmp_login = explode(" ", $tmp_login);
- if (count($ar_tmp_login)>1) {
- $login = $user->work_email;
- }else{
- $login = $tmp_login;
- }
- $user_id = wp_create_user($login, $random_password, $user->work_email);
- $args = array(
- 'ID' => $user_id,
- //'display_name' => $user->name." ".$user->last_name,
- 'display_name' => $user->work_company,
- 'first_name' => $user->name,
- 'last_name' => $user->last_name,
- 'role' => 'cs_employer',
- );
- wp_update_user($args);
- update_user_meta($user_id, 'cs_user_last_activity_date', time());
- update_user_meta($user_id, 'cs_user_status', 'active');
- update_user_meta($user_id, 'cs_phone_number', $user->work_phone);
- update_user_meta($user_id, 'cs_work_company', $user->work_company);
- update_user_meta($user_id, 'site_url', $user->work_www);
- update_user_meta($user_id, 'description', $user->work_profile);
- update_user_meta($user_id, 'position', $user->work_position);
- update_user_meta($user_id, 'remote_id', $user->id);
- $url = $user->work_logo;
- makeEmpAvatar($url, $user_id);
- $cntr++;
- echo "User created. User Id #" . $user_id . "\n";
- }
- }
- get_remote_employers();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement