Last active
January 24, 2018 16:25
-
-
Save jtsternberg/9fd9e5e5b44421b3a9445963e58b596d to your computer and use it in GitHub Desktop.
Working with the GatherContent pull filters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Modify post data when GatherContent does a pull. | |
* | |
* @param array $post_data Array of post data to be updated/modified. | |
* @param GatherContent\Importer\Sync\Pull $pull_object The GC Pull object. | |
* @param boolean $update Whether this is a post update (vs new). Default: false. | |
* | |
* @return array Array of post data to be updated/modified. | |
*/ | |
function my_gc_new_post_filter( $post_data, $pull_object, $update = false ) { | |
// use the $update variable if you only want to do things on post-update | |
if ( $update ) { | |
// Do something. | |
} | |
/** | |
* Use $pull_object to get access to the mapped GC item, our mapping, etc. | |
* https://github.com/gathercontent/wordpress-plugin/blob/master/includes/classes/sync/pull.php | |
* https://github.com/gathercontent/wordpress-plugin/blob/master/includes/classes/sync/base.php | |
* Properties include: | |
* | |
* $pull_object->item - The GC item being synced. | |
* The actual field data will be in $pull_object->item->config | |
* $pull_object->api - For making additional api requests | |
* https://github.com/gathercontent/wordpress-plugin/blob/master/includes/classes/api.php | |
* $pull_object->mapping - The mapping object | |
* https://github.com/gathercontent/wordpress-plugin/blob/master/includes/classes/mapping-post.php | |
*/ | |
// If we don't have the config for reason, maybe we should bail at this point. | |
if ( ! isset( $pull_object->item->config ) || empty( $pull_object->item->config ) ) { | |
return $post_data; | |
} | |
// $pull_object->item->config[0] === Tab 1 | |
// $pull_object->item->config[1] (etc) === Tab 2-etc | |
// $pull_object->item->config[0]->label === Tab 1 name/label | |
// $pull_object->item->config[0]->elements[0] === Field 1 on Tab 1 | |
return $post_data; | |
} | |
add_filter( 'gc_new_wp_post_data', 'my_gc_new_post_filter', 10, 2 ) | |
/** | |
* Modify post data when GatherContent does a pull. | |
* | |
* @param array $post_data Array of post data to be updated/modified. | |
* @param GatherContent\Importer\Sync\Pull $pull_object The GC Pull object. | |
* | |
* @return array Array of post data to be updated/modified. | |
*/ | |
function my_gc_update_post_filter( $post_data, $pull_object ) { | |
return my_gc_new_post_filter( $post_data, $pull_object, true ); | |
} | |
add_filter( 'gc_update_wp_post_data', 'my_gc_update_post_filter', 10, 2 ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment