How to disable/enable a context programmatically I want to disable contexts programmatically (for automated updates, where a new release of a website needs a context to be disabled).

I manage contexts using Features, but Features doesn't hold the enabled/disabled status of the context.

I can't find a function to change context status programmatically. There's a support request but the snippet is not working (nothing happens, context remains the same status).

After some investigation I came across the context_status variable. It seems to hold an array with context names as key and TRUE as value: each of these contexts is disabled. If you edit that variable by unsetting one context, the context becomes enabled.

So it seems the only way to disable/enable a context programmatically is to edit this conext_status.

Is there a better way to do it?
Use the context_status to enable/disable contexts.

This variable is an array with context names as key and TRUE as value: each of this context is disabled. 

To disable a context: add a new pair to the array like this: 

$contexts = variable_get('context_status', array());
$contexts['context_name'] = TRUE;
variable_set('context_status', $contexts);


To enable a context: unset the context name from context_status.

$contexts = variable_get('context_status', array());
unset($contexts['context_name']);
variable_set('context_status', $contexts);


Also you can use Features, exporting the context_status to a feature.