Plugin SDK

PL_Plugin fluent API

The PL_Plugin class is a thin fluent wrapper over the raw hook engine. Use it for clarity — under the hood it just calls add_action and add_filter.

Actions (fire-and-forget)

PL_Plugin::register('my-plugin')
    ->on('article.afterSave', $callback, 10)        // any hook
    ->onArticleSave($callback)                      // article.afterSave
    ->onArticleBeforeSave($callback)                // article.beforeSave (filter shortcut)
    ->onArticleDelete($callback)                    // article.beforeDelete
    ->onMediaUpload($callback)                      // media.afterUpload
    ->onLogin($callback);                           // user.afterLogin

Filters (pipeline a value)

PL_Plugin::register('my-plugin')
    ->filter('article.beforeSave', function ($data) {
        $data['slug'] = strtolower($data['slug']);
        return $data;
    }, 10);

UI extension points

PL_Plugin::register('my-plugin')
    ->addAdminMenuItem($label, $href, $icon, $minLevel = 0)
    ->addDashboardCard(function () { /* echo HTML */ })
    ->addEditorButton($label, $icon, $jsHandler);

Raw API

Anywhere inside plugin.php:

add_action('article.afterSave', function ($article, $id, $action) {
    // log it, send a webhook, generate a thumbnail
});

add_filter('article.beforeSave', function ($data) {
    return $data;
});

// Discover what's registered
PL_Hooks::listActions();
PL_Hooks::listFilters();

Migrations

Drop *.sql files into <plugin>/migrations/. They run in lexicographic order on first activation. Pressline remembers what's been applied in the plugins table.