Magento: Installer script to remove the customer attribute & data by code

Installer script to remove the customer attribute & data by code.

[php]
$setup = Mage::getModel('customer/entity_setup', 'core_setup');

$attributeId = $setup->getAttributeId('customer', $customerAttributeCode);

// retrieve attribute table to delete the leftover records after the attribute removal
$attributeTable = $setup->getAttributeTable('customer', $customerAttributeCode);
if(!empty ($attributeId) && !empty ($attributeTable)) {
// remove attribute first so that another record won't be added to its table values
$setup->removeAttribute('customer', $customerAttributeCode);

// remove attribute values so that no data is leftover after attribute removal
$installer->run('DELETE FROM ' . $attributeTable . ' WHERE attribute_id = ' . $attributeId);
}

[/php]