messing with post_status to secure posts
-
On the WP course I’m doing, the tutor has said that for a custom post type we’ve created called ‘notes’ it’s best to set the post_status to private. Otherwise another user not logged in to the website could via the REST API URL query/see all the notes created by a sites users. Incidentally I’m using Local by Flywheel to host my site locally and it’s not been deployed or hosted.
According to him one way of achieving this protection is to set the note’s status to ‘private’ in my JS file in modules, when posting to the database.
The other way is to use this code in functions.php
add_filter('wp_insert_post_data', 'makeNotePrivate'); function makeNotePrivate($data){ if($data['post_type'] == 'note') { $data['post_status'] = "private"; } }
According to my tutor the caveat to the first method is a user could maliciously change my JS code so all ‘note’ posts are saved with a post status of ‘public’!
My question is if this malicious end user could access and change the code in a JS file could they not also do the same to functions.php? At my knowledge level I’m not even sure how a malicious user would do this but apparently it’s possible.
All I’m looking for is an explanation of why this is the case I’m not looking for an alternative solution so pls no posts saying oh why don’t you try this. I just want to understand why he is saying what he is. Thanks
- The topic ‘messing with post_status to secure posts’ is closed to new replies.