royboy789 / gutenberg-array-save
Saving Gutenberg as a clean array of data to the database
Installs: 7
Dependents: 0
Suggesters: 0
Security: 0
Stars: 247
Watchers: 12
Forks: 16
Open Issues: 8
Type:wordpress-plugin
pkg:composer/royboy789/gutenberg-array-save
Requires
- php: ^7.0
- composer/installers: ^1.5
- dev-master
- 2.0.0
- 1.6.0
- 1.5.0
- 1.4.1
- 1.4.0
- 1.3.0
- 1.2.0
- dev-dependabot/npm_and_yarn/debug-2.6.9
- dev-dependabot/npm_and_yarn/set-value-and-union-value-2.0.1
- dev-dependabot/npm_and_yarn/hawk-and-fsevents--removed
- dev-dependabot/npm_and_yarn/qs-6.4.1
- dev-dependabot/npm_and_yarn/minimist-and-mkdirp-1.2.8
- dev-dependabot/npm_and_yarn/decode-uri-component-0.2.2
- dev-dependabot/npm_and_yarn/loader-utils-1.4.2
- dev-dependabot/npm_and_yarn/async-2.6.4
- dev-2.0.0-alpha.1
- dev-bug-27
This package is not auto-updated.
Last update: 2025-11-06 08:30:41 UTC
README
The purpose of this plugin is to save Gutenberg (New WordPress Editor) data as an array in the database which is accessible via the REST API.
Installation
- Clone
- Run
composer install - Run
npm install npm run dev/npm run build- Activate plugin.
WIKI
I am adding docs to the WIKI
WHY
While the new UI for the WordPress Editor is amazing, the data as it is stored lends a lot ot be desired with HTML comments as a basis for data
WHERE
Data will be saved in a new database table [prefix]_gutes_arrays
REST API
I have included a filter to adda editor_block to the normal post content response.
API ENDPOINTS
Includes 1 new route:
wp-json/gutes-db/v1/[post-id]- Supports GET & POSTwp-json/gutes-db/v1/[post-id]/revisions- Supports GET only
GET
GET: wp-json/gutes-db/v1/[post-id]
Returns
- is_gutes: Is the post created with Gutenberg
- post_id: Post ID
- data: Gutenberg Data
- _embedded['post']: optional with _embed - response from WP REST API for post
SAVE
POST: wp-json/gutes-db/v1/[post-id]
- id - required - post ID
- gutes_data - required - Data array
Hooks
To send the data to the API to save we must first transform data. Using wp.hooks You can tie into this process by adding a filter
- namespace - 'gutes_array'
- filter name -
clean_data_[hyphenated-block-name] - data - data sent and returned is an array of the attributes
EXAMPLE
wp.hooks.addFilter( 'clean_data_core-paragraph', 'gutes-array', callback );
Adding editor_blocks to other CPT Responses
V 1.1.0+
Do you have another CPT (post type) that you are using Gutenberg with? Great! all you have to do is define GUTENBERG_OBJECT_PLUGIN_CPTS before rest_api_init with a comma separated list of CPTs.
add_action( 'init', 'my_custom_cpts', 10 );
function my_custom_cpts() {
if ( ! defined( 'GUTENBERG_OBJECT_PLUGIN_CPTS' ) ) {
define( 'GUTENBERG_OBJECT_PLUGIN_CPTS', 'product,page,other_cpt' );
}
}
Once GUTENBERG_OBJECT_PLUGIN_CPTS is defined as a comma separated list the editor_block data will apaper in that CPT's API response
Helper Functions
<?php get_editor_blocks( $post_id ); ?>- returns array of block data
Releases / Built Packages
I will try to create packaged releases if you are not comforatble with using composer, webpack, or npm and just want to try this plugin on your site.
Head over to the Releases to download a packaged zip that is ready to use.
Third Party Block Support
If you have a plugin that adds blocks, just create an issue with a link to the plugin and I'll try to add in support!