Tribe__Process__Post_Thumbnail_Setter::sync_handle( $data_source = null )
{@inheritdoc}
Source
File: src/Tribe/Process/Post_Thumbnail_Setter.php
public function sync_handle( array $data_source = null ) {
/** @var Tribe__Log $logger */
$logger = tribe( 'logger' );
$log_src = 'Featured image setter';
$logger->log_debug( "(ID: {$this->identifier}) - handling request.", $log_src );
$data_source = isset( $data_source ) ? $data_source : $_POST;
if ( ! isset( $data_source['post_id'], $data_source['post_thumbnail'] ) ) {
return;
}
$id = filter_var( $data_source['post_id'], FILTER_SANITIZE_NUMBER_INT );
$post_thumbnail = filter_var( $data_source['post_thumbnail'], FILTER_SANITIZE_STRING );
$logger->log_debug( "(ID: {$this->identifier}) - fetching {$post_thumbnail} for post {$id}", $log_src );
$thumbnail_id = tribe_upload_image( $post_thumbnail );
if ( false === $thumbnail_id ) {
$logger->log_debug( "(ID: {$this->identifier}) - could not fetch {$post_thumbnail} for post {$id}, done.", $log_src );
return;
}
$set = set_post_thumbnail( $id, $thumbnail_id );
if ( false === $set ) {
$logger->log_debug( "(ID: {$this->identifier}) - fetched {$post_thumbnail}, created attachment with ID {$thumbnail_id}, unable to set thumbnail for post {$id}, done.", $log_src );
return 0;
}
$logger->log_debug( "(ID: {$this->identifier}) - fetched {$post_thumbnail}, created attachment with ID {$thumbnail_id}, set thumbnail for post {$id}, done.", $log_src );
}