0, 'bytes' => 0, 'references' => array() ); foreach ( (array) ( $wp_query->posts ?? array() ) as $post ) { if ( $post instanceof \WP_Post && self::content_contains_form( $post->post_content, $state, 0 ) ) { wp_enqueue_style( 'accessible-forms' ); return; } } // Block themes resolve their selected template before calling wp_head(). // Inspect only that template, not every template or sidebar on the site. if ( is_string( $_wp_current_template_content ) && self::content_contains_form( $_wp_current_template_content, $state, 0 ) ) { wp_enqueue_style( 'accessible-forms' ); } } /** * Detect direct embeds and the reusable content WordPress resolves for them. * * @param string $content Post, pattern or template content. * @return bool Whether a form or its unavailable notice can be rendered. */ public static function contains_form( $content ) { $state = array( 'blocks' => 0, 'bytes' => 0, 'references' => array() ); return self::content_contains_form( (string) $content, $state, 0 ); } /** Inspect content without executing any shortcodes or render callbacks. */ private static function content_contains_form( $content, array &$state, $depth ) { $state['bytes'] += strlen( $content ); if ( $depth > self::MAX_DEPTH || $state['bytes'] > self::MAX_BYTES || $state['blocks'] >= self::MAX_BLOCKS ) { return false; } if ( false !== strpos( $content, '[accessible_form' ) && preg_match_all( '/' . get_shortcode_regex( array( 'accessible_form' ) ) . '/s', $content, $matches, PREG_SET_ORDER ) ) { foreach ( $matches as $match ) { if ( '[' !== $match[1] || ']' !== $match[6] ) { return true; } } } return false !== strpos( $content, '