Coder Social home page Coder Social logo

models's Introduction

Models

Models is a WordPress plugin allowing you to create custom post types and taxonomies using JSON, YAML or PHP files.

Installation

Composer:

Recommended methods:

Roots Bedrock

$ composer require soberwp/models:1.1.0

Models is a mu-plugin so it doesn't have to be activated.

Roots Sage

$ composer require soberwp/models:1.1.0-p

Manual:

  • Download the zip file
  • Unzip to your sites plugin folder
  • Activate via WordPress

Requirements:

Setup

By default, create foldexr models/ within the active theme directory.

If you are a Roots Sage the default folder is app/models/

Alternatively, you can define a custom path using the filter below within your themes functions.php file:

add_filter('sober/models/path', function () {
    return get_stylesheet_directory() . '/your-custom-folder';
});

That's it, now go ahead and add model-name.json files, in the folder or subfolders to begin creating your models. Use Unravel to automatically move the config files outside of your theme path for better separation of concerns.

Usage

The data structure follows a similar data structure to WordPress taxonomies and post types arrays, so if an config option is missing from the examples below, follow the developers reference and place it within "config": {}

If values are not specified, defaults are the same as WordPress defaults.

Additionally, if the Extended CPTs library is available, Models will use it when registering your post types and taxonomies instead allowing extended functionality within your Models.

Extracted examples presented below are in JSON format.

Post Types

Create a custom post type.

Required:

{
  "type": "post-type",
  "name": "book"
}

Basic:

{
  "type": "cpt",
  "name": "book",
  "supports": [
    "title", "editor", "thumbnail"
  ],
  "labels": {
    "has_one": "Book",
    "has_many": "Books",
    "text_domain": "sage"
  }
}

In the above example, "labels": {} are redundant because "Book" and "Books" would have been generated from "name".

Multiple:

[
  {
    "type": "cpt",
    "name": "book",
    "supports": [
      "title", "editor", "thumbnail"
    ]
  },
  {
    "type": "cpt",
    "name": "album",
    "supports": [
      "title", "editor", "comments"
    ]
  }
]

All Fields:

Post Type Tips:

  • "active": false stops the post type from being created. Default is set to true.
  • "type": "post-type" also accepts a shorthand "type": "cpt";

Taxonomies

Create a custom taxonomy.

Required:

{
  "type": "taxonomy",
  "name": "genre"
}

Basic:

{
  "type": "tax",
  "name": "genre",
  "links": [
    "post", "book"
  ],
  "labels": {
    "has_one": "Book Genre",
    "has_many": "Book Genres",
    "text_domain": "sage"
  }
}

"links": (string|array) assigns the taxonomy to post types. Defaults to "links": "post"

Multiple:

[
  {
    "type": "category",
    "name": "genre",
    "links": "book"
  },
  {
    "type": "tag",
    "name": "author",
    "links": "book"
  }
]

"type": "category" and "type": "tag" shorthands are explained below under Tips.

All Fields:

Taxonomy Tips:

  • "active": false stops the taxonomy from being created. Default is set to true.
  • "type": "taxonomy" also accepts shorthands;
    • "type": "tax"
    • "type": "category" or "type": "cat" creates a category taxonomy.
    • "type": "tag" creates a tag taxonomy.

Updates

Composer:

  • Change the composer.json version to ^1.0.4**
  • Check CHANGELOG.md for any breaking changes before updating.
$ composer update

WordPress:

Includes support for github-updater to keep track on updates through the WordPress backend.

Other

models's People

Contributors

log1x avatar dmgawel avatar

Watchers

Jeremy Tweddle avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.