It would be preferable to alter these in hooks rather than at render time so that you are not undermining site performance and caching. Took me age to figure out that hook_views_pre_build() fires too late, you need hook_views_pre_view().
I found reference to using $view->add_item() but struggled for examples, below was my solution for filtering a set of taxonomy terms to only include certain vocabs:
function MODULENAME_views_pre_view(&$view, &$display_id, &$args) {
if ($view->name == 'VIEWNAME' && $display_id == 'DISPLAYID') {
// Add all the terms of a vocabulary to the terms listing widget select field
$vids = array();
$vocab = taxonomy_vocabulary_machine_name_load('vocab_name');
$vids[ $vocab->vid ] = $vocab->vid;
// Get the existing filters
$filters = $view->display_handler->get_option('filters');
if (empty($filters['vid'])) {
// There is no vid filter so we have to add it
$view->add_item(
$view->current_display,
'filter',
'taxonomy_term_data',
'vid',
array(
'operator' => 'in',
'value' => $vids,
'group' => 1
)
);
}
else {
// Add to pre-existing filter
foreach($vids as $vid) {
$filters['vid']['value'][ $vid ] = $vid;
}
$view->display_handler->override_option('filters', $filters);
}
}
}
Edit note: This comment on d.o group helped me figure out how to get the views filters using $view->display_handler->get_option('filters')
and to then override them using $view->display_handler->override_option('filters', $filters);
.