/** * Change a resumes location data upon editing * @param int $resume_id * @param string $new_location */ public function change_location_data($resume_id, $new_location) { if (apply_filters('resume_manager_geolocation_enabled', true)) { $address_data = WP_Job_Manager_Geocode::get_location_data($new_location); WP_Job_Manager_Geocode::clear_location_data($resume_id); WP_Job_Manager_Geocode::save_location_data($resume_id, $address_data); } }
/** * save_job_listing_data function. * * @access public * @param mixed $post_id * @param mixed $post * @return void */ public function save_job_listing_data($post_id, $post) { global $wpdb; foreach ($this->job_listing_fields() as $key => $field) { // Expirey date if ('_job_expires' == $key) { if (!empty($_POST[$key])) { update_post_meta($post_id, $key, date('Y-m-d', strtotime(sanitize_text_field($_POST[$key])))); } else { update_post_meta($post_id, $key, ''); } continue; } elseif ('_job_location' == $key) { if (update_post_meta($post_id, $key, sanitize_text_field($_POST[$key]))) { do_action('job_manager_job_location_edited', $post_id, sanitize_text_field($_POST[$key])); } elseif (apply_filters('job_manager_geolocation_enabled', true) && !WP_Job_Manager_Geocode::has_location_data($post_id)) { WP_Job_Manager_Geocode::generate_location_data($post_id, sanitize_text_field($_POST[$key])); } } else { if (isset($_POST[$key])) { if (is_array($_POST[$key])) { update_post_meta($post_id, $key, array_map('sanitize_text_field', $_POST[$key])); } else { update_post_meta($post_id, $key, sanitize_text_field($_POST[$key])); } } elseif (!empty($field['type']) && $field['type'] == 'checkbox') { update_post_meta($post_id, $key, 0); } } } }
/** * Save Resume Meta * * @param mixed $post_id * @param mixed $post */ public function save_resume_data($post_id, $post) { global $wpdb; // These need to exist add_post_meta($post_id, '_featured', 0, true); foreach ($this->resume_fields() as $key => $field) { // Expirey date if ('_resume_expires' === $key) { if (!empty($_POST[$key])) { update_post_meta($post_id, $key, date('Y-m-d', strtotime(sanitize_text_field($_POST[$key])))); } else { update_post_meta($post_id, $key, ''); } } elseif ('_candidate_location' === $key) { if (update_post_meta($post_id, $key, sanitize_text_field($_POST[$key]))) { do_action('resume_manager_candidate_location_edited', $post_id, sanitize_text_field($_POST[$key])); } elseif (apply_filters('resume_manager_geolocation_enabled', true) && !WP_Job_Manager_Geocode::has_location_data($post_id)) { WP_Job_Manager_Geocode::generate_location_data($post_id, sanitize_text_field($_POST[$key])); } continue; } elseif ('_resume_author' === $key) { $wpdb->update($wpdb->posts, array('post_author' => $_POST[$key] > 0 ? absint($_POST[$key]) : 0), array('ID' => $post_id)); } else { $type = !empty($field['type']) ? $field['type'] : ''; switch ($type) { case 'textarea': update_post_meta($post_id, $key, wp_kses_post(stripslashes($_POST[$key]))); break; case 'checkbox': if (isset($_POST[$key])) { update_post_meta($post_id, $key, 1); } else { update_post_meta($post_id, $key, 0); } break; default: if (is_array($_POST[$key])) { update_post_meta($post_id, $key, array_filter(array_map('sanitize_text_field', $_POST[$key]))); } else { update_post_meta($post_id, $key, sanitize_text_field($_POST[$key])); } break; } } } $save_repeated_fields = array('_links' => $this->resume_links_fields(), '_candidate_education' => $this->resume_education_fields(), '_candidate_experience' => $this->resume_experience_fields()); foreach ($save_repeated_fields as $meta_key => $fields) { $this->save_repeated_row($post_id, $meta_key, $fields); } }
/** * After importing via WP ALL Import, add default meta data * @param int $post_id */ public function pmxi_saved_post($post_id) { if ('job_listing' === get_post_type($post_id)) { $this->maybe_add_default_meta_data($post_id); if (!WP_Job_Manager_Geocode::has_location_data($post_id) && ($location = get_post_meta($post_id, '_job_location', true))) { WP_Job_Manager_Geocode::generate_location_data($post_id, $location); } } }
/** * save_job_listing_data function. * * @access public * @param mixed $post_id * @param mixed $post * @return void */ public function save_job_listing_data($post_id, $post) { global $wpdb; // These need to exist add_post_meta($post_id, '_filled', 0, true); add_post_meta($post_id, '_featured', 0, true); // Save fields foreach ($this->job_listing_fields() as $key => $field) { // Expirey date if ('_job_expires' === $key) { if (!empty($_POST[$key])) { update_post_meta($post_id, $key, date('Y-m-d', strtotime(sanitize_text_field($_POST[$key])))); } else { update_post_meta($post_id, $key, ''); } } elseif ('_job_location' === $key) { if (update_post_meta($post_id, $key, sanitize_text_field($_POST[$key]))) { // Location data will be updated by hooked in methods } elseif (apply_filters('job_manager_geolocation_enabled', true) && !WP_Job_Manager_Geocode::has_location_data($post_id)) { WP_Job_Manager_Geocode::generate_location_data($post_id, sanitize_text_field($_POST[$key])); } } elseif ('_job_author' === $key) { $wpdb->update($wpdb->posts, array('post_author' => $_POST[$key] > 0 ? absint($_POST[$key]) : 0), array('ID' => $post_id)); } elseif ('_application' === $key) { update_post_meta($post_id, $key, sanitize_text_field(urldecode($_POST[$key]))); } else { $type = !empty($field['type']) ? $field['type'] : ''; switch ($type) { case 'textarea': update_post_meta($post_id, $key, wp_kses_post(stripslashes($_POST[$key]))); break; case 'checkbox': if (isset($_POST[$key])) { update_post_meta($post_id, $key, 1); } else { update_post_meta($post_id, $key, 0); } break; default: if (!isset($_POST[$key])) { continue; } elseif (is_array($_POST[$key])) { update_post_meta($post_id, $key, array_filter(array_map('sanitize_text_field', $_POST[$key]))); } else { update_post_meta($post_id, $key, sanitize_text_field($_POST[$key])); } break; } } } }
/** * Create an array of all of the points found. * * @since Jobify 1.0 * * @return void */ public function json_points() { $points = array(); while ($this->jobs->have_posts()) { $this->jobs->the_post(); $job = get_post(); if (!$job->geolocation_lat) { if (!class_exists('WP_Job_Manager_Geocode')) { continue; } $address_data = WP_Job_Manager_Geocode::get_location_data($job->_job_location); if (!is_wp_error($address_data) && $address_data) { foreach ($address_data as $key => $value) { if ($value) { update_post_meta($job->ID, 'geolocation_' . $key, $value); } } } } $points[] = array('job' => $job->ID, 'location' => array($job->geolocation_lat, $job->geolocation_long), 'permalink' => get_permalink(get_post()->ID), 'title' => sprintf(_x('%s at %s', 'Job title at Company Name', 'jobify'), get_post_field('post_title', get_post()->ID), get_the_company_name(get_post()->ID))); } return $points; }
/** * Convert all the jobs */ public function process_jobs() { $jobs = get_posts(array('posts_per_page' => -1, 'post_type' => 'job_listing', 'post_status' => 'publish', 'fields' => 'ids')); foreach ($jobs as $job_id) { // Already converted if (get_post_meta($job_id, '_job_location', true) || !get_post_meta($job_id, '_Company', true)) { $this->skipped++; continue; } // Convert it $company_name = get_post_meta($job_id, '_Company', true); $company_website = get_post_meta($job_id, '_CompanyURL', true); $expiry_date = get_post_meta($job_id, '_expires', true); $company_logo = ''; $address = get_post_meta($job_id, 'geo_address', true); if ($address) { $location = $address; } else { $location = ''; } if (has_post_thumbnail($job_id)) { $thumb = wp_get_attachment_image_src(get_post_thumbnail_id($job_id), 'full'); $company_logo = $thumb[0]; } $how_to_apply = get_post_meta($job_id, '_how_to_apply', true); preg_match_all('/(http|https|ftp|ftps)\\:\\/\\/[a-zA-Z0-9\\-\\.]+\\.[a-zA-Z]{2,3}(\\/\\S*)?/', $how_to_apply, $url_matches); preg_match_all('/[a-z0-9_\\-\\+]+@[a-z0-9\\-]+\\.([a-z]{2,3})(?:\\.[a-z]{2})?/i', $how_to_apply, $email_matches); if (sizeof($email_matches[0]) > 0) { $apply = current($email_matches[0]); } elseif (sizeof($url_matches[0]) > 0) { $apply = current($url_matches[0]); } else { $apply = ''; } add_post_meta($job_id, '_company_name', $company_name); update_post_meta($job_id, '_company_website', $company_website); add_post_meta($job_id, '_company_logo', $company_logo); add_post_meta($job_id, '_featured', 0); add_post_meta($job_id, '_filled', 0); add_post_meta($job_id, '_company_tagline', ''); add_post_meta($job_id, '_company_twitter', ''); add_post_meta($job_id, '_job_location', $location); update_post_meta($job_id, '_application', $apply); if ($expiry_date) { add_post_meta($job_id, '_job_expires', date('Y-m-d', $expiry_date)); } if ($location) { WP_Job_Manager_Geocode::generate_location_data($job_id, $location); } printf('<p>' . __('<strong>%s</strong> product was converted', 'wp-job-manager-jobroller-import') . '</p>', get_the_title($job_id)); $this->converted++; } printf('<p>' . __('<strong>Done</strong>. Converted %d jobs and skipped %d.', 'wp-job-manager-jobroller-import') . '</p>', $this->converted, $this->skipped); }
/** * Save Resume Meta * * @param mixed $post_id * @param mixed $post */ public function save_resume_data($post_id, $post) { global $wpdb; // These need to exist add_post_meta($post_id, '_featured', 0, true); foreach ($this->resume_fields() as $key => $field) { // Expirey date if ('_resume_expires' === $key) { if (!empty($_POST[$key])) { update_post_meta($post_id, $key, date('Y-m-d', strtotime(sanitize_text_field($_POST[$key])))); } else { update_post_meta($post_id, $key, ''); } } elseif ('_candidate_location' === $key) { if (update_post_meta($post_id, $key, sanitize_text_field($_POST[$key]))) { do_action('resume_manager_candidate_location_edited', $post_id, sanitize_text_field($_POST[$key])); } elseif (apply_filters('resume_manager_geolocation_enabled', true) && !WP_Job_Manager_Geocode::has_location_data($post_id)) { WP_Job_Manager_Geocode::generate_location_data($post_id, sanitize_text_field($_POST[$key])); } continue; } elseif ('_resume_author' === $key) { $wpdb->update($wpdb->posts, array('post_author' => $_POST[$key] > 0 ? absint($_POST[$key]) : 0), array('ID' => $post_id)); } else { $type = !empty($field['type']) ? $field['type'] : ''; switch ($type) { case 'textarea': update_post_meta($post_id, $key, wp_kses_post(stripslashes($_POST[$key]))); break; case 'checkbox': if (isset($_POST[$key])) { update_post_meta($post_id, $key, 1); } else { update_post_meta($post_id, $key, 0); } break; default: if (is_array($_POST[$key])) { update_post_meta($post_id, $key, array_filter(array_map('sanitize_text_field', $_POST[$key]))); } else { update_post_meta($post_id, $key, sanitize_text_field($_POST[$key])); } break; } } } // Education $candidate_education = array(); $locations = isset($_POST['resume_education_location']) ? $_POST['resume_education_location'] : array(); $qualifications = isset($_POST['resume_education_qualification']) ? $_POST['resume_education_qualification'] : array(); $dates = isset($_POST['resume_education_date']) ? $_POST['resume_education_date'] : array(); $notes = isset($_POST['resume_education_notes']) ? $_POST['resume_education_notes'] : array(); foreach ($locations as $index => $location) { if (!empty($location) && !empty($qualifications[$index]) && !empty($dates[$index])) { $candidate_education[] = array('location' => sanitize_text_field(stripslashes($location)), 'qualification' => sanitize_text_field(stripslashes($qualifications[$index])), 'date' => sanitize_text_field(stripslashes($dates[$index])), 'notes' => wp_kses_post(stripslashes($notes[$index]))); } } update_post_meta($post_id, '_candidate_education', $candidate_education); // Education $candidate_experience = array(); $employers = isset($_POST['resume_experience_employer']) ? $_POST['resume_experience_employer'] : array(); $job_titles = isset($_POST['resume_experience_job_title']) ? $_POST['resume_experience_job_title'] : array(); $dates = isset($_POST['resume_experience_date']) ? $_POST['resume_experience_date'] : array(); $notes = isset($_POST['resume_experience_notes']) ? $_POST['resume_experience_notes'] : array(); foreach ($employers as $index => $employer) { if (!empty($employer) && !empty($job_titles[$index]) && !empty($dates[$index])) { $candidate_experience[] = array('employer' => sanitize_text_field(stripslashes($employer)), 'job_title' => sanitize_text_field(stripslashes($job_titles[$index])), 'date' => sanitize_text_field(stripslashes($dates[$index])), 'notes' => wp_kses_post(stripslashes($notes[$index]))); } } update_post_meta($post_id, '_candidate_experience', $candidate_experience); // URLS $links = array(); $resume_url_names = isset($_POST['resume_url_name']) ? $_POST['resume_url_name'] : array(); $resume_urls = isset($_POST['resume_url']) ? $_POST['resume_url'] : array(); foreach ($resume_url_names as $index => $name) { if (!empty($name) && !empty($resume_urls[$index])) { $links[] = array('name' => sanitize_text_field(stripslashes($name)), 'url' => sanitize_text_field(stripslashes($resume_urls[$index]))); } } update_post_meta($post_id, '_links', $links); }