jobrelay_sanitize_meta_value_callback hook

apply_filters( ‘jobrelay_sanitize_meta_value_callback’, $callback string, $post_id int, $meta_key string, $meta_value mixed, $posted_key string, $job_data array )

In this article

Filters the callback used to sanitize meta data before it is saved. The default callback is sanitize_text_field.

Parameters

  • $callback string
    The current post object
  • $post_id int
    Whether this is a update (true) or a save (false)
  • $meta_key string
    The meta key this meta field is saved against
  • $meta_value mixed
    The meta value to be saved for this field
  • $posted_key string
    The key in the job data array for this field
  • $job_data array
    The array of job data sent from the posting provider

More information

Developers can change the sanitization callback that is used to sanitize meta values before they are saved.

Example usage

Saving JobRelay rich text fields as meta data

Saving JobRelay rich text fields as meta data

Sometimes you might have a rich text field (containing things like HTML) sent over from JobRelay as the value of a field.

The best example of this is the job_description field. This contains HTML sometimes with formatting and images etc.

Although by default this is saved as the post_content field for the newly created or updated job, sometimes you theme might require this to be saved as a custom field instead.

All fields by default, have their values sanitized before they are saved. The default function for carrying this out is santiize_text_field. This removes HTML.

To prevent this happening for the job description field, the following code could be used, placing this either in your active themes functions.php file or in a plugin.

<?php
function hd_jobrelay_job_description_sanitize_callback( $callback, $post_id, $meta_key, $posted_key, $job_data ) {

	// if this is not the field with the posted key of job_description.
	if ( 'job_description' !== $posted_key ) {
		return $callback; // return the original callback.
	}

	// return the santized callback name for job description.
	return 'wp_kses_post';

}
add_filter( 'jobrelay_sanitize_meta_value_callback', 'hd_jobrelay_job_description_sanitize_callback', 10, 5 );

All docs

Can’t find what you need?

Our integrations team set up every JobRelay site, so they know it inside out. Get in touch and we’ll help.