I thought I had this fixed, however it appears that even when using the below function to set the author to the current author id, it is returning a 1 when I test. The odd thing is that the author field on the admin side shows the correct name. Here is the code I'm using:
To set the author on submit:
function my_save_data_action2 ($post_id, $form_data) {
if ($form_data['id']==57 || $form_data['id']==50) {
$post= array(
'ID' => $post_id,
'post_author' => get_current_user_id(),
);
wp_update_post( $post );
}
}
add_action('cred_submit_complete', 'my_save_data_action2',10,2);
To redirect if the current user and author don't match:
function redirect_private_draft_portfolios() {
global $post;
$author_id = $post->post_author;
$current_user_id = get_current_user_id();
//variable testing
$text = 'userID: ' . $current_user_id . ' authID: ' . $author_id;
$var_str = var_export($text, true);
$var = "<?php\n\n\$text = $var_str;\n\n?>";
file_put_contents('testing.php', $var);
if($post_type == 'athlete-profile' && !current_user_can('manage_options')) {
if( $current_user_id != $author_id ) {
wp_redirect( home_url() );
exit();
}
}
}
add_action('template_redirect', 'redirect_private_draft_portfolios');
I'm sure I'm missing something, any help you can provide would be very appreciated.