Composer library for WordPress plugins · v0.1.3

Install, upgrade and uninstall, handled.

WP Foundation takes care of the lifecycle work every WordPress plugin needs: requirement checks, activation, upgrades with migrations, uninstall cleanup and multisite. It can also ask people why they're deactivating.

composer require bignall/wp-foundation

Read the guide View on GitHub

PHP 8.1+ · WordPress 6.4+ · GPL-2.0-or-later

acme-bookings.php
Plugin::create( __FILE__ )
	->requires( php: '8.1', wp: '6.4' )
	->options( [ 'acme_settings' => [ 'slots' => 30 ] ] )
	->role( 'acme_manager', 'Booking Manager' )
	->cron( 'acme_send_reminders', 'hourly' )
	->tables( new BookingsTable() )
	->migration( '1.1.0', [ Migrations::class, 'addStatus' ] )
	->flushRewriteRules()
	->deactivationSurvey()
	->deleteDataOnUninstall()
	->onReady( fn () => App::run() )
	->boot();

One definition covers every stage

Describe what your plugin needs once. WP Foundation sets it up, keeps it current, and removes it when asked.

  1. Activation

    Checks requirements first and refuses to activate with a clear message if they aren't met. Then creates tables, default options, roles, capabilities and cron events.

  2. Every request

    Checks requirements again, in case a plugin you depend on was switched off. If something is missing, admins see a notice, and your code doesn't run.

  3. Upgrade

    Spots a new version, including automatic updates, and runs your migrations in order. Then it syncs table schemas and adds new options and capabilities.

  4. Deactivation

    Unschedules cron events and removes rewrite rules, but keeps the site's data. It can optionally ask why the plugin is being deactivated.

  5. Uninstall

    Drops tables and removes options, roles and cron events, but only if you opt in or the site owner chooses to.

  6. Multisite

    Network activation and uninstall reach every site. New sites are set up automatically, and deleted sites take their tables with them.

The details plugins usually get wrong

These are the edge cases that cause white screens, missing tables and broken permalinks. WP Foundation handles them for you.

Automatic updates skip the activation hook
Upgrades run when a page loads, not only on activation. A lock stops two requests from running the same migration.
Activation runs before your post types exist
Flushing rewrite rules there misses your post types. The flush is put off to the end of the next init, after they're registered.
A failed migration shouldn't break the site
The stored version only advances past migrations that finished. Admins see the error, and the next page load resumes where it stopped.
Old PHP versions shouldn't white-screen the site
A version guard in your main file and Composer's platform check switched off mean old hosts get a notice, not a fatal error.
Uninstall shouldn't surprise anyone
Data is kept unless you opt in, or let the site owner decide with a setting. A filter has the final say.
Two plugins can bundle different versions
The library is designed to be prefixed with Strauss, and its survey script and styles are inlined, so each plugin keeps its own copy.

Ask why they're leaving

When someone clicks Deactivate, a short survey asks why. The answer goes to your handler: stored on the site, sent to your server, or both.

  • Skippable, and deactivation always goes ahead, even if sending fails.
  • Add, remove or replace reasons, and ask for details where they help.
  • Says when answers leave the site, and only includes the site address if the user agrees.
  • Protected by a nonce and a capability check, with input sanitized and length-limited.

Survey guide →

Try it: this is the plugin's own survey script

Plugins

PluginDescription
Acme Bookings
Settings | Deactivate
Example plugin built on WP Foundation. Version 1.1.0

What your feedback handler receives

Click Deactivate to try the survey.

Get started in three steps

  1. Require the library

    composer require bignall/wp-foundation
  2. Describe your plugin

    use Bignall\WPFoundation\Plugin;
    
    Plugin::create( __FILE__ )
    	->requires( wp: '6.4' )
    	->options( [ 'acme_settings' => [] ] )
    	->onReady( fn () => Acme\App::run() )
    	->boot();
  3. Bump the version and ship

    Change the Version: header in your plugin file. Next time a site loads a page, the upgrade runs. Prefix the library with Strauss before you release.

    Full getting-started guide →