Skip to main content
  1. All Posts/


Tools Open Source PHP WordPress

WordPress Toolkit

Work with common WordPress Plugin and Theme APIs in a
modern, object-oriented way.

By Max Melzer
The WordPress Toolkit is a Composer
module that offers easy access to common WordPress functionality,
inspired by modern PHP frameworks like Symfony.
It’s aim is to provide consistent, object-oriented methods
for WordPress plugin and theme development.


To use the toolkit, add it to your theme or plugin via

cd wp-content/themes/your-awesome-theme
composer init
composer require moehrenzahn/wp-toolkit

Then, you can initialize the Client class in your PHP script. This is
the entry point to all functionality of the toolkit.

$client = new MoehrenzahnToolkitApiClient();


  • Composer
  • PHP >= 7.1
  • WordPress >= 5.0 (older versions may work but are untested)


  • convenient API around WordPress action and filter management
  • object manager with simple, automatic dependency injection
  • template rendering with Model-View-Controller architecture
  • add and manage
    • JavaScript files
    • CSS files
    • image sizes
    • shortcodes
    • virtual user accounts
    • Transients
    • Post Types
    • Post Terms and Meta
    • Post Meta boxes
    • Post filters
    • comment Meta
    • comment Meta boxes
    • settings pages
    • admin pages
    • admin notices
    • AJAX actions
    • POST actions

Usage example

Add a CSS file to your theme:

// Entry point for all actions is the Client object
$client = new MoehrenzahnToolkitApiClient();
$stylesheets = $client->getStylesheetManager();
$stylesheets->add('eule-stylesheet', 'src/css/style.css', '1.0.0');

Add a shortcode with a custom template:

$client = new MoehrenzahnToolkitApiClient();
$shortcodes = $client->getShortcodeManager();

Create a custom settings page with pre-built input type templates.

$client = new MoehrenzahnToolkitApiClient();
    'Sample settings page',

 * @param MoehrenzahnToolkitApiClient $client
 * @return MoehrenzahnToolkitViewSettingsSection[]
function getSections(MoehrenzahnToolkitApiClient $client): array
    $sectionBuilder = $client->getSettingsSectionBuilder();
        'A sample setting title',
        'A sample setting description.'

        'Select your thing',
        'You can also do select inputs!',
           'sample-option-value' => 'Sample option label',
           'another-option-value' => 'Another option!',
    return [$sectionBuilder->create('sample-section', 'A sample settings section')];

Use the built-in View class to render your templates and get
access to features like lazy-loading images and partials:

<?php /** @var MoehrenzahnToolkitView $view */ ?>
<h2>Here comes a lazy-loaded partial that is only loaded when it's scrolled into view:</h2>
<?php $view->renderLazyPartial(
) ?>

Use the object manager to initalize objects with automatic dependency resolution.

$client = new MoehrenzahnToolkitApiClient();
$objectManager = $client->getObjectManager();
 * The object manager will try to automatically and recursively
 * resolve all dependencies of the given class.
 * Don't use this for very large projects since it can impact performance.
$customObject = $objectManager->getSingleton(YourCustomClass::class);

Release History

  • 1.0.0
    • Initial release


Max Melzer – @_maxmelzer
Distributed under the GNU General Public License. See for more information.


  1. Fork it (
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request