creode/wordpress-blocks-rector

Rector rules for Upgrades to the WordPress blocks package

1.0.0 2025-06-17 14:12 UTC

This package is auto-updated.

Last update: 2025-06-24 15:25:51 UTC


README

Rector rules for performing upgrades to the WordPress blocks package.

Installation

composer require --dev creode/wordpress-blocks-rector

Usage

Upgrade from 0.x to 1.x

To upgrade from 0.x to 1.x, run the following command, replacing {theme-name} with the name of your WordPress theme:

vendor/bin/rector process wp-content/themes/{theme-name} --config=vendor/creode/wordpress-blocks-rector/config/blocks-1-0.php

Block Plugin Documentation

Documentation for the block plugins can be found here.

Development

Using the DocBlockAttributeExtractor Trait

The DocBlockAttributeExtractor trait provides a convenient way to extract specific attributes from PHP docblock comments. This can be particularly useful when you need to parse metadata from comments in your code.

How to Use

  1. Include the Trait in Your Class:

    To use the DocBlockAttributeExtractor trait, include it in your class definition:

    use Creode\WordpressBlocksRector\Traits\DocBlockAttributeExtractor;
    
    class MyClass
    {
        use DocBlockAttributeExtractor;
    
        // Your class methods and properties
    }
  2. Extracting Attributes:

    Once the trait is included, you can use the extractDocBlockAttribute method to extract attributes from a docblock comment. This method requires two parameters:

    • $docComment: An instance of PhpParser\Comment\Doc representing the docblock comment.
    • $attributeKey: The key of the attribute you want to extract.

    Example usage:

     // Extract @wordpress-blocks-version from docblock if present
     $docComment = $node->getDocComment();
     $blocksVersion = $this->extractDocBlockAttribute($docComment, 'wordpress-blocks-version');
     if (!$blocksVersion) {
         return null;
     }
    
     // Run a version check to see if the block is compatible with the current version of the plugin.
     if (version_compare($blocksVersion, '1.3.0', '<')) {
         return null;
     }