Skip to content

humanmade/rehydrator

Repository files navigation

Rehydrator

Pattern-based content transformation for WordPress block migrations. Provides utilities for loading block patterns, resolving nested pattern references, and applying targeted transformations to populate templates with content.

Full documentation →

Installation

Via Composer:

composer require humanmade/rehydrator

As a WordPress plugin: Clone or download this repository to wp-content/plugins/ and activate.

Requirements

  • PHP 8.0+
  • WordPress 6.0+

Quick Start

use HM\Rehydrator\Template;

$transformer = new Template( 'theme/template-article' );

$content = $transformer
    ->replace_text( 'theme/hero', 'core/heading', occurrence: 0, text: $title )
    ->replace_text( 'theme/hero', 'core/paragraph', occurrence: 0, text: $standfirst )
    ->replace_attributes( 'theme/hero', 'core/image', occurrence: 0, attrs: [
        'id'  => $image_id,
        'url' => $image_url,
    ] )
    ->replace_placeholder( 'content-placeholder', $body_blocks )
    ->get_content();

wp_update_post( [
    'ID'           => $post_id,
    'post_content' => $content,
] );

For full API documentation including all transformation methods and helper namespaces, see the docs site.

Development

Running Tests

composer install
composer test

Code Style

composer lint

License

GPL-2.0-or-later

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Packages

 
 
 

Contributors

Languages