{"id":35624071,"url":"https://github.com/badasswp/convert-blocks-to-json","last_synced_at":"2026-05-26T21:01:10.561Z","repository":{"id":254345150,"uuid":"845547410","full_name":"badasswp/convert-blocks-to-json","owner":"badasswp","description":"Convert your WP blocks to JSON.","archived":false,"fork":false,"pushed_at":"2026-05-25T12:27:47.000Z","size":721,"stargazers_count":11,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-05-25T14:26:11.388Z","etag":null,"topics":["blocks","export","import","json","plugin","wordpress"],"latest_commit_sha":null,"homepage":"https://wordpress.org/plugins/convert-blocks-to-json/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/badasswp.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-08-21T13:11:14.000Z","updated_at":"2026-05-25T12:23:10.000Z","dependencies_parsed_at":"2025-03-26T11:25:01.816Z","dependency_job_id":"25c4c214-a2f5-4bb4-9259-2393fceb8b96","html_url":"https://github.com/badasswp/convert-blocks-to-json","commit_stats":null,"previous_names":["badasswp/convert-blocks-to-json"],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/badasswp/convert-blocks-to-json","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badasswp%2Fconvert-blocks-to-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badasswp%2Fconvert-blocks-to-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badasswp%2Fconvert-blocks-to-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badasswp%2Fconvert-blocks-to-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/badasswp","download_url":"https://codeload.github.com/badasswp/convert-blocks-to-json/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badasswp%2Fconvert-blocks-to-json/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33538660,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"ssl_error","status_checked_at":"2026-05-26T15:22:15.568Z","response_time":63,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blocks","export","import","json","plugin","wordpress"],"created_at":"2026-01-05T07:24:05.179Z","updated_at":"2026-05-26T21:01:10.550Z","avatar_url":"https://github.com/badasswp.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# convert-blocks-to-json\nConvert your WP blocks to JSON.\n\n[![Coverage Status](https://coveralls.io/repos/github/badasswp/convert-blocks-to-json/badge.svg?branch=master)](https://coveralls.io/github/badasswp/convert-blocks-to-json?branch=master)\n\n\u003cimg src=\"https://github.com/user-attachments/assets/875acd91-b2ed-4832-8df7-9ebe013e9c35\" alt=\"Convert Blocks to JSON\" height=\"300\"\u003e\n\n## Download\n\nDownload from [WordPress plugin repository](https://wordpress.org/plugins/convert-blocks-to-json/).\n\nYou can also get the latest version from any of our [release tags](https://github.com/badasswp/convert-blocks-to-json/releases).\n\n## Why Convert Blocks to JSON?\n\nThis plugin offers a powerful solution for __importing and exporting WordPress blocks in JSON format__, making it easy to move posts across different WP websites. It is also beneficial for WP engineers who are adopting a __Headless CMS__ approach and would like a way to be able to fetch data from the front-end using tools like __React__, __Vue__ \u0026 so on.\n\nIt's __simple__, yet very __powerful__!\n\nhttps://github.com/user-attachments/assets/9dedf30f-9df0-4307-b634-cecef930a6e5\n\n## Why can't I upload JSON files?\n\nYou might need to configure the `ALLOW_UNFILTERED_UPLOADS` option in your `wp-config.php` file like so:\n\n```php\ndefine( 'ALLOW_UNFILTERED_UPLOADS', true );\n```\n\n### Hooks\n\n#### `cbtj_blocks`\n\nThis custom hook (filter) provides the ability to customise the block classes:\n\n```php\nadd_filter( 'cbtj_blocks', [ $this, 'custom_blocks' ], 10 );\n\npublic function custom_blocks( $blocks ): array {\n    $blocks[] = \\YourNameSpace\\YourCustomBlock::class;\n\n    return $block;\n}\n```\n\n**Parameters**\n\n- blocks _`{Block[]}`_ By default, this is an array consisting of block classes.\n\u003cbr/\u003e\n\n#### `cbtj_import_block`\n\nThis custom hook (filter) provides the ability to customise any block array during import:\n\n```php\nadd_filter( 'cbtj_import_block', [ $this, 'custom_import_block' ], 10 );\n\npublic function custom_import_block( $block ): array {\n    if ( 'core/image' !== $block['name'] ) {\n        return $block;\n    }\n\n    // Get block attributes.\n    $block['attributes'] = json_decode( $block['attributes'], true );\n\n    // Set Caption using Post meta.\n    $block['attributes']['caption'] = get_post_meta( get_the_ID(), 'featured_image_caption', true );\n\n    // Encode attributes finally.\n    $block['attributes'] = wp_json_encode( $block['attributes'] );\n\n    return $block;\n}\n```\n\n**Parameters**\n\n- block _`{mixed[]}`_ By default, this would be a block array containing `name`, `originalContent`, `attributes` \u0026 `innerBlocks` key/value pairs.\n\u003cbr/\u003e\n\n#### `cbtj_export_block`\n\nThis custom hook (filter) provides the ability to customise any block array during export:\n\n```php\nadd_filter( 'cbtj_export_block', [ $this, 'custom_export_block' ], 10 );\n\npublic function custom_export_block( $block ): array {\n    if ( 'core/image' !== $block['name'] ) {\n        return $block;\n    }\n\n    // Set Caption using Post meta.\n    $block['attributes']['caption'] = get_post_meta( get_the_ID(), 'featured_image_caption', true );\n\n    return $block;\n}\n```\n\n**Parameters**\n\n- block _`{mixed[]}`_ By default, this would be a block array containing `name`, `content`, `filtered`, `attributes` \u0026 `innerBlocks` key/value pairs.\n\u003cbr/\u003e\n\n#### `cbtj_rest_export`\n\nThis custom hook (filter) provides the ability to customise the REST response obtained:\n\n```php\nadd_filter( 'cbtj_rest_export', [ $this, 'custom_rest_export' ], 10, 2 );\n\npublic function custom_rest_export( $response, $post_id ): array {\n    $response['content'] = wp_parse_args(\n        [\n            'name'    =\u003e 'custom/post-meta-block',\n            'content' =\u003e 'Lorem ipsum dolor sit amet...',\n            'meta'    =\u003e [\n                'address'   =\u003e get_post_meta( $post_id, 'address', true ),\n                'telephone' =\u003e get_post_meta( $post_id, 'telephone', true ),\n                'country'   =\u003e get_post_meta( $post_id, 'country', true ),\n            ],\n        ],\n        $response['content']\n    );\n\n    return (array) $response;\n}\n```\n\n**Parameters**\n\n- response _`{mixed[]}`_ REST Response.\n- post_id _`{int}`_ Post ID.\n\u003cbr/\u003e\n\n#### `cbtj_rest_import`\n\nThis custom hook (filter) provides the ability to customise the REST import. For e.g To import only paragraphs, you can do:\n\n```php\nadd_filter( 'cbtj_rest_import', [ $this, 'custom_rest_import' ], 10, 2 );\n\npublic function custom_rest_import( $import, $post_id ): array {\n    return array_filter(\n        $import,\n        function( $block ) {\n            return ( 'core/paragraph' === ( $block['name'] ?? '' ) );\n        }\n    );\n}\n```\n\n**Parameters**\n\n- import _`{mixed[]}`_ REST Import. By default this is an array of Blocks.\n- post_id _`{int}`_ Post ID.\n\u003cbr/\u003e\n\n#### `cbtj_rest_namespace`\n\nThis custom hook (filter) provides users the ability to customize the default REST namespace. For e.g.\n\n```php\nadd_filter( 'cbtj_rest_namespace', [ $this, 'custom_namespace' ] );\n\npublic function custom_namespace( $namespace ): array {\n    return 'my-custom-namespace/v1';\n}\n```\n\n**Parameters**\n\n- namespace _`{string}`_ REST Namespace. By default, this is a string which contains the Route namespace.\n\u003cbr/\u003e\n\n#### `cbtj.afterImport`\n\nThis custom hook (action) provides the ability to fire some logic after the import is completed like so:\n\n```js\nimport { addAction } from '@wordpress/hooks';\n\naddFilter(\n    'cbtj.afterImport',\n    'yourNamespace',\n    ( { blocks } ) =\u003e {\n        if ( blocks.some( ( { name } === 'core/footnotes' ) ) ) {\n            editPost( { title: 'A footnote was imported' } );\n        }\n    }\n);\n```\n\n**Parameters**\n\n- title _`{string}`_ Post title.\n- blocks _`{any[]}`_ Array of imported blocks.\n\u003cbr/\u003e\n\n#### `cbtj.innerBlocks`\n\nThis custom hook (filter) provides the ability to filter the way we create the inner blocks like so:\n\n```js\nimport { addFilter } from '@wordpress/hooks';\n\naddFilter(\n    'cbtj.innerBlocks',\n    'yourNamespace',\n    ( innerBlocks, name ) =\u003e {\n        if ( 'my/custom-block' === name ) {\n            return innerBlocks.map( ( { name, attributes } ) =\u003e\n                createBlock( name, { ...JSON.parse( attributes ) } )\n            );\n        }\n\n        return innerBlocks;\n    }\n);\n```\n\n**Parameters**\n\n- innerBlocks _`{any[]}`_ Array of inner blocks.\n- name _`{string}`_ Name of block.\n\u003cbr/\u003e\n\n---\n\n## Contribute\n\nContributions are __welcome__ and will be fully __credited__. To contribute, please fork this repo and raise a PR (Pull Request) against the `master` branch.\n\n### Pre-requisites\n\nYou should have the following tools before proceeding to the next steps:\n\n- Composer\n- Yarn\n- Docker\n\nTo enable you start development, please run:\n\n```bash\nyarn start\n```\n\nThis should spin up a local WP env instance for you to work with at:\n\n```bash\nhttp://cbtj.localhost:5478\n```\n\nYou should now have a functioning local WP env to work with. To login to the `wp-admin` backend, please username as `admin` \u0026 password as `password`.\n\n__Awesome!__ - Thanks for being interested in contributing your time and code to this project!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbadasswp%2Fconvert-blocks-to-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbadasswp%2Fconvert-blocks-to-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbadasswp%2Fconvert-blocks-to-json/lists"}