admin notice after clearing used_css table. * * @since 3.9 * * @return void */ public function clear_usedcss_result() { if ( ! current_user_can( 'rocket_remove_unused_css' ) ) { return; } if ( ! $this->settings->is_enabled() ) { return; } $response = get_transient( 'rocket_clear_usedcss_response' ); if ( ! $response ) { return; } delete_transient( 'rocket_clear_usedcss_response' ); rocket_notice_html( $response ); } /** * Add Clean used CSS link to WP Rocket admin bar item * * @since 3.9 * * @param \WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance, passed by reference. * * @return void */ public function add_clean_used_css_menu_item( $wp_admin_bar ) { $this->settings->add_clean_used_css_menu_item( $wp_admin_bar ); } /** * Set optimize css delivery value * * @since 3.10 * * @param array $field_args Array of field to be added to settings page. * * @return array */ public function set_optimize_css_delivery_value( $field_args ): array { return $this->settings->set_optimize_css_delivery_value( $field_args ); } /** * Set optimize css delivery method value * * @since 3.10 * * @param array $field_args Array of field to be added to settings page. * * @return array */ public function set_optimize_css_delivery_method_value( $field_args ): array { return $this->settings->set_optimize_css_delivery_method_value( $field_args ); } /** * Displays the RUCSS currently processing notice * * @since 3.11 * * @return void */ public function display_processing_notice() { $this->settings->display_processing_notice(); } /** * Displays the RUCSS success notice * * @since 3.11 * * @return void */ public function display_success_notice() { $this->settings->display_success_notice(); } /** * Display a notification on wrong license. * * @return void */ public function display_wrong_license_notice() { $transient = get_option( 'wp_rocket_no_licence' ); if ( ! $transient ) { return; } $this->settings->display_wrong_license_notice(); } /** * Display error notice when connection to SAAS fails * * @return void */ public function display_saas_error_notice() { $this->settings->display_saas_error_notice(); } /** * Display admin notice when detecting any missed Action scheduler tables. * * @since 3.11.0.3 * * @return void */ public function display_as_missed_tables_notice() { $screen = get_current_screen(); if ( isset( $screen->id ) && 'tools_page_action-scheduler' === $screen->id ) { return; } if ( $this->is_valid_as_tables() ) { return; } $this->settings->display_as_missed_tables_notice(); } /** * Adds the notice end time to WP Rocket localize script data * * @since 3.11 * * @param array $data Localize script data. * @return array */ public function add_localize_script_data( $data ): array { return $this->settings->add_localize_script_data( $data ); } /** * Clear UsedCSS for the current URL. * * @return void */ public function clear_url_usedcss() { check_admin_referer( 'rocket_clear_usedcss_url' ); if ( ! current_user_can( 'rocket_remove_unused_css' ) ) { wp_nonce_ays( '' ); } $url = wp_get_referer(); if ( 0 !== strpos( $url, 'http' ) ) { $parse_url = get_rocket_parse_url( untrailingslashit( home_url() ) ); $url = $parse_url['scheme'] . '://' . $parse_url['host'] . $url; } $this->used_css->clear_url_usedcss( $url ); wp_safe_redirect( esc_url_raw( wp_get_referer() ) ); rocket_get_constant( 'WP_ROCKET_IS_TESTING', false ) ? wp_die() : exit; } /** * Add clear UsedCSS adminbar item. * * @param WP_Admin_Bar $wp_admin_bar Adminbar object. * * @return void */ public function add_clear_usedcss_bar_item( WP_Admin_Bar $wp_admin_bar ) { $this->used_css->add_clear_usedcss_bar_item( $wp_admin_bar ); } /** * Disables combine CSS if RUCSS is enabled when updating to 3.11 * * @since 3.11 * * @param string $new_version New plugin version. * @param string $old_version Previous plugin version. * * @return void */ public function set_option_on_update( $new_version, $old_version ) { $this->settings->set_option_on_update( $old_version ); if ( version_compare( $old_version, '3.11', '>=' ) ) { return; } $this->database->truncate_used_css_table(); rocket_clean_domain(); $this->set_notice_transient(); } /** * Updates safelist items for new SaaS compatibility * * @since 3.11.0.2 * * @param string $new_version New plugin version. * @param string $old_version Previous plugin version. * * @return void */ public function update_safelist_items( $new_version, $old_version ) { $this->settings->update_safelist_items( $old_version ); } /** * Cancel pending jobs actions in Action Scheduler on update to 3.11.3 * * @since 3.11.3 * * @param string $new_version New plugin version. * @param string $old_version Previous plugin version. * * @return void */ public function cancel_pending_jobs_as( $new_version, $old_version ) { if ( version_compare( $old_version, '3.11.3', '>=' ) ) { return; } try { $this->queue->cancel_pending_jobs_cron(); } catch ( \InvalidArgumentException $e ) { // nothing to do. return; } } /** * Sets the processing transient if RUCSS is enabled * * @since 3.11 * * @param mixed $old_value Option old value. * @param mixed $value Option new value. * * @return void */ public function maybe_set_processing_transient( $old_value, $value ) { if ( ! isset( $old_value['remove_unused_css'], $value['remove_unused_css'] ) ) { return; } if ( 0 === (int) $value['remove_unused_css'] ) { return; } if ( $old_value['remove_unused_css'] === $value['remove_unused_css'] ) { return; } $this->set_notice_transient(); } /** * Sets the transient for the processing notice * * @since 3.11 * * @return void */ private function set_notice_transient() { set_transient( 'rocket_rucss_processing', time() + 90, 1.5 * MINUTE_IN_SECONDS ); rocket_renew_box( 'rucss_success_notice' ); } /** * Sends a request to run cron when switching to RUCSS completed notice * * @since 3.11 * * @return void */ public function spawn_cron() { if ( rocket_get_constant( 'DISABLE_WP_CRON', false ) ) { return;// Bailout and don't fire the CRON. } check_ajax_referer( 'rocket-ajax', 'nonce' ); if ( ! current_user_can( 'rocket_manage_options' ) ) { wp_send_json_error(); return; } spawn_cron(); wp_send_json_success(); } /** * Cancel queues and crons for RUCSS. * * @return void */ public function cancel_queues() { // Will unhook check for dispatching an async request without RUCSS process running. \ActionScheduler_QueueRunner::instance()->unhook_dispatch_async_request(); // Will unhook check for dispatching an async request when RUCSS process is already running. RUCSSQueueRunner::instance()->unhook_dispatch_async_request(); $this->queue->cancel_pending_jobs_cron(); if ( ! wp_next_scheduled( 'rocket_rucss_clean_rows_time_event' ) ) { return; } wp_clear_scheduled_hook( 'rocket_rucss_clean_rows_time_event' ); } /** * Delete the transient for Action scheduler once admin visits the AS tools page. * * @return void */ public function delete_as_tables_transient_on_tools_page() { delete_transient( 'rocket_rucss_as_tables_count' ); } /** * Deletes the used CSS on update to 3.11.4 for new storage method * * @since 3.11.4 * * @param string $new_version New plugin version. * @param string $old_version Previous plugin version. * * @return void */ public function delete_used_css( $new_version, $old_version ) { if ( version_compare( $old_version, '3.11.4', '>=' ) ) { return; } $this->database->truncate_used_css_table(); } /** * Disable RUCSS on wrong license. * * @return bool */ public function disable_russ_on_wrong_license() { if ( false !== (bool) get_option( 'wp_rocket_no_licence' ) ) { return false; } return null; } /** * Remove the resources table & version stored in options table on update to 3.12 * * @since 3.12 * * @param string $new_version New plugin version. * @param string $old_version Previous plugin version. * * @return void */ public function drop_resources_table( $new_version, $old_version ) { if ( version_compare( $old_version, '3.12', '>=' ) ) { return; } $this->database->drop_resources_table(); } /** * Displays a notice if the used CSS folder is not writable * * @since 3.11.4 * * @return void */ public function notice_write_permissions() { $this->used_css->notice_write_permissions(); } /** * Display a notice on table missing. * * @return void */ public function display_no_table_notice() { $this->settings->display_no_table_notice(); } /** * Maybe delete transient. * * @param mixed $old_value Option old value. * @param mixed $value Option new value. * * @return void */ public function maybe_delete_transient( $old_value, $value ) { if ( ! isset( $old_value['remove_unused_css'], $value['remove_unused_css'] ) ) { return; } if ( 1 === (int) $value['remove_unused_css'] ) { return; } if ( $old_value['remove_unused_css'] === $value['remove_unused_css'] ) { return; } delete_transient( 'wp_rocket_no_licence' ); } /** * Checks if the RUCSS deletion is enabled. * * @return bool */ protected function is_deletion_enabled(): bool { /** * Filters the enable RUCSS deletion value * * @param bool $delete_rucss True to enable deletion, false otherwise. */ return (bool) apply_filters( 'rocket_rucss_deletion_enabled', true ); } }