Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't define WP_ROCKET_CACHE_PATH if already set #6116

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

tfgrass
Copy link

@tfgrass tfgrass commented Aug 22, 2023

Description

We are using WP Rocket with our Bedrock sites. One Problem we encountered, is that we have to set WP_ROCKET_CACHE_PATH early in our configurations, because else the constant is not ready when advanced-cache.php is executed.

Since we already defined WP_ROCKET_CACHE_PATH, we always get a Warning:
Constant WP_ROCKET_CACHE_PATH already defined
app/plugins/wp-rocket/wp-rocket.php:63

Type of change

  • Bug fix (non-breaking change which fixes an issue).

Is the solution different from the one proposed during the grooming?

Please describe in this section if there is any change to the groomed solution, and why.

Checklists

Generic development checklist

  • My code follows the style guidelines of this project, with adapted comments and without new warnings.
  • I have added unit and integration tests that prove my fix is effective or that my feature works.
  • The CI passes locally with my changes (including unit tests, integration tests, linter).
  • Any dependent changes have been merged and published in downstream modules.
  • If applicable, I have made corresponding changes to the documentation. Provide a link to the documentation.

Test summary

  • I triggered all changed lines of code at least once without new errors/warnings/notices.
  • I validated all Acceptance Criteria of the related issues. (If applicable, provide proof).
  • I validated all test plan the QA Review asked me to.

If not, detail what you could not test.

Please describe any additional tests you performed.

@piotrbak
Copy link
Contributor

Hello @tfgrass thanks for creating the PR.

Any reason why not to use WP_ROCKET_CACHE_ROOT_PATH constant?

@tfgrass
Copy link
Author

tfgrass commented Aug 22, 2023

@piotrbak we are also setting WP_ROCKET_CACHE_ROOT_PATH

/**
 * define wp_rocket paths
 */
Config::define('WP_ROCKET_CONFIG_PATH', $root_dir . '/config/wp-rocket-config/');
Config::define('WP_ROCKET_CACHE_ROOT_PATH', $webroot_dir . '/app/cache/');
Config::define('WP_ROCKET_CACHE_PATH', $webroot_dir . '/app/cache/wp-rocket/');

Problem is - in advanced-cache.php it tries to access WP_ROCKET_CACHE_PATH before the wp-rocket.php is executed, so we have to set it seperatly.


<?php
defined('ABSPATH') or exit;

define('WP_ROCKET_ADVANCED_CACHE', true);

$rocket_path        = WP_CONTENT_DIR.'/plugins/wp-rocket/';
$rocket_config_path = WP_ROCKET_CONFIG_PATH;
$rocket_cache_path  = WP_ROCKET_CACHE_PATH;

if (file_exists($rocket_path . 'inc/front/process.php')) {
    include($rocket_path . 'inc/front/process.php');
} else {
    define('WP_ROCKET_ADVANCED_CACHE_PROBLEM', true);
}

Maybe it would make sense to somehow include the wp-rocket.php so the constants are ready for use in advanced cache, but I'm not sure whether this would break something

@piotrbak
Copy link
Contributor

@tfgrass I might be missing something, but for me it doesn't make sense to define WP_ROCKET_CACHE_PATH like this. Mentioned constant is dependent on the WP_ROCKET_CACHE_ROOT_PATH, so if you set WP_ROCKET_CACHE_ROOT_PATH to be /app/cache/, WP_ROCKET_CACHE_PATH will automatically be /app/cache/wp-rocket/ as you can see here:

wp-rocket/wp-rocket.php

Lines 60 to 63 in 68b2aa2

if ( ! defined( 'WP_ROCKET_CACHE_ROOT_PATH' ) ) {
define( 'WP_ROCKET_CACHE_ROOT_PATH', WP_CONTENT_DIR . '/cache/' );
}
define( 'WP_ROCKET_CACHE_PATH', WP_ROCKET_CACHE_ROOT_PATH . 'wp-rocket/' );

If I'm missing something, please elaborate on this. We have many customers using Bedrock and that's the first request related to this constant.

@piotrbak
Copy link
Contributor

Also, inc/front/process.php is not used since many many years

@tfgrass
Copy link
Author

tfgrass commented Aug 22, 2023

@piotrbak just for my understanding - this is an old version of wp-rockets advanced-cache.php dropin?

I just checked the backend, to see if it gives me this error https://docs.wp-rocket.me/article/134-advanced-cache-error-message - but in the backend I don't see any message like this.

I will check if using the latest version of the drop in fixes the issue - this would be the right one, i guess?

use WP_Rocket\Buffer\Config;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants