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

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 );