wp-rocket icon indicating copy to clipboard operation
wp-rocket copied to clipboard

Fixes #4570 generate config file when activating the plugin using WP CLI

Open dmleonov-cloudlinux opened this issue 2 years ago • 7 comments

Description

When activating WP Rocket using WP CLI, the configuration file is not generated.

Once the user accesses the admin, the configuration file is then generated.

This can cause WP Rocket not working when activated using: wp plugin activate wp-rocket

Not until the user manually access the Admin section of WordPress.

Fixes #4570

dmleonov-cloudlinux avatar Jul 11 '22 14:07 dmleonov-cloudlinux

@vmanthos Added changes, can you check, please?

dmleonov-cloudlinux avatar Sep 08 '22 11:09 dmleonov-cloudlinux

@dmleonov-cloudlinux It's still not working.

@wp-media/php can you maybe look into this, please? 🙏

vmanthos avatar Sep 08 '22 11:09 vmanthos

The license is still not validated after the latest commit.

Shameless ping following.

@wp-media/php Would you mind helping @dmleonov-cloudlinux out, please?

vmanthos avatar Sep 12 '22 06:09 vmanthos

The license is still not validated after the latest commit.

Shameless ping following.

@wp-media/php Would you mind helping @dmleonov-cloudlinux out, please?

Hi @dmleonov-cloudlinux ,

Look like there is a problem when we are activating the license due to the fact a subscriber adding the header with the license. For that purpose, you need to add this logic inside the Activate class at the line 47:

		$api_url = wp_parse_url( WP_ROCKET_WEB_INFO );

		$container->share( 'plugin_updater_common_subscriber', UpdaterApiCommonSubscriber::class )
			->addArgument(
				[
					'api_host'           => $api_url['host'],
					'site_url'           => home_url(),
					'plugin_version'     => WP_ROCKET_VERSION,
					'settings_slug'      => WP_ROCKET_SLUG,
					'settings_nonce_key' => WP_ROCKET_PLUGIN_SLUG,
					'plugin_options'     => $container->get( 'options' ),
				]
			)
			->addTag( 'common_subscriber' );

		$event_manager->add_subscriber( $container->get( 'plugin_updater_common_subscriber' ) );

CrochetFeve0251 avatar Sep 13 '22 19:09 CrochetFeve0251

@CrochetFeve0251 @dmleonov-cloudlinux I'm getting a PHP Fatal error when activating the plugin, both when using wp-cli and WordPress's UI:

Fatal error: Uncaught Error: Undefined constant "WP_Rocket\Engine\Activation\WP_ROCKET_PLUGIN_SLUG" in /var/www/example.com/htdocs/wp-content/plugins/wp-rocket/inc/Engine/Activation/Activation.php:56
Stack trace:
#0 /var/www/example.com/htdocs/wp-includes/class-wp-hook.php(307): WP_Rocket\Engine\Activation\Activation::activate_plugin()
#1 /var/www/example.com/htdocs/wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters()
#2 /var/www/example.com/htdocs/wp-includes/plugin.php(476): WP_Hook->do_action()
#3 /var/www/example.com/htdocs/wp-admin/includes/plugin.php(691): do_action()
#4 phar:///usr/local/bin/wp/vendor/wp-cli/extension-command/src/Plugin_Command.php(333): activate_plugin()
#5 [internal function]: Plugin_Command->activate()
#6 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/CommandFactory.php(100): call_user_func()
#7 [internal function]: WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher\{closure}()
#8 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/Subcommand.php(491): call_user_func()
#9 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(417): WP_CLI\Dispatcher\Subcommand->invoke()
#10 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(440): WP_CLI\Runner->run_command()
#11 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1237): WP_CLI\Runner->run_command_and_exit()
#12 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Bootstrap/LaunchRunner.php(28): WP_CLI\Runner->start()
#13 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/bootstrap.php(78): WP_CLI\Bootstrap\LaunchRunner->process()
#14 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/wp-cli.php(27): WP_CLI\bootstrap()
#15 phar:///usr/local/bin/wp/php/boot-phar.php(11): include('...')
#16 /usr/local/bin/wp(4): include('...')
#17 {main}
  thrown in /var/www/example.com/htdocs/wp-content/plugins/wp-rocket/inc/Engine/Activation/Activation.php on line 56

Can you please look into this?

vmanthos avatar Sep 16 '22 05:09 vmanthos

This constant is defined in the function that is hooked in plugins_loaded, which is not used during the activation process. Since the plugin was not created with CLI in mind originally, there might be more instances of things like that where the expectation is that the plugin is fully loaded and used through the admin.

remyperona avatar Sep 16 '22 13:09 remyperona

Could you provide the license key for testing at dmleonov ..dog.. cloudlinux ..dot.. com?

dmleonov-cloudlinux avatar Sep 19 '22 09:09 dmleonov-cloudlinux

Hello @dmleonov-cloudlinux do you still need a license for this website?

piotrbak avatar Sep 25 '22 17:09 piotrbak

@piotrbak yes, without it I can't test the fix.

dmleonov-cloudlinux avatar Sep 26 '22 08:09 dmleonov-cloudlinux

@dmleonov-cloudlinux Could you reach me at piotr[at]wp-media.me using an email registered at WP Rocket website? I'll share with you the license then.

piotrbak avatar Sep 29 '22 11:09 piotrbak

@vmanthos Could you test again?

dmleonov-cloudlinux avatar Oct 20 '22 13:10 dmleonov-cloudlinux

@wp-media/php Whenever you have a spare second, could you take a look at Vasilis' comment there? How we could move forward?

piotrbak avatar Dec 07 '22 11:12 piotrbak

@wp-media/php Whenever you have a spare second, could you take a look at Vasilis' comment there? How we could move forward?

The reason why the WP_CACHE is not set to true is because the activator wp_cache in charge of it is called before we activate the license.

A solution for me would be to create an action rocket_activation_after that will run after we did all licenses steps. We will then change the even the callback inside WPCache class is attached to to the new action. This way the constant will be added with the right value.

CrochetFeve0251 avatar Dec 30 '22 15:12 CrochetFeve0251

@vmanthos Could you test again?

dmleonov-cloudlinux avatar Jan 05 '23 15:01 dmleonov-cloudlinux

@Tabrisrp Looks like there are changes in this PR that need an experienced eye, could you check it?

piotrbak avatar Jan 05 '23 18:01 piotrbak

@wp-media/php I tested the PR.

  • The WP_CACHE is added.
  • The configuration file is generated (please check below).
  • The license is validated when accessing WP Rocket's dashboard.

List of issues

  • The .htaccess rules are not added until there is action in the admin area.
  • The .htaccess rules are not removed when WP Rocket is deactivated either using wp-cli or through the UI.
  • Although the cache is created if someone visits the front end, preload isn't running.

In the configuration file:

  • The $rocket_cache_ignored_parameters array isn't populated.
  • The $rocket_cache_reject_uri contains only the default URLs, e.g. feeds, REST API, etc. If WooCommerce is already enabled, it won't contain the WooCommerce-specific rejected URIs.

The configuration file will be like that until an action triggers its regeneration.

Can you please look into these? :pray:

vmanthos avatar Jan 27 '23 10:01 vmanthos