• Stars
    star
    139
  • Rank 262,169 (Top 6 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 4 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

JSON schemas for WordPress PHP objects and REST API responses

WordPress JSON Schemas

This package provides well-documented JSON schemas that describe the shape of:

  • WordPress core PHP objects such as WP_Post, WP_Term, and WP_User
  • WordPress REST API responses such as those from /wp/v2/posts, /wp/v2/categories, and /wp/v2/users
  • Various property types and values of both

The schemas in this library are used to generate the WordPress TypeScript definitions provided by the wp-types package.

The schemas were last updated for WordPress 6.2.

What's included?

PHP Object Schemas

  • WP_Post
  • WP_Term
  • WP_User
  • WP_Comment
  • WP_Error
  • WP_Query
  • WP_Block
  • WP_Block_Type
  • WP_Block_Template
  • WP_Site
  • WP_Locale
  • WP_Taxonomy
  • WP_Post_Type
  • WP_Role
  • WP_Network
  • WP_Screen

REST API Response Schemas

Route Schema
/wp/v2/block-directory/search WP_REST_API_Block_Directory_Items
/wp/v2/block-patterns/categories WP_REST_API_Block_Pattern_Categories
/wp/v2/block-patterns/patterns WP_REST_API_Block_Patterns
/wp/v2/block-renderer/{name} WP_REST_API_Rendered_Block
/wp/v2/block-types WP_REST_API_Block_Types
/wp/v2/block-types/{namespace} WP_REST_API_Block_Type
/wp/v2/block-types/{namespace}/{name} WP_REST_API_Block_Type
/wp/v2/blocks WP_REST_API_Blocks
/wp/v2/blocks/{id} WP_REST_API_Block
/wp/v2/blocks/{id}/autosaves Todo
/wp/v2/blocks/{parent}/autosaves/{id} Todo
/wp/v2/blocks/{parent}/revisions WP_REST_API_Revisions
/wp/v2/blocks/{parent}/revisions/{id} WP_REST_API_Revision
/wp/v2/categories WP_REST_API_Categories
/wp/v2/categories/{id} WP_REST_API_Category
/wp/v2/comments WP_REST_API_Comments
/wp/v2/comments/{id} WP_REST_API_Comment
/wp/v2/global-styles/{id} Todo
/wp/v2/global-styles/themes/{stylesheet}/variations Todo
/wp/v2/global-styles/themes/{stylesheet} Todo
/wp/v2/media WP_REST_API_Attachments
/wp/v2/media/{id} WP_REST_API_Attachment
/wp/v2/media/{id}/edit Todo
/wp/v2/media/{id}/post-process Todo
/wp/v2/menu-items Todo
/wp/v2/menu-items/{id} Todo
/wp/v2/menu-items/{id}/autosaves Todo
/wp/v2/menu-items/{parent}/autosaves/{id} Todo
/wp/v2/menu-locations Todo
/wp/v2/menu-locations/{location} Todo
/wp/v2/menus Todo
/wp/v2/menus/{id} Todo
/wp/v2/navigation Todo
/wp/v2/navigation/{id} Todo
/wp/v2/navigation/{id}/autosaves Todo
/wp/v2/navigation/{parent}/autosaves/{id} Todo
/wp/v2/navigation/{parent}/revisions Todo
/wp/v2/navigation/{parent}/revisions/{id} Todo
/wp/v2/pages WP_REST_API_Pages
/wp/v2/pages/{id} WP_REST_API_Page
/wp/v2/pages/{id}/autosaves Todo
/wp/v2/pages/{parent}/autosaves/{id} Todo
/wp/v2/pages/{parent}/revisions WP_REST_API_Revisions
/wp/v2/pages/{parent}/revisions/{id} WP_REST_API_Revision
/wp/v2/pattern-directory/patterns Todo
/wp/v2/plugins Todo
/wp/v2/plugins/{plugin} Todo
/wp/v2/posts WP_REST_API_Posts
/wp/v2/posts/{id} WP_REST_API_Post
/wp/v2/posts/{id}/autosaves Todo
/wp/v2/posts/{parent}/autosaves/{id} Todo
/wp/v2/posts/{parent}/revisions WP_REST_API_Revisions
/wp/v2/posts/{parent}/revisions/{id} WP_REST_API_Revision
/wp/v2/search WP_REST_API_Search_Results
/wp/v2/settings WP_REST_API_Settings
/wp/v2/sidebars Todo
/wp/v2/sidebars/{id} Todo
/wp/v2/statuses WP_REST_API_Statuses
/wp/v2/statuses/{status} WP_REST_API_Status
/wp/v2/tags WP_REST_API_Tags
/wp/v2/tags/{id} WP_REST_API_Tag
/wp/v2/taxonomies WP_REST_API_Taxonomies
/wp/v2/taxonomies/{taxonomy} WP_REST_API_Taxonomy
/wp/v2/templates Todo
/wp/v2/templates/{id} Todo
/wp/v2/templates/{id}/autosaves Todo
/wp/v2/templates/{parent}/autosaves/{id} Todo
/wp/v2/templates/{parent}/revisions Todo
/wp/v2/templates/{parent}/revisions/{id} Todo
/wp/v2/templates/lookup Todo
/wp/v2/template-parts Todo
/wp/v2/template-parts/{id} Todo
/wp/v2/template-parts/{id}/autosaves Todo
/wp/v2/template-parts/{parent}/autosaves/{id} Todo
/wp/v2/template-parts/{parent}/revisions Todo
/wp/v2/template-parts/{parent}/revisions/{id} Todo
/wp/v2/template-parts/lookup Todo
/wp/v2/themes Todo
/wp/v2/themes/{stylesheet} Todo
/wp/v2/types WP_REST_API_Types
/wp/v2/types/{type} WP_REST_API_Type
/wp/v2/users WP_REST_API_Users
/wp/v2/users/({id}|me) WP_REST_API_User
/wp/v2/users/({id}|me)/application-passwords WP_REST_API_Application_Passwords
/wp/v2/users/({id}|me)/application-passwords/{uuid} WP_REST_API_Application_Password
/wp/v2/users/({id}|me)/application-passwords/introspect WP_REST_API_Application_Password
/wp/v2/widget-types Todo
/wp/v2/widget-types/{id} Todo
/wp/v2/widget-types/{id}/encode Todo
/wp/v2/widget-types/{id}/render Todo
/wp/v2/widgets Todo
/wp/v2/widgets/{id} Todo
Any REST API error WP_REST_API_Error

The REST API schemas use JSON Hyper-Schema.

Property Schemas

Schemas are provided for various properties:

  • WP_Error_Data
  • WP_Error_Messages
  • WP_Post_Type_Caps
  • WP_Post_Type_Labels
  • WP_Post_Type_Rewrite
  • WP_Taxonomy_Caps
  • WP_Taxonomy_Labels
  • WP_Taxonomy_Rewrite
  • WP_User_Cap_Name
  • WP_User_Caps
  • WP_User_Data

Enums

Enums are provided for various values:

  • WP_Comment_Status_Name
  • WP_Comment_Type_Name
  • WP_Post_Comment_Status_Name
  • WP_Post_Format_Name
  • WP_Post_Status_Name
  • WP_Post_Type_Name
  • WP_Taxonomy_Name
  • WP_User_Role_Name
  • WP_HTTP_Status_Code

Installation

npm install wp-json-schemas

Versioning

This package is versioned so that you can specify both the schema version and the WordPress branch version in a way that's compatible with semantic versioning. Given version x.y.z:

  • The major version number (x) indicates the schema version number, currently 3
  • The minor version number (y) indicates the WordPress branch version number without its decimal place, eg. 62 for WordPress 6.2
  • The patch version number (z) indicates the schema patch version number

Examples:

  • ~3.62.0 - Schema version 3 for WordPress 6.2
  • ~3.61.0 - Schema version 3 for WordPress 6.1
  • ~3.60.0 - Schema version 3 for WordPress 6.0
  • ~3.59.0 - Schema version 3 for WordPress 5.9
  • ~3.58.0 - Schema version 3 for WordPress 5.8
  • ~3.57.0 - Schema version 3 for WordPress 5.7
  • ^3.0.0 - Schema version 3 for the latest WordPress version

Usage

Usage depends on what you're doing with the schemas. You could use them for validation or just for understanding the shape of an object.

If you're using TypeScript, check out the TypeScript definitions provided by the wp-types package.

FAQs

When do these schemas apply?

The PHP object schemas apply whenever a supported PHP object is encoded to JSON. For example:

printf(
	'let wpPost = %s;',
	wp_json_encode( get_post() )
);

The REST API object schemas apply to the response to a REST API request. For example:

const api = wp.apiFetch( {
	path: '/wp/v2/categories/'
} );

The schemas also apply outside of an HTTP request, for example if you're saving data as a JSON file and reading it in a Node application.

Why are there different schemas for PHP objects and REST API responses?

An object in a REST API response is not the same as its corresponding object in PHP, in fact they are substantially different.

Schemas are available via an OPTIONS request to the REST API endpoints, but the schemas do not adhere strictly to the JSON Schema standard. Here's an article by Timothy B. Jacobs with more info.

Are these schemas automatically generated from WordPress core?

No. I started down that path (using wp-parser-lib) but realised it's quicker to generate them manually and then copy most of the documentation from core, especially as I'm adding extra documentation and schemas for properties when I can.

How do I know the schemas are accurate?

They're all tested against actual output from WordPress core.

Tests

To run the tests:

  • nvm use
  • npm install
  • composer install
  • composer test

License

MIT

More Repositories

1

query-monitor

The developer tools panel for WordPress
PHP
1,580
star
2

extended-cpts

A library which provides extended functionality to WordPress custom post types and taxonomies.
PHP
971
star
3

wp_mail

Documentation for all the situations where WordPress core sends an email, how and when they happen, and how to filter or disable each one.
344
star
4

wp-crontrol

Take control of the cron events on your WordPress website
PHP
208
star
5

user-switching

WordPress plugin that provides instant switching between user accounts.
PHP
185
star
6

extended-template-parts

A library which provides extended functionality to WordPress template parts, including template variables and caching.
PHP
114
star
7

args

Array arguments made bearable
PHP
107
star
8

extended-taxos

PHP
100
star
9

ext

WP-CLI command which checks the existence of PHP extensions needed to run WordPress.
PHP
71
star
10

wp-types

TypeScript definitions for WordPress PHP objects and REST API responses
27
star
11

php-docs-standards

PHPUnit tests for documentation standards of PHP functions and methods.
PHP
24
star
12

wordpress-keyboard-shortcuts

A WordPress plugin which adds keyboard shortcuts for navigation and actions
PHP
23
star
13

wordpress-x

The most powerful and smartest admin toolbar ever in a CMS.
PHP
18
star
14

probot-semver

A GitHub app that provides automatic semantic versioning support
JavaScript
15
star
15

plugin-infrastructure

Reusable infrastructure relating to testing, building, and deploying my WordPress plugins
Shell
13
star
16

user-switching-for-regular-admins

Adds support to the User Switching plugin for regular admins on multisite
PHP
11
star
17

vip-go-indicator

Adds an admin toolbar indicator which identifies the current WordPress.com VIP Go environment
PHP
9
star
18

ideas

Ideas for things that I'll build just as soon as I find the time
8
star
19

global-post-password

WordPress plugin to globally set a password for all password protected posts and pages
PHP
8
star
20

revisions-digest

A WordPress plugin which generates digests of changes to content via their revisions.
PHP
7
star
21

plugin-info

Provides a simple way of displaying up-to-date information about specific WordPress Plugin Directory hosted plugins in your blog posts and pages.
PHP
7
star
22

falsey-assertequals-detector

Marks a PHPUnit test as risky if it tests a falsey value with assertEquals()
PHP
7
star
23

wp-git-status

WordPress plugin that shows the Git branch and current status in the admin toolbar
PHP
6
star
24

extended-widgets

PHP
5
star
25

wctrn-login-lockdown

Login Lockdown plugin for the WordCamp Torino 2018 WP-CLI workshop
PHP
4
star
26

wp-stats

HTML
4
star
27

https-indicator

PHP
3
star
28

php-errors

PHP error handling tests
PHP
3
star
29

slurpetta

Slurps down the most popular plugins and themes from WordPress.org
PHP
3
star
30

wp-contributors-map

A Node.js server for generating a GeoJSON file of contributors to WordPress.
JavaScript
3
star
31

wctrn-site-setup-script

Site setup script for the WordCamp Torino 2018 WP-CLI workshop
Shell
3
star
32

user-switching-duo-security

User Switching add-on plugin so it plays nicely with Duo Security
PHP
3
star
33

PrettyFilters

A proof-of-concept WordPress plugin which adds a much nicer interface to the filters on post listing screens
PHP
3
star
34

qm-self-awareness

Self-profiling plugin for Query Monitor.
PHP
3
star
35

gitattributes-globs

Parse a .gitattributes file and return its export-ignore entries as an array of glob patterns.
JavaScript
2
star
36

resource-host-monitor

PHP
1
star
37

ssl-helper

PHP
1
star
38

.github

1
star
39

johnbillion

1
star