REST API blocks
A simple plugin to add block data in json format into the rest api. Once installed, there will be two new fields added to the rest api, has_blocks and blocks. For example output. "has_blocks": true, "block_data": [ { "blockName": "core/image", "attrs": { "url": "https://www.spacedmonkey.com/wp-content/uploads/2018/12/test-image.jpg", "alt": "Terminal de aeropuerto", "caption": "fsfsdfdsfdssfd", "href": "https://www.spacedmonkey.com/test-image", "rel": "noreferrer noopener", "linkClass": "jonny-123", "linkTarget": "_blank", "id": 147355, "width": 582, "height": 327, "linkDestination": "attachment" }, "innerBlocks": [ ], "innerHTML": "\n fsfsdfdsfdssfd \n", "innerContent": [ "\n fsfsdfdsfdssfd \n" ], "rendered": "\n fsfsdfdsfdssfd \n" } ], Technical Notes Requires PHP 5.6+. Requires WordPress 5.5+. Issues and Pull requests welcome on the GitHub repository: https://github.com/spacedmonkey/wp-rest-blocks Development This plugin uses @wordpress/env for local development and testing. Prerequisites Node.js 20+ and npm Docker Desktop (must be installed and running) Setup Clone the repository Install dependencies: bash npm install composer install Start the WordPress environment: bash npm run env:start This will start a local WordPress instance at http://localhost:8888 (admin: http://localhost:8888/wp-admin with username admin and password password) Note: Docker must be running for this to work. The first time you run this, it will download WordPress and set up the database, which may take a few minutes. Available Commands npm run env:start – Start the WordPress environment npm run env:stop – Stop the WordPress environment npm run env:reset – Reset the environment (clean database) npm run env:destroy – Destroy the environment completely npm run test:php – Run PHPUnit tests npm run test:php:multisite – Run PHPUnit tests in multisite mode npm run lint:php – Run PHP CodeSniffer npm run lint:php:fix – Fix PHP coding standards issues automatically Running Tests After starting the environment with npm run env:start, you can run the tests: `bash npm run test:php ` For multisite tests: `bash npm run test:php:multisite ` Accessing the Site Development site: http://localhost:8888 Admin dashboard: http://localhost:8888/wp-admin (admin/password) Test site: http://localhost:8889 Test admin: http://localhost:8889/wp-admin (admin/password)
REST API Enabler
Like this plugin? Please consider leaving a 5-star review. By default, custom post types and custom fields are not accessible via the WordPress REST API. REST API Enabler allows you to: Enable the WP REST API for custom post types and specify WP REST API custom endpoints. Choose which custom fields to include in WP REST API responses for posts, pages, and custom post types. All enabled custom field data is included in the REST API response, nested under the rest_api_enabler key, like so: [ { "id": 179, "date": "2016-07-03T18:06:50", "title": { "rendered": "Test Job" }, . . . "rest_api_enabler": { "custom_meta_1": "Value 1", "custom_meta_2": "Value 2", "custom_meta_3": [ "Array value 1", "Array value 2" ] } } ] Note: prior to verion 1.1.0, all meta keys were included as top-level keys in the API response. Additionally, all values were returned as arrays, regardless of whether the original value was actually an array. This functionality is now deprecated as it risks key-name collisions. Please reference the rest_api_enabler top-level key instead. Usage Activate the plugin, then go to Settings → REST API Enabler in the admin. Click the Post Types tab to enable/disable post types and customize their endpoints. Click the Post Meta tab to enable/disable post meta (custom fields). NOTE: by default, the plugin does not display settings for protected post meta (post meta that begins with an underscore and is intended for internal use only). If you wish to include protected post meta in the plugin settings, you can use the rae_include_protected_meta filter to do so. The following code can be placed in your theme’s functions.php file, or in a custom plugin (on init priority 10 or earlier): add_filter( 'rae_include_protected_meta', '__return_true' );