Skip to content

Instantly share code, notes, and snippets.

@tripflex
Last active January 24, 2017 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tripflex/c2bfdb855f6516263a9825dbacbedea4 to your computer and use it in GitHub Desktop.
Save tripflex/c2bfdb855f6516263a9825dbacbedea4 to your computer and use it in GitHub Desktop.
Allow empty Listing Description (job_description) field in WP Job Manager (to prevent white screen of death)
<?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;
}
@tripflex
Copy link
Author

You can find this same code for Resumes here:
https://gist.github.com/tripflex/cbb04b5d45d607703a2486c7ba6c8acd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment