WordPress Plugins, “activate”, Initial Content and Flow

I was working on a site for a client at work the other day when I ran into an issue that was somewhat puzzling. I was given an XML file with about 1500 records, and needed to get that data entered into WordPress… was it easy? Well, yes and no, more frustrating than anything.

I’ve been using the WordPress Plugin Boilerplate a lot lately as a starting point to plugin development. It’s fantastic, and it allows my team at work to all be on the same page as far as how we should be building plugins. I set up a custom post type and a custom taxonomy in the “init” hook, and then set up a simple XML parser to read the data when the plugin is activated and enter it as the newly created custom post type (obviously I did checks to see if the content had already been entered in case the plugin was deactivated and re-activated).

I created everything and then just had output print to the screen, rather then enter the content immediately to make sure my flow was correct. Once I verified everything was good to go, this is where I hit my snag. The plugin was throwing an error which I discovered was happening when I was attempting to create a taxonomy term based on the XML data.

The issue, I discovered soon thereafter, was found in the wp-admin/plugins folder at line 150 (WP 3.5.2).

do_action('activate_' . $plugin);
exit;

Basically, when the “activate” hook is called, that’s it. It doesn’t enter the typical action flow outlined here in the WP Codex.

The solution, ugly as it may be, was to add manual calls to the hook functions that would normally be called in “init” to create my custom post type and custom taxonomy. It’s not a solution I’m particularly proud of, but it worked and doesn’t appear to be causing any real issues.

Has anyone else ever run into a similar situation? If so, how did you handle it?