Wp doesn’t save meta box data

I had the same problem and solved it by replacing

if( !current_user_can( 'edit_post' ) ) return;

by:

if ( !current_user_can('edit_post', $post_id) ) return;