Download the PHP package grottopress/wordpress-suv without Composer
On this page you can find all versions of the php package grottopress/wordpress-suv. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download grottopress/wordpress-suv
More information about grottopress/wordpress-suv
Files in grottopress/wordpress-suv
Package wordpress-suv
Short Description A scaffold for implementing the SUV architecture
License MIT
Informations about the package wordpress-suv
WordPress SUV
SUV is our own architecture for building WordPress themes and plugins at GrottoPress. 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
- PHP >= 7.0
- Composer
Code style
Code should comply with PSR-1, PSR-2 and 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
Note: From here on, app refers to your theme or plugin.
Directory Structure
Set up your own app's directory structure as follows:
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
Your composer.json
autoload config:
Require SUV
From the root of your app, run:
Sample WordPress plugin
Let's write a sample WordPress plugin using SUV, shall we?
You may file utility classes in app/MyPlugin/Utilities/
. Utility classes do not interact directly with WordPress, but contain functionality that setup classes and views can use to accomplish their goal.
Since our plugin extends
SUV's AbstractPlugin
, it is essentially a singleton. The entire plugin (with all objects) can be retrieved with a call to Vendor\MyPlugin\MyPlugin::getInstance()
Let's create a helper to do this in app/helpers.php
.
Other plugins and themes now have access to the singleton plugin instance, and can remove an action in our plugin thus:
Now, to conclude with our plugin's bootstrap:
Building a plugin?
We created a WordPress plugin scaffold that uses SUV. It sets up the most common stuff for you to dive straight into code.
You should check it out »
Building a theme?
If you're looking to build a theme using SUV, you should check out Jentil.
Jentil is a framework for rapid WordPress theme development, built using the SUV architecture.
It comes with numerous features, and includes a loader that loads templates (eg: page.php
, index.php
, single.php
etc) only from the app/templates
directory, and partials (eg: header.php
, footer.php
, sidebar.php
) from the app/partials
directory.
Development
Run tests with composer run test
.
Contributing
- Fork it
- Switch to the
master
branch:git checkout master
- Create your feature branch:
git checkout -b my-new-feature
- Make your changes, updating changelog and documentation as appropriate.
- Commit your changes:
git commit
- Push to the branch:
git push origin my-new-feature
- Submit a new Pull Request against the
GrottoPress:master
branch.