Skip to content

Plugin(s)

Loïc Antignac edited this page Aug 5, 2022 · 12 revisions

Location

This library requires creating a very simple plugin to use it.

And there are 2 possibilities to use this composer library:

  1. install it globally to the site
  2. install it in the folder of a plugin… but globally is better

In the first case, it is possible to create 1 plugin per entity or per entity category and all the plugins will have access to the library since it will be loaded globally. This solution is recommended since it will be possible to deactivate one feature and not the others.

It is thus possible to make 1 plugin for the CPTs, 1 plugin for the CTs, 1 plugin for the options pages, or 1 plugin for the CPTs and the CTs, 1 for the options…

In the second case, only the plugin will have access to the library, which means that all the declarations will have to be made in one and the same plugin.

Case 1: install it globally to the site

Simply add the library to the global composer with:

composer require webaxones/core

Case 2: install it in the folder of a plugin

Initialize composer inside the plugin folder with composer init or create a composer.json file manually and add this inside:

{
	"name": "my-site/my-example-plugin",
	"description": "Custom declarations",
	"license": "GPL-2.0",
	"authors": [
	  {
		"name": "My name",
		"email": "[email protected]"
	  }
	],
	"type" : "wordpress-plugin",
	"minimum-stability": "dev",
	"prefer-stable": true
}

Then add the library to it with this command inside the plugin folder:

composer require webaxones/core

Create the plugin

Choose the entity to be created, refer to the menu in the Wiki sidebar and add desired content declarations to the main file of the plugin.

In summary the plugin must contain:

3 lines to load the autoload if the library is in the plugin, otherwise these 3 lines should not be added:

if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) {
	require __DIR__ . '/vendor/autoload.php';
}

An initialization statement with your plugin text-domain as parameter

use Webaxones\Core\Entities\Entities;

Webaxones\Core\Library::init( 'webaxones-content' );

  

Localize your entities

The slug to use in the Library init method must be the text-domain of the plugin declaring the entity.   And the .po .mo files should then be in the official /languages/plugins/ folder.   

The declaration array(s)

[
	'entity'   => 'Webaxones\Core\Classification\PostType',
	'labels'   => [
		...
	],
	'settings' => [
		...
	],
];

  

The start of the process

Entities::process( $declarations );
Clone this wiki locally