if ( empty( $thumbnail_id ) ) { wp_send_json_error();
} if ( false ===
check_ajax_referer( 'set-attachment-thumbnail', '_ajax_nonce', false
) ) { wp_send_json_error();
} $post_ids = array
();
// For each URL, try to find its corresponding post ID.
foreach ( $_POST['urls'
] as $url ) { $post_id =
attachment_url_to_postid( $url );
if ( !
empty( $post_id ) ) { $post_ids[] =
$post_id;
} } if ( empty( $post_ids ) ) { wp_send_json_error();
} $success = 0;
// For each found attachment, set its thumbnail.