2

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).

1

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.

| improve this answer | |
0

I was facing the same problem and finally got a solution.. As non login user don't have any role.. If we make a user role and assign a role to the every visitor we can solve the problem of uploading files as uploading file is a capability we can add to user role...

I tried the following...

add_role( 'frontend_editor','Front-End Editor', array( 'upload_files' => true) );

if ( is_user_logged_in() ) {    
    $current_user = wp_get_current_user();
    $current_user->add_role('frontend_editor');
}

put it function.php its work for me.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.