skip to Main Content

on WordPress website, how to disable anyone, including all admins to add new plugins. I want to be able to add plugins only via ftp, so no one can add them from WordPress menu.

Is there a custom function for this or any similar code? I searched but could not find any simple solution without any plugins that restrict access. I need solution without any extra plugin.

Thanks a lot.

2

Answers


  1. Add this to your functions.php file. Get the specific users and remove their roles.

    <?php
    
    // Get users with this role/s.
    $users = get_users( array(
        'role'    => 'administrator',
        // 'role__in' => array( 'administrator', 'editor' )
    ) );
    
    foreach( $users as $user ):
        $user = new WP_User( $user->ID );
        $user->add_cap( 'install_plugins' );
    endforeach;
    

    Just remember when the capability is removed then it is gone for good. If you change your mind you can use this to add the capability again.

    $users = get_users( array(
        'role'    => 'administrator',
    ) );
    
    foreach( $users as $user ):
        $user = new WP_User( $user->ID );
        $user->add_cap( 'install_plugins' );
    endforeach;
    
    Login or Signup to reply.
  2. To disable plugin installation in wordpress admin panel, the following code can be put in file "wp-config.php".

    define('DISALLOW_FILE_MODS', true);
    

    It can be checked, if it works.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search