How to revert a Features module programmatically

This is how you can revert a Features module in Drupal 6 programmatically in for instance a install file or elsewhere.

<?php
       
//If used in a install file you need to include the Features module functions
require_once('sites/all/modules/features/features.module');

$feature = features_get_features('my_feature_module_name');
$components = array_keys($feature->info['features']);
features_revert(array('my_feature_module_name' => $components));

?>

<?php

//In your module you can also create a function like this
function mymodule_features_revert_module($module) {
 
$feature = features_get_features($module);
 
$components = array_keys($feature->info['features']);
 
features_revert(array($module => $components));
}

//...and call it like this
mymodule_features_revert_module('my_feature_module_name');

?>
Knowledge keywords: