3 * Simple Tags Plugin Importer
10 * Simple Tags Plugin Tags converter class.
12 * Will convert Simple Tags Plugin tags over to the WordPress 2.3 taxonomy.
18 echo '<div class="wrap">';
20 echo '<h2>'.__('Import Simple Tagging').'</h2>';
21 echo '<p>'.__('Steps may take a few minutes depending on the size of your database. Please be patient.').'<br /><br /></p>';
29 echo '<div class="narrow">';
30 echo '<p>'.__('Howdy! This imports tags from Simple Tagging 1.6.2 into WordPress tags.').'</p>';
31 echo '<p>'.__('This has not been tested on any other versions of Simple Tagging. Mileage may vary.').'</p>';
32 echo '<p>'.__('To accommodate larger databases for those tag-crazy authors out there, we have made this into an easy 4-step program to help you kick that nasty Simple Tagging habit. Just keep clicking along and we will let you know when you are in the clear!').'</p>';
33 echo '<p><strong>'.__('Don’t be stupid - backup your database before proceeding!').'</strong></p>';
34 echo '<form action="admin.php?import=stp&step=1" method="post">';
35 wp_nonce_field('import-stp');
36 echo '<p class="submit"><input type="submit" name="submit" class="button" value="'.esc_attr__('Step 1').'" /></p>';
41 function dispatch () {
42 if ( empty( $_GET['step'] ) ) {
45 $step = (int) $_GET['step'];
54 check_admin_referer('import-stp');
55 $this->import_posts();
58 check_admin_referer('import-stp');
62 check_admin_referer('import-stp');
63 $this->cleanup_import();
71 function import_posts ( ) {
72 echo '<div class="narrow">';
73 echo '<p><h3>'.__('Reading STP Post Tags…').'</h3></p>';
75 // read in all the STP tag -> post settings
76 $posts = $this->get_stp_posts();
78 // if we didn't get any tags back, that's all there is folks!
79 if ( !is_array($posts) ) {
80 echo '<p>' . __('No posts were found to have tags!') . '</p>';
84 // if there's an existing entry, delete it
85 if ( get_option('stpimp_posts') ) {
86 delete_option('stpimp_posts');
89 add_option('stpimp_posts', $posts);
90 $count = count($posts);
91 echo '<p>' . sprintf( _n('Done! <strong>%s</strong> tag to post relationships were read.', 'Done! <strong>%s</strong> tags to post relationships were read.', $count), $count ) . '<br /></p>';
94 echo '<form action="admin.php?import=stp&step=2" method="post">';
95 wp_nonce_field('import-stp');
96 echo '<p class="submit"><input type="submit" name="submit" class="button" value="'.esc_attr__('Step 2').'" /></p>';
102 function import_t2p ( ) {
103 echo '<div class="narrow">';
104 echo '<p><h3>'.__('Adding Tags to Posts…').'</h3></p>';
106 // run that funky magic!
107 $tags_added = $this->tag2post();
109 echo '<p>' . sprintf( _n('Done! <strong>%s</strong> tag was added!', 'Done! <strong>%s</strong> tags were added!', $tags_added), $tags_added ) . '<br /></p>';
110 echo '<form action="admin.php?import=stp&step=3" method="post">';
111 wp_nonce_field('import-stp');
112 echo '<p class="submit"><input type="submit" name="submit" class="button" value="'.esc_attr__('Step 3').'" /></p>';
117 function get_stp_posts ( ) {
119 // read in all the posts from the STP post->tag table: should be wp_post2tag
120 $posts_query = "SELECT post_id, tag_name FROM " . $wpdb->prefix . "stp_tags";
121 $posts = $wpdb->get_results($posts_query);
125 function tag2post ( ) {
128 // get the tags and posts we imported in the last 2 steps
129 $posts = get_option('stpimp_posts');
131 // null out our results
134 // loop through each post and add its tags to the db
135 foreach ( $posts as $this_post ) {
136 $the_post = (int) $this_post->post_id;
137 $the_tag = $wpdb->escape($this_post->tag_name);
138 // try to add the tag
139 wp_add_post_tags($the_post, $the_tag);
143 // that's it, all posts should be linked to their tags properly, pending any errors we just spit out!
147 function cleanup_import ( ) {
148 delete_option('stpimp_posts');
153 echo '<div class="narrow">';
154 echo '<p><h3>'.__('Import Complete!').'</h3></p>';
155 echo '<p>' . __('OK, so we lied about this being a 4-step program! You’re done!') . '</p>';
156 echo '<p>' . __('Now wasn’t that easy?') . '</p>';
160 function STP_Import ( ) {
165 // create the import object
166 $stp_import = new STP_Import();
168 // add it to the import page!
169 register_importer('stp', 'Simple Tagging', __('Import Simple Tagging tags into WordPress tags.'), array($stp_import, 'dispatch'));