All Projects → wppunk → Wpplugin

wppunk / Wpplugin

Licence: mit
Boilerplate for WordPress plugin using autoload, coding standard, webpack, PHP/JS tests, etc.

Projects that are alternatives of or similar to Wpplugin

Swiftdi
SwiftDI the new way to use your dependency in Swift 5.1
Stars: ✭ 107 (-4.46%)
Mutual labels:  dependency-injection
Wp React Boilerplate
Boilerplate for creating WordPress plugin UI's with REST API, BrowserSync, Webpack and React
Stars: ✭ 109 (-2.68%)
Mutual labels:  wordpress
S3 Uploads
The WordPress Plugin to Store Uploads on Amazon S3
Stars: ✭ 1,573 (+1304.46%)
Mutual labels:  wordpress
Wp Postviews
Enables you to display how many times a post/page had been viewed.
Stars: ✭ 107 (-4.46%)
Mutual labels:  wordpress
Wordpress Rest Admin
A frontend for admin area of WordPress, using WP REST API and React. It works with Self-Hosted WordPress
Stars: ✭ 108 (-3.57%)
Mutual labels:  wordpress
Frontpress
⚡️ A full front-end AngularJS template for WordPress Rest API.
Stars: ✭ 109 (-2.68%)
Mutual labels:  wordpress
Phpcompat
WordPress Plugin: PHP Compatibility Checker
Stars: ✭ 106 (-5.36%)
Mutual labels:  wordpress
Unity
This repository contains all relevant information about Unity Container suit
Stars: ✭ 1,513 (+1250.89%)
Mutual labels:  dependency-injection
Wordpress App With Flutter
Fully Functional IOS/Android App for WordPress Website with Flutter
Stars: ✭ 109 (-2.68%)
Mutual labels:  wordpress
Plate
Plate: a super stripped-down WordPress starter theme for developers.
Stars: ✭ 110 (-1.79%)
Mutual labels:  wordpress
Event Espresso Core
Event Espresso 4 Core for WordPress: Build an Event Ticketing Website Today!
Stars: ✭ 107 (-4.46%)
Mutual labels:  wordpress
Nextjs Wordpress Starter
WebDevStudios Next.js WordPress Starter
Stars: ✭ 104 (-7.14%)
Mutual labels:  wordpress
Behat Wordpress Extension
WordHat: Behat for WordPress
Stars: ✭ 109 (-2.68%)
Mutual labels:  wordpress
Wp Enforcer
Git hooks to encourage well-written WordPress.
Stars: ✭ 107 (-4.46%)
Mutual labels:  wordpress
Ionmag
Blogging and news theme for WordPress.
Stars: ✭ 110 (-1.79%)
Mutual labels:  wordpress
Dagger2 Mvp Sample
Android Sample to explain Dagger 2 and MVP in android applications.
Stars: ✭ 106 (-5.36%)
Mutual labels:  dependency-injection
Rxgithub
An example of MVVM using RxSwift and Swinject (DI)
Stars: ✭ 109 (-2.68%)
Mutual labels:  dependency-injection
Wp E2e Tests
Automated end-to-end tests for WordPress.com
Stars: ✭ 111 (-0.89%)
Mutual labels:  wordpress
Wp Cache Remember
Helper for the WordPress object cache and transients.
Stars: ✭ 111 (-0.89%)
Mutual labels:  wordpress
Theme
The Themosis framework theme.
Stars: ✭ 109 (-2.68%)
Mutual labels:  wordpress

WP Plugin

Get Started

One-line install:

composer create-project wppunk/wpplugin your-plugin-directory

Or you can copy the archive or clone via Git and then run:

composer init-project

Requirements

Make sure all dependencies have been installed before moving on:

  • WordPress
  • PHP >= 7.2.5 (You can easily downgrade it)
    • DOM extension
    • CURL extension
  • Composer
  • Node.js >= 14.8
  • npm
  • ChromeDriver (for acceptance tests)

Structure

plugins/your-awesome-plugin/        # → Root of your plugin.
├── .codeception/                   # → Codeception additional directories.
│   ├── _config/                    # → Configs for DB connection.
│   ├── _data/                      # → Folder for SQL dump.
│   └── _support/                   # → Additional classes for the Codeception tests.
├── .github/                        # → GitHub additional directories.
│   └── workflows/                  # → Workflows.
│       ├── plugin-name.conf        # → Config for the server.
│       └── plugin-name.yml         # → Actions for GitHub.
├── .tests/                         # → Tests.
│   └── php                         # → PHP tests.
│       ├── acceptance              # → PHP Acceptance tests.
│       ├── unit                    # → PHP Unit tests.
│       │   └── _bootstrap.php      # → Bootstrap file for PHP unit tests.
│       ├── acceptance.suite.yml    # → Config file for the acceptance tests.
│       └── unit.suite.yml          # → Config file for the unit tests.
├── assets/                         # → Assets directory.
│   ├── build/                      # → Assets build directory.
│   └── src/                        # → Assets source directory.
├── node_modules/                   # → JS packages (never edit).
├── src/                            # → PHP directory. 
├── templates/                      # → Templates for plugin views.
├── vendor/                         # → Composer packages (never edit).
├── vendor_prefixes/                # → Prefixed composer packages for non-conflict mode (never edit).
├── .codeception.yml                # → Main codeception config.
├── .eslintignore                   # → JS Coding Standards ignore file.
├── .eslintrc.js                    # → JS Coding Standards config.
├── .gitconfig                      # → Config for git.
├── .gitignore                      # → Git ignore file.
├── .phpcs.xml                      # → Custom PHP Coding Standards.
├── .scoper.inc.php                 # → Config for the PHP Scoper.
├── .stylelintrc                    # → Config for the style linter.
├── .webpack.mix.js                 # → Laravel Mix configuration file.
├── CHANGELOG.md                    # → Changelog file for GH.
├── composer.json                   # → Composer dependencies and scripts.
├── composer.lock                   # → Composer lock file (never edit).
├── LICENSE                         # → License file.
├── package.json                    # → JS dependencies and scripts.
├── package-lock.json               # → Package lock file (never edit).
├── plugin-name.php                 # → Bootstrap plugin file.
├── README.md                       # → Readme MD for GitHub repository.
├── readme.txt                      # → Readme TXT for the wp.org repository.
└── uninstall.php                   # → Uninstall file.

Autoload

We use PSR-4 and composer autoload for PSR-4. You can find it in composer.json in directive autoload.

Coding Standards

To check all coding standards:

npm run cs

PHP Coding Standard (PHPCS)

We use a custom coding standard based on WordPress Coding Standard. We disabled rules for the naming of WordPress files for using PSR-4 autoload. Also, we have a feature, which can allow testing your code using different PHP environments.

Custom PHPCS your can find in the .phpcs.xml.

Your can check PHPCS using a CLI:

composer cs

or

npm run cs:php

PHPCS checked before each commit, before the push, and in GH Actions.

JS Coding Standard (JSCS)

We use a default WordPress JSCS, but you can modify it in the .eslintrc file.

You can check JSCS using a CLI:

npm run cs:js

SCSS Coding Standard (SCSSCS)

We use a default standards for SCSS, but you can modify it in the .stylelintrc file.

You can check SCSSCS using a CLI:

npm run cs:scss

Frontend

All assets are located in assets/src/*.

All builds are located in assets/build/*.

CSS preprocessor is SCSS.

We use Laravel Mix for the assets build. You can modify it in .webpack.mix.js file.

For run Laravel mix you can use the next commands depend on situation:

npm run build
npm run build:producation
npm run start

GitHub

GH Actions

All steps for GH Actions you can find in .github/workflows/plugin-name.yml file. Also, for wake up a webserver, we need to add .github/workflows/plugin-name.conf

GH Hooks

Just make you GH repository clear. We use the Husky library to add actions before commit, push, etc. This helps developers make their GH more clear.

GH Templates

Basic GH templates for better security issues, support requests, bug reports, enhancements, feature requests, pull requests, and contributing templates.

Dependency injection container

The lightweight Dependency Injection component implements a PSR-11 compatible service container that allows you to standardize and centralize the way objects are constructed in your application.

Automatic load your dependencies using the type hinting.

You can disable plugin hooks very easily using a DIC. Just get the plugin object from the dependency injection container $container_builder->get( PluginName\Front\Front::class ). Example just disabling frontend assets:

function remove_plugin_name_frontend_assets( $injector ) {
    $front = $injector->make( PluginName\Front\Front::class );
    if ( ! $front ) {
        return;
    }
    remove_action( 'wp_enqueue_scripts', [ $front, 'enqueue_styles' ] );
    remove_action( 'wp_enqueue_scripts', [ $front, 'enqueue_scripts' ] );
}

add_action( 'plugin_name_init', 'remove_plugin_name_frontend_assets' );

PHP Scoper

You need to add prefixes for each outside dependency because other plugins or themes can use the same dependencies, and it can conflict between packages.

composer scoper

Automated testing

We are using for automated testing a Codeception library runs all types of PHP tests.

PHP unit tests

For running use a CLI command:

composer unit
  • Main configuration file .tests/php/unit.suite.yml
  • Unit tests inside .tests/php/unit/* folder.
  • Bootstrap file .tests/php/unit/_bootstrap.php
  • Each filename for test class must have a suffix on *Test.php.
  • Each test class must extend a PluginNameUnitTests\TestCase class.
  • You can also add some code to PluginNameUnitTests\TestCase.php
  • Each test method must have prefix test_
  • Additional files for autoloading in tests running you can add to .codeception/_support/* folder.

Also, unit tests will be checked on a push to repository action and inside the GH Actions pipeline.

PHP acceptance tests

Warning! The acceptance tests make REAL actions on your site. Before running need to create another database and create a dump.sql file with fresh WP install.

Before running, you need to (It needs to make just one time. I hope you can do it):

  1. Install a ChromeDriver
  2. Create a new database. For example, I named a database codeception_db
  3. Install a clear WordPress
  4. Export database to dump.sql
  5. Move a dump.sql file to the .codeception/_data/ folder.
  6. Copy a file .codeception/_config/params.example.php to .codeception/_config/params.local.php.
  7. Update your connection information to the testing site connection in .codeception/_config/params.local.php file.
  8. Update your wp-config.php file:
if ( 
    isset( $_SERVER['HTTP_X_TESTING'] )
    || ( isset( $_SERVER['HTTP_USER_AGENT'] ) && $_SERVER['HTTP_USER_AGENT'] === 'wp-browser' )
    || getenv( 'WPBROWSER_HOST_REQUEST' )
) {
    // Use the test database if the request comes from a test.
    define( 'DB_NAME', 'codeception_db' );
} else {
    // Else use the default one (insert your local DB name here).
    define( 'DB_NAME', 'local' );
}

For running use a CLI command:

composer acceptance
  • Main configuration file .tests/php/acceptance.suite.yml
  • Unit tests inside .tests/php/acceptace/* folder.
  • Each filename for test class must have a suffix on *Cest.php.
  • Each test method must have prefix test_
  • Each test method must include AcceptanceTester as argument.
  • You can add some methods to AcceptanceTester in .codeception/_support/AcceptanceTests.php.
  • Additional files for autoload in tests running you can add to .codeception/_support/* folder.

JS unit tests

For running use a CLI command:

npm run unit
  • Main configuration inside .tests/js/package.json in directory jest
  • Unit tests inside .tests/js/unit/* folder.
  • Bootstrap file .tests/js/setupTests.js
  • Each filename for test class must have a suffix on *.test.js.
  • Just import your class for testing and write tests.

Also, unit tests will be checked on a push to repository action and inside the GH Actions pipeline.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].