How to add new blocks when "The block X was assigned to the invalid region Y and has been disabled"
In D7 I finally got rid of that message by placing an if ($theme == variable_get('theme_default', '0')) around the region assignment. So the block only gets assigned to my (default) frontend theme which actually contains the region the block is assigned to.

function MYMODULE_block_info_alter(&amp;$blocks, $theme, $code_blocks) {
  if ($theme == variable_get('theme_default', '0')) {
        if (isset($blocks['MYMODULE']['MYMODULE_block'])) {
            $blocks['MYMODULE']['MYMODULE_block']['status'] = 1;
            $blocks['MYMODULE']['MYMODULE_block']['region'] = 'header';
            $blocks['MYMODULE']['MYMODULE_block']['weight'] = 2;
            $blocks['MYMODULE']['MYMODULE_block']['visibility'] = BLOCK_VISIBILITY_NOTLISTED;
        }
    }
}