[wpseo_breadcrumb]

ACF: Image Aspect Ratio Crop Field

acf+user+profile+image+not+access+to+all+medias

1. Installer le plugin ACF – Image Aspect Ratio Crop Field

2. Créer le champ ACF faisant appel à ce plugin

3. Pour les utilisateurs Abonnés, le plugin ne fonctionne pas en Front, car il faut modifier la capacité WP des Abonnés, pour avoir : 

C’est écrit dans le FAQ du plugin :

« Unfortunately this is not supported right now since the plugin requires upload_files capability to access the media library. If user does not have this permission, a basic upload dialog will be displayed without a cropper. You can enable cropping by assigning upload_files capability to the user role but this means that users are able to access the media library like admin users. […] »

Grâce au plugin AAM, il faut donc changer la capability des Abonnnés :

Capture d’écran 2020-11-27 à 19.17.04.png

4. Mais pour que l’Abonné n’ait pas accès à tous les médias de la Librairie, il faut ajouter un hook :

images – Restricting users to view only media library items they have uploaded? – WordPress Development Stack Exchange

Lui-même venant d’ici : https://support.advancedcustomfields.com/forums/topic/uploaded-gallery-images-visible-to-all-in-media-library/

This is a modified version of the accepted answer. Since the accepted answer only targets the Media menu item on the left, users could still see the whole media library within the modal box when uploading a photo to a post. This slightly modified code fixes that situation. The targeted users will only see their own media items from the Media Library tab of the modal box that pops up within a post.

This is the code from the accepted answer with a comment marking the line to edit…

add_action('pre_get_posts','users_own_attachments');
function users_own_attachments( $wp_query_obj ) {

    global $current_user, $pagenow;

    if( !is_a( $current_user, 'WP_User') )
        return;

    if( 'upload.php' != $pagenow ) // <-- let's work on this line (j’ai choisi les lignes en gras ci-dessous)
        return;

    if( !current_user_can('delete_pages') )
        $wp_query_obj->set('author', $current_user->id );

    return;
}

For users to only view their own media from Media menu AND Media Library tab of the upload modal, replace the indicated line with this…

if( (   ‘upload.php’ != $pagenow ) &&

    ( ( ‘admin-ajax.php’ != $pagenow ) || ( $_REQUEST[‘action’] != ‘query-attachments’ ) ) )

(line-breaks & spacing only inserted for readability here)

The following is the same as above but also restricts them to seeing their own posts from the Posts menu item.

if( (   'edit.php' != $pagenow ) &&
    (   'upload.php' != $pagenow ) &&
    ( ( 'admin-ajax.php' != $pagenow ) || ( $_REQUEST['action'] != 'query-attachments' ) ) )

(line-breaks & spacing only inserted for readability here)

Notes: as in the accepted answer, the posts and media counters will be wrong. However, there are solutions for this in some other answers on this page. I did not incorporate those simply because I had not tested them.

Autre plugin (noté : “V1 ne fonctionne pas en Front”) :

https://github.com/andersthorborg/ACF-Image-Crop