diff --git a/README.md b/README.md index 4142b5a..2b78c86 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ composer require fsylum/rector-wordpress --dev ## Use Sets -To add a set to your config, use `Fsylum\RectorWordPress\Set\WordPressSetList` class and pick one of the constants. For example, to update the codebase to WordPress 6.8, use `WordPressSetList::WP_6_8`. +To add a set to your config, use `Fsylum\RectorWordPress\Set\WordPressSetList` class and pick one of the constants. For example, to update the codebase to WordPress 7.0, use `WordPressSetList::WP_7_0`. ```php use Fsylum\RectorWordPress\Set\WordPressSetList; @@ -25,12 +25,12 @@ use Rector\Config\RectorConfig; return static function (RectorConfig $rectorConfig): void { $rectorConfig->sets([ - WordPressSetList::WP_6_8, + WordPressSetList::WP_7_0, ]); }; ``` -You can also use a level set list to include all the applicable rules from the lowest version, 0.71 up to the one you specified. For example, `WordPressLevelSetList::UP_TO_WP_6_8` will include all the rules from WordPress 0.71 up to 6.8. In most cases, this is the preferable way to transform your code as you only need to specify it once. +You can also use a level set list to include all the applicable rules from the lowest version, 0.71 up to the one you specified. For example, `WordPressLevelSetList::UP_TO_WP_7_0` will include all the rules from WordPress 0.71 up to 7.0. In most cases, this is the preferable way to transform your code as you only need to specify it once. ```php use Fsylum\RectorWordPress\Set\WordPressLevelSetList; @@ -38,17 +38,18 @@ use Rector\Config\RectorConfig; return static function (RectorConfig $rectorConfig): void { $rectorConfig->sets([ - WordPressLevelSetList::UP_TO_WP_6_8, + WordPressLevelSetList::UP_TO_WP_7_0, ]); }; ``` ## Supported WordPress Versions -This package provides upgrade rules for WordPress versions from 0.71 to 6.8, covering: +This package provides upgrade rules for WordPress versions from 0.71 to 7.0, covering: - WordPress 0.71, 1.0, 1.2, 1.5 - WordPress 2.x (2.0 through 2.9) - WordPress 3.x (3.0 through 3.9) - WordPress 4.x (4.0 through 4.9) - WordPress 5.x (5.0 through 5.9) -- WordPress 6.x (6.0 through 6.8) +- WordPress 6.x (6.0 through 6.9) +- WordPress 7.0 diff --git a/config/config.php b/config/config.php index 4a6714a..b0d9804 100644 --- a/config/config.php +++ b/config/config.php @@ -5,8 +5,10 @@ use Fsylum\RectorWordPress\Rules\FuncCall\ParameterAdderRector; use Fsylum\RectorWordPress\Rules\MethodCall\ParameterAdderRector as MethodParameterAdderRector; use Fsylum\RectorWordPress\Rules\FuncCall\ParameterPrependerRector; +use Fsylum\RectorWordPress\Rules\FuncCall\RenameFunctionWithArgumentsRector; use Fsylum\RectorWordPress\ValueObject\FunctionParameterAdder; use Fsylum\RectorWordPress\ValueObject\FunctionParameterPrepender; +use Fsylum\RectorWordPress\ValueObject\FunctionRenameWithArguments; use Fsylum\RectorWordPress\ValueObject\MethodParameterAdder; use Rector\Config\RectorConfig; use Rector\Removing\Rector\FuncCall\RemoveFuncCallArgRector; @@ -42,6 +44,10 @@ new FunctionParameterPrepender('_imaginary_function_that_should_not_exists', 'foo'), ]); + $rectorConfig->ruleWithConfiguration(RenameFunctionWithArgumentsRector::class, [ + new FunctionRenameWithArguments('_imaginary_function_that_should_not_exists', '_new_imaginary_function_that_should_not_exists', []), + ]); + $rectorConfig->ruleWithConfiguration(RenameMethodRector::class, [ new MethodCallRename('_imaginary_class', '_old_imaginary_method_that_should_not_exists', '_new_imaginary_method_that_should_not_exists'), ]); diff --git a/config/sets/level/up-to-wp-6.9.php b/config/sets/level/up-to-wp-6.9.php new file mode 100644 index 0000000..f364bd9 --- /dev/null +++ b/config/sets/level/up-to-wp-6.9.php @@ -0,0 +1,9 @@ +sets([WordPressSetList::WP_6_9, WordPressLevelSetList::UP_TO_WP_6_8]); +}; diff --git a/config/sets/level/up-to-wp-7.0.php b/config/sets/level/up-to-wp-7.0.php new file mode 100644 index 0000000..908609d --- /dev/null +++ b/config/sets/level/up-to-wp-7.0.php @@ -0,0 +1,9 @@ +sets([WordPressSetList::WP_7_0, WordPressLevelSetList::UP_TO_WP_6_9]); +}; diff --git a/config/sets/wp-6.9.php b/config/sets/wp-6.9.php new file mode 100644 index 0000000..5b47a64 --- /dev/null +++ b/config/sets/wp-6.9.php @@ -0,0 +1,27 @@ +import(__DIR__ . '/../config.php'); + + $rectorConfig->ruleWithConfiguration(RenameFunctionRector::class, [ + 'seems_utf8' => 'wp_is_valid_utf8', + 'wp_print_auto_sizes_contain_css_fix' => 'wp_enqueue_img_auto_sizes_contain_css_fix', + ]); + + $rectorConfig->ruleWithConfiguration(RenameFunctionWithArgumentsRector::class, [ + new FunctionRenameWithArguments('utf8_encode', 'mb_convert_encoding', ['UTF-8', 'ISO-8859-1']), + new FunctionRenameWithArguments('utf8_decode', 'mb_convert_encoding', ['ISO-8859-1', 'UTF-8']), + ]); + + /* + * TODO: these are not handled currently + * + * ARGUMENTS + * - _wp_can_use_pcre_u (the $set argument is no longer used; private/internal function) + */ +}; diff --git a/config/sets/wp-7.0.php b/config/sets/wp-7.0.php new file mode 100644 index 0000000..2ac1657 --- /dev/null +++ b/config/sets/wp-7.0.php @@ -0,0 +1,32 @@ +import(__DIR__ . '/../config.php'); + + $rectorConfig->ruleWithConfiguration(RenameFunctionRector::class, [ + 'addslashes_gpc' => 'wp_slash', + 'block_core_navigation_submenu_render_submenu_icon' => 'block_core_shared_navigation_render_submenu_icon', + ]); + + $rectorConfig->ruleWithConfiguration(RenameFunctionWithArgumentsRector::class, [ + new FunctionRenameWithArguments( + 'block_core_navigation_block_contains_core_navigation', + 'block_core_navigation_block_tree_has_block_type', + ['core/navigation'] + ), + ]); + + /* + * TODO: these are not handled currently + * + * FUNCTIONS + * - wp_sanitize_script_attributes: no safe automatic replacement. It returns a string of HTML + * attributes, whereas its suggested replacements wp_get_script_tag() / wp_get_inline_script_tag() + * return a full