ss_generation['message'], ( 'cpcss_generation_successful' === $cpcss_generation['code'] ) ); } } /** * Launches when the CPCSS generation is complete. * * @since 3.6 */ private function generation_complete() { $running = get_transient( 'rocket_critical_css_generation_process_running' ); if ( false === $running ) { return; } if ( ! isset( $running['total'], $running['items'] ) ) { return; } if ( $running['total'] > count( $running['items'] ) ) { return; } /** * Fires when the critical CSS generation process is complete. * * @since 2.11 */ do_action( 'rocket_critical_css_generation_process_complete' ); rocket_clean_domain(); set_transient( 'rocket_critical_css_generation_process_complete', get_transient( 'rocket_critical_css_generation_process_running' ), HOUR_IN_SECONDS ); delete_transient( 'rocket_critical_css_generation_process_running' ); } /** * Enqueue CPCSS heartbeat script on all admin pages. * * @since 3.6 */ public function enqueue_admin_cpcss_heartbeat_script() { if ( ! $this->is_async_css_enabled() ) { return; } wp_enqueue_script( 'wpr-heartbeat-cpcss-script', rocket_get_constant( 'WP_ROCKET_ASSETS_JS_URL' ) . 'wpr-cpcss-heartbeat.js', [], rocket_get_constant( 'WP_ROCKET_VERSION' ), true ); wp_localize_script( 'wpr-heartbeat-cpcss-script', 'rocket_cpcss_heartbeat', [ 'nonce' => wp_create_nonce( 'cpcss_heartbeat_nonce' ), ] ); } /** * Add Regenerate Critical CSS link to WP Rocket admin bar item * * @since 3.6 * * @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance, passed by reference. * * @return void */ public function add_regenerate_menu_item( $wp_admin_bar ) { if ( ! current_user_can( 'rocket_regenerate_critical_css' ) ) { return; } if ( ! is_admin() ) { return; } if ( ! $this->is_async_css_enabled() ) { return; } // This filter is documented in inc/Engine/CriticalPath/CriticalCSS.php. if ( ! apply_filters( 'do_rocket_critical_css_generation', true ) ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals return; } $referer = ''; $action = 'rocket_generate_critical_css'; if ( ! empty( $_SERVER['REQUEST_URI'] ) ) { $referer_url = filter_var( wp_unslash( $_SERVER['REQUEST_URI'] ), FILTER_SANITIZE_URL ); $referer = '&_wp_http_referer=' . rawurlencode( remove_query_arg( 'fl_builder', $referer_url ) ); } $wp_admin_bar->add_menu( [ 'parent' => 'wp-rocket', 'id' => 'regenerate-critical-path', 'title' => __( 'Regenerate Critical Path CSS', 'rocket' ), 'href' => wp_nonce_url( admin_url( "admin-post.php?action={$action}{$referer}" ), $action ), ] ); } /** * Checks if the "async_css" option is enabled. * * @since 3.6 * * @return bool true when "async_css" option is enabled. */ private function is_async_css_enabled() { return (bool) $this->options->get( 'async_css', 0 ); } } juillet, 2024 - JusteInfos- Information générale
Archives mensuelles

juillet 2024