This is the most "standard" way that I have found so far to set posts visibility to private by default:
function wp_118970_force_type_private($post) {
if ($post['post_status'] != 'trash' && $post['post_status'] != "draft" && $post['post_status'] != "auto-draft") {
$post['post_status'] = 'private';
}
return $post;
}
add_filter('wp_insert_post_data', 'wp_118970_force_type_private');
Note that you have to ensure that post_status is not "trash" otherwise you wouldn't be able to delete your post. We also check for "draft" and "auto-draft" status to avoid setting posts as "private" while redacting them.
With this, there is no need to add some JS, the visibility will be set to private from the beginning.
If you want to target a specific post type, you can do it this way:
function wp_118970_force_type_private($post) {
if ($post['post_status'] != 'trash' && $post['post_status'] != "draft" && $post['post_status'] != "auto-draft" && $post['post_type'] == 'my_post_type') {
$post['post_status'] = 'private';
}
return $post;
}
add_filter('wp_insert_post_data', 'wp_118970_force_type_private');
I first found the solution here: http://wpsnipp.com/index.php/functions-php/force-custom-post-type-to-be-private/