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?

  • BTW, as context_status is a varialbe I can pack it into a feature, and move config from dev sites to prod site, but I can't just pack only one context: this variable seems to hold all system context that are disabled.
    – sanzante
    Jul 15, 2014 at 15:54
  • Thanks for the tip, it's not ideal like you say but at least it's someting we can work with. Aug 19, 2014 at 9:49

2 Answers 2


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());
variable_set('context_status', $contexts);

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

  • 2
    Should be variable_set('context_status', $contexts); rather than variable_set('context_name', $contexts); Aug 27, 2014 at 14:18
  • Yes, you are right, thanks for pointing it out. I've updated my answer.
    – sanzante
    Aug 27, 2014 at 16:56

You may also find Context Disable Context to be useful. It is a Context plugin that adds a reaction which allows you to disable a context.

  • I think is not what I need because this is needed for automatic updates. It's a module to get in mind, thought, thanks for the reference.
    – sanzante
    Apr 5, 2016 at 10:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.