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": "1.0.3",
"slug": "blockparty-anchors"
}
2 changes: 1 addition & 1 deletion .wordpress-org/blueprints/blueprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"pluginData": {
"resource": "git:directory",
"url": "https://github.com/BeAPI/blockparty-anchors",
"ref": "1.0.2",
"ref": "1.0.3",
"refType": "tag"
},
"options": {
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to Blockparty Anchors are documented in this file.

## 1.0.3

- Add WP-CLI command `migrate-from-anchor-block` to convert legacy `beapi/anchor` and `beapi/anchor-list` blocks to Blockparty Anchors, with `MIGRATION.md` documentation.

## 1.0.2

- Add frontend scroll-spy on the Anchors List block, with an `is-active` state, smooth in-page scrolling, URL hash sync, and sticky position support.
Expand Down
92 changes: 92 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Migrating from `beapi/anchor` to `blockparty-anchors`

This document describes how to move from the old BeAPI anchor blocks to `beapi/blockparty-anchors`.

## Package swap

```bash
composer require beapi/blockparty-anchors
```

Activate `blockparty-anchors` and deactivate the previous anchor plugin.

## Block model changes

| Old | New |
|---|---|
| `beapi/anchor` | `blockparty/anchor` |
| `beapi/anchor-list` | `blockparty/anchors-list` |
| CSS `.wp-block-beapi-anchor` | CSS `.wp-block-blockparty-anchor` |
| CSS `.wp-block-beapi-anchor-list` | CSS `.wp-block-blockparty-anchors-list` |

Attributes (`title`, `slug`, `className`, and any extra attrs) are kept as-is.

Old blocks are typically void / self-closing. After migration they are serialized as empty self-closing `blockparty/*` comments:

```
<!-- wp:beapi/anchor {"title":"My section","slug":"my-section"} /-->
<!-- wp:beapi/anchor-list /-->
```

becomes:

```
<!-- wp:blockparty/anchor {"title":"My section","slug":"my-section"} /-->
<!-- wp:blockparty/anchors-list /-->
```

## Content migration (WP-CLI)

After activating `blockparty-anchors`:

```bash
# Preview (current site)
wp blockparty-anchors migrate-from-anchor-block --dry-run

# Apply on the current site
wp blockparty-anchors migrate-from-anchor-block

# Limit post types
wp blockparty-anchors migrate-from-anchor-block --post-type=post,page
```

The command always targets **one site only**. On multisite, repeat it yourself with `--url=` for each site:

```bash
wp blockparty-anchors migrate-from-anchor-block --url=https://example.com/
wp blockparty-anchors migrate-from-anchor-block --url=https://example.com/site-2/
```

The command:

1. Scans `post_content` for `beapi/anchor` (covers `beapi/anchor` and `beapi/anchor-list`)
2. Parses blocks, converts markup recursively (including nested group/columns), serializes back
3. Updates the post with `wp_slash()` on content (required so `\u002d` escapes for `--` in block comments are not stripped by `wp_update_post()`)
4. Logs migrated / skipped counts

If `wp_update_post()` fails with `invalid_page_template` (orphaned `_wp_page_template` meta), the command does not abort. It updates `post_content` only via `$wpdb->update()` (unslashed), then calls `clean_post_cache()`. Those posts are logged as `[update-fallback]`.

### Revisions

Only the scanned post types are migrated (public REST post types + `wp_block` by default). **Revisions are not included**, so parent posts are updated while historical revisions (and trash) can still contain the old `beapi/anchor` / `beapi/anchor-list` markup. That is expected. To migrate revisions as well, pass them explicitly, for example:

```bash
wp blockparty-anchors migrate-from-anchor-block --post-type=revision
```

### Duplicate Post (Yoast)

If [Yoast Duplicate Post](https://wordpress.org/plugins/duplicate-post/) is active, updating a Rewrite & Republish **copy** via `wp_update_post()` (especially without `--user=`) can call `wp_die( 'You are not allowed to republish this post.' )` and abort the whole WP-CLI run.

Preferred workaround: skip that plugin for the migration only (global WP-CLI flag):

```bash
wp --skip-plugins=duplicate-post blockparty-anchors migrate-from-anchor-block --url=https://example.com/
```

## Front-end checklist

- Re-register custom block styles on `blockparty/anchor` / `blockparty/anchors-list`
- Update theme SCSS selectors from `.wp-block-beapi-anchor` / `.wp-block-beapi-anchor-list` to `.wp-block-blockparty-anchor` / `.wp-block-blockparty-anchors-list`
- Update block patterns / allowlists
- Smoke-test in-page links, the anchors list, and nested anchors inside groups/columns
10 changes: 8 additions & 2 deletions blockparty-anchors.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Plugin Name: Blockparty Anchors
* Description: Adds two new blocks to the WordPress editor: an anchor block to create an anchor system on your pages, and an anchor list block to list those anchors.
* Version: 1.0.2
* Version: 1.0.3
* Requires at least: 6.8
* Requires PHP: 8.1
* Author: Be API Technical Team
Expand All @@ -16,6 +16,8 @@

namespace Blockparty\Anchors;

use Blockparty\Anchors\Cli\MigrateFromAnchorBlockCommand;

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
Expand All @@ -24,7 +26,7 @@
include_once __DIR__ . '/vendor/autoload.php';
}

define( 'BLOCKPARTY_ANCHORS_VERSION', '1.0.2' );
define( 'BLOCKPARTY_ANCHORS_VERSION', '1.0.3' );
define( 'BLOCKPARTY_ANCHORS_URL', plugin_dir_url( __FILE__ ) );
define( 'BLOCKPARTY_ANCHORS_DIR', plugin_dir_path( __FILE__ ) );
define( 'BLOCKPARTY_ANCHORS_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
Expand Down Expand Up @@ -69,3 +71,7 @@ function init() {
}

add_action( 'init', __NAMESPACE__ . '\\init', 0 );

if ( defined( 'WP_CLI' ) && WP_CLI ) {
\WP_CLI::add_command( 'blockparty-anchors migrate-from-anchor-block', MigrateFromAnchorBlockCommand::class );
}
Loading
Loading