Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/bernskioldmedia/wp-plugin-scaffold

This is a simple plugin base for a WordPress plugin that we use at Bernskiold Media when creating custom plugin's for our clients.
https://github.com/bernskioldmedia/wp-plugin-scaffold

wordpress wordpress-boilerplate wordpress-development wordpress-plugin wordpress-plugin-boilerplate

Last synced: about 2 months ago
JSON representation

This is a simple plugin base for a WordPress plugin that we use at Bernskiold Media when creating custom plugin's for our clients.

Awesome Lists containing this project

README

        

# BM WP Plugin Scaffold

This is a simple plugin base for a WordPress plugin that we use at Bernskiold Media when creating custom plugin's for our clients.

This base is kept extremely simple in order to just facilitate a quick start. The only code bits that we have included are for taxonomies and post types, which are almost always
used in every new plugin.

We will add more (or less) to this plugin base as our development needs change.

In general, refer to our WP Plugin Base documentation for help on how to work with the scaffold.

## Getting Started

To get started developing a plugin, it's easiest to use the `bmwp` CLI.

With it installed, place yourself in the plugins folder and run: `bmwp create:plugin plugin-name`, replacing plugin-name with your desired folder name. You will then be asked a
series of setup questions.

After running it, remove this setion from the README and update it to be more specific about the plugin project.

## Development How-tos

### How to add block editor support

We often find ourselves having to add block support for a plugin that offers a few additional block editor blocks.

To make this simple, we have abstracted a composer library, (Block Plugin Support)[https://github.com/bernskioldmedia/Block-Plugin-Support], that contains a Trait with helper
functions.

Refer to its documentation on how to add it.

#### Where to place blocks?

Block code is expected to be placed in the `blocks/` directory. With a sub-folder for each block.

#### Block Folder Structure

As a general guideline, each block should have the following structure. We prefer splitting into more files for cleanliness and brevity.

```
block.json
index.js
edit.js
icon.js
inspector.js
save.js
```

#### Server-side Rendered Block Base

For a server-side rendered block, we have a base block class that provides helpful methods. This is provided by the Block Plugin Support library.

This is how a bare block class could look, inheriting methods from the abstract Block class:

```
use BernskioldMedia\WP\Block_Plugin_Support\Block;

class My_Thing_Block extends Block {

/**
* Render the content
*
* @param array $attributes
*
* @return false|string
*/
public static function render( $attributes ): string {

ob_start();
?>

is_main_query() ) {
return $query;
}

if ( $query->get( 'post_type' ) !== static::get_key() ) {
return $query;
}

// $query->set( 'prop', 'value' );

return $query;

}
```

#### Setting Capabilities

By default, the data store will have a common-sense default permission structure. The abstract `Custom_Post_Type` and `Taxonomy` classes house the default settings.

You may override by setting a similarily structured `role => permissions` array on the `::$permissions` property. Anything in the permissions property will override the default
permissions set by `::$default_permissions`.

You can load the capabilities array for the register function by calling `self::get_capabilities()`.

## Coding Style

We exclusively try and use the WordPress coding practices for all languages, which includes PHP, HTML, CSS and JavaScript.

This base plugin is in part OOP based to both live in its own namespace, and to make extending, updating and maintaining code simple and easy.

## Open Source

The reason we are open sourcing it is because it's the right thing to do. Perhaps someone finds a use out of it all, or parts. This is not going to be an actively developed "master
plugin base" that is set out to be the next greatest thing in the WordPress community. It's just going to be what we use internally, just published for the world to see and use as
you see fit.