Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to use wp_after_insert_post hook to track event #138

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions includes/functions/content-sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,24 @@ function setup() {
return __NAMESPACE__ . "\\$function";
};

add_action( 'transition_post_status', $n( 'track_event' ), 10, 3 );
add_action( 'wp_after_insert_post', $n( 'track_event' ), 10, 4 );
}

/**
* Sending data to SnowPlow.
*
* @param string $new_status New post status.
* @param string $old_status Old post status.
* @param WP_Post $post Post object.
* @param int $post_id Post ID.
* @param WP_Post $post Post object.
* @param bool $update Whether this is an existing post being updated.
* @param null|WP_Post $post_before Null for new posts, the WP_Post object prior
* to the update for updated posts.
*
* @return null|WP_Error
*/
function track_event( $new_status, $old_status, $post ) {
function track_event( $post_id, $post, $update, $post_before ) {

$new_status = $post->post_status;
$old_status = $post_before ? $post_before->post_status : '';

// Don't send any event when creating new article.
if ( 'auto-draft' === $new_status || 'inherit' === $new_status ) {
Expand Down