Error in Function wpCRMSystemCustomFields::saveContactTitle modifying wrong cpt
-
Hi Scott
I am working on an extension to link your crm plugin to a document management plugin. Today I came a across a strange error which I manage to narrow down to this function
wpCRMSystemCustomFields:saveContactTitlein your main file,wp-crm-system.php.This function is hooked to
save_post, and executes if the saved post is type ‘wpcrm-contact’.I am hooking on the the same post update/publish. When a new contact is created/updates I am creating another cpt using the function
wp_insert_post. This fires your function and is able to execute it because your are checking for the post_type based on the$_POSTvalue. Since my newly created cpt is executed from the result ofPOSTed wpcrm-contact post, your function is unable to distinguish the two.Currently I am overcoming this problem by updating the the post title after inserting the post.
However, could I suggest the following change to your code?
-
You could either hook the
save_postwith 2 parameters,add_action( 'save_post', array( &$this, 'saveContactTitle' ), 2, 2 ); function saveContactTitle( $post_id, $post ) { if('wpcrm-contact' != $post->post_type){ return; } ... }-
or you could use the
post_idto verify the post before updating it,function saveContactTitle( $post_id) { $post = get_post($post_id); if('wpcrm-contact' != $post->post_type){ return; } ... }your thoughts?
The topic ‘Error in Function wpCRMSystemCustomFields::saveContactTitle modifying wrong cpt’ is closed to new replies.