PHPackages                             oan/wordpress-helpers - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. oan/wordpress-helpers

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

oan/wordpress-helpers
=====================

A collection of abstract PHP classes to work easier with WordPress themes using Composer.

v0.0.7(6y ago)0110UnlicensePHPPHP &gt;=7.1

Since Apr 10Pushed 3y ago1 watchersCompare

[ Source](https://github.com/johanhermansson/Wordpress-Helpers)[ Packagist](https://packagist.org/packages/oan/wordpress-helpers)[ Docs](https://github.com/johanhermansson/Wordpress-Helpers)[ RSS](/packages/oan-wordpress-helpers/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (1)Versions (8)Used By (0)

Wordpress Helpers
=================

[](#wordpress-helpers)

A collection of abstract PHP classes to work easier with WordPress themes using Composer.

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

[](#installation)

```
composer require oan/wordpress-helpers

```

AbstractTheme
-------------

[](#abstracttheme)

The class is of Singleton implementation, which means you should not instantiate it with `new MyTheme`. Instead you should use the static method `MyTheme::instance()` to get the **only** available instance.

By default the AbstractTheme will remove som functionality without you setting it; Some default widgets and some meta elements in the header. Look at the file for specifics.

### Example

[](#example)

```
use OAN\Wordpress\AbstractTheme;

class MyTheme extends AbstractTheme {
	protected static $styles = [
		// Handle will be generated from Theme name
		'style.css',
		// Or pass wp_enqueue_style parameters as an array
		[ 'my-theme-style', 'dist/css/another-style.css' ]
	];

	protected static $scripts = [
		// Handle will be generated from Theme name
		'script.js',
		// Or pass wp_enqueue_script arguments as an array
		[ 'my-theme-scripts', 'dist/js/scripts.js' ]
	];

	protected static $actions = [
		// Will look for method within instance
		// with the same name as action
		'init',
		// Pass add_action arguments as an array
		[ 'init', 'this::init', 10, 0 ],
	];

	protected static $filters = [
		// Will look for method within instance
		// with the same name as action
		'the_content',
		// Pass add_action arguments as an array
		[ 'the_content', 'this::the_content', 10, 1 ],
	];

	protected static $menus = [
		'main-menu' => __( 'Main menu', 'my-theme' ),
	];

	protected static $sidebars = [
		'second-sidebar' => __( 'Second sidebar', 'my-theme' ),
	];

	protected static $widgets = [
		// Activate
		'MyWidgetClass',
		// Deactivate, but won't work because of the line above
		'MyWidgetClass' => false,
		// Deactivate
		'Namespace\AnotherWidgetClass' => false,
	];

	public function init() {
		// Do awesome stuff
	}

	public function the_content( $content = '' ) {
		// Do awesome stuff
		return $content;
	}

	public static function awesome_static_function( $content = '' ) {
		// Do awesome stuff
		return $content;
	}

	public function awesome_function( $content = '' ) {
		// Do awesome stuff
		return $content;
	}
}

MyTheme::instance()

// Add filters and actions use self for static methods
->add_filter( 'the_content', 'self::awesome_static_function' )

// And this for normal methods (chaining works great btw)
// Also. There's support for priority and number of arguments.
->add_filter( 'the_content', 'this::awesome_function', 10, 2 )

// Or other classes
->add_action( 'save_post', 'MyAwesomeClass::my_awesome_method' )
->add_action( 'save_post', [ $awesomeClassInstance, 'my_awesome_method' ] )

// Add nav menus
->add_menu( 'footer-menu', __( 'Footer menu', 'my-theme' ) )

// Add sidebars
->add_sidebar( 'second-sidebar', __( 'Second sidebar', 'my-theme' ) )

// Add widgets by adding the global class name
->add_widget( 'MyThemeWidget' )

// To send everything to WordPress,
// you'll have to initialize the instance.
// It's only possible to do this once!
->initialize();
```

Hooks Trait
-----------

[](#hooks-trait)

If your class need access to `->add_action()` and `->add_filter()`, just use the Hooks trait.

```
use OAN\Wordpress\Traits\Hooks;

class MyClass {
	use Hooks {
		// Alias the construct to get it running
		// with the below example, otherwise you
		// need to add actions and filters with
		// ->add_action and ->add_filter
		Hooks::__construct as hooks_construct;
	}

	protected $actions = [
		// Each item in the array will be sent
		// to the ->add_action() method
		[ 'after_setup_theme', 'this::my_awesome_function' ],
		// Priority and number of arguments
		[ 'after_setup_theme', 'this::my_awesome_function', 10, 2 ],
		// Single strings will look for a method
		// with the same name within the class
		'after_setup_theme',
	];

	protected $filters = [
		// Use in the same way as with actions
	];

	public function __construct() {
		$this->hooks_construct();
	}
}
```

Future plans
------------

[](#future-plans)

- AbstractPostType
- AbstractTaxonomy
- Handling of manifest.json
- ... and probably a lot more

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

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 ~11 days

Total

7

Last Release

2522d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ea158040f2c705703fc4f18fbf4bbe01029fb1a06e93f96b5e6bc6da9859e897?d=identicon)[sumway](/maintainers/sumway)

---

Top Contributors

[![johanhermansson](https://avatars.githubusercontent.com/u/1567642?v=4)](https://github.com/johanhermansson "johanhermansson (30 commits)")

### Embed Badge

![Health badge](/badges/oan-wordpress-helpers/health.svg)

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

PHPackages © 2026

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