PHPackages                             studiolemon/wp-lemon-rector - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. studiolemon/wp-lemon-rector

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

studiolemon/wp-lemon-rector
===========================

Rector ruleset for WP Lemon projects

0130PHP

Since Apr 12Pushed 2mo agoCompare

[ Source](https://github.com/Studio-Lemon/wp-lemon-rector)[ Packagist](https://packagist.org/packages/studiolemon/wp-lemon-rector)[ RSS](/packages/studiolemon-wp-lemon-rector/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

WP Lemon Rector
===============

[](#wp-lemon-rector)

A comprehensive Rector package with custom rules specifically designed for WP Lemon projects. This package includes Rector itself along with custom transformation rules for the Bulldozer block framework.

Installation
------------

[](#installation)

Install this package in your WP Lemon project using Composer:

```
composer require --dev studiolemon/wp-lemon-rector
```

This will install Rector along with all custom WP Lemon rules.

Usage
-----

[](#usage)

Since this package includes Rector, you can run it directly without any additional configuration:

```
# Using the WP Lemon Rector executable
vendor/bin/wp-lemon-rector --dry-run
vendor/bin/wp-lemon-rector
```

```
### Custom Configuration (Optional)

If you need to customize paths, add additional rules, or change settings, create a `rector.php` file in your project root:

```php
withPaths([
        __DIR__ . '/web/app/themes/your-theme/blocks',
        __DIR__ . '/web/app/plugins/your-plugin/src',
    ])
    // Import the WP Lemon Rector configuration
    ->withSets([
        __DIR__ . '/vendor/studiolemon/wp-lemon-rector/rector.php',
    ]);
```

Custom Rules
------------

[](#custom-rules)

This package includes custom Rector rules tailored for WP Lemon's Bulldozer block framework:

### 1. ClassesArrayToAddClassMethodRector

[](#1-classesarraytoaddclassmethodrector)

Transforms array assignments to the `add_class()` method:

```
// Before
$this->classes[] = 'section hero alignfull has-background';

// After
$this->add_class(['section', 'hero', 'alignfull', 'has-background']);
```

### 2. MergeConsecutiveAddClassCallsRector

[](#2-mergeconsecutiveaddclasscallsrector)

Optimizes multiple consecutive `add_class()` calls by merging them into a single call:

```
// Before
$this->add_class(['bg-pill']);
$this->add_class(['section', 'has-background']);

// After
$this->add_class(['bg-pill', 'section', 'has-background']);
```

### 3. AttributesAlignToSetAlignmentRector

[](#3-attributesaligntosetalignmentrector)

### 3. SiteIconsAttributesToConstructorRector

[](#3-siteiconsattributestoconstructorrector)

Transforms property assignments on a `Site_Icons` instance into a single constructor array argument:

```
// Before
$icons = new Site_Icons();
$icons->short_name = 'BusinessBase';
$icons->background_color = '#ffffff';
$icons->theme_color = '#f5f9e5';

// After
$icons = new Site_Icons([
    'short_name' => 'BusinessBase',
    'background_color' => '#ffffff',
    'theme_color' => '#f5f9e5',
]);
```

Transforms the `align` attribute assignment to the `set_alignment()` method:

```
// Before
$this->attributes['align'] = 'full';

// After
$this->set_alignment('full');
```

### 4. AttributesIdToSetAnchorRector

[](#4-attributesidtosetanchorrector)

Transforms the `id` attribute assignment to the `set_anchor()` method:

```
// Before
$this->attributes['id'] = 'formulier';

// After
$this->set_anchor('formulier');
```

### 5. AttributesArrayToSetAttributeMethodRector

[](#5-attributesarraytosetattributemethodrector)

Fallback transformation for attribute assignments into `set_attribute()` when no more-specific rule applies:

```
// Before
$this->attributes['foo'] = 'bar';

// After
$this->set_attribute('foo', 'bar');
```

### 6. FieldsArrayToGetFieldMethodRector

[](#6-fieldsarraytogetfieldmethodrector)

Transforms field array access to the `get_field()` method:

```
// Before
$value = $this->fields['image_field'];

// After
$value = $this->get_field('image_field');
```

### 7. AcfInitToIncludeFieldsRector

[](#7-acfinittoincludefieldsrector)

In files prefixed with `field-` or `fields-` (e.g. `field-hero.php`, `fields-hero.php`), replaces the `acf/init` hook with `acf/include_fields`. This ensures ACF field groups are registered at the correct point in the WordPress lifecycle.

```
// Before (in field-hero.php or fields-hero.php)
add_action('acf/init', 'my_acf_add_local_field_groups');

// After
add_action('acf/include_fields', 'my_acf_add_local_field_groups');
```

> **Note:** This rule only applies to files whose filename starts with `field-` or `fields-`. Files with other names are left untouched.

### 8. IsPreviewPropertyToMethodRector

[](#8-ispreviewpropertytomethodrector)

Transforms `is_preview` property access to method call:

```
// Before
if ($this->is_preview) {
    // do something
}

// After
if ($this->is_preview()) {
    // do something
}
```

### 9. BlockDisabledPropertyToMethodRector

[](#9-blockdisabledpropertytomethodrector)

Transforms `block_disabled` property assignment to the `set_disabled()` method:

```
// Before
$this->block_disabled = true;

// After
$this->set_disabled();
```

### 10. InnerBlocksStringToMethodRector

[](#10-innerblocksstringtomethodrector)

Transforms InnerBlocks HTML string concatenation to the `create_inner_blocks()` method:

```
// Before
'InnerBlocks' => ''

// After
'InnerBlocks' => self::create_inner_blocks($allowed_blocks, $template)
```

Standard Rector Sets
--------------------

[](#standard-rector-sets)

In addition to custom rules, this package includes:

- **PHP 8.3+ Features**: Modern PHP syntax and features
- **Dead Code Removal**: Removes unused code and variables
- **Code Quality**: Improves overall code quality
- **Coding Style**: Enforces consistent coding standards
- **Type Declarations**: Adds type hints where possible
- **Privatization**: Makes properties and methods private when possible
- **Naming**: Improves variable and method naming
- **Early Return**: Promotes early return patterns
- **Strict Booleans**: Enforces strict boolean comparisons

### WordPress Compatibility

[](#wordpress-compatibility)

Some rules are intentionally skipped to maintain compatibility with WordPress:

- `StaticClosureRector` - WordPress often uses dynamic closures
- `StaticArrowFunctionRector` - WordPress often uses dynamic arrow functions
- `ReadOnlyPropertyRector` - May conflict with WordPress patterns

Contributing
------------

[](#contributing)

Contributions are welcome! To add or modify rules:

1. Edit or add Rector rules in the `src/` directory
2. Update the `rector.php` configuration to register new rules
3. Add test cases in `tests/blocks/`
4. Submit a pull request

License
-------

[](#license)

MIT

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance56

Moderate activity, may be stable

Popularity13

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity12

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/17764157?v=4)[Erik van der Bas](/maintainers/levdbas)[@Levdbas](https://github.com/Levdbas)

---

Top Contributors

[![Levdbas](https://avatars.githubusercontent.com/u/17764157?v=4)](https://github.com/Levdbas "Levdbas (24 commits)")

### Embed Badge

![Health badge](/badges/studiolemon-wp-lemon-rector/health.svg)

```
[![Health](https://phpackages.com/badges/studiolemon-wp-lemon-rector/health.svg)](https://phpackages.com/packages/studiolemon-wp-lemon-rector)
```

###  Alternatives

[naoray/nova-json

Nova json field to spread a json column throughout multiple fields.

37510.5k](/packages/naoray-nova-json)[t3docs/site-package

Site Package - This site package is an example used to understand the TYPO3 Site Package Tutorial.

1416.9k](/packages/t3docs-site-package)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
