0

I want to remove plugin settings from the bottom of the post creating page for a given user type. enter image description hereI want to remove the "Plugin Organization" drop-down from the post creating page for a specific user type as shown in the image attached. Any code or plugin to do it?

  • 1
    You could check with the plugin's author, or look through their code to see whether they provided any hooks or ways to make their settings only appear for certain roles or capabilities. – WebElaine May 27 at 18:24
  • @WebElaine I checked the documentation and didnt find anything, I sent them emails but didnt get a reply. Im trying to do it myself anyway – shimii May 28 at 10:57
0

As you've already done, the first step is to contact the plugin author directly.

If it's a plugin in the .org repo, you can also try asking the question on the plugin's support page there. Others in the community might see it and help, though that might take awhile. (If it's not on .org, there may still be public discussion or question boards available, so seek those out.)

The next thing to do is look through the code itself, to see if you can determine how this section is added to the editor, and whether the author provided some built-in way for it to be conditional.

If they did not build in a way to meet your needs, you can either code the change yourself or hire someone to do so. Then you will want to submit this change as a pull request to the author. Best case scenario, they will accept the change and it will become part of the plugin, so you can continue updating it. Worst case scenario, they never accept the change, and you will need to manually add in your change every time the plugin has an update available, or just maintain it as a fork (your own entirely separate version, where you need to make security and compatibility updates yourself) as long as you need the plugin.


More specifically:

You may be able to call remove_action() for that wppb_content_restriction_add_meta_box() function in your own custom plugin. You would then add a new add_action() with your conditional inside it - check if the user has a certain capability - and if it meets your criteria, then re-hook the function.

It depends on where they've hooked that function - you'll need to check, as it may not be init - but here's some code to get you started. (You'll need to determine what capability to check for so you're targeting the users you want; you'll need to check the hooks and priorities, but this should be close to what you're looking for.)

<?php
/* Plugin Name: Make Metabox Conditional
*/
// First, remove the action completely
add_action('init', 'wpse_367691_unhook', 11);
function wpse_367691_unhook() {
    remove_action('init', 'wppb_content_restriction_add_meta_box', 15);
}
// Now, add your own action which will include the conditional
add_action('init', 'wpse_367691_rehook, 20);
function wpse_367691_rehook() {
    // If the current user can publish Posts
    // (change this capability to target users who should see the box)
    if(current_user_can('publish_posts')) {
        wppb_content_restriction_add_meta_box();
    }
}
?>

You can then continue updating the original plugin - checking to make sure they don't change the name of their function or priority, which are likely not to change - and also keep this plugin which only makes the one function conditional.

| improve this answer | |
  • Thank You for the answer, and I just received a response from the plugin author saying that this feature is unavailable, and meanwhile I found the function which displays the metabox(thats what they call it) its called "wppb_content_restriction_add_meta_box()". – shimii May 28 at 15:51
  • I'm trying to create a function to check on page load if "wppb_content_restriction_add_meta_box()" is included, if yes it will check for the user role, if the user role is a selected role it has to stop it from being displayed. Please tell me if it is possible to do so, and any support will be very much appreciated :) – shimii May 28 at 15:57
  • It should be, but will still depend on you researching a few things. I've updated the answer above to include the type of code you can try. – WebElaine May 29 at 14:19
  • Thank You @WebElaine :D I managed to change the plugins code with current_user_can('Administrator') to show it only for Admins. And your code solves the problem from the themes side. Thank You so much, really appreciate your support – shimii May 30 at 15:28
  • Hopefully you changed the behavior without editing the plugin directly. If you edited any plugin files, be aware that every time you update the plugin, you'll have to make your change again, which is why editing plugins directly is not recommended. If you just used the hooks in a custom theme or plugin (not the original plugin) you're safe. – WebElaine Jun 1 at 13:23

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.