@@ -0,0 +1,55 @@ | |||||
<div class="wrap"> | |||||
<h2>Tag Importer</h2> | |||||
<?php | |||||
if ( 'POST' == $_SERVER['REQUEST_METHOD'] ) { | |||||
$tax = $_POST['taxonomy']; | |||||
$terms = split("\n", $_POST['terms']); | |||||
$success = 0; | |||||
foreach ( $terms as $term ) { | |||||
if ( trim( $term ) > '' && wp_insert_term( $term, $tax) ) { | |||||
$success++; | |||||
} | |||||
} | |||||
echo "<h3>Saved $success terms.</h3>"; | |||||
} | |||||
?> | |||||
</div> | |||||
<form method="POST" action=""> | |||||
<p>Choose a taxonomy to import into:</p> | |||||
<select name="taxonomy"> | |||||
<option></option> | |||||
<?php | |||||
$args = array( | |||||
'public' => true, | |||||
); | |||||
$output = 'names'; // or objects | |||||
$operator = 'and'; // 'and' or 'or' | |||||
$taxonomies = get_taxonomies( $args, $output, $operator ); | |||||
if ( $taxonomies ) { | |||||
sort( $taxonomies ); | |||||
foreach ( $taxonomies as $taxonomy ) { | |||||
echo "<option value=\"$taxonomy\">" . $taxonomy . "</option>\n"; | |||||
} | |||||
} | |||||
?> | |||||
</select> | |||||
<p> | |||||
Paste in your tag names (terms), one tag on each row. Duplicate tags will only be added once. | |||||
</p> | |||||
<textarea name="terms" rows="15" cols="60"> | |||||
Apples | |||||
Oranges | |||||
Pears | |||||
</textarea> | |||||
<input class="button-primary" type="submit" value="Import Tags" /> | |||||
</form> |
@@ -0,0 +1,32 @@ | |||||
<?php | |||||
/* | |||||
Plugin Name: Tag Importer | |||||
Plugin URI: | |||||
Description: Import terms (tags) into a non-hierarchical taxonomy | |||||
Version: 0.2 | |||||
Author: Adrian Short | |||||
Author URI: https://adrianshort.org/ | |||||
License: CC0/public domain | |||||
*/ | |||||
add_action( 'admin_menu', 'as_tagimporter_menu' ); | |||||
// Add submenu to Tools menu | |||||
function as_tagimporter_menu() { | |||||
add_submenu_page( | |||||
'tools.php', // top-level handle | |||||
'Tag Importer', // page title | |||||
'Tag Importer', // submenu title | |||||
'manage_options', // capabilities | |||||
'as_tagimporter', // submenu handle | |||||
'as_tagimporter_page' //function | |||||
); | |||||
} | |||||
function as_tagimporter_page() { | |||||
if ( ! current_user_can( 'manage_options' ) ) { | |||||
wp_die("You do not have sufficient permissions to access this page."); | |||||
} | |||||
require_once ( dirname( __FILE__ ) . '/settings.php' ); | |||||
} |