Download the PHP package bernskioldmedia/wp-plugin-base without Composer

On this page you can find all versions of the php package bernskioldmedia/wp-plugin-base. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package wp-plugin-base

WP Plugin Base

Total Downloads Latest Stable Version License

The WP Plugin Base is a feature-rich composer project to be included in WordPress plugins. It provides a good base scaffolding, as well as many common base features to speed up development.

Note: We recommend scoping your end plugin using PHP Scoper to prevent version conflicts across plugins.

Installation

The plugin base is used by the Bernskiold Media WP Plugin Scaffold. We generally use this to start off new plugin development.

To use the Plugin Base, load it via composer in your plugin:

composer require bernskioldmedia/wp-plugin-base

Overview

In this plugin base you'll find classes to help you create:

Forge CLI

Included in the plugin base is our forge CLI that helps you scaffold new classes that extend the base classes provided by the plugin base. The CLI is automatically installed to your vendor's bin folder for easy access.

For even simpler access, you may define a composer script in your project, such as our scaffold has:

You can then access the CLI by running: composer forge COMMAND.

The following commands are available:

forge make:customizer {name} - Customizer

Generate a class that can be used to add a customizer section and settings.

Options:

forge make:data {name} - Data Class

Generate a data class where getters and setters are used to interact with a data store.

Options:

forge make:cpt {name} - Custom Post Type Data Store Class Generate a custom post type data store.

Options: --namespace="MyPlugin\Namespace" The root plugin namespace. --textdomain="my-plugin" The plugin textdomain.

forge make:taxonomy {name} - Taxonomy Data Store Class

Generate a taxonomy data store.

Options:

forge make:facet {name} - Facet WP Facet Class

Generate a class to register a FacetWP Facet based on a FacetWP facet export.

Options:

forge make:fieldgroup {name} - ACF Field Group Class

Generate a class to register an ACF field group based on the ACF field group export.

Options:

forge make:rest {name} - REST Endpoint Class

Generate a class to create a custom REST API endpoint.

Options:

forge make:block {prefix} {name} - Creating a custom block

Generate all the files needed for a custom block.

Options:

Example:

forge setup:block-build - Sets up build assets for blocks

Generates the webpack config file as well as requires all the various NPM dependencies for building blocks.

Booting Classes

We typically need to boot (run) a series of classes and hooks/init functions when the plugin loads. This to boot further features.

Normally we do this by running the function (usually containing action calls) within the init_hooks() function.

To make this simpler, you can add your class to the $boot = [] array on the base plugin class. It will then be run on the init hooks function automatically. This way you don't have to extend the init hooks method for simple bootable operations.

Note: A function that you load via the boot property must implement the Hookable interface.

Loading Assets

The abstract class AssetManager can be used to load styles and script both public or admin intelligently.

It gives you two options. Either defining all values yourself, or if you are using @wordpress/scripts (which we almost always are), rely on the name.asset.php file that it generates for dependencies and version.

The process is the same for public/admin scripts and styles.

When extending the class, you can define four arrays and methods. The array properties auto-registers the scripts, while the four methods are responsible for enqueuing.

Because you likely want to enqueue the scripts conditionally, the helper library doesn't do this automatically.

Registering scripts

Registering scripts by using the asset meta file, requires just the simple config:

This configuration assumes the following structure:

  1. Script is called my-script.js.
  2. Script is placed in the assets/scripts/dist folder.
  3. There is a my-script.asset.php file next to the script file in the same folder.

Alternatively, you can define the full settings (with their defaults):

Scripts are registered with the array key name as handle.

Registering styles

Registering styles by using the asset meta file, requires just the simple config:

This configuration assumes the following structure:

  1. Stylesheet is called my-style.css.
  2. Stylesheet is placed in the assets/styles/dist folder.
  3. There is a my-style.asset.php file next to the stylesheet file in the same folder.

Alternatively, you can define the full settings (with their defaults):

Styles are registered with the array key name as handle.

Enqueue scripts and styles

We don't automatically enqueue scripts or styles. Instead we have four magic methods that hook in correctly when defined. This allows you to conditionally enqueue scripts and styles easily as needed.

When they exist in the file, they are hooked appropriately:

They are run at priority 100 by default. To override, you can set the protected static int $enqueue_priority.

Customizing Register Priority

By default we run the registration at priority 10. To customize, set the protected static int $register_priority to a custom value.

Adding Admin Columns Support

To easily share Admin Columns Pro sets between environments, it's often a good idea to commit them. To export and save them easily, the plugin base hooks into Admin Columns for custom data stores.

First, include the HasAdminColumns trait on the main plugin class.

Then, on the custom data stores that you want to store admin column sets for, set the $store_admin_columns property to true:

Data Stores

Adding a new data store is best done via the Forge CLI forge make:cpt MyDataStore.

To register the data store, add it to the $data_stores property in the main plugin class:

Note: When creating a data store, you should also create a matching Data class with getters and setters.

Special data store features:

Data Class

By creating a data class, we have a simple method for interacting with data from the data store. It's best created with the Forge CLI forge make:data {name}. It's name should match the data store.

It's used as: $data = new DataClass( $id );. Within the class $this->get_id() will always get you the current object ID.

Note: When creating a data class for a taxonomy, the TaxonomyData class will ensure ACF taxonomy compatibility automatically.

Add your getters and setters to the data class. It has built-in support for ACF fields especially through the following methods:

It also has some easy querying features that return the data class.

You may convert all the data for an object into an array with the to_array() method.

Custom Blocks

We find ourselves increasingly creating a bunch of plugins that add one or more blocks to the block editor. This requires a few functions to load and register.

All you need to do is include the Has_Blocks trait in the base plugin class.

Blocks are assumed to be placed in a blocks subfolder, and they are being built to dist/blocks.

Required Folder Structure for Blocks

The trait assumes the following folder structure:

blocks/ is the location of all blocks with one folder per block. The index.js file in each block folder is the entrypoint for the build script.

dist/blocks is the location of built JavaScript blocks with the same filename as the main folder name.

languages/ is the location of the translation files. The handle and domain are both set to {$block_prefix}-{$block_name}.

Defining a custom block prefix

The trait will default to using the 'bm' prefix for blocks. Blocks are named with a prefix to scope them to the project they are a part of. This also influences how the script and style handles are registered ($prefix-block-$block_name).

Your project probably requires its custom prefix. You can set it on the main plugin class like so:

Defining a custom job

When you have a long-running process that you need to run in the background, a job is what you want to run.

You can then dispatch your job like this:

Adding a bulk action

The framework contains an abstract class that you can extend to add a bulk action to one of the post type table views.

Don't forget to load the bulk action by adding it to the $boot array in the main plugin file.

Adding a multisite tab

Extend this abstract class to add a new tab to the network admin website edit screen.

Don't forget to load the tab by adding it to the $boot array in the main plugin file.


All versions of wp-plugin-base with dependencies

PHP Build Version
Package Version
Requires monolog/monolog Version ~1.25
php Version ^7.4|^8.0
symfony/console Version ^4.0|^5.0
symfony/process Version ^4.0|^5.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package bernskioldmedia/wp-plugin-base contains the following files

Loading the files please wait ....