WordPress entities creation library (CPT, CT, native option page, ACF option page, user role, block pattern category, block category…)

Overview

Webaxones Core

Custom declarations

1- Create a folder for your plugin

wp-content\plugins\my-example-plugin\

The example below integrates all the declarations in 1 single plugin for simplification but:
using a library inside a main global composer/vendor like in Bedrock allows you to make as many plugins as you want.

2- Add library

Add Webaxones Core library to the global composer if you have one:

composer require webaxones/core

If you don’t have one, you can initialize composer inside plugin folder with composer init or create a composer.json file manually:

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

Then add the Webaxones Core library to it:

composer require webaxones/core

3- Create the plugin

Add desired content declarations to your my-example-plugin.php file:

'manage_options', 'icon_url' => 'dashicons-admin-generic', 'position' => 99, ], ] ); /** * Custom ACF option page: Projects archive */ $declarations[] = new EntityFactory( [ 'entity' => 'Webaxones\Core\Option\AcfOptionsPage', 'labels' => [ 'page_title' => _x( 'Projects archive', 'Option page title', 'webaxones-content' ), 'menu_title' => _x( 'Projects page', 'Option page menu title', 'webaxones-content' ), ], 'settings' => [ 'slug' => 'wax-projects-settings', 'location' => 'custom', /*'custom', 'dashboard', 'posts', 'pages', 'comments', 'theme', 'plugins', 'users', 'management', 'options'*/ 'parent_slug' => 'edit.php?post_type=project', /* if location is "custom" */ 'capability' => 'manage_options', 'icon_url' => '', 'position' => 99, ], ] ); /** * Add Custom role: Owner */ $declarations[] = new EntityFactory( [ 'entity' => 'Webaxones\Core\Role\Role', 'labels' => [ 'role_name' => _x( 'Owner', 'Custom role name', 'webaxones-content' ), ], 'settings' => [ 'slug' => 'owner', 'action' => 'add', 'role_to_clone_slug' => 'administrator', 'capabilities_to_remove' => [ 'manage_options', 'switch_themes', 'remove_users', 'activate_plugins', 'delete_others_pages', 'delete_site', 'delete_pages', 'delete_private_pages', 'delete_published_pages', 'delete_others_posts', 'delete_posts', 'delete_private_posts', 'edit_theme_options', 'export', 'import', 'edit_private_pages', 'edit_private_posts', 'promote_users', 'customize', ], ], ] ); /** * Remove Custom role: Test */ $declarations[] = new EntityFactory( [ 'entity' => 'Webaxones\Core\Role\Role', 'labels' => [], 'settings' => [ 'slug' => 'test', 'action' => 'remove', 'role_to_clone_slug' => '', 'capabilities_to_remove' => [], ], ] ); /** * Update Custom role: Owner */ $declarations[] = new EntityFactory( [ 'entity' => 'Webaxones\Core\Role\Role', 'labels' => [ 'role_name' => _x( 'Owner', 'Custom role name', 'webaxones-content' ), ], 'settings' => [ 'slug' => 'owner', 'action' => 'update', 'role_to_clone_slug' => 'administrator', 'capabilities_to_remove' => [ 'manage_options', 'switch_themes', 'remove_users', 'promote_users', 'customize', ], ], ] ); /** * Add custom block pattern category: Webaxones Patterns */ $declarations[] = new EntityFactory( [ 'entity' => 'Webaxones\Core\Block\BlockPatternCategory', 'labels' => [ 'label' => _x( 'Webaxones Patterns', 'Custom block pattern name', 'webaxones-content' ), ], 'settings' => [ 'slug' => 'webaxones_patterns', 'action' => 'add', ], ] ); /** * Remove custom block pattern category: test */ $declarations[] = new EntityFactory( [ 'entity' => 'Webaxones\Core\Block\BlockPatternCategory', 'labels' => [], 'settings' => [ 'slug' => 'test', 'action' => 'remove', ], ] ); /** * Add custom block category: Custom category */ $declarations[] = new EntityFactory( [ 'entity' => 'Webaxones\Core\Block\BlockCategory', 'labels' => [ 'title' => _x( 'Custom category', 'Custom block category name', 'webaxones-content' ), ], 'settings' => [ 'slug' => 'webaxones_custom_category', 'icon' => 'dashicons-admin-generic', /* Slug of a WordPress Dashicon or custom SVG */ ], ] ); array_walk( $declarations, function( $declaration ) { try { $entity = $declaration->createEntity(); $entity->hook(); } catch ( Exception $e ) { error_log( $e->getMessage() ); } } ); ">

/**
 * Plugin Name:       Example Custom Content
 * Author:            My Name
 * Text Domain:       wax-custom-content
 * Domain Path:       /languages
 */
defined( 'ABSPATH' ) || exit;

// In this case, library is inside Bedrock root vendor so we just create a constant inside Config/Application.php just after $root_dir definition:
// Config::define('WAX_ROOT_DIR', $root_dir);
// So that we can use it now to load our classes inside plugin(s)

require_once wp_normalize_path( WAX_ROOT_DIR ) . '/vendor/autoload.php';

use Webaxones\Core\I18n\I18n;
use Webaxones\Core\Utils\ContentFactory;

$i18n = new I18n( 'webaxones-content' );
$i18n->hook();

/**
 * Custom Post Type: Project
 */
$declarations[] = new EntityFactory(
	[
		'entity'   => 'Webaxones\Core\Classification\PostType',
		'labels'   => [
			'gender'            => 'm',
			'plural_name'       => _x( 'Projects', 'Capitalized Plural Name', 'webaxones-content' ),
			'singular_name'     => _x( 'Project', 'Capitalized Singular Name', 'webaxones-content' ),
			'parent_item_colon' => __( 'Parent project: ', 'webaxones-content' ),
			'all_items'         => __( 'All projects', 'webaxones-content' ),
			'new_item'          => __( 'New project', 'webaxones-content' ),
			'the_singular'      => __( 'The project', 'webaxones-content' ),
			'the_plural'        => __( 'The projects', 'webaxones-content' ),
		],
		'settings' => [
			'slug'          => 'project',
			'taxonomies'    => [],
			'supports'      => [ 'title', 'thumbnail', 'editor', /*'excerpt', 'author', 'comments', 'revisions', 'page-attributes', 'post-formats', 'custom-fields', 'trackbacks'*/ ],
			'menu_icon'     => 'dashicons-portfolio',
			'menu_position' => 7,
			'hierarchical'  => false,
			'public'        => true,
			'show_in_rest'  => true,
			'has_archive'   => true,
		],
	]
);

/**
 * Custom Taxonomy: Project category
 */
$declarations[] = new EntityFactory(
	[
		'entity'   => 'Webaxones\Core\Classification\Taxonomy',
		'labels'   => [
			'gender'            => 'f',
			'plural_name'       => _x( 'Project categories', 'Capitalized Plural Name', 'webaxones-content' ),
			'singular_name'     => _x( 'Project category', 'Capitalized Singular Name', 'webaxones-content' ),
			'parent_item_colon' => __( 'Parent project category: ', 'webaxones-content' ),
			'all_items'         => __( 'All project categories', 'webaxones-content' ),
			'new_item'          => __( 'New project category', 'webaxones-content' ),
			'the_singular'      => __( 'The project category', 'webaxones-content' ),
			'the_plural'        => __( 'The project categories', 'webaxones-content' ),
		],
		'settings' => [
			'slug'              => 'project-category',
			'hierarchical'      => false,
			'public'            => true,
			'show_admin_column' => true,
			'show_in_rest'      => true,
			'object_type'       => ['project'],
		],
	]
);

/**
 * Custom native option page: Company data
 */
$declarations[] = new EntityFactory(
	[
		'entity'   => 'Webaxones\Core\Option\OptionsPage',
		'labels'   => [
			'page_title' => _x( 'Company data', 'Option page title', 'webaxones-content' ),
			'menu_title' => _x( 'Parameters', 'Option page menu title', 'webaxones-content' ),
		],
		'settings' => [
			'slug'        => 'wax-company-settings',
			'location'    => 'top_level', /*'custom', 'dashboard', 'posts', 'pages', 'comments', 'theme', 'plugins', 'users', 'management', 'options'*/
			'parent_slug' => '', /* if location is "custom" */
			'capability'  => 'manage_options',
			'icon_url'    => 'dashicons-admin-generic',
			'position'    => 99,
		],
	]
);

/**
 * Custom ACF option page: Projects archive
 */
$declarations[] = new EntityFactory(
	[
		'entity'   => 'Webaxones\Core\Option\AcfOptionsPage',
		'labels'   => [
			'page_title' => _x( 'Projects archive', 'Option page title', 'webaxones-content' ),
			'menu_title' => _x( 'Projects page', 'Option page menu title', 'webaxones-content' ),
		],
		'settings' => [
			'slug'        => 'wax-projects-settings',
			'location'    => 'custom', /*'custom', 'dashboard', 'posts', 'pages', 'comments', 'theme', 'plugins', 'users', 'management', 'options'*/
			'parent_slug' => 'edit.php?post_type=project', /* if location is "custom" */
			'capability'  => 'manage_options',
			'icon_url'    => '',
			'position'    => 99,
		],
	]
);

/**
 * Add Custom role: Owner
 */
$declarations[] = new EntityFactory(
	[
		'entity'   => 'Webaxones\Core\Role\Role',
		'labels'   => [
			'role_name' => _x( 'Owner', 'Custom role name', 'webaxones-content' ),
		],
		'settings' => [
			'slug'                   => 'owner',
			'action'                 => 'add',
			'role_to_clone_slug'     => 'administrator',
			'capabilities_to_remove' => [
				'manage_options',
				'switch_themes',
				'remove_users',
				'activate_plugins',
				'delete_others_pages',
				'delete_site',
				'delete_pages',
				'delete_private_pages',
				'delete_published_pages',
				'delete_others_posts',
				'delete_posts',
				'delete_private_posts',
				'edit_theme_options',
				'export',
				'import',
				'edit_private_pages',
				'edit_private_posts',
				'promote_users',
				'customize',
			],
		],
	]
);

/**
 * Remove Custom role: Test
 */
$declarations[] = new EntityFactory(
	[
		'entity'   => 'Webaxones\Core\Role\Role',
		'labels'   => [],
		'settings' => [
			'slug'                   => 'test',
			'action'                 => 'remove',
			'role_to_clone_slug'     => '',
			'capabilities_to_remove' => [],
		],
	]
);

/**
 * Update Custom role: Owner
 */
$declarations[] = new EntityFactory(
	[
		'entity'   => 'Webaxones\Core\Role\Role',
		'labels'   => [
			'role_name' => _x( 'Owner', 'Custom role name', 'webaxones-content' ),
		],
		'settings' => [
			'slug'                   => 'owner',
			'action'                 => 'update',
			'role_to_clone_slug'     => 'administrator',
			'capabilities_to_remove' => [
				'manage_options',
				'switch_themes',
				'remove_users',
				'promote_users',
				'customize',
			],
		],
	]
);

/**
 * Add custom block pattern category: Webaxones Patterns
 */
$declarations[] = new EntityFactory(
	[
		'entity'   => 'Webaxones\Core\Block\BlockPatternCategory',
		'labels'   => [
			'label' => _x( 'Webaxones Patterns', 'Custom block pattern name', 'webaxones-content' ),
		],
		'settings' => [
			'slug'   => 'webaxones_patterns',
			'action' => 'add',
		],
	]
);

/**
 * Remove custom block pattern category: test
 */
$declarations[] = new EntityFactory(
	[
		'entity'   => 'Webaxones\Core\Block\BlockPatternCategory',
		'labels'   => [],
		'settings' => [
			'slug'   => 'test',
			'action' => 'remove',
		],
	]
);

/**
 * Add custom block category: Custom category
 */
$declarations[] = new EntityFactory(
	[
		'entity'   => 'Webaxones\Core\Block\BlockCategory',
		'labels'   => [
			'title' => _x( 'Custom category', 'Custom block category name', 'webaxones-content' ),
		],
		'settings' => [
			'slug' => 'webaxones_custom_category',
			'icon' => 'dashicons-admin-generic', /* Slug of a WordPress Dashicon or custom SVG */
		],
	]
);

array_walk(
	$declarations,
	function( $declaration )
	{
		try {
			$entity = $declaration->createEntity();
			$entity->hook();
		} catch ( Exception $e ) {
			error_log( $e->getMessage() );
		}
	}
);
You might also like...
Simple WordPress plugin to learn how to understand WordPress Crons and the Action Scheduler library.

Simple WordPress plugin to learn how to understand WordPress Crons and the Action Scheduler library. Import Jamendo playlists with tracks in WordPress posts.

A WordPress plugin for managing user permission, education, and communication.

A WordPress plugin for managing user permission, education, and communication. Texas A&M University System

This is code to create a new user as admin use for Wordpress FrontEnd Developer to prevent any scaming from clients

theme-setup This is code to create a new user as admin use for Wordpress FrontEnd Developer to prevent any scaming from clients How to use Just copy c

A Wordpress plugin that allows you to customize a news feed on your home page

=== Plugin Name === Contributors: Noora Chahine Requires at least: 4.0.1 Tested up to: 5.4 Stable tag: 5.2 License: GPLv2 or later License URI: http:/

Surge is a very simple and fast page caching plugin for WordPress.

=== Surge === Contributors: kovshenin Donate link: https://github.com/kovshenin/surge Tags: cache, performance, caching Requires at least: 5.7 Tested

WordPress single-page theme with profile patterns.

X3P0 - Reflections A one-page user-profile WordPress theme. Really, it's just a single page. View Demo → Recommended This theme is designed to work wi

Free WordPress plugin to generate Admin Settings Page.

ClioWP Settings Page ClioWP Setting Page is a free WordPress Plugin which creates a sample Settings Page. This “test” page contains almost any type of

A custom WordPress nav walker class to fully implement the Twitter Bootstrap 4.0+ navigation style (v3-branch available for Bootstrap 3) in a custom theme using the WordPress built in menu manager.

WP Bootstrap Navwalker This code in the main repo branch is undergoing a big shakeup to bring it in line with recent standards and to merge and test t

A curated list of Awesome WordPress Theme, Plugins and Framework development Resources and WordPress Communities.

Awesome WordPress A curated list of Awesome WordPress Theme, Plugins and Framework development Resources and WordPress Communities. Inspired by bayand

Owner
Loïc Antignac
build sites with wOrDpReSs                     « And more, much more than this,                  I did it my way »
Loïc Antignac
A plugin to disable the drop cap option in Gutenberg editor paragraph block. This is version 2.

Disable Drop Cap (v2) A plugin to disable drop cap option in the Gutenberg editor block editor paragraph block. Note for WordPress 5.8 With WordPress

Johannes Siipola 4 Jan 4, 2022
The easiest to use WordPress option framework.

Titan Framework The easiest to use WordPress options framework. Titan Framework allows theme and plugin developers to create admin pages, options, met

Gambit Technologies 374 Nov 14, 2022
Création du thème "mytheme" WordPress from Scratch

<!DOCTYPE html> <html lang="fr"> <head> <meta name="viewport" content="width=device-width" /> <meta http-equiv="Content-Type" content="text/html;

Jules Eulalie 0 Dec 27, 2021
Wordless is a junction between a WordPress plugin and a theme boilerplate that dramatically speeds up and enhances your custom theme creation

Wordless is a junction between a WordPress plugin and a theme boilerplate that dramatically speeds up and enhances your custom theme creation. Some of

weLaika 1.4k Dec 9, 2022
🔍️ A WordPress plugin to automatically send a user to the page or post if it's the only search result available.

One Search Result A WordPress plugin to automatically send a user to the page or post if it's the only search result available. When there is only one

Brad Parbs 9 Oct 6, 2021
A one-page user-profile WordPress theme

X3P0 - Profile A one-page user-profile WordPress theme. Currently, it ships with a few patterns. More will be added. Credits patterns/artist.php - Pho

X3P0 25 Nov 4, 2022
📦 A zero-configuration #0CJS developer toolkit for building WordPress Gutenberg block plugins.

create-guten-block is zero configuration dev-toolkit (#0CJS) to develop WordPress Gutenberg blocks in a matter of minutes without configuring React, w

Ahmad Awais ⚡️ 3.1k Dec 23, 2022
WordPress plugin to make it easier to create block patterns.

=== Templets === Contributors: mkaz Tags: block patterns, patterns Requires at least: 5.8 Tested up to: 5.8 Requires PHP: 7.3 Stable tag: 0.2.0 Licens

Marcus Kazmierczak 9 Jan 3, 2023
A simple little WordPress block that allows you add social share icons to your website.

Social Sharing Block This plugin requires WordPress 5.9+ or 5.8+ with Gutenberg active. A simple little block that allows you to add social share icon

Nick Diego 18 Dec 27, 2022
WordPress plugin boilerplate using React and Block Editor components.

PluginWP Foundation ?? UNDER DEVELOPMENT ?? This code serves as a starting point for building a WordPress plugin using React and the block editor comp

JR Tashjian 5 Dec 8, 2022