Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

WebDevStudios/WDS-Required-Plugins

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

109 Commits
109 Commits
 
 
 
 
 
 
 
 

Repository files navigation

WDS Required Plugins

A library you can use to make any plugins required and auto-activate.

  • Nobody can de-activate the plugin from the WordPress Admin
  • They are auto-activated when required

To use, place this library in your mu-plugins/ directory (if you don't have one, create one in wp-content/), then use the example below:

WebDevStudios. WordPress for big brands.

Installation & Update

With Composer

Add the following to your composer.json

{
    "extra": {
        "installer-paths": {
            "mu-plugins/{$name}/": ["type:wordpress-muplugin"]
        }
    }
}

Then use:

composer require webdevstudios/wds-required-plugins

This will install the mu-plugin, e.g. mu-plugins/wds-required-plugins in wp-content based projects.

You will have to require it in e.g. mu-plugins/wds-required-plugins-list.php:

<?php

require WPMU_PLUGIN_DIR . '/wds-required-plugins/wds-required-plugins.php';

function wds_required_plugins_add( $required ) {
    return array_merge(
      $required,
      [
        'my-plugin/my-plugin.php',
      ]
    );
}
add_filter( 'wds_network_required_plugins', 'wds_required_plugins_add' );

Example Usage

<?php

/**
 * Add required plugins to WDS_Required_Plugins.
 *
 * @param  array $required Array of required plugins in `plugin_dir/plugin_file.php` form.
 *
 * @return array           Modified array of required plugins.
 */
function wds_required_plugins_add( $required ) {
  return array_merge(
    $required,
    [
      'jetpack/jetpack.php',
      'sample-plugin/sample-plugin.php',
    ]
  );
}
add_filter( 'wds_required_plugins', 'wds_required_plugins_add' );

Use the following filter instead to network activate plugins:

add_filter( 'wds_network_required_plugins', 'wds_required_plugins_add' );

Change the Text:

To change the label from Required Plugin to something else, use the following filter/code:

/**
 * Modify the required-plugin label.
 *
 * @param  string  $label Label markup.
 *
 * @return string         (modified) label markup.
 */
function change_wds_required_plugins_text( $label ) {

	$label_text = __( 'Required Plugin for ACME', 'acme-prefix' );
	$label = sprintf( '<span style="color: #888">%s</span>', $label_text );

	return $label;
}
add_filter( 'wds_required_plugins_text', 'change_wds_required_plugins_text' );

Hide Required Plugins (off by default)

To hide your required plugins from the plugins list, use the following filter/code:

add_filter( 'wds_required_plugins_remove_from_list', '__return_true' );

This will make any plugin that is required simply not show in the plugins list.

About

Make certain plugins required so that they cannot be (easily) deactivated. | Gatekeeper: @aubreypwd

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.