Creating a temporary content type on the fly? I want to create a temporary content type, and a node of that type, in code. It preferably should not live past page load. Can I do that?

For the reason to this very strange request, please see Using field widgets in non-field forms.

If you have suggestions for completely different solutions, then please take those to the linked issue, since this question is mainly a "support" question to the current answer to that question.
$node_type = array(
  'type' =&gt; 'temporary_node_type', // This is the machine name.
  'name' =&gt; t('Temporary Node'), // This is the human name.
  'base' =&gt; 'node_content', // If you set this to your module name, then
                            // *your module's* hook_insert(), hook_delete(),
                            // etc. will get called in addition to
                            // hook_node_*()
  'description' =&gt; t('Description.')
  // A full list of options is at http://api.drupal.org/hook_node_info.
);

$node_type = node_type_set_defaults($node_type);

node_type_save($node_type);

// Do something with your node type. You can also add fields here if you
// would like.

node_type_delete($node_type);


Note 1: People with the "administrator" role will see this type on node/add every once and a while, depending on how often you do this.

Note 2: You want to use something more then a hard-coded string for your type attribute to avoid collisions.