Created
August 31, 2020 21:39
-
-
Save tripflex/98ed3200b15079fee85eb9b39dc78001 to your computer and use it in GitHub Desktop.
Set candidate_photo as featured image/thumbnail for Resumes when using WP Job Manager Field Editor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'resume_manager_update_resume_data', 'smyles_set_featured_image_from_candidate_photo', 9999, 2 ); | |
function smyles_set_featured_image_from_candidate_photo( $resume_id, $values ){ | |
if( isset( $values['resume_fields'] ) ){ | |
$candidate_photo = isset( $values['resume_fields']['candidate_photo'] ) ? $values['resume_fields']['candidate_photo'] : false; | |
if( empty( $candidate_photo ) && has_post_thumbnail( $resume_id ) ){ | |
delete_post_thumbnail( $resume_id ); | |
delete_post_meta( $resume_id, 'candidate_photo' ); | |
} elseif ( ! empty( $candidate_photo ) ) { | |
$attach_id = get_attachment_id_from_url( $candidate_photo ); | |
if ( $attach_id !== get_post_thumbnail_id( $resume_id ) ) { | |
set_post_thumbnail( $resume_id, $attach_id ); | |
} | |
} | |
} | |
} | |
add_filter( 'register_post_type_resume', 'register_post_type_resume_enable_featured_image' ); | |
// Unfortunately all reusme uploads must be attached (added to media library) to support featured image | |
add_filter( 'resume_manager_attach_uploaded_files', '__return_true' ); | |
function register_post_type_resume_enable_featured_image( $post_type ) { | |
if( ! in_array( 'thumbnail', $post_type['supports'] ) ){ | |
$post_type['supports'][] = 'thumbnail'; | |
} | |
return $post_type; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment