wp-media / wp-rocket

Performance optimization plugin for WordPress
https://wp-rocket.me
GNU General Public License v2.0
698 stars 218 forks source link

Conflict with Yoast SEO and ATF feature #6751

Open adumont-tokilab opened 4 months ago

adumont-tokilab commented 4 months ago

Describe the bug A notice is thrown when saving a post when Yoast is installed and if that post exists in the "wpr_above_the_fold" table. In fact, WordPress calls the method "clean_post_cache" once on save. WP-Rocket cleans the URL of that post from the "wpr_above_the_fold" table. Later on, Yoast also calls "clean_post_cache", which triggers the same hook that WP-Rocket uses but fails because the database entry doesn't exists anymore. WP-Rocket caches the database results. The first time they are used, it is okay but the second time, it returns an array of elements but those elements equals "false".

Notice: Trying to get property 'id' of non-object in /web/app/plugins/wp-rocket/inc/Engine/Common/Database/Queries/AbstractQuery.php on line 402

public function delete_by_url( string $url ) {
    if ( ! self::$table_exists && ! $this->table_exists() ) {
        return false;
    }

    $items = $this->get_rows_by_url( $url ); // <-- Returns an array of "false" elements

    if ( ! $items ) {
        return false;
    }

    $deleted = true;
    foreach ( $items as $item ) {
        $deleted = $deleted && $this->delete_item( $item->id );
    }

    return $deleted;
}

To Reproduce Steps to reproduce the behavior:

  1. Development mode must be activated and/or errors must be displayed.
  2. WP-Rocket 3.16 or newer must be installed.
  3. Yoast SEO must be installed.
  4. Edit a post in the backend. Make sure that post appears in the "wpr_above_the_fold" table.
  5. Save that post.
  6. See error.

Expected behavior The post should be saved without throwing a notice.

alfonso100 commented 3 months ago

Two additional Cases

Could not be only related to Yoast, but also to other 3rd parties calling clean_post_cache

https://secure.helpscout.net/conversation/2656511889/503466 (not using Yoast) https://secure.helpscout.net/conversation/2661231689/504375

related slack thread with more details: https://wp-media.slack.com/archives/C43T1AYMQ/p1721925394744229