I'm trying to create a customization, which works like this. I have two user roles, one which has the ability to add both videos and pictures to a custom post type, and the other has only the ability to add pictures. I have created a script which runs on the user role which is only allowed to use pictures. If I switch one user to the user role which doesn't allow video I want it removed from the post. The script looks like this:

 jQuery(document).ready( function($) {
         if (jQuery('#background-video-button').length>0) {
             jQuery('#background-video-remove a').trigger('click'); // Click Remove button
             jQuery('#background-video-button').hide(); // Hides Select/Upload Video button
             jQuery('#background-video-preview').hide(); // Hides preview

What happens is, first the Remove button is triggered, which will remove the video from the post. Then it hides the buttons (the ability to add a new video). But nothing happens to the post until you press the Publish button.

Is it possible somehow to update the posts, of a specific custom post type when a user is moved from one user role to another? And how do you make sure not all posts of the custom post type are updated when this happens?

Thank you, and I hope this question is a good one, I am sure this can be applied for many other things!

  • 1
    But why would you like to do such things in JS? What is user disables JS in his browser? I think that you should assure such things with server-side scripts. – Krzysiek Dróżdż Mar 20 '18 at 18:32
  • That is true, but this is the only way I could think of. I am using this script together with User Role Editor, and enabling it on a user role. How would I do it otherwise? – jockebq Mar 20 '18 at 19:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.