PHPackages                             grottopress/wordpress-suv - 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. [Framework](/categories/framework)
4. /
5. grottopress/wordpress-suv

ActiveLibrary[Framework](/categories/framework)

grottopress/wordpress-suv
=========================

A scaffold for implementing the SUV architecture

v1.1.0(2y ago)11.1k1MITPHPPHP &gt;=7.0

Since Jan 7Pushed 2y ago1 watchersCompare

[ Source](https://github.com/GrottoPress/wordpress-suv)[ Packagist](https://packagist.org/packages/grottopress/wordpress-suv)[ RSS](/packages/grottopress-wordpress-suv/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (22)Used By (1)

WordPress SUV
=============

[](#wordpress-suv)

**SUV** is our own architecture for building WordPress themes and plugins at [*GrottoPress*](https://www.grottopress.com). This package is a scaffold for implementing **SUV**.

**SUV** is short for *Setups-Utilities-Views*. It emphasises an object oriented approach to writing WordPress plugins and themes, and provides for a cleaner, more organised code base.

SUV employs object composition extensively, and makes full use of the express power of core WordPress' event-driven architecture.

**Setups**: Includes all objects with methods that interact directly with WordPress, usually by means of action and filter hooks.

**Utilities**: Utilities are objects with methods that are needed by setups and views to accomplish their goals.

**Views**: Views are templates and partials to be loaded by the theme/plugin or WordPress.

Requirements
------------

[](#requirements)

- PHP &gt;= 7.0
- [Composer](https://getcomposer.org)

Code style
----------

[](#code-style)

Code should comply with [PSR-1](http://www.php-fig.org/psr/psr-1/), [PSR-2](http://www.php-fig.org/psr/psr-2/) and [PSR-4](http://www.php-fig.org/psr/psr-4/), at least.

You are strongly encouraged to use strict typing in PHP 7, and specify types for function/method arguments and return values.

As much as possible:

- Aim for immutable objects
- Prefer declarative syntax
- Don't inherit concrete classes
- Avoid static methods
- Do away with *fancy* design patterns

Usage
-----

[](#usage)

**Note:** From here on, *app* refers to your theme or plugin.

### Directory Structure

[](#directory-structure)

Set up your own app's directory structure as follows:

```
.
├── app/
│   ├── MyApp/
│   │   ├── Setups/
│   │   ├── Utilities/
│   │   └── Utilities.php
│   ├── helpers.php
│   └── MyApp.php
├── assets/
│   ├── css/
│   └── js/
├── dist/
│   ├── css/
│   └── js/
├── lang/
├── node_modules/
├── partials/
├── templates/
├── tests/
├── vendor/
├── .editorconfig
├── .gitignore
├── CHANGELOG.md
├── codeception.yml
├── composer.json
├── composer.lock
├── .php (functions.php or my-plugin.php)
├── LICENSE
├── package.json
├── package-lock.json
├── postcss.config.js
├── README.md
├── tailwind.config.js
├── tsconfig.json
└── webpack.mix.js

```

Not all directories/files may apply in your case. Remove whichever you do not need, and add whatever you require as necessary. Just keep the general concept in mind.

### Autoloading

[](#autoloading)

Your `composer.json` autoload config:

```
{

  "autoload": {
    "psr-4": {
      "Vendor\\": "app/"
    },
    "files": [
      "app/helpers.php"
    ]
  }

}
```

### Require SUV

[](#require-suv)

From the root of your app, run:

```
composer require grottopress/wordpress-suv
```

Sample WordPress plugin
-----------------------

[](#sample-wordpress-plugin)

Let's write a sample WordPress plugin using SUV, shall we?

```
// @ wp-content/plugins/my-plugin/app/MyPlugin.php
