How to allow to user non logged in WP system upload in media library?

I’m stuck right now. For my project, I have to create login not using WP user system but another system.

Now, when with my system API login, I created some cookie but, obviously I didn’t also create wp cookie for user logged in. So, I want to allow a user upload with media library of WP (link of WP codex) some files, but it doesn’t work.

I have also edited (temporary core wordpress change) admin-ajax.php for forcing it to create post attachment also in the case of user not logged in:

if ( is_user_logged_in() ) {    
    do_action( 'wp_ajax_' . $_REQUEST['action'] );
} else {
   do_action( 'wp_ajax_' . $_REQUEST['action'] );
 }

but async-upload.php responds with 302 and I don’t know how to go forward.

UPDATE:
the problem is the same of this user: click here

I tried to use wp_ajax_my_action and wp_ajax_nopriv_myaction but nothing change.
My need is allow to not logged user in WP to upload attachment, and assign this attachment with his ID author (for example, 12345), cause each user must see only yours media (i will use pre_get_posts and yet work).

2 Answers
2

First, you do not want to edit core WP files, because your changes will disappear when there’s an update. That’s why you are encouraged to create child themes.

Second, you may want to peruse this Codex page on AJAX. Note that it shows how to handle both kinds of users (logged in and not logged in):

add_action( 'wp_ajax_my_action', 'my_action' );
add_action( 'wp_ajax_nopriv_my_action', 'my_action' );

The my_action function would go in your theme files (when I was working on mine, I created my own plugin to handle AJAX).

Hope this starts you down the right path.

Leave a Comment