Download the PHP package alleyinteractive/wp-block-converter without Composer

On this page you can find all versions of the php package alleyinteractive/wp-block-converter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package wp-block-converter

WP Block Converter

Testing Suite

Convert HTML into Gutenberg Blocks with PHP

Installation

Requires PHP 8.4 or later, since HTML parsing is handled by the Dom\HTMLDocument API.

You can install the package via Composer:

This package does not use any NPM library such as @wordpress/blocks to convert HTML to blocks, and — aside from the optional WordPressImageUploader described below — has no WordPress dependency of its own, so it can be used inside a WordPress plugin/theme or in a plain PHP project.

Usage

Use this package like so to convert HTML into Gutenberg Blocks:

Logging

Pass a PSR-3 LoggerInterface into the logger constructor parameter to receive error-level log entries when an individual image fails to sideload (the conversion otherwise continues without that image):

Filtering the Blocks

The blocks can be filtered on a block-by-block basis or for an entire HTML body by passing closures into the BlockConverter constructor.

onBlock

Filter the generated block for a specific node.

onDocumentHtml

Filter the generated blocks for an entire HTML body.

Other hooks

The remaining hook points work the same way — pass a closure into the constructor:

Constructor parameter Called with
onSkipMinifyBlock ( bool $skipMinifyBlock, string $block, \Dom\Node $node ): bool
onPreSideloadImage ( bool $pre, string $src, \Dom\Node $childNode, BlockConverter $converter ): bool
onSideloadedImage ( string $src, \Dom\Node $childNode ): void
onSanitizedImageUrl ( string $sanitizedUrl, string $url ): string

Each hook accepts a single closure; if you need multiple listeners for the same hook, compose them into one closure yourself.

Sideloading Images

By default, BlockConverter leaves <img> sources untouched — no HTTP requests are made and no images are downloaded. To sideload images, pass an ImageUploader implementation into the uploader constructor parameter. Inside WordPress, pass WordPressImageUploader, which sideloads into the media library:

Outside of WordPress (or if you want different sideloading behavior inside WordPress), implement the ImageUploader interface yourself:

Attachment Parents

When converting HTML to blocks with a WordPressImageUploader (or any ImageUploader that tracks attachment IDs), you may need to attach the images that were sideloaded to a post parent. After the HTML is converted to blocks, you can get the attachment IDs that were created or simply attach them to a post.

Extending the Converter with Macros

You can extend the converter with macros to add custom tags that are not yet supported by the converter.

Macros can also completely override the default behavior of the converter. This is useful when you need to make one-off changes to the way the converter works for a specific tag.

Rich Embeds

URLs on their own line (e.g. a link to a tweet or a YouTube video) are converted into the corresponding embed block (Twitter/X, Instagram, Facebook, YouTube, Vimeo, and other providers WordPress core supports via oEmbed) using a static, hardcoded provider table rather than a live oEmbed HTTP request — so embed URLs convert identically with or without WordPress loaded. The trade-off: some providers (notably YouTube) vary details like aspect ratio per-URL in ways that normally require an oEmbed response to detect; the provider table uses sensible fixed defaults instead. URLs that don't match a known provider fall back to a plain link/paragraph. If you need live oEmbed responses, you can do this yourself by filtering the block output using a closure passed to the constructor, either using core WordPress functions if you are running your conversion in a WordPress install, or using pure PHP.

Using outside of WordPress

BlockConverter has no WordPress dependency of its own — the only WordPress-specific code in this package is the optional WordPressImageUploader class described in Sideloading Images above. By default (new BlockConverter( $html ), no uploader passed), converting HTML to blocks runs entirely in plain PHP: no WordPress functions, classes, globals, or database access, and no HTTP calls.

WP-CLI Command

This package includes a ConvertToBlocksCommand class to bulk convert posts from HTML to Gutenberg blocks, using wp-bulk-task for efficient processing of large numbers of posts with resume support. The class is not registered with WP-CLI automatically — register it yourself (e.g. in your plugin or theme's functions.php):

Basic Usage

Command Options

Features

Upgrading from v1.x

Version 2.0.0 contains several breaking changes related to a shift in philosophy: this package no longer assumes WordPress is loaded. Previously, BlockConverter (formerly Block_Converter) threw a RuntimeException unless WordPress was present, used WordPress hooks and wp_oembed_get() internally, and always sideloaded through the media library. Now WordPress is entirely optional, and every WordPress-specific behavior is something you opt into explicitly rather than something the library assumes.

Specifically:

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

This project is actively maintained by Alley Interactive. Like what you see? Come work with us.

License

The GNU General Public License (GPL) license. Please see License File for more information.


All versions of wp-block-converter with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
alleyinteractive/composer-wordpress-autoloader Version ^1.0
alleyinteractive/wp-bulk-task Version ^1.0
mantle-framework/support Version ^1.6
psr/log Version ^2.0 || ^3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package alleyinteractive/wp-block-converter contains the following files

Loading the files please wait ...