A WordPress theme.json generator from a PHP array

Overview

ItalyStrap Theme Json Generator

Build Status

WordPress Theme Json Generator the OOP way

This is a WIP project and still experimental.

The idea is to generate a file theme.json from PHP because json sucks :D (just kidding)

With PHP you have the ability to split the file in multiple files, add comments, generate the content as you wish, PHP is not limited like json.

I'm experimenting this library as composer and WP_CLI plugin for generating the file.

Table Of Contents

Installation

The best way to use this package is through Composer:

composer require italystrap/theme-json-generator --dev

This package adheres to the SemVer specification and will be fully backward compatible between minor versions.

Basic Usage

This library works on composer events:

function getSubscribedEvents(): array {
    return [
        'post-autoload-dump'	=> 'run',
        'post-install-cmd'		=> 'run',
        'post-update-cmd'		=> 'run',
    ];
}

That's it.

How it works

Basically, this plugin executes the following steps:

  • This plugin searches for a custom callback you provide trough composer.json inside extra field.
  • The callback needs to return an array with your theme config and accept a string argument where you get the path of the theme.
  • And it generates the theme.json in the root folder of the theme you are developing.

Example project

The following is an example Composer project.

{
    "name": "italystrap/experimental-theme",
    "description": "Experimental theme",
    "type": "wordpress-theme",
    "require-dev": {
        "italystrap/theme-json-generator": "dev-master"
    },
    "extra": {
        "theme-json": {
            "callable": "\\YourVendor\\YourProject::your_callback"
        }
    },
    "repositories": [{
        "type": "vcs",
        "url": "https://github.com/ItalyStrap/theme-json-generator.git"
    }]
}

It is not yet on packagist and you have to add also the "repositories" field with the github url.

The callable must be a valid PHP callable and must return an array with your configuration following the schema provided from the documentation.

Example:

namespace YourVendor\YourProject;
/**
 * @argument string $path The path of the theme
 */
function your_callback( string $path ): array {
    // You can check against the $path argument in case you have parent and child theme.

    return [
        'version'   => 1,
        'settings'  => 	[
            'layout' => [
                'contentSize' => '620px',
                'wideSize' => '1000px',
            ],
        ]
    ];
}

And this will generate the following json:

{
  "version": 1,
  "settings": {
    "layout": {
      "contentSize": "620px",
      "wideSize": "1000px"
    }
  }
}

If you want to load manually using composer add your command inside the script field and load the ItalyStrap\\ThemeJsonGenerator\\ComposerPlugin::run method like below:

{
  "scripts": {
    "your-command": [
      "ItalyStrap\\ThemeJsonGenerator\\ComposerPlugin::run"
    ]
  }
}

And then run:

composer run your-command

WP_CLI command

As I said this is also a WP_CLI plugin, for now it is all included in this library for testing purpose, maybe I can split in other library if I see the need of doing that.

For using as WP_CLI command you have to create a file wp-cli.local.yml or wp-cli.yml in the root of your theme or better in the root of the WordPress installation.

Inside that file add this line for adding your custom callback:

THEME_JSON_CALLABLE: '\YourVendor\YourProject\your_callback'

And in the command line just use the command:

wp theme-json generate

This will generate the theme.json on the root of the active theme, parent or child. If you want to generate the theme.json for both add the option --parent

wp theme-json generate --parent

And remember to check inside the callback the path to provide the right config for the theme you want to generate the file.

This command is still experimental, could be changed in future.

Advanced Usage

Contributing

All feedback / bug reports / pull requests are welcome.

License

Copyright (c) 2021 Enea Overclokk, ItalyStrap

This code is licensed under the MIT.

Credits

You might also like...
Wordpress plugin to allow websites to sell and distribute NFTs through the Enjin platform

MyMeta Basket is the world's first plug-and-play Wordpress/Enjin/Ethereum integration that allows you to start selling blockchain assets through your website within minutes. All you need is Wordpress, MyMeta Basket, and an Enjin subscription.

酱茄企业官网小程序,酱茄专为中小企业开发的轻量级企业建站小程序(基于uni-app+wordpress),后台操作简单,维护方便,无需过多配置就能搭建一个企业小程序。
酱茄企业官网小程序,酱茄专为中小企业开发的轻量级企业建站小程序(基于uni-app+wordpress),后台操作简单,维护方便,无需过多配置就能搭建一个企业小程序。

一、小程序介绍 酱茄企业官网小程序,酱茄专为中小企业开发的轻量级企业建站小程序(基于uni-app + wordpress),后台操作简单,维护方便,无需过多配置就能搭建一个企业小程序。

Create WordPress themes with beautiful OOP code and the Twig Template Engine
Create WordPress themes with beautiful OOP code and the Twig Template Engine

Timber helps you create fully-customized WordPress themes faster with more sustainable code. With Timber, you write your HTML using the Twig Template Engine separate from your PHP files.

Wrapping all composer vendor packages inside your own namespace. Intended for WordPress plugins

Wrapping all composer vendor packages inside your own namespace. Intended for WordPress plugins.

Bedrock is a modern WordPress stack that helps you get started with the best development tools and project structure.
Bedrock is a modern WordPress stack that helps you get started with the best development tools and project structure.

WordPress boilerplate with modern development tools, easier configuration, and an improved folder structure

Divide / Split your WordPress Blog visitors into 4 links by using Re-skinning URL splitter
Divide / Split your WordPress Blog visitors into 4 links by using Re-skinning URL splitter

Re-skinning URL splitter Tool Divide / Split your Wordpress Blog visitors into 4 links by using Re-skinning URL splitter Re-skinning URL Splitter Feat

Sensei LMS WordPress Plugin

Sensei LMS A learning management plugin for WordPress, which provides the smoothest platform for helping you teach anything. Sensei LMS is a commercia

Intuitive Website Styling integrated into WordPress' Customizer
Intuitive Website Styling integrated into WordPress' Customizer

Customify - Intuitive Website Styling for WordPress With Customify, developers can easily create advanced theme-specific options inside the WordPress

A toolkit for using self-hosted Natural Language Processing with Elasticsearch and WordPress

Natural Language Processing Tools for WordPress A toolkit for using self-hosted Natural Language Processing in WordPress This plugin is a Proof of Con

Comments
  • Search for slugs usage in template files and do something

    Search for slugs usage in template files and do something

    The idea is to search in template files the preset slug usage, an example to be clear:

    Let say that we start with a naming convention , for example a slug for a smaller font size "fontSize":"x-small", in this case the slug is x-small, if we want to chabge the name from x-small to xs we need a sistem to search in files and let us know where do we need to change the name, maybe doing a search and replace directly?

    I have to think about this, but this will be only for development, not for production.

    For db we can do this with wp-cli.

    opened by overclokk 0
Owner
null
Sage is a productivity-driven WordPress starter theme with a modern development workflow.

WordPress starter theme with a modern development workflow

Roots 12k Jan 5, 2023
A minimal boilerplate theme for WordPress using TailwindCSS, with PostCSS and Laravel Mix.

A minimal boilerplate theme for WordPress using TailwindCSS, with PostCSS and Laravel Mix.

Pixel Devs 74 Nov 25, 2022
This is a white minimal wordpress theme

_s Hi. I'm a starter theme called _s, or underscores, if you like. I'm a theme meant for hacking so don't use me as a Parent Theme. Instead try turnin

Mahmud Hasan Imran 3 Oct 7, 2021
An example starter theme and block-type plugin that use @wordpress/scripts for JS & CSS

Brad’s Boilerplate This repo contains one folder that is an example theme, and another folder that is an example block-type plugin. Both folders use t

Brad Schiff 185 Dec 26, 2022
Basic Bedrock Theme for Concrete CMS

Basic Bedrock Theme Package for Concrete CMS v9 Basic Bedrock Theme Package for Concrete CMS v9 Concrete CMS Bedrock Documentation Description Persona

David 11 Nov 27, 2022
(Hard) Fork of WordPress Plugin Boilerplate, actively taking PRs and actively maintained. Following WordPress Coding Standards. With more features than the original.

Better WordPress Plugin Boilerplate This is a Hard Fork of the original WordPress Plugin Boilerplate. The Better WordPress Plugin Boilerplate actively

Beda Schmid 46 Dec 7, 2022
Html menu generator

Html Menu Generator The spatie/menu package provides a fluent interface to build menus of any size in your php application. If you're building your ap

Spatie 657 Dec 30, 2022
Plugin Vite is the conduit between Craft CMS plugins and Vite, with manifest.json & HMR support

Plugin Vite Related Articles: Vite.js Next Generation Frontend Tooling + Craft CMS A Vite Buildchain for Craft CMS Plugins Requirements Craft CMS 3.0.

nystudio107 8 Dec 30, 2022
A Simple and Lightweight WordPress Option Framework for Themes and Plugins

A Simple and Lightweight WordPress Option Framework for Themes and Plugins. Built in Object Oriented Programming paradigm with high number of custom fields and tons of options. Allows you to bring custom admin, metabox, taxonomy and customize settings to all of your pages, posts and categories. It's highly modern and advanced framework.

Codestar 241 Dec 23, 2022
Zero-Config plugin to disable FLoC in your WordPress Website.

Disable FLoC by WP Munich A simple zero-config plugin to opt-out of Google FLoC. This plugin is made with love and brought to you by the folks of WP M

Luehrsen // Heinrich 9 Jun 1, 2022