functions.php
functions.php
<?php
// ^ there should only be one of these at the very top of your functions.php file.
// Omit the <?php above if adding this code to the bottom of your functions.php file (and one exists already at the top)
// Add one filter before Field Editor to make sure required shows as disabled in list table
add_filter( 'submit_job_form_fields', 'smyles_set_job_description_not_required', 99 );
// Add another one to actually set the value after Field Editor updates fields
add_filter( 'submit_job_form_fields', 'smyles_set_job_description_not_required', 101 );
function smyles_set_job_description_not_required( $fields ){
if( is_array( $fields ) && ! empty( $fields['job'] ) ){
if( ! empty( $fields['job']['job_description'] ) ){
$fields['job']['job_description']['required'] = false;
}
}
return $fields;
}
// This filter handles preventing fatal error from empty value in post_content
add_filter( 'submit_job_form_save_job_data', 'submit_listing_allow_empty_job_description', 99999, 5 );
/**
* Allow empty Listing Description (job_description) field in WP Job Manager
*
* If you're using the Field Editor plugin, and want to configure the Description (job_description meta key) field
* to only show for specific packages, you will need this code to prevent a white screen of death, as the core
* WP Job Manager plugin requires this value to not be NULL. This function will filter the core WP Job Manager
* job data, and set the post_content (used for job_description meta key) to an empty string, instead of NULL.
*
*
* @param $job_data
* @param $post_title
* @param $post_content
* @param $status
* @param $values
*
* @return mixed
*/
function submit_listing_allow_empty_job_description( $job_data, $post_title, $post_content, $status, $values ){
/**
* If we disabled the job_description meta key field, the post_content value will be NULL,
* so we set it to an empty string to prevent any fatal PHP errors.
*/
if( $job_data['post_content'] === NULL ) {
$job_data['post_content'] = '';
}
return $job_data;
}