Skip to content
This repository was archived by the owner on Aug 31, 2022. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,44 @@ public function get_related_terms( $object_id ) {
}
return array();
}

/**
* Trash attachments which are unlinked from TMS Object's database.
*
* @param array $params
*/
protected function after_run( $params = array() ) {

parent::after_run( $params );

if ( ! empty( $this->data ) && ! empty( $this->parent_object->wp_parent_id ) ) {

// First get all attachments for related to WP posts.
$medias = get_attached_media( 'image', $this->parent_object->wp_parent_id );

if ( ! empty( $medias ) ) {

$processed_medias = array();

// Get all media attachment object of TMS Object.
foreach ( $this->data as $media_object ) {

$processed_medias[ $media_object->MediaMasterID ] = $media_object;
}

foreach ( $medias as $media ) {

$media_legacy_id = get_post_meta( $media->ID, 'tmsc_legacy_id', true );

// If TMS object is not containing any attachment id of WP_Post then
if ( ! isset( $processed_medias[ $media_legacy_id ] ) ) {

// Move attachment to trash.
wp_delete_attachment( $media->ID );
}
}
}
}
}

}