For drupal 7 the best way will be write hook_enable function in *.install file of your custom module:
<?php
function YOUR_MODULE_NAME_enable() {
$blocks = array(
array(
'status' => 1,
'weight' => 20,
'region' => 'sidebar_second',
'visibility' => 1,
'pages' => "instruments/*",
'module' => 'instruments',
'delta' => 'instruments_sidebar',
'theme' => 'markets',
),
array(
'status' => 1,
'weight' => 19,
'region' => 'sidebar_second',
'visibility' => 1,
'pages' => "instruments/*\n<front>",
'module' => 'instruments',
'delta' => 'instruments_search',
'theme' => 'markets',
)
);
foreach($blocks as $block){
db_merge('block')
->key(array(
'module'=>$block['module'],
'delta'=> $block['delta'],
'theme'=> $block['theme']
))
->fields(array(
'status' => $block['status'],
'weight' => $block['weight'],
'region' => $block['region'],
'visibility' => $block['visibility'],
'pages' => $block['pages'],
))
->execute();
}
}
This is code from my custom module, and it works :)
Here I enable my custom blocks, so I modify 'block' table. For custom blocks you should update 'block_custom' table too.
If you don't know how drupal store settings, just make changes manually and then check DB.
NOTE: db_merge function is very useful - it inserts data if they absent (if you just installed your module) or updates it (if you disabled and then enabled module)
hook_page_alter()