disable rule or view programmatically on feature enable snippet
/**
* Implementing hook_post_features_enable_feature
*/
function myfeature_post_features_enable_feature($component) {
// no need to call it for every $component,
// so we choose 'features_api' which is always present
// bit of a workaround until http://drupal.org/node/1844566,
// or is there a better way?
if ($component == 'features_api') {
$rules_config = rules_config_load('commerce_checkout_order_email'); // replace with your rules machine name
$rules_config->active = FALSE;
$rules_config->save();
// below is taken from http://drupal.org/node/1733808
// a list of views (their view name) I want to disable
$viewnames = array(
'commerce_cart_block'
);
// grab list of views that are already disabled
$views_status = variable_get('views_defaults', array());
// add our views to be disabled to the list
foreach ($viewnames as $key => $viewname) {
$views_status[$viewname] = TRUE;
}
// reset the variable with the new list
variable_set('views_defaults', $views_status);
// empty cache now
if (function_exists('views_invalidate_cache')) {
views_invalidate_cache();
}
}
}