• Resolved schoefl

    (@zemekis148)


    Logged in users with the role “author” can use the form. There is a problem inserting images from the media library. You can upload a file and watch the upload process. Then comes the error message: “Sorry, you are not allowed to attach files to this post”.

    It is possible to insert existing images via the media library.
    The message comes from /wp-admin/includes/ajax-actions.php, line 2504 et sequentes:

    
    if ( ! current_user_can( 'edit_post', $post_id ) ) {
     echo wp_json_encode(
      array(
       'success' => false,
       'data'    => array(
                     'message'  => __( 'Sorry, you are not allowed to attach files to this post.' ),
                     'filename' => esc_html( $_FILES['async-upload']['name'] ),
        ),
       )
      );
     wp_die();
    }
    

    The error also occurs also with deactivated plugins. I echoed the capabilities of my existing dummy author and the test script confirms that [edit_post] => 1. The error no longer occurs with the user role “editor”.

    Could you please help me.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Jeff Starr

    (@specialk)

    I have no idea why that might be happening, but you may want to look at this guide on how to troubleshoot file uploads, it explains some common things to check. Also this post on enabling non-admins to upload media may be useful. Note that both articles are written for pro users, but much of the information also applies to free version or any plugin for that matter.

    Let me know if I can provide any further infos, glad to help however possible.

    Thread Starter schoefl

    (@zemekis148)

    Thanks for the quick reply. With $data = get_userdata( get_current_user_id() ) and $data->allcaps I printed out all the capabilities of my “author”. Then i checked with $user = wp_get_current_user(); and $user->has_cap(‘upload_files’) etc. all found capabilities. With this method the capabilities ‘edit_files’ and ‘edit_post’ are classified as FALSE for the “author”.

    I don’t know where I “lost” these both capabilities. I tested other front-end editors before USP. Maybe it left some wrong settings.

    Do you know a method how I can update my user role “author”, so that ‘user_can’ and ‘has_cap’ recognize again: ‘edit_post’=true?

    Plugin Author Jeff Starr

    (@specialk)

    Yeah there are “user profile” type management plugins that can be used to edit roles, capabilities, etc. For example:

    https://www.ads-software.com/plugins/user-role-editor/

    Should do the trick.

    Thread Starter schoefl

    (@zemekis148)

    User Role Editor capabilities have the same problem. I spent a night trying to get to the bottom of things. The problem is certainly not in your department. It should be the theme, I will ask there.

    In any case, capabilities that are added with the ‘admin_init’ hook do not work. With the hook ‘map_meta_cap‘ I was able to add ‘edit_files’ successfully. But ‘edit_post’ plus ‘map_meta_cap’ means that the author gets all administrator caps. How I narrow it down to the specific context is far beyond my know-how. I will see.

    Finally: I love your plugins: Contact Form X, BBQ and Disable WP REST API.

    Thank you very much!

    Plugin Author Jeff Starr

    (@specialk)

    Cheers @zemekis148, I hope you get it sorted. Let me know if I can provide any further infos about any of my plugins. Always glad to help.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Problem with the media library’ is closed to new replies.