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

Defining WP_ROCKET_PLUGIN_NAME in wp-config.php causes PHP Warning

Open joejoe04 opened this issue 1 year ago • 5 comments

Describe the bug When defining WP_ROCKET_PLUGIN_NAME in wp-config.php to change the WP Rocket name to something else in the WP Admin, the following error is logged:

[12-Dec-2024 04:03:30 UTC] PHP Warning: Constant WP_ROCKET_PLUGIN_NAME already defined in /home/user/example.com/wp-content/plugins/wp-rocket/inc/main.php on line 40

To Reproduce

  1. Add define( 'WP_ROCKET_PLUGIN_NAME', 'Site Cache' ); to wp-config.php
  2. Clear cache and view some pages
  3. Check error log

Expected behavior Here, we should check if WP_ROCKET_PLUGIN_NAME is already defined and only define it if not. Something like the following:

if ( ! defined( 'WP_ROCKET_PLUGIN_NAME' ) ) {
  define( 'WP_ROCKET_PLUGIN_NAME', 'WP Rocket' );
}

AC

  • Safeguard the constant from prompting a warning if already declared.

Additional context Ticket: https://secure.helpscout.net/conversation/2789608151/530064

joejoe04 avatar Dec 12 '24 15:12 joejoe04

Thanks @joejoe04

May I ask, what is the reason behind having our constant inside wp-config.php?

From my point of view, I think those constants are forming the base functionality of the plugin so changing them will change the core functionality, and showing a warning is a good thing :)

It's a @wp-media/product call but I can't think of this one as an issue.

wordpressfan avatar Dec 12 '24 20:12 wordpressfan

@wordpressfan

I'm not sure what decisions were made about it previously, but it's currently in our documentation for white labeling WP Rocket in the WP Admin.

You're right, product can make the call.

If we're not going to support doing this, then we would need to also remove it from the doc.

joejoe04 avatar Dec 12 '24 20:12 joejoe04

Thanks @joejoe04 I wasn't aware that we have something like that in our docs :) In this case, you are correct.

wordpressfan avatar Dec 12 '24 20:12 wordpressfan

Well, maybe not. You would know better than I if allowing that constant to be changed might lead to unexpected bad outcomes. If so, then maybe we shouldn't allow it to be changed or have it in the doc. What do you think?

joejoe04 avatar Dec 12 '24 20:12 joejoe04

It's resulting from us instructing users to use a constant. We should have a way to prevent the warning.

DahmaniAdame avatar Jan 31 '25 07:01 DahmaniAdame