wp-media / wp-rocket

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

Pantheon Host Support #2371

Open pcfreak30 opened 4 years ago

pcfreak30 commented 4 years ago

While Pantheon has some quirks due to their inforced git based setup, the following is a starting point for supporting it. This was developed through a client project.

https://wordpress.org/plugins/pantheon-advanced-page-cache/ is required

The intent is this can kick start adding some support to the core.

<?php

namespace WP_Rocket\Subscriber\Third_Party\Hostings;

use Pantheon_Advanced_Page_Cache\Purger;
use WP_Rocket\Event_Management\Subscriber_Interface;

/**
 * Subscriber for compatibility with Pantheon
 *
 * @since  3.4.1
 * @author Soponar Cristina
 */
class Pantheon_Subscriber implements Subscriber_Interface {
    /**
     * Subscribed events for Pantheon.
     *
     * @since  3.4.1
     * @author Soponar Cristina
     * @inheritDoc
     */
    public static function get_subscribed_events() {
        if ( ! ( class_exists( '\Pantheon_Advanced_Page_Cache\Purger' ) && class_exists( '\Pantheon_Cache' ) ) ) {
            return [];
        }

        return [
            'do_rocket_generate_caching_files'   => [ 'return_false', PHP_INT_MAX ],
            'before_rocket_clean_domain' => 'pantheon_clean_domain',
            'before_rocket_clean_term'   => 'pantheon_clean_term',
            'before_rocket_clean_post'   => 'pantheon_clean_post',
            'before_rocket_clean_home'   => [ 'pantheon_clean_home', 0 ],
        ];
    }

    /**
     * Purge Pantheon all domain.
     *
     * @param string $root The path of home cache file.
     * @param string $lang The current lang to purge.
     * @param string $url  The home url.
     *
     * @author Soponar Cristina
     *
     * @since  3.4.1
     */
    public function pantheon_clean_domain() {
        pantheon_clear_edge_all();
    }

    public function pantheon_clean_term( \WP_Term $term ) {
        Purger::action_clean_term_cache( $term->term_id );
    }

    public function pantheon_clean_post( \WP_Post $post ) {
        Purger::action_clean_post_cache( $post->ID );
    }

    /**
     * Purge the homepage and its pagination
     *
     * @param string $root The path of home cache file.
     * @param string $lang The current lang to purge.
     *
     * @since  3.4.1
     * @author Soponar Cristina
     *
     */
    public function pantheon_clean_home() {
        pantheon_wp_clear_edge_keys( [ 'home' ] );
    }

}
GeekPress commented 4 years ago

Hi @pcfreak30 🤚

Thanks a million for your contribution!

Will it be possible to make a Pull Request? 😇

pcfreak30 commented 4 years ago

Sorry I am leaving this as is as there is more that is needed given how Pantheon works. See https://pantheon.io/docs/plugins-known-issues#wp-rocket, but ignore the no WP_CACHE.

mainly the cache and wp-rocket config need a relative symlink to the files folder, which is a sibling to the code folder as the install

on the host which would be from the root install ln -s ../files/cache wp-content/cache and ln -s ../files/wp-rocket-config wp-content/wp-rocket-config . Folders may need to be manually created 1st, and UI help for this.

Overall this should be enough info to add in support.

Thanks.

carl-alberto commented 4 years ago

Hi @pcfreak30 & @GeekPress, I'm Carl from Pantheon Support and have been investigating the conflicts happening with WP-Rocket with Pantheon. Happy to help out seeing more plugins being compatible with the Platform.

For this specific plugin, we have observed that it keeps on modifying the WP_CACHE value to true which at the moment is conflicting with Pantheon's built-in cache.

At the moment, the suggested https://docs.wp-rocket.me/article/61-disable-page-caching is not working so what we would like to suggest to as much as possible set WP_CACHE to be always false using this snippet https://gist.github.com/carl-alberto/32dfb84d2aa485430ae7a1b848767309

We would like to know what plugin features will be affected if it is disabled if it is set to false or maybe there would be a way to make it work that we haven't discovered yet so the plugin will play along nicely in the platform?

NicholasRBowers commented 4 years ago

https://pantheon.io/docs/plugins-known-issues#wp-rocket should be updated.

GeekPress commented 4 years ago

@carl-alberto We plan to work on an auto-compatibility as soon as possible 😀 Will it be possible to give us a Pantheon test account? It will be required to make our QA process. You can contact me at jonathan [at] wp-media.me

carl-alberto commented 4 years ago

Thanks for the reply @GeekPress, sent you an email to assist you in setting up a testing account

Tabrisrp commented 4 years ago

Scope a solution ✅

inc/Plugin.php

inc/main.php

inc/ThirdParty/Hostings/Pantheon.php

Add a new third party subscriber Pantheon. In this subscriber, we will:

Other considerations

Estimate the effort ✅

An [M] task considering the development & testing work needed to make sure it all works

carl-alberto commented 3 years ago

Hi @GeekPress! Where would be a good place to collaborate and track down issues raised by Pantheon customers with the WP Rocket plugin?

GeekPress commented 3 years ago

@carl-alberto Sorry for the delay.

You can report any issues related to WP Rocket on this repo :)

carl-alberto commented 3 years ago

Thanks for the reply @GeekPress , seems no critical issues popping up from Pantheon's end from the past 3 months so it seems your recent deployments are working fine :)

If there are users having issues in the platform, please refer them here https://pantheon.io/docs/plugins-known-issues#wp-rocket or if you have all the autocompatibility in the plugin in place and feel that those workarounds that we have are not needed anymore and can be removed from out documentation, feel free to ping us or open up a PR in the Pantheon docs

vmanthos commented 3 years ago

Related ticket: https://secure.helpscout.net/conversation/1559941223/276126/

DahmaniAdame commented 1 year ago

Related - https://secure.helpscout.net/conversation/1954916245/357146/

DahmaniAdame commented 1 year ago

Related as well - https://secure.helpscout.net/conversation/1870169543/340933/ (waiting for feedback)

DahmaniAdame commented 1 year ago

Related - https://secure.helpscout.net/conversation/2074575621/383322/ (advanced-cache.php got wiped up on a Pantheon commit and not re-added after that by WP Rocket)