Sorry if this is already answered on here. I looked around and couldn't see any answers to my question so I thought I'd post my own.
I'm building a plugin for a client that gathers customer feedback on a recent project that has been completed.
The admin would use the system to send a "prompt" to the customer asking them for their feedback with a link to a form on the site.
I have created a custom post type called "customer_prompts" which only has a title field and a few custom fields which are stored in a custom database table, not post meta.
Below is my code for the save_post action. It seems that when I hit publish, it does not fire the save_post action and only saves the title value to wp_posts.
add_action('save_post', 'save_prompt');
function save_prompt($post_id){
$post = get_post($post_id);
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
if ( 'customer_prompt' == $_POST['post_type'] )
{
if ( !current_user_can( 'edit_page', $post_id ) )
return;
}
else
{
if ( !current_user_can( 'edit_post', $post_id ) )
return;
}
global $wpdb;
$prompt_id = com_create_guid();
$customer_feedback_name = $_POST['_sdg_customer_feedback_name'];
$customer_feedback_email = $_POST['_sdg_customer_feedback_email'];
$salesperson = $_POST['_sdg_salesperson'];
$values = array(
'id' => $prompt_id,
'sdg_customer_name' => $customer_feedback_name,
'sdg_customer_email' => $customer_feedback_email,
'sdg_salesperson' => $salesperson,
'sdg_post_id' => $post->id
);
$insert = $wpdb->insert($table_name, $values);
if($insert) {
mail($customer_feedback_email, 'hello', 'hello');
}
}
Any help would be greatly appreciated as I cannot work out what is going on here.
Thanks, Jamie.