Skip to content
This repository has been archived by the owner on May 6, 2023. It is now read-only.

Commit

Permalink
Fixed issue between Rector and WP
Browse files Browse the repository at this point in the history
  • Loading branch information
leoloso committed Sep 22, 2020
1 parent 4a5a46d commit 40b3b84
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
27 changes: 21 additions & 6 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@
// get parameters
$parameters = $containerConfigurator->parameters();

// Rector relies on autoload setup of your project; Composer autoload is included by default; to add more:
$parameters->set(Option::AUTOLOAD_PATHS, [
// full directory
__DIR__ . '/vendor/wordpress/wordpress',
]);

// paths to refactor; solid alternative to CLI arguments
$parameters->set(Option::PATHS, [
__DIR__ . '/src',
Expand All @@ -41,4 +35,25 @@

// is your PHP version different from the one your refactor to? [default: your PHP version]
$parameters->set(Option::PHP_VERSION_FEATURES, '7.1');

// Rector relies on autoload setup of your project; Composer autoload is included by default; to add more:
$parameters->set(Option::AUTOLOAD_PATHS, [
// full directory
__DIR__ . '/vendor/wordpress/wordpress',
]);

/**
* This constant is defined in wp-load.php, but never loaded.
* It is read when resolving class WP_Upgrader in Plugin.php.
* Define it here again, or otherwise Rector fails with message:
*
* "PHP Warning: Use of undefined constant ABSPATH -
* assumed 'ABSPATH' (this will throw an Error in a future version of PHP)
* in .../graphql-api-for-wp/vendor/wordpress/wordpress/wp-admin/includes/class-wp-upgrader.php
* on line 13"
*/
/** Define ABSPATH as this file's directory */
if (!defined('ABSPATH')) {
define('ABSPATH', __DIR__ . '/vendor/wordpress/wordpress/');
}
};
13 changes: 3 additions & 10 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use GraphQLAPI\GraphQLAPI\Blocks\AccessControlRuleBlocks\AccessControlDisableAccessBlock;
use GraphQLAPI\GraphQLAPI\ModuleResolvers\SchemaConfigurationFunctionalityModuleResolver;
use GraphQLAPI\GraphQLAPI\Blocks\AccessControlRuleBlocks\AccessControlUserCapabilitiesBlock;
use WP_Upgrader;

class Plugin
{
Expand Down Expand Up @@ -152,20 +153,12 @@ function () use ($isPluginJustActivatedOptionName): void {

/**
* This function runs when WordPress completes its upgrade process
* If this plugin is updated, it sets a transient flag.
*
* Use `object` as param type for $upgrader_object, instead of the
* more specific `WP_Upgrader`, because Rector fails with it:
*
* "PHP Warning: Use of undefined constant ABSPATH -
* assumed 'ABSPATH' (this will throw an Error in a future version of PHP)
* in /home/travis/build/GraphQLAPI/graphql-api-for-wp/vendor/wordpress/wordpress/wp-admin/includes/class-wp-upgrader.php
* on line 13"
* If this plugin is updated, it sets a transient flag
*
* @param array<string, mixed> $options
* @see https://codex.wordpress.org/Plugin_API/Action_Reference/upgrader_process_complete
*/
public function checkIsPluginUpgraded(object $upgrader_object, array $options): void
public function checkIsPluginUpgraded(WP_Upgrader $upgrader_object, array $options): void
{
// If an update has taken place and the updated type is plugins and the plugins element exists,
// or an install of a new version of the plugin
Expand Down

0 comments on commit 40b3b84

Please sign in to comment.