22-63ms across five runs. * * How: a buffer pass over the final HTML finds top-level section * containers by class, leaves the first N alone (the above-fold * estimate), and stamps the rest with a `data-xspeed-cv` attribute. One * inline '; $head_end = stripos( $html, '' ); return substr_replace( $html, $style, (int) $head_end, 0 ); } /** @return string[] */ private function section_classes(): array { $classes = $this->get_setting( 'section_classes', self::DEFAULT_CLASSES ); $classes = is_array( $classes ) ? array_values( array_filter( array_map( 'strval', $classes ) ) ) : self::DEFAULT_CLASSES; /** * Filter the class names identifying a top-level page section. * * @param string[] $classes */ $classes = (array) apply_filters( 'xspeed_render_skip_classes', $classes ); // Class names end up inside a regex alternation; anything that is // not a plausible CSS class token is dropped rather than escaped // into something surprising. return array_values( array_filter( array_map( 'strval', $classes ), static fn( string $c ): bool => (bool) preg_match( '/^[A-Za-z0-9_-]+$/', $c ) ) ); } private static function mask( string $html ): string { return (string) preg_replace_callback( '#' . self::MASKED_SPANS . '#is', static fn( array $m ): string => str_repeat( "\0", strlen( $m[0] ) ), $html ); } public function cli_commands(): array { return array( array( 'name' => 'xspeed render-skip status', 'callback' => array( $this, 'cli_status' ), 'shortdesc' => 'Show below-fold render-skip status.', 'ai_hint' => 'Is content-visibility stamping of below-fold sections on, and with what above-fold allowance? Use when diagnosing TBT / main-thread style & layout cost on long builder pages.', 'synopsis' => array(), ), ); } /** * `wp xspeed render-skip status`. * * @param array $args Positional args (unused). * @param array $assoc Associative args (unused). */ public function cli_status( array $args, array $assoc ): void { unset( $args, $assoc ); $enabled = (bool) $this->get_setting( 'enabled', false ); \WP_CLI::log( 'Render skip: ' . ( $enabled ? 'enabled' : 'disabled' ) ); \WP_CLI::log( 'Above-fold skip: first ' . (int) $this->get_setting( 'skip_first', self::DEFAULT_SKIP_FIRST ) . ' sections' ); \WP_CLI::log( 'Section classes: ' . implode( ', ', $this->section_classes() ) ); } }