WP All Import Action Reference

Just like WordPress, WP All Import has its own actions. If you are unfamiliar with the WordPress Plugin API, read the Action Reference page on the WordPress.org Codex to learn more about what actions are.

pmxi_saved_post

Description
This hook is called after WP All Import creates or updates a post. It is generally used if you need to perform further actions on the imported data, like serialize it, use an API for geocoding coordinates, use it for some other purpose like comment generation, etc.

Parameters
$post_id – the ID of the post/page/Custom Post Type that was just created.

Examples

a.

<?php
add_action('pmxi_saved_post', 'post_saved', 10, 1);

function post_saved($id) {
    echo $id;
}

?>

b.

<?php
add_action('pmxi_saved_post', 'post_saved', 10, 1);

function post_saved($id) {
    $x = get_post_meta($id, 'your_meta_key', true);
    // do something with $x
    update_post_meta($id, 'your_meta_key', $x);
}

?>

 

pmxi_before_xml_import

Description
This hook is called before WP All Import starts the import process. It is generally used if you are performing cron based imports and you need to run some code before WP All Import starts the import process.

Parameters
$import_id – the ID of the import (as shown on the Manage Imports page) that is about to be run

Examples

a.

<?php
add_action('pmxi_before_xml_import', 'before_xml_import', 10, 1);

function before_xml_import($import_id) {
    <%%KEEPWHITESPACE%%> echo 'pmxi_before_xml_import';
}

?>

pmxi_after_xml_import

Description
This hook is called after WP All Import finishes an import. It is generally used if you are performing cron based imports and you need to do some clean up after the import is complete.

Parameters
$import_id – the ID of the import (as shown on the Manage Imports page) that just ran.

Examples

a.

<?php
add_action('pmxi_after_xml_import', 'after_xml_import', 10, 1);

function after_xml_import($import_id) {
    <%%KEEPWHITESPACE%%> echo 'pmxi_after_xml_import';
}

?>

pmxi_update_post_meta

Description
This hook is called after WP All Import creates/updates a post meta.

Parameters
$pid – the ID of the post/page/Custom Post Type that was just created.
$m_key – the Name of custom field that importing
$m_value – the Value that was imported to the $m_key field

Examples

a.

<?php
add_action('pmxi_update_post_meta', 'my_update_post_meta', 10, 3);

function update_post_meta($pid, $m_key, $m_value) {
    if ( $m_key == 'my_custom_field') {
        update_post_meta($pid, $m_key, unserialize($m_value));
    }
}

?>

pmxi_gallery_image

Description
This hook is called after WP All Import creates/updates a post attachment image(s).

Parameters
$pid – the ID of the post/page/Custom Post Type that was just created.
$attid – the ID of the attachment
$image_filepath – the full path to the file: C:\path\to\wordpress\wp-content\uploads\2010\05\filename.png

Examples

a.

<?php 
add_action('pmxi_gallery_image', 'my_gallery_image', 10, 3);

function my_gallery_image($pid, $attid, $image_filepath) {
    $attachment = get_post($attid);
    // do something with $attachment image
}

?>

pmxi_attachment_uploaded

Description
This hook is called after WP All Import creates/updates a post attachment file(s).

Parameters
$pid – the ID of the post/page/Custom Post Type that was just created
$attid – the ID of the attachment
$filepath – the full path to the file: C:\path\to\wordpress\wp-content\uploads\2010\05\filename.png

Examples

a.

<?php
add_action('pmxi_attachment_uploaded', 'my_attachment_uploaded', 10, 3);

function my_attachment_uploaded($pid, $attid, $filepath){
    $attachment = get_post($attid);
    // do something with $attachment file
}

?>

wp_all_import_is_post_to_update

Description
This filter can be called to determine if a post should be updated or skipped. It takes the post ID and, optionally, an array of XML nodes. The returned value should be either true to update the post or false to skip it.

Parameters
$pid – the ID of the post/page/Custom Post Type that was just created
$xml_node – an array of XML nodes that created the current post.

Examples

a. Do not update posts that have a custom field named ‘do_not_update’

<?php

add_filter('wp_all_import_is_post_to_update', 'is_post_to_update', 10, 1);

function is_post_to_update($pid) {
   $do_not_update = get_post_meta($pid, 'do_not_update', true);
   return (!empty($do_not_update)) ? false : true;
}
?>

b. Do not update posts if the record in the import file that created this post contains a node named ‘title’ with a value equal to ‘TEST’

<?php 

add_filter('wp_all_import_is_post_to_update', 'is_post_to_update', 10, 2);

function is_post_to_update($pid, $xml_node) {
   if ($xml_node['title'] == "TEST") {
      return false;
   }
   return true;
}
?>