Giter Club home page Giter Club logo

rmla's Introduction

Restrict Media Library Access

Just another WordPress Plugin https://wordpress.org/plugins/restrict-media-library-access/

Description

This plugin restricts access for Authors and Contributors so they can only see their own Media Library uploads.

This has two main uses: Make it easier for Authors to locate their own uploads when Media Libraries grow very big and prevent Authors from using or downloading media that belongs to other users.

Admins and Editors will still be able to see everyone’s uploads.

rmla's People

Contributors

mrfoxtalbot avatar

Watchers

 avatar

rmla's Issues

Check for capabilities, not for roles

At the moment, the plugin only checks for roles (admin, editor, author & contributor), not for specific capabilities. This means that any custom roles will be considered as authors in terms of permissions and will only be able to see their own uploads.

With this code, any role that has the capability to edit other users’ post (edit_others_posts) will be able to see everyone’s uploads. Custom roles that can only edit their own pots, will only see their uploads:

/**
 * Plugin Name: Restrict Media Library Access
 * Description: Restricts access for Authors, Contributors, and any role that cannot edit other users' posts so they can only see their own Media Library uploads.
 * Plugin URI: https://wordpress.org/plugins/restrict-media-library-access
 * Version: 1.4.1
 * Author: mrfoxtalbot
 * Author URI: http://mrfoxtalbot.com
 * Text Domain: restrict-media-library-access
 * License: GPLv2
 */

// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
    die;
}
// Filter Ajax view
add_filter( 'ajax_query_attachments_args', 'mrfx_show_current_user_attachments' );

function mrfx_show_current_user_attachments( $query ) {
    $user_id = get_current_user_id();
    if ( $user_id && !current_user_can('edit_others_posts')) {
        $query['author'] = $user_id;
    }
    return $query;
}
// Filter list view
add_filter( 'request', 'mrfx_show_current_user_attachments_list' );
function mrfx_show_current_user_attachments_list( $query ) {
    $screen = null;
    if ( function_exists( 'get_current_screen' ) ) { 
     $screen = get_current_screen(); 
    } 
    if ( !is_null($screen) && in_array($screen->id, array('upload') ) ) {
        $user_id = get_current_user_id();
        if ( $user_id && !current_user_can('edit_others_posts')) {
            $query['author'] = $user_id;
        }
    }
    return $query;
} 

Media Inserter does not support filtering media by capability/rol

The new Media Inserter (WordPress/gutenberg#44496) does not support filtering media by capabilities or roles yet. This means that the RMLA plugin will not be able to limit access to other user's files on sites where the block editor is active. I have flagged this upstream in WordPress/gutenberg#58944 but it needs to be fixed in Gutenberg core.

This was flagged in a forum thread here https://wordpress.org/support/topic/conflict-with-media-inserter-in-block-editor/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.