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.

Table of Contents

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.

Set remote positions

The feed of data to your site includes a field called working_arrangement. The value of this field with either be Remote, Hybrid or Office Based.

WP Job Manager includes a checkbox for a remote position and when checked it saves the value to meta data using the meta key of _remote_position.

The ensure this works correctly, if the value sent is Remote we need to make sure that this is converted to a 1.

The code below will ensure this happens and the remote position is marked correctly in the WP Job Manager plugin.

<?php
/**
 * Saves the remote position if the working arrangement value is remote.
 *
 * @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 hd_jobrelay_maybe_set_wpjm_remote_position( $job_data ) {

	// if we don't have a working arrangement field.
	if ( empty( $job_data['working_arrangement'] ) ) {
		return $job_data;
	}

	// if the working arrangement field value is "Remote".
	if ( "Remote" === $job_data['working_arrangement'] ) {

		// set the working arrange value to 1.
		$job_data['working_arrangement'] = 1;

	} else {

		// make sure remote is not saved.
		$job_data['working_arrangement'] = 0;

	}

	// return the job data.
	return $job_data;

}

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

/**
 * Removes the remote position if the working arrangement value is not remote.
 *
 * @param integer $job_post_id The ID of the newly created job post.
 * @param array   $job_data    The array of job data sent to the site.
 */
function hd_jobrelay_maybe_remove_wpjm_remote_value( $job_post_id, $job_data ) {

	// if working arrangement is not present.
	if ( ! isset( $job_data['working_arrangement'] ) ) {
		return;
	}

	// if working arrange is not remote.
	if ( 'Remote' !== $job_data['working_arrangement'] ) {
		
		// update the remote position meta to reflect not a remote position.
		update_post_meta( $job_post_id, '_remote_position', 0 );

	}

}

add_action( 'jobrelay_wpcon_job_inserted_complete', 'hd_jobrelay_maybe_remove_wpjm_remote_value', 10, 2 );