PHPackages                             givanov95/wp-plugin-core - 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. givanov95/wp-plugin-core

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

givanov95/wp-plugin-core
========================

Core PHP toolkit for building WordPress plugins: service providers, Vite asset integration, REST helpers, admin menus, validation, and a thin DB layer.

09PHP

Since May 26Pushed 1mo agoCompare

[ Source](https://github.com/givanov95/wp-plugin-core)[ Packagist](https://packagist.org/packages/givanov95/wp-plugin-core)[ RSS](/packages/givanov95-wp-plugin-core/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

wp-plugin-core
==============

[](#wp-plugin-core)

A small PHP toolkit for building WordPress plugins. Provides:

- **Service providers** — `PluginServiceProvider` (with Vite dev/prod asset enqueueing) and `RestEndpointServiceProvider` (with built-in nonce + capability checks).
- **Admin menus** — `AdminMenu` with top-level and submenu factories, registered in batch by `AdminMenuRegistrar`.
- **Controllers** — input validation and sanitization via `ValidationRule`enums, plus `success()` / `error()` JSON response helpers.
- **Database** — a thin wrapper around `$wpdb` with safe identifier escaping and `paginate()`.
- **Pagination** — a `Paginator` value object and a configurable `PaginationLinks` component.

Requires PHP 8.3+.

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

[](#installation)

```
composer require givanov95/wp-plugin-core
```

Quickstart
----------

[](#quickstart)

```
// my-plugin.php
require_once __DIR__ . '/vendor/autoload.php';

use MyPlugin\Providers\AssetsProvider;
use MyPlugin\Providers\ApiProvider;
use WpPluginCore\Providers\RestEndpointsManager;

(new AssetsProvider())->boot();
(new ApiProvider())->boot();

add_action('wp_enqueue_scripts', function () {
    RestEndpointsManager::localizeEndpoints('my-plugin', 'MyPluginData');
}, 20);
```

### Assets provider

[](#assets-provider)

```
use WpPluginCore\Providers\PluginServiceProvider;

class AssetsProvider extends PluginServiceProvider
{
    protected function pluginMainFile(): string { return MY_PLUGIN_FILE; }
    protected function scriptHandle(): string   { return 'my-plugin'; }
    protected function styleHandle(): string    { return 'my-plugin'; }
    protected function devServerUrl(): string   { return 'http://localhost:5173'; }
    protected function entryPoint(): string     { return 'assets/js/main.ts'; }
    protected function distDirectory(): string  { return 'dist'; }
}
```

Place a file named `.vite-dev` in the plugin root to load from the dev server; otherwise assets are read from the Vite `manifest.json`.

### REST endpoints

[](#rest-endpoints)

```
use WpPluginCore\Providers\RestEndpointServiceProvider;

class ApiProvider extends RestEndpointServiceProvider
{
    protected function registerEndpoints(): void
    {
        $this->addRestEndpoint(
            namespace: 'my-plugin/v1',
            route:     '/items',
            callback:  [new ItemsController(), 'index'],
            method:    'GET',
            public:    false,
            capability: 'edit_posts',
        );
    }
}
```

Endpoints are auto-localized to JavaScript via `RestEndpointsManager`, so the companion `@givanov95/wp-plugin-core-frontend` package can call them by route without manually wiring nonces.

### Admin menus

[](#admin-menus)

```
use WpPluginCore\Admin\Interfaces\ShouldHaveAdminMenu;
use WpPluginCore\Admin\Menu\AdminMenu;
use WpPluginCore\Admin\Menu\AdminMenuRegistrar;

class SettingsMenuProvider implements ShouldHaveAdminMenu
{
    public function getAdminMenu(): AdminMenu
    {
        return AdminMenu::topLevel(
            pageTitle: 'My Plugin',
            menuTitle: 'My Plugin',
            capability: 'manage_options',
            menuSlug: 'my-plugin',
            pageRenderCallback: fn () => (new SettingsPage())->render(),
        );
    }
}

AdminMenuRegistrar::register([
    SettingsMenuProvider::class,
    LogsSubmenuProvider::class, // returns AdminMenu::submenu(...)
]);
```

### Validation

[](#validation)

```
use WpPluginCore\Controllers\Controller;
use WpPluginCore\Enums\ValidationRule;

class ItemsController extends Controller
{
    public function store(\WP_REST_Request $request): void
    {
        $data = $this->validate($request->get_json_params(), [
            'email' => ['required' => true,  'rule' => ValidationRule::EMAIL],
            'age'   => ['required' => false, 'rule' => ValidationRule::INT],
        ]);

        $this->success($data);
    }
}
```

### Database

[](#database)

```
use WpPluginCore\Database\Database;

$db = new Database('my_items', allowedColumns: ['id', 'email', 'created_at']);

$id    = $db->insert(['email' => 'a@b.c']);
$item  = $db->find($id);
$page  = $db->paginate(['status' => 'active'], page: 1, perPage: 20,
    orderBy: ['created_at' => 'DESC']);
```

The `allowedColumns` argument is optional. When provided, any column referenced in `where()` / `orderBy` must be in the list. Otherwise, identifiers are validated against `[A-Za-z_][A-Za-z0-9_]*` and backticked.

License
-------

[](#license)

MIT — see [LICENSE](LICENSE).

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance61

Regular maintenance activity

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/63155374?v=4)[givanov95](/maintainers/givanov95)[@givanov95](https://github.com/givanov95)

---

Top Contributors

[![givanov95](https://avatars.githubusercontent.com/u/63155374?v=4)](https://github.com/givanov95 "givanov95 (10 commits)")

### Embed Badge

![Health badge](/badges/givanov95-wp-plugin-core/health.svg)

```
[![Health](https://phpackages.com/badges/givanov95-wp-plugin-core/health.svg)](https://phpackages.com/packages/givanov95-wp-plugin-core)
```

PHPackages © 2026

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