Paulund
2013-06-19 #wordpress

Always Installed WordPress Plugins

When you are doing client work and hand over the website for them to use, you would normally give them an administrator account so they have full access to make changes to plugins, themes, users...anything that they would need to. This can be great for the user as they can do whatever they want, it's their website, why not? But if you have developed a plugin that is vital for them to have installed or the website will not function correctly, like a plugin to create a custom post type and the user decides to deactivate this on the plugin screen, removing all this functionality, you could end up getting a few support calls. You have a number of options that can stop users from doing something like this...

  • You can not give them an administrator account.
  • Remove the plugin option from the plugin screen
  • Install this plugin in the mu-plugins folder.

Not Giving A Administrator Account

The problem you have by not giving them an administrator account is that any time the client wants to install a new plugin, change the theme, they will need to call you. This could be billable time but a client will unlikely want to pay you for something they can do themselves if you just gave them access to their own website. This is why I always give them an administrator account when handing over a website. They need full access to make any changes to the website that they need to. ## Remove Plugin From Plugin Screen

One option that you have is to remove the plugin from view on the plugin screen. In WordPress you have access to the all_plugins filter, which means you can then search for the plugin you want and remove it from the plugin list.


<?php
add_filter( 'all_plugins', 'hide_plugins');
function hide_plugins($plugins)
{
    // Hide hello dolly plugin
    if(is_plugin_active('hello.php')) {
        unset( $plugins['hello.php'] );
    }

    // Hide disqus plugin
    if(is_plugin_active('disqus-comment-system/disqus.php')) {
        unset( $plugins['disqus-comment-system/disqus.php'] );
    }

    return $plugins;
}

Just make sure that you activate your plugin first before removing it from the plugin screen. ## Install Plugin In mu-plugins Folder

This is a folder located at the same level as the plugin folder, inside the content folder wp-content/mu-plugins, this is where you can install all must use plugins. These plugins can be used by all sites on this WordPress installation, the benefit of putting a plugin in this folder is that they will not appear in the normal plugins screen. But they can be seen in there own specific must use plugins section in the admin area. They can only be removed from the installation by being removed from the mu-plugins folder. The default location for this folder is wp-content/mu-plugins but it can be changed, you just need to override the variable in the wp-config file.


define('WPMU_PLUGIN_DIR', '/wp-content/must-use-folder-leave-it-alone');
define('WPMU_PLUGIN_URL', 'http://www.example.com/wp-content/must-use-folder-leave-it-alone');

One thing to note that if you move a plugin into the mu-plugins folder then you can't see it on the plugin screen, therefore you can't deactivate it or enable it. But when you move a plugin into the mu-plugins folder it will automatically be activated. ### Disadvantages Of The mu-plugins Folder

This sounds great for all the plugins that you would always want on a WordPress blog, like Yoast SEO plugin and Akismet plugin, so why not move these plugins into the mu-plugins folder? There are disadvantages to using the mu-plugins folder, as these plugins do not appear on the plugin screen there will no longer be a notification for when there is an update for the plugin. As the Yoast SEO plugin is constantly getting new updates I do not recommend putting this plugin in the mu-plugins folder or you will have to manually update this plugin on new releases. When you move the plugin into the mu-plugins folder it becomes activate the plugin activation hooks will not run, so if the plugin uses this hook to setup the database structure then these will not exist when using the mu-plugins folder. The mu-plugins folder can not have sub-directory folders, so any plugins that you want to run will need to added to the root of the folder. ## Removing Plugin Action Links

Another option to use instead of the mu-plugin folder is to simply remove the action links allowing the user to delete or edit the plugins that you want them to use. WordPress comes with 100s of filters that allow you to change the content output, one of the filters is plugin_action_links this allows us to get what actions the links have an change them in anyway we want. In the below example we are going to remove the edit link and remove the delete link on certain plugins.


add_filter( 'plugin_action_links', 'remove_plugin_actions', 10, 4 );
function remove_plugin_actions( $actions, $plugin_file, $plugin_data, $context ) 
{
    // Remove all the edit links
    if ( isset( $actions['edit'] ) )
    {
        unset( $actions['edit'] );
    }

    // Remove the deactivate link only from plugins in the switch
    if( isset( $actions['deactivate'] ) )
    {
        switch($plugin_file)
        {
            case 'hello.php':
            case 'disqus-comment-system/disqus.php':
                unset( $actions['deactivate'] );

            break;
        }
    }

    return $actions;
}