// Add a new instance of this block, if allowed
$block = blocks_get_record($blockid);
- if(!$block->visible) {
- // Only allow adding if the block is enabled
+ if(empty($block) || !$block->visible) {
+ // Only allow adding if the block exists and is enabled
return false;
}
$newinstance->weight = $weight;
$newinstance->visible = 1;
$newinstance->configdata = '';
- insert_record('block_instance', $newinstance);
- ++$weight;
+
+ if(!empty($newinstance->blockid)) {
+ // Only add block if it was recognized
+ insert_record('block_instance', $newinstance);
+ ++$weight;
+ }
}
}