Using JobRelay with the WP Job Manager plugin

If you are using JobRelay with the excellent WP Job Manager plugin, there are a few things you might want to do to increase the compatibility of JobRelay.

Correct the salary_per field

WP Job Manager contains a field labelled salary unit. This is the equivalent field to salary_per. JobRelay sends one of the following in this field.

WP Job Manager saves these values slightly differently, most notably saving the values as UPPERCASE and also using the word “year” instead of “annum”.

To correct this you can use the following code:

<?php
/**
 * Saves the salary per data in the correct format for WP Job Manager.
 *
 * @param  array $job_data The current array of job data passed to the site.
 * @return array $job_data The maybe modified array of job data passed to the site.
 */
function jobrelay_correct_salary_unit_for_wpjm( $job_data ) {

	// if we have no salary per data.
	if ( empty( $job_data['salary_per'] ) ) {
		return $job_data;
	}

	// if the wp job manager plugin is not active.
	if ( ! function_exists( 'WPJM' ) ) {
		return $job_data;
	}

	// if the salary per value is annum.
	if ( 'annum' === $job_data['salary_per'] ) {

		// change the salary per value to year.
		$job_data['salary_per'] = 'year';

	}

	// capitalise the salary per value.
	$job_data['salary_per'] = strtoupper( $job_data['salary_per'] );

	// return the modified job data array.
	return $job_data;

}

add_filter( 'jobrelay_wpcon_job_data', 'jobrelay_correct_salary_unit_for_wpjm', 10, 1 );

You can either place this code in your active themes functions.php file or you could add it into another plugin.

Combine job type and job hours for LogicMelon

LogicMelon send two fields instead of 1 for job type. They send job_type as one field which includes values such as contract, temporary and job_hours as a separate field for things such as full time and part time.

You can combine these together into just job type, to be saved the WP Job Manager job type taxonomy (job_listing_type) using the following code.

<?php
/**
 * Saves the job hours data as job types.
 *
 * @param  array $job_data The current array of job data passed to the site.
 * @return array $job_data The maybe modified array of job data passed to the site.
 */
function jobrelay_save_job_hours_as_job_type( $job_data ) {

	// if we have no job hours.
	if ( empty( $job_data['job_hours'] ) ) {
		return $job_data;
	}

	// if we have job types.
	if ( ! empty( $job_data['job_type'] ) ) {

		// get the value of the job type field.
		$job_types = $job_data['job_type'];

		// turn job types into an array.
		$job_types = explode( '|', $job_types );

	} else {

		// make job types an empty array.
		$job_types = array();

	}

	// turn the job hours into an array.
	$job_hours = explode( '|', $job_data['job_hours'] );

	// merge the job types and job hours arrays.
	$job_types = array_merge( $job_types, $job_hours );

	// set the value of job types.
	$job_data['job_type'] = implode( '|', $job_types );
	
	// return the modified data.
	return $job_data;

}

add_filter( 'jobrelay_wpcon_job_data', 'jobrelay_save_job_hours_as_job_type' );

You can either place this code in your active themes functions.php file or you could add it into another plugin.