1. Amlan
  2. Feature ideas for WP Media Folder
  3. Monday, 18 November 2019
  4.  Subscribe via email
Hi JoomUnited Team !

It will be top feature to add role selected way for the "WP Media Folder Frontend" switch on General Settings.

If someone is looking for a method while waiting, it's possible, you could update the wp-media-folder.php file (*) with replacing the line number 567
Original :

567 : $frontend = get_option('wpmf_option_mediafolder');


Replace by :


if (!function_exists('wp_get_current_user')) {
include_once(ABSPATH . "wp-includes/pluggable.php");
}
$user = wp_get_current_user();
// Method 1 : create dedicated option
// $auth_roles = get_option('here_custom_option');
// Method 2 : because you need to rewrite this lines after each update perhaps dedicated option isn't needed
$auth_roles = ['administrator', 'other_role'];
if (count(array_intersect($auth_roles, $user->roles)) >= 1) {
//retrieve value only if current user role is in authorized roles list.
$frontend = get_option('wpmf_option_mediafolder');
}


Have a nice day :)

(*) but lost after each update.
Responses (3)
Accepted Answer Pending Moderation
Hi,

Thanks for sharing this tip.

But there is an easiest way to do that :) We provide some hooks so you don't have to hack plugin files: https://www.joomunited.com/wp-media-folder-developer-documentation

Here is some code you can add to your functions.php file that should do what you want

if (!is_admin()) { // For improved security you may also want to check against DOING_AJAX
add_filter('wpmf_user_can', function($return) {
$userdata = get_userdata(get_current_user_id());
if (!empty($userdata->roles)) {
$role = array_shift($userdata->roles);
}

if (isset($role) && in_array($role, array('list roles you want to disable'))) {
return false;
}

return $return;
}, 10, 1);
}


Best regards
Accepted Answer Pending Moderation
Hi,
Awesome !
I had focused on execution in front and not a second on the simple execution of the plugin. It was so simply :)

Thank you so much for this helpfull code !

Best regards.

(ps. You could delete my ugly tip lol)
Accepted Answer Pending Moderation
Don't worry, it's our own plugin, we know it better than anyone else ;)
  • Page :
  • 1


There are no replies made for this post yet.
Be one of the first to reply to this post!