Skip to content

creode/wordpress-blocks-rector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WordPress Blocks Rector

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;
     }

About

Rector rules for performing upgrades to the WordPress blocks package

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages