I added it like this and so far it seems to have fixed the problem.
// ensure is_plugin_active() exists (not on frontend)
if( !function_exists('is_plugin_active') ) {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
}
// bail early if not a plugin (included in theme)
if( !is_plugin_active($basename) ) {
return $transient;
}