REST API Reference
BF Blocks extends the WordPress REST API under the /wp-json/bf-blocks/v1/ namespace.
Authentication
Read endpoints are public. Write and delete endpoints require authentication via:
- WordPress nonce — pass
X-WP-Nonceheader. Usewp_create_nonce('wp_rest'). - Application Password — HTTP Basic auth. Generate in Users → Profile → Application Passwords.
Endpoints
| Method | Path | Description | Auth |
|---|---|---|---|
| GET | /wp-json/bf-blocks/v1/blocks | List all registered block definitions | None (public) |
| GET | /wp-json/bf-blocks/v1/blocks/:slug | Get a single block definition by slug | None (public) |
| POST | /wp-json/bf-blocks/v1/blocks | Create a new block definition | Editor+ or nonce |
| PUT | /wp-json/bf-blocks/v1/blocks/:slug | Update an existing block definition | Editor+ or nonce |
| DELETE | /wp-json/bf-blocks/v1/blocks/:slug | Delete a block definition | Administrator |
| GET | /wp-json/bf-blocks/v1/templates | List all templates (built-in + custom) | None (public) |
| POST | /wp-json/bf-blocks/v1/export | Export one or more blocks as JSON | Editor+ or nonce |
| POST | /wp-json/bf-blocks/v1/import | Import block definitions from JSON | Administrator |
Example: List All Blocks
fetch('https://yoursite.com/wp-json/bf-blocks/v1/blocks')
.then(res => res.json())
.then(blocks => console.log(blocks));Response:
[
{
"id": 1,
"slug": "bf-blocks/testimonial",
"name": "Testimonial",
"icon": "format-quote",
"category": "theme",
"fields": [ ... ]
}
]Example: Create a Block (Authenticated)
const response = await fetch(
'https://yoursite.com/wp-json/bf-blocks/v1/blocks',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-WP-Nonce': wpApiSettings.nonce,
},
body: JSON.stringify({
name: 'My Block',
fields: [
{ key: 'heading', type: 'text', label: 'Heading' }
]
})
}
);