pinkcrab / wp-rest-schema
Library for writing WP Json Rest Schema
Installs: 7 258
Dependents: 2
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
Open Issues: 11
Requires
- php: >=7.1.0
Requires (Dev)
- dealerdirect/phpcodesniffer-composer-installer: *
- gin0115/wpunit-helpers: ~1.0.0
- object-calisthenics/phpcs-calisthenics-rules: *
- pcov/clobber: ^2.0
- php-stubs/wordpress-stubs: ^5.6.0
- phpstan/phpstan: ^0.12.6
- phpunit/phpunit: ^7.0
- roots/wordpress: ^5.6
- symfony/var-dumper: 4.*
- szepeviktor/phpstan-wordpress: ^0.7.2
- wp-coding-standards/wpcs: *
- wp-phpunit/wp-phpunit: ^5.0
- yoast/phpunit-polyfills: ^0.2.0 || ^1.0.0
- dev-master
- 0.0.1-beta3
- 0.0.1-beta2
- 0.0.1-beta
- dev-dependabot/composer/yoast/phpunit-polyfills-tw-0.2.0or-tw-1.0.0or-tw-3.0.0
- dev-dependabot/composer/roots/wordpress-tw-5.6or-tw-6.0
- dev-dependabot/composer/wp-phpunit/wp-phpunit-tw-5.0or-tw-6.0
- dev-dependabot/composer/php-stubs/wordpress-stubs-tw-5.6.0or-tw-6.0.0
- dev-feature/use-new-pipeline
- dev-develop
- dev-feature/update-dev-deps-perique-2_0_1
- dev-feature/gh17-update-dev-deps-to-wp6_1
- dev-feature/gh12-update-dev-deps
- dev-feature/create-parsers
- dev-feature/import-from-perique-route
This package is auto-updated.
Last update: 2024-12-09 17:06:57 UTC
README
....
Version 0.1.0-beta3
Why?
Defining valid JSON rest schema in WordPress is a little messy and easy to make a mistake with it being lots of nested arrays. This library attempts to make this process cleaner and simpler with a fully fluent, object driven interface.
Setup
To install, you can use composer
$ composer require pinkcrab/wp-rest-schema
for_meta_data
Basic Usage
This can be used for Register Post Meta
register_post_meta( 'post', 'fixed_in', array( 'type' => 'string', 'show_in_rest' => array( 'single' => true, 'schema' => Argument_Parser::for_meta_data( String_Type::on('fixed_in') ->min_length(10) ->max_length( 42 ) ->required() ->description('This is a required string value, that must be between 10 and 42 chars long.') ), ), ) );
Can also be used with the Perique Registerable library
$meta_data = (new Meta_Data('fixed_in')) ->post_type('post') ->type('string') ->rest_schema( Argument_Parser::for_meta_data( String_Type::on( 'fixed_in' ) ->min_length(10) ->max_length( 42 ) ->required() ->description('This is a required string value, that must be between 10 and 42 chars long.') ) );
The WP Rest Schema Builder can be used in various places where you would normally define a schema, such as Rest Routes, Registering Post Types, Taxonomies and Meta Data.
Change Log
- 0.1.0 Inital version