PHPackages                             piotrpress/wordpress-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. [Templating &amp; Views](/categories/templating)
4. /
5. piotrpress/wordpress-plugin

ActiveLibrary[Templating &amp; Views](/categories/templating)

piotrpress/wordpress-plugin
===========================

This library is WordPress plugin singleton base class with methods to get data from plugin's header fields.

v3.0.0(1y ago)012411GPL-3.0PHPPHP &gt;=7.4

Since Nov 25Pushed 1y ago1 watchersCompare

[ Source](https://github.com/PiotrPress/wordpress-plugin)[ Packagist](https://packagist.org/packages/piotrpress/wordpress-plugin)[ Docs](https://github.com/PiotrPress/wordpress-plugin)[ RSS](/packages/piotrpress-wordpress-plugin/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (4)Used By (1)

WordPress Plugin
================

[](#wordpress-plugin)

This library is WordPress plugin singleton base class with methods to get data from [plugin's header fields](https://developer.wordpress.org/plugins/plugin-basics/header-requirements/).

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

[](#installation)

```
composer require piotrpress/wordpress-plugin
```

Usage
-----

[](#usage)

```
/**
 * Plugin Name:       Example Plugin
 * Plugin URI:        https://example.com/plugin/
 * Description:       Example Plugin description.
 * Version:           1.0.0
 * Requires at least: 6.2.2
 * Requires PHP:      7.4
 * Author:            John Smith
 * Author URI:        https://example.com/plugin/author/
 * License:           GPL v3 or later
 * License URI:       https://www.gnu.org/licenses/gpl-3.0.txt
 * Update URI:        https://example.com/plugin/update/
 * Text Domain:       example-plugin
 * Domain Path:       /languages
 */

require __DIR__ . '/vendor/autoload.php';

use PiotrPress\WordPress\Plugin;

class Example extends Plugin {
    public function activation() : void {}
    public function deactivation() : void {}
}

Example::getInstance( __FILE__ );

echo Example::getName();
```

**NOTE:** Plugin's translations are loaded automatically according to `Text Domain` and `Domain Path` plugin's header fields.

Methods
-------

[](#methods)

### Basic static methods handling plugin's default header fields

[](#basic-static-methods-handling-plugins-default-header-fields)

- `getName()` - returns `string` with the name of the plugin from `Plugin Name` header field
- `getPluginURI()` - returns `string` with the home page of the plugin or empty `string` if `Plugin URI` header field is not set
- `getVersion()` - returns `string` with the current version number of the plugin or empty `string` if `Version` header field is not set
- `getDescription()` - returns `string` with a short description of the plugin or empty `string` if `Description` header field is not set
- `getAuthor()` - returns `string` with the name of the plugin author or empty `string` if `Author` header field is not set
- `getAuthorURI()` - returns `string` with the website of the plugin's author or empty `string` if `Author URI` header field is not set
- `getTextDomain()` - returns `string` with the gettext text domain of the plugin or directory name of the plugin if `Text Domain` header field is not set
- `getDomainPath()` - returns `string` with the path to translations directory or empty `string` if `Domain Path` header field is not set
- `getNetwork()` - returns `bool` whether the plugin can only be activated network-wide according to `Network` header field
- `getRequiresWP()` - returns `string` with the lowest WordPress version that the plugin will work on or empty `string` if `Requires at least` header field is not set
- `getRequiresPHP()` - returns `string` with the minimum required PHP version or empty `string` if `Requires PHP` header field is not set
- `getUpdateURI()` - returns `string` with third-party plugin's update server or empty `string` if `Update URI` header field is not set
- `RequiresPlugins()` - returns `string` with the comma-separated list of WordPress.org-formatted slugs for its dependencies or empty `string` if `Requires Plugins` header field is not set

### Additional static methods handling plugin's paths

[](#additional-static-methods-handling-plugins-paths)

- `getSlug()` - returns `string` with the sanitized name of the plugin
- `getPrefix()` - returns `string` with the prefix for plugin's hooks
- `getFile()` - returns `string` with the path to main plugin's file
- `getDir()` - returns `string` with the path to plugin's directory
- `getUrl()` - returns `string` with the url to plugin's directory
- `getBaseName()` - returns `string` with the basename of the plugin
- `getDirName()` - returns `string` with the directory name of the plugin

### Inherited Singleton's static methods

[](#inherited-singletons-static-methods)

- `getInstance()` - returns the instance of the Plugin class

### Abstract methods handling plugin's de/activation

[](#abstract-methods-handling-plugins-deactivation)

- `activation()` - executed while plugin activation
- `deactivation()` - executed while plugin deactivation

### Handling custom plugin's header fields

[](#handling-custom-plugins-header-fields)

1. Add WordPress support for extra plugin's header fields using `extra_plugin_headers` filter:

```
add_filter( 'extra_plugin_headers', function () {
    return [ 'License', 'License URI' ];
} );
```

2. Add methods to handle extra plugin's header fields:

```
class Example extends Plugin {
    public static function getLicenseURI() {
        return self::get( 'License URI' );
    }
}
```

**NOTE:** `get` prefixed methods are automagically created for plugin's header fields that meet valid function name rules. e.g. `getLicense()` method.

Requirements
------------

[](#requirements)

PHP &gt;= `7.4` version.

License
-------

[](#license)

[GPL 3.0](license.txt)

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~512 days

Total

3

Last Release

655d ago

Major Versions

v1.0.0 → v2.0.02022-02-22

v2.0.0 → v3.0.02024-09-15

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/10326736?v=4)[Piotr Niewiadomski](/maintainers/PiotrPress)[@PiotrPress](https://github.com/PiotrPress)

---

Top Contributors

[![PiotrPress](https://avatars.githubusercontent.com/u/10326736?v=4)](https://github.com/PiotrPress "PiotrPress (3 commits)")

---

Tags

phppluginpluginswordpresswordpress-plwordpress-pluginwordpress-plugin-boilerplatewordpress-plugin-developmentwordpress-plugin-frameworkwordpress-plugin-librarywordpress-plugin-starterwordpress-plugin-templatewordpress-pluginspluginwordpresstemplateboilerplatewppluginsbootstrapbasestarter

### Embed Badge

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

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

###  Alternatives

[balbuf/composer-wp

Manage WordPress core, plugins, and themes with composer.

173.6k](/packages/balbuf-composer-wp)

PHPackages © 2026

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