wp-media / wp-rocket

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

Display a notice for users that are still using CPCSS #5905

Closed piotrbak closed 1 year ago

piotrbak commented 1 year ago

Before submitting an issue please check that you’ve completed the following steps:

Describe the bug For users that are still using CPCSS we'll display a message convincing them to switch to RUCSS.

It'll be WordPress notice, as shown below.

Screenshots Capture d’écran 2023-05-11 à 08 06 06

Acceptance Criteria

Backlog Grooming (for WP Media dev team use only)

Mai-Saad commented 1 year ago

Related tests

jeawhanlee commented 1 year ago

Scope a solution ✅

We will create a new method in WP_Rocket\Engine\CriticalPath\CriticalCSSSubscriber switch_to_rucss_notice which will hook to admin_notices https://github.com/wp-media/wp-rocket/blob/6a6d8d36f25cfaccfba3f999bc612ad58bd125f7/inc/Engine/CriticalPath/CriticalCSSSubscriber.php#L78

import WP_Rocket\Engine\License\API\User;

We will do the following checks:

$args = [
    'action' => 'switch_to_rucss',
    'value'=>'true',
];
add_query_arg( $args, wp_nonce_url( admin_url( 'admin-post.php' ), 'rucss_switch' ) );

In WP_Rocket\Engine\Optimization\RUCSS\Admin\Settings create a new method to activate the rucss option. Import options class use WP_Rocket\Admin\Options;

public function switch_to_rucss() {
    $options = get_option( 'wp_rocket_settings', [] );

    if ( isset( $options['minify_concatenate_css'] ) && 1 === (int) $options['minify_concatenate_css'] ) {
      $options['minify_concatenate_css'] = 0;
    }

    $options['async_css'] = 0;
    $options['remove_unused_css'] = 0;
    update_option( 'wp_rocket_settings', $options );
}

Add a new event - admin_post_switch_to_rucss to the subscriber: https://github.com/wp-media/wp-rocket/blob/6a6d8d36f25cfaccfba3f999bc612ad58bd125f7/inc/Engine/Optimization/RUCSS/Admin/Subscriber.php#LL62C1-L62C1 and add a callback: Then we use our new method to enable switch_to_rucss

public function switch_to_rucss() {
    if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( $_GET['_wpnonce'] ), 'rucss_switch' ) ) {
        wp_nonce_ays( '' );
    }

    if ( ! current_user_can( 'administrator' ) ) {
        wp_safe_redirect( wp_get_referer() );
        exit;
    }

    if ( 'true' === $_GET['value'] ) {
        $this->settings->switch_to_rucss();
        $this->delete_used_css_rows();
    }

    $this->set_notice_transient();

    rocket_dismiss_box( 'switch_to_rucss_notice' );

    wp_safe_redirect( wp_get_referer() );
    exit;
}

Add tests.

Estimate the effort ✅

[M]

pedddro commented 1 year ago

@piotrbak I wonder why CCSS is still offered considering it doesn't offer filters for trying to improve CLS and the fact the RUCSS has been polished enough to be used on page builders. Is it due to compatibility, server resources?