Add-On Structure
WP All Import add-ons are WordPress plugins that make use of WP All Import’s Rapid Add-On API.
Here’s how to create a basic add-on:
1. Create a new WordPress plugin, and include the rapid-addon.php file.
<?php /* Plugin Name: My First Add-On Description: A super awesome add-on for WP All Import! Version: 1.0 Author: Richard Wang */ include "rapid-addon.php";
2. Initialize your add-on.
Create a new instance of the RapidAddon class. Pass your add-on’s name, and a slug to the class constructor. The slug should be unique to your add-on.
$my_addon = new RapidAddon('My First Add-On', 'my_first_addon');
3. Add fields to your add-on.
$my_addon->add_field('property_location', 'Property Location', 'text'); $my_addon->add_field('property_address', 'Property Address', 'text');
The code above will add two text fields to your add-on – one for Property Location, and one for Property Price.
4. Register your import function.
Each time WP All Import imports or updates a post, WP All Import will call this function and pass the post ID and the data to be imported to it.
$my_addon->set_import_function('my_addon_import_function');
5. Write your import function.
In this example, I’m just going to put the values of the two fields we created earlier in the postmeta table.
function my_addon_import_function( $post_id, $data, $import_options, $article ) { global $my_addon; $fields = array( 'property_location', 'property_address' ); foreach ( $fields as $field ) { if ( empty( $article['ID'] ) or $my_addon->can_update_meta( $field, $import_options ) ) { update_post_meta( $post_id, $field, $data[ $field ] ); } } }
6. Specify when your add-on runs.
$my_addon->run( array( "themes" => array("Twenty Fourteen", "Twenty Fifteen") ) );
The above code will make the add-on run when the Twenty Fourteen or Twenty Fifteen theme is active.
6. That’s all, you are done coding!
To see the add-on in action, install and activate this plugin, and do an import with WP All Import.
The add-on will appear in Step 3 of WP All Import as a box titled My First Add-On:
