I've just written a blog post on how to add a button to delete all taxonomy terms here.
Essentially:
I’m using the jQuery Easy Confirm Dialog plugin for this. First download the library from here and put this in your themes js folder.
We can then add a “Delete All Terms” button with a little code in a custom module:
function hook_form_alter(&$form, &$form_state, $form_id) {
switch($form_id) {
case 'taxonomy_overview_terms':
if($form['#total_entries']) {
drupal_add_library('system', 'ui.dialog');
drupal_add_js(drupal_get_path('theme', 'YOUR_THEME_NAME').'/js/jquery.easy-confirm-dialog.js');
$js = 'jQuery(document).ready(function($){$(".confirm").easyconfirm({locale: { title: \'Delete all '.$form['#vocabulary']->name.' terms\', button: [\'No\',\'Yes\']}});});';
drupal_add_js($js, array('type'=>'inline'));
$form['actions']['delete_all'] = array(
'#markup' => '<a href="/admin/structure/taxonomy/'.$form['#vocabulary']->vid.'/delete-all" class="button confirm" title="Are you sure you want to delete all terms from the '.$form['#vocabulary']->name.' vocabulary?">Delete All Terms</a>',
'#weight' => 10,
'#attributes' => array('class' => array('button'))
);
}
break;
}
}
Now we need to define the path to our function to delete the terms:
function hook_menu() {
$items = array();
$items['admin/structure/taxonomy/%/delete-all'] = array(
'title' => 'Delete all taxonomy terms',
'type' => MENU_CALLBACK,
'page callback' => 'delete_all_taxonomy_terms',
'page arguments' => array(3),
'access arguments' => array('administer taxonomy'),
);
return $items;
}
And finally add the functionality to actually delete the terms:
function delete_all_taxonomy_terms($vid) {
$vocabulary = taxonomy_vocabulary_load($vid);
$query = new EntityFieldQuery();
$result = $query
->entityCondition('entity_type', 'taxonomy_term')
->propertyCondition('vid', $vid)
->execute();
foreach($result['taxonomy_term'] as $term) {
taxonomy_term_delete($term->tid);
}
drupal_set_message('All terms have been deleted from the '.$vocabulary->name.' vocabulary');
drupal_goto('admin/structure/taxonomy/'.$vocabulary->machine_name);
}