1.0.0 • Published 3 years ago

wp-classic-to-blocks v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

WordPress Classic to Blocks Content Mass Converter

About

Bulk/Mass convert Classic Editor WordPress post to Blocks Editor posts while keeping database sanity.

The goal is to covert thousands of posts with a minimal impact on the database, and an under-control impact on the hosting server ressources. No additional row will be set, only post_content cell for all non-null classic published posts will be updated.

Note

This tool is targeting power users or admin who want to reduce database alterations at the minimum while converting old posts to WordPress Blocks posts.
After last validation, changes are not reversible (not to say destructive).

If a more user-friendly with a graphical interface is wanted (and is more important than database sanity), please have a look at the Bulk Block Converter plugin.

As always, backup your database before.

Usage

Prerequisites

CLI

  • Download runner
    • Docker image
      docker run ghcr.io/leocolomb/wp-classic-to-blocks
    • NPM package
      npx wp-classic-to-blocks
  1. Database information will be asked
  • Host
  • Database name
  • Username
  • Password
  • WordPress Table Prefix
  1. WordPress REST-API information will be asked
  • Base URL (e.g. https://my-wp.domain)
  • Optional IP address to bypass DNS resolution
  • Optional insecure certificate validation
  1. Precessing confirmation will be asked

API

registerDatabase(connection, options?)

Returns a promise for generating database interface.

connection

Type: Object

Database connection information.

prefix

Type: String Default: wp_

Database tables prefix.

registerWordPressAPI(options)

Returns a promise for generating WordPress REST-API interface.

options

Type: Object

baseUrl

Type: String

Base URL to the WordPress site.

username

Type: String

Username to connect to the API.

password

Type: String

Password to connect to the API.

ip

Type: String? Default: null

IPv4 address to resolve the domain name provided in the base URL.

insecure

Type: Boolean Default: false

Disable certificate validation.

options

Type: Object Default: {}

Additional got options.

registerBlocksHandler(options)

Returns a promise for generating a classic to block content raw-handler.

FAQ

Why use Node.js environment? Why not PHP?

Since WordPress Blocks environment is written in JavaScript and targets browsers, the best server-side emulation is Node.js.

Why browser polyfills are loaded?

The only way to register blocks used for conversion uses matchMedia function, which is not available on Node.js environment, as expected.

Why WordPress REST-API usage is required?

In order to let the WordPress Blocks raw handler handle the post content, the data provided has to be HTML rendered using the_content filter under edit (editor) context.

Why the Basic Auth plugin is required?

Since WordPress REST-API does not support authentification (seriously), we need to the non-official official authentification public to get rendered content.

Why is this so complicated?

WordPress makes things complicated for developers, sometimes. And https://github.com/WordPress/gutenberg/issues/12694.

License

ISC © Léo Colombaro