HEX
Server: Apache
System: Linux server1.panigaletech.com 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64
User: ubuntu (1000)
PHP: 7.4.30
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/panigaletech.com/wp-content/themes/panigale/template-parts/get_allcandidate_and_save.php
<?php
/**
 * Template Name: Get All Candidate And Save
 *
 * @package WordPress
 * @subpackage Twenty_Fourteen
 * @since Twenty Fourteen 1.0
 */
 ini_set('max_execution_time', 900000);
set_time_limit(0);
global $wpdb;
 $client_secret = 'MpZixnLHV6sAFGZUA8M0QwJw';
 $client_id = 'edf1089c-c6a7-43a1-a6ed-7f85c0cd7fe2';
 
$table_name = "bullhorn_token";
$token_details = $wpdb->get_results( "SELECT * FROM $table_name ORDER BY i_id DESC LIMIT 1" );
 
/****  Get Access Token From Refresh Token start ****/

$refresh_token = $token_details[0]->s_refresh_token;

$token_url = 'https://auth.bullhornstaffing.com/oauth/token?grant_type=refresh_token&refresh_token='.$refresh_token.'&client_id='.$client_id.'&client_secret='.$client_secret.'';
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch,CURLOPT_URL, $token_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_POST, '1');
//execute post
$token_result = curl_exec($ch);
//close connection
curl_close($ch);

$token_result_arr = json_decode($token_result);
$access_token = $token_result_arr->access_token;
$new_refresh_token = $token_result_arr->refresh_token;
//print_r($token_result_arr);
$table = 'bullhorn_token';
$data = array('s_access_token' => $access_token, 's_refresh_token' => $new_refresh_token,'dt_created_date'=>date('Y-m-d H:i:s'));
$wpdb->insert($table,$data);
unset($ch);
/****  Get Access Token From Refresh Token end ****/


/****  Create BHRestToken start ****/

$bhrest_token_url = 'https://rest.bullhornstaffing.com/rest-services/login?version=*&access_token='.$access_token.'';
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch,CURLOPT_URL, $bhrest_token_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
//execute post
$bhrest_token_result = curl_exec($ch);
//close connection
curl_close($ch);

$bhrest_token_result_arr = json_decode($bhrest_token_result);
$bhrest_token 	= $bhrest_token_result_arr->BhRestToken;
$rest_url 		= $bhrest_token_result_arr->restUrl;
unset($ch);
/****  Create BHRestToken end ****/


/****  Get All Job start ****/

$job_api_url = $rest_url.'search/Candidate?query=isDeleted:0&BhRestToken='.$bhrest_token.'&fields=id,email,firstName,lastName&start=0&count=600';
#$job_api_url = $rest_url.'search/Candidate?query=firstName:"Christopher" AND lastName:"Morgan"AND email:"christoper.morgan@gmail.com"&BhRestToken='.$bhrest_token.'&fields=*';
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch,CURLOPT_URL, $job_api_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
//execute post
$candidate_result = curl_exec($ch);
//close connection
curl_close($ch);

$candidate_result_arr = json_decode($candidate_result);
echo '<pre>';print_r($candidate_result_arr);echo '<pre>';exit;

/****  Get All Candidate end ****/
$total_candidate = $job_result_arr->total;
if($total_jobs >0)
{
	$all_job_data = $job_result_arr->data;
	foreach($all_job_data as $all_job_data_val)
	{
		$job_id = $all_job_data_val->id;
		$full_address = $all_job_data_val->address;
		$address1 = $full_address->address1;
		$city = $full_address->city;
		$state = $full_address->state;
		$zip = $full_address->zip;
		$country_id = $full_address->countryID;
		$country_name = $full_address->countryName;
		
		$description = $all_job_data_val->description;
		$occupation = $all_job_data_val->occupation;
		$owner_name = $all_job_data_val->owner->firstName.' '.$all_job_data_val->owner->lastName;
		
		
		$my_post = array(
		  'post_title'    => $occupation,
		  'post_content'  => '',
		  'post_status'   => 'publish',
		  'post_author'   => 1,
		  'post_type' => 'jobs'
		);
		//print_r($my_post);
		// Insert the post into the database
		$wp_job_id = wp_insert_post( $my_post );
		
		add_post_meta( $wp_job_id, 'id', $job_id, true );
		add_post_meta( $wp_job_id, 'address1', $address1, true );
		add_post_meta( $wp_job_id, 'owner_name', $owner_name, true );
		add_post_meta( $wp_job_id, 'description', $description, true );
		add_post_meta( $wp_job_id, 'city', $city, true );
		add_post_meta( $wp_job_id, 'state', $state, true );
		add_post_meta( $wp_job_id, 'zip', $zip, true );
		add_post_meta( $wp_job_id, 'country', $country_id, true );
		add_post_meta( $wp_job_id, 'full_data', $all_job_data_val, true );
		
		unset($my_post);
	}
	
}
?>