rtmedia_media_delete_priv

I read in another post here that this is used to check if another user, not the user whom originally uploaded the video/picture, is allowed to delete media.

I’m looking for a way to allow users with the custom created role “Moderator” to be able to edit, re-attribute (Pro) and delete others media if it violates the terms of service.

Thanks!

Hi Ben,

Yes, it is possible. All you need to do is to check the user role in filter and return true/false accordingly to allow edit/delete media.

For delete use this filter -> rtmedia_media_delete_priv
For edit use this filter -> rtmedia_media_edit_priv

Thanks Ritesh… I’m having trouble figuring it out still, though.

I installed User Role Editor, and the rtmedia_media_delete_priv and rtmedia_media_edit_priv are not capabilities. So, I added them, and it doesnt show up anywhere.

Where do you use these filters at?

Thanks in advance,

Ben

Hi Ben,
You need to use those filters in your theme’s functions.php file.

Could you please offer a sample code of how to use it? I’m no programmer. :wink:

Here is the sample code you asked for. Use it in your theme’s functions.php file.

add_filter( 'rtmedia_media_edit_priv', 'custom_role_rtmedia_media_edit_priv' )  
function custom_role_rtmedia_media_edit_priv( $flag ) {  
	// check current user for your role using current_user_can() and according to that return true/false  
}

Reference: current_user_can codex

Sorry for the delay in my replying…

I made a custom capability called “wpb_moderator” in User Role Editor, and then I wrote:

add_filter( 'rtmedia_media_edit_priv', 'custom_role_rtmedia_media_edit_priv' )  
function custom_role_rtmedia_media_edit_priv( $flag ) {  
	if ( current_user_can('wpb_moderator') ) {  
       $wpb_moderator = true;  
	   return $wpb_moderator;  
       }  
	   $wpb_moderator = false;  
	   return $wpb_moderator;  
}

…and it returns this error:

Parse error: syntax error, unexpected ‘function’ (T_FUNCTION) (Referring to the line that says “function custom_role_rtmedia_media_edit_priv( $flag ) {”

Any ideas? :slight_smile:

Sorry for so many support requests this week, the sites nearly ready to launch just need a few things buttoned up.

Ben

Disregard the last message, the sample code you provided was missing a ; at the end of the function line.

To anyone who wishes to do this, copy paste this code into your functions.php:

add_filter( 'rtmedia_media_edit_priv', 'custom_role_rtmedia_media_edit_priv' );  
function custom_role_rtmedia_media_edit_priv( $flag ) {  
	if ( current_user_can('wpb_moderator') ) {  
       $wpb_moderator = true;  
	   return $wpb_moderator;  
       }  
	   $wpb_moderator = false;  
	   return $wpb_moderator;  
}  

add_filter( 'rtmedia_media_delete_priv', 'custom_role_rtmedia_media_delete_priv' );  
function custom_role_rtmedia_media_delete_priv( $flag ) {  
	if ( current_user_can('wpb_moderator') ) {  
       $wpb_moderator = true;  
	   return $wpb_moderator;  
       }  
	   $wpb_moderator = false;  
	   return $wpb_moderator;  
}

…and add a Custom Capability of wpb_moderator to User Role Editor and check it for your site moderators.

Thanks Ritesh!

Hi Ben,
I am glad you had figure it out.

Quick bump! :slight_smile:

Is there a filter to allow for deleting comments? Being able to edit media and delete media is solved, but our site moderators need a way to be able to delete comments from spammers and idiots, too.

Thanks!

Bump!

Hi @illusionsglass,

Sorry for the late reply. We don’t have any filter for that right now. We will be adding one which will be available in next update of rtMedia.

Awesome, thanks! What will the filter be named? Is it in the 3.7.5 that just came out today?

Ben

Name of the filter will be rtmedia_allow_comment_delete and it is not available in v3.7.5 as it has been already released.

Hi Ritesh,

The code here apparently has some unintended consequences. :slight_smile: It turns out, that it does work to allow our Moderators to edit/delete media of other users. However, it sets the flag to NOT allowed if the user is the owner of the media. That means moderators can delete and edit, but the owner of the media can not. Is there a modification to the code below that would be able check if the user can delete/edit as well and still set the flags accordingly?

Thank you!

/* Filters to allow site moderators.  Without these, moderators can not edit or delete content */
add_filter( 'rtmedia_media_edit_priv', 'custom_role_rtmedia_media_edit_priv' );
function custom_role_rtmedia_media_edit_priv( $flag ) {
	if ( current_user_can('wpb_moderator_edit') ) {
       $wpb_moderator = true;
	   return $wpb_moderator;
       }
}
add_filter( 'rtmedia_media_delete_priv', 'custom_role_rtmedia_media_delete_priv' );
function custom_role_rtmedia_media_delete_priv( $flag ) {
	if ( current_user_can('wpb_moderator_delete') ) {
       $wpb_moderator = true;
	   return $wpb_moderator;
       }
}

Bump!

Hi @illusionsglass,

The function definition should be like this for both the functions,

function custom_role_rtmedia_media_edit_priv( $flag ) {
	if ( current_user_can('wpb_moderator_edit') ) {
		$flag = true;
	}
	return $flag;
}

In your definition it won’t return any value if current user hasn’t wpb_moderator_edit capability and if you are using filter than you should definitely return some value otherwise it will throw warning notices and might break some functionality.

Thank you Ritesh. Returning the flag empty fixed the problem. Before I had it returning “false”, which apparently overwrote the rtmedia settings. Returning an empty $flag fixed it.

Greatly appreciated. Your a star. :smile: