PHPackages                             wpsmith/plugin - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. wpsmith/plugin

ActiveLibrary

wpsmith/plugin
==============

Core class for extending WordPress plugins and hiding WordPress plugins on the plugins page.

2.0.3(4y ago)11783GPL-2.0+PHPPHP &gt;=7.4.0

Since Jun 12Pushed 4y ago1 watchersCompare

[ Source](https://github.com/wpsmith/Plugin)[ Packagist](https://packagist.org/packages/wpsmith/plugin)[ Docs](https://github.com/wpsmith/Plugin)[ RSS](/packages/wpsmith-plugin/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependencies (1)Versions (23)Used By (3)

Plugin
======

[](#plugin)

[![Code Climate](https://camo.githubusercontent.com/eb63759ae39db990874de7a7ec58f076a15dcce40ab5bf14135e5d4912b4c81a/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f7770736d6974682f506c7567696e2f6261646765732f6770612e737667)](https://codeclimate.com/github/wpsmith/Plugin)

A class to use in your WordPress plugin to prevent updates to the plugin, ensure dependency plugin(s) is/are active, and to hide specific plugin(s).

Description
-----------

[](#description)

These classes solve three (3) particular problems:

1. *Preventing plugins from updating*

    Plugins and themes are automatically checked by WordPress for updates in the WordPress repository. This poses a special problem for private plugins if the plugin slug happens to match.
2. *Hiding Plugins*

    It is a best practice to move specific functionality to a core functionality plugin. One could use a mu-plugin but most use a standard plugin. However, the client could easily deactivate or delete the plugin. Therefore, hiding the plugin from the plugins page becomes very important.
3. *Extending Plugins*

    Many core functionality plugins extend/modify other plugins. If the dependency plugin that is being extended is deactivated, then the plugin makes the WordPress instance unstable and breaks the whole site.
4. *Uninstalling Plugins*

    It is a best practice to always uninstall your plugin data and files. However, an interface to determine what should be uninstalled needs to be built. This uses WP Pointers to create such an interface giving the user the choice to uninstall just the plugin files or everything.
5. *Building Plugins*

    When building a plugin, this library provides a base class to be extended as the new plugins core class.

Installation
------------

[](#installation)

This isn't a WordPress plugin on its own, so the usual instructions don't apply. Instead you can install manually or using `composer`.

### Manually install class

[](#manually-install-class)

Copy [`Plugin/src`](src) folder into your plugin for basic usage. Be sure to require the various files accordingly.

or:

### Install class via Composer

[](#install-class-via-composer)

1. Tell Composer to install this class as a dependency: `composer require wpsmith/plugin`
2. Recommended: Install the Mozart package: `composer require coenjacobs/mozart --dev` and [configure it](https://github.com/coenjacobs/mozart#configuration).
3. The class is now renamed to use your own prefix to prevent collisions with other plugins bundling this class.

Implementation &amp; Usage
--------------------------

[](#implementation--usage)

### Update Prevention

[](#update-prevention)

To prevent the current plugin from updating:

```
new \WPS\WP\Plugin\PreventUpdate( plugin_basename( __FILE__ ) );
```

To prevent another plugin (e.g., ACF) from updating:

```
new \WPS\WP\Plugin\PreventUpdate( 'advanced-custom-fields-pro/acf.php' );
```

### Hiding Plugin(s)

[](#hiding-plugins)

To hide the current plugin:

```
new \WPS\WP\Plugin\HidePlugin( plugin_basename( __FILE__ ) );
```

To hide another plugin (e.g., ACF):

```
new \WPS\WP\Plugin\HidePlugin( 'advanced-custom-fields-pro/acf.php' );
```

### Extending Plugin(s)

[](#extending-plugins)

To extend ACF, you would do something like this:

```
new \WPS\WP\Plugin\ExtendPlugin( 'advanced-custom-fields-pro/acf.php', __FILE__, '5.8.7', 'plugin-text-domain' );
```

### Uninstalling Plugin(s)

[](#uninstalling-plugins)

To use the `UninstallManager`, you would do something like this at the plugin's root:

#### Simple example

[](#simple-example)

Within the plugin's main file:

```
global $my_plugin_uninstaller;
$my_plugin_uninstaller = new \WPS\WP\Plugin\UninstallManager( __FILE__ );

// Register activation stuffs.
register_activation_hook( __FILE__, function() {
    global $my_plugin_uninstaller;
    UninstallManager::on_activation( $my_plugin_uninstaller );
} );

// Register deactivation stuffs.
register_deactivation_hook( __FILE__, function() {
    global $my_plugin_uninstaller;
    UninstallManager::on_deactivation( $my_plugin_uninstaller );
} );

// If not using an uninstall.php, you need to register uninstall stuffs.
register_uninstall_hook( __FILE__, function() {
    global $my_plugin_uninstaller;
    $wps_codeable_delete_action = $my_plugin_uninstaller->get_uninstall_action();

    // Bail if not deleting everything.
    if ( 'everything' !== $wps_codeable_delete_action ) {
    	return;
    }

    // Delete Options.
    $my_plugin_uninstaller->uninstall();
} );
```

#### A Better Example

[](#a-better-example)

Within the main plugin file:

```
/**
 * Gets uninstall manager.
 *
 * This function can be placed anywhere. Alternatively, you can use a global variable to hold the uninstaller.
 *
 * @param string $plugin_file Absolute path to plugin base file.
 *
 * @return \WPS\WP\Plugin\UninstallManager
 */
function get_uninstall_manager( $plugin_file ) {
    static $mgr;
    if ( null === $mgr ) {
        $mgr = new \WPS\WP\Plugin\UninstallManager( $plugin_file );
    }

    return $mgr;
}

// Setup Uninstall Manager at base of the plugin.
get_uninstall_manager( __FILE__ );

register_activation_hook( __FILE__, function() {
    UninstallManager::on_activation( get_uninstall_manager() );
} );
register_deactivation_hook( __FILE__, function() {
    UninstallManager::on_deactivation( get_uninstall_manager() );
} );
```

Then in `uninstall.php`:

```
// Require the main plugin file.
require_once( 'plugin.php' );

// Get what we are supposed to do on deletion/uninstall.
$uninstall_manager = get_uninstall_manager();
$wps_codeable_delete_action = $uninstall_manager->get_uninstall_action();

// Bail if not deleting everything.
if ( 'everything' !== $wps_codeable_delete_action ) {
	return;
}

// Delete Options.
$uninstall_manager->uninstall();
```

### Building a Plugin

[](#building-a-plugin)

For all my plugins, I build a base class for the main plugin. Out of the box, `PluginBase` does three things:

1. Loads plugin's text domain accordingly.
2. Implements `Singleton` so there can only be one.
3. Provides the following methods:

- `Plugin::doing_ajax()` or `PluginBase::doing_ajax()` - determines whether WP is processing an AJAX request.
- `Plugin::get_version()` - gets the plugin's version. Defaults to `0.0.0`.
- `Plugin::get_plugin_name()` - gets the plugin's name. Defaults to `wps`.~~~~
- `$this->get_template_loader()` - gets the plugin's template loader. See [TemplateLoader](https://github.com/wpsmith/templates).
- `$this->add_action()` - Either adds the action to the correct hook or performs the action if the hook has already been done or is being done.

Generally speaking, it goes something like this:

```
namespace WPS\WP\Plugins\MyPlugin;

use WPS\WP\Plugin\PluginBase;

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( ! class_exists( __NAMESPACE__ . '\Plugin' ) ) {
	/**
	 * Class Plugin
	 *
	 * @package \WPS\WP\Plugins\MyPlugin
	 */
	class Plugin extends PluginBase {
	    /**
         * Plugin constructor.
         *
         * @param array $args Optional args.
         *
         * @since 0.0.1
         */
        protected function __construct( $args = array() ) {
            // Construct the parent.
            parent::__construct( $args );
        }
    }
}

// Instantiate.
Plugin::get_instance( array(
    'name'    => 'my-plugin',
    'version' => '0.0.1',
    'file'    => __FILE__,
) );
```

Change Log
----------

[](#change-log)

See the [change log](CHANGELOG.md).

License
-------

[](#license)

[GPL 2.0 or later](LICENSE).

Contributions
-------------

[](#contributions)

Contributions are welcome - fork, fix and send pull requests against the `master` branch please.

Credits
-------

[](#credits)

Built by [Travis Smith](https://twitter.com/wp_smith)
Copyright 2013-2020 [Travis Smith](https://wpsmith.net)

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 82.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~64 days

Recently: every ~72 days

Total

22

Last Release

1552d ago

Major Versions

0.0.10 → 1.0.02019-02-21

1.1.3 → 2.0.32022-02-13

PHP version history (2 changes)0.0.1PHP &gt;=5.2.4

1.1.3PHP &gt;=7.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/46adebc3eebe7494dba592e75ac8f8572222050648b0283515b4a5896648d846?d=identicon)[wpsmith](/maintainers/wpsmith)

---

Top Contributors

[![wpsmith](https://avatars.githubusercontent.com/u/817366?v=4)](https://github.com/wpsmith "wpsmith (32 commits)")[![wpsmithtwc](https://avatars.githubusercontent.com/u/15801496?v=4)](https://github.com/wpsmithtwc "wpsmithtwc (7 commits)")

---

Tags

pluginwordpressdependencyextension

### Embed Badge

![Health badge](/badges/wpsmith-plugin/health.svg)

```
[![Health](https://phpackages.com/badges/wpsmith-plugin/health.svg)](https://phpackages.com/packages/wpsmith-plugin)
```

###  Alternatives

[sybrew/the-seo-framework

An automated, advanced, accessible, unbranded and extremely fast SEO solution for any WordPress website.

47078.8k](/packages/sybrew-the-seo-framework)[alleyinteractive/pest-plugin-wordpress

WordPress Pest Integration

263.7k1](/packages/alleyinteractive-pest-plugin-wordpress)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
