How to allow logged out users to upload attachments?By Milan Jovanovic on 10/10/18 in
By default WordPress does not allow this. Reason is: logged out user has no ID (id is 0), and no permissions/capabilities enabled for him.
A solution would be to create an actual user that will be used as a single user for all logged-out users, and copy his ID (e.g. id = 100).
Then you can add a simple hook to identify logged out users as User with ID 100. To do this you can use a hook like this:
function set_loggedout_id( $user_id ){ if( empty( $user_id ) ){ $user_id = 100; } return $user_id; } add_filter( 'determine_current_user', 'set_loggedout_id', 999, 1 );
Basically, it “tells” WordPress to replace the empty ID of a logged out user with a value of 100.
Then you can allow uploading for this user.