Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .plugin-data
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "1.0.2",
"version": "2.0.0",
"slug": "blockparty-faq"
}
5 changes: 5 additions & 0 deletions .wp-env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"plugins": [
"."
]
}
72 changes: 69 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,77 @@
# Blockparty FAQ

A Gutenberg block for SEO friendly FAQ in an accessible accordion.

## Development Setup

### Prerequisites

- Node.js 20.12.0 (managed by Volta)
- Docker (for wp-env)

### Installation

1. Clone the repository
2. Install dependencies:

```bash
npm install
```

3. Build the blocks:

```bash
npm run build
```

4. Start the WordPress environment and install Yoast SEO:

```bash
npm run setup:env
```

**Note:** On Windows, you may need to run the commands separately:

```bash
npm run start:env
# Wait for WordPress to be ready (about 10-15 seconds)
npm run setup
```

### Available Scripts

- `npm run build` - Build the blocks for production
- `npm run start` - Start the development server with hot reload
- `npm run start:env` - Start the WordPress environment (wp-env)
- `npm run stop:env` - Stop the WordPress environment
- `npm run install:yoast` - Install and activate Yoast SEO plugin (required for schema generation)
- `npm run setup:env` - Start wp-env and install Yoast SEO in one command

### Note

Yoast SEO is required for the FAQ schema (JSON-LD) generation. It is installed automatically via `npm run setup:env` but is not versioned in the repository.

## Changelog

### 1.0.0 - 2024-04-02
* initial commit.

- initial commit.

### 1.0.1 - 2024-04-03
* fix css variable names

- fix css variable names

### 1.0.2 - 2024-06-06
* Add support for PHP 8.2

- Add support for PHP 8.2

### 2.0.0 - 2026-01-26

- **Major block structure refactoring** : Transition from a monolithic block to a nested architecture with child blocks (`faq-item`, `faq-question`, `faq-answer`)
- **Configurable accordion mode** : Added `isAccordion` attribute allowing to toggle between an interactive accordion mode and a static mode
- **InnerBlocks support in answers** : Ability to add any Gutenberg block (lists, paragraphs, images, etc.) in FAQ answers
- **Front-end JavaScript** : Added `script.js` to handle accordion interactivity on the front-end with customizable configuration via the `beapi_faq_block_config` filter
- **Automatic migration** : Migration system from the old format (`questions` array attribute) to the new format (InnerBlocks)
- **Complete internationalization** : Support for PO/MO translations for PHP and JSON for JavaScript
- **Aligned build structure** : Reorganization to follow the `blockparty-accordion` model with `block.json` in each block directory
- **Add/remove buttons** : Added buttons to add and remove FAQ items directly from the editor
22 changes: 0 additions & 22 deletions block.json

This file was deleted.

51 changes: 46 additions & 5 deletions blockparty-faq.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php
/**
* Plugin Name: Blockparty Faq
* Description: A Gutenberg block for SEO friendly FAQ in an accessible accordion
* Plugin Name: Blockparty FAQ
* Description: A FAQ block for WordPress Editor that provided structured data based on FAQ schema.
* Requires at least: 6.2
* Requires PHP: 8.1
* Version: 1.0.2
* Version: 2.0.0
* Plugin URI: https://beapi.fr
* Author: Be API Technical team
* Author URI: https://beapi.fr
Expand Down Expand Up @@ -41,7 +41,7 @@
}

// Plugin constants
define( 'BLOCKPARTY_FAQ_VERSION', '1.0.2' );
define( 'BLOCKPARTY_FAQ_VERSION', '2.0.0' );

// Plugin URL and PATH
define( 'BLOCKPARTY_FAQ_DIR', plugin_dir_path( __FILE__ ) );
Expand All @@ -50,8 +50,49 @@
require_once BLOCKPARTY_FAQ_DIR . 'includes/hooks/schema.php';
require_once BLOCKPARTY_FAQ_DIR . 'includes/schema/faq_schema.php';

/**
* Initialize plugin blocks.
*
* @since 1.0.0
*
* @return void
*/
function blockparty_faq_init(): void {
register_block_type( __DIR__ );
load_plugin_textdomain( 'blockparty-faq', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );

// Register main block (from src/faq/block.json)
register_block_type( __DIR__ . '/build/faq' );

// Register child blocks
// These blocks are also registered via JavaScript in src/index.js,
// but we need to register them in PHP so WordPress knows about their block.json metadata
register_block_type( __DIR__ . '/build/faq-item' );
register_block_type( __DIR__ . '/build/faq-question' );
register_block_type( __DIR__ . '/build/faq-answer' );

// Load translations for JS
wp_set_script_translations( 'blockparty-faq-editor-script', 'blockparty-faq', BLOCKPARTY_FAQ_DIR . 'languages' );

// Pass PHP values to main script
$constants = [
'accordionConfig' => apply_filters(
'beapi_faq_block_config',
[
'allowMultiple' => true,
'closedDefault' => true,
'forceExpand' => false,
'hasAnimation' => true,
'openMultiple' => false,
'panelSelector' => '.faq__panel',
'prefixId' => 'block-faq',
'triggerSelector' => '.faq__trigger',
]
),
];

wp_localize_script( 'blockparty-faq-view-script', 'beapiFaqBlock', $constants );

do_action( 'blockparty_faq_init' );
}

add_action( 'init', __NAMESPACE__ . '\\blockparty_faq_init' );
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
}
},
"require": {
"php": "^8.1 | ^8.2",
"php": "^8.1 | ^8.2 | ^8.3 | ^8.4",
"ext-json": "*",
"composer/installers": "^1.0 || ^2.0"
},
Expand Down
Loading
Loading