creode / wordpress-blocks-rector
Rector rules for Upgrades to the WordPress blocks package
Installs: 14
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/creode/wordpress-blocks-rector
Requires
- rector/rector: ^2.0
Requires (Dev)
- phpunit/phpunit: ^11
This package is auto-updated.
Last update: 2025-10-19 08:11:58 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
-
Include the Trait in Your Class:
To use the
DocBlockAttributeExtractortrait, include it in your class definition:use Creode\WordpressBlocksRector\Traits\DocBlockAttributeExtractor; class MyClass { use DocBlockAttributeExtractor; // Your class methods and properties }
-
Extracting Attributes:
Once the trait is included, you can use the
extractDocBlockAttributemethod to extract attributes from a docblock comment. This method requires two parameters:$docComment: An instance ofPhpParser\Comment\Docrepresenting 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; }