How to programmatically change settings of input filters and activate them? I'm looking for a way to programmatically change the settings of an input filter and activate it in Drupal 7. Let's take the Footnotes module as an example: It adds a new input filter that can be activated on input formats. I can navigate to admin/config/content/formats/2 to edit my "Full HTML" input format and there activate the Footnote filter and configure it. But how can I achieve that programmatically?

My first guess was to load the input format using filter_format_load(), change some values and then do a filter_format_save(). But in the object that I get from filter_format_load(), there are no input filters, i.e. $format-&gt;filters doesn't exist.

I can get all available filters using filter_list_format() and I believe I could change some values there. But then again, I can't find a way to save those settings.
If you read the API page for the functions you mentioned in your question, you can easily see that there is a bug(or a feature) that it does not load populate $filter-&gt;filters indeed. 

For a workaround, you could do something like this, with the help of filter_list_format()

$format_id = 'full_html';
$filter_id = 'your_filter';


First, load the format object

$format = filter_format_load($format_id);


Now, since we do not have the $filter-&gt;filters populated, we do so by loading the currently enabled filters. 

$filters = filter_list_format($format_id);
foreach ($filters as $filter_id =&gt; $filter_opts) { //Convert to an array, which is expected by the save function.
  $filters[$filter_id] = (array) $filter_opts;
}


You can now make changes in the filter that you are interested in. 

$filters[$filter_id]['status'] = TRUE; //Enable. 
$filters[$filter_id]['settings']['something'] = 'foobar';


Inject filters to the format we have already loaded. 

$format-&gt;filters = $filters;


Save!!

filter_format_save($format);