]*)style=["\'](.*?)["\']/i', $content, $matches, PREG_SET_ORDER ); foreach ( $matches as $match ) { $tag = $match[1]; // The HTML tag (e.g., div, span). $attributes = $match[2]; // Additional attributes of the element. $styles = explode( ';', $match[3] ); // Extract class and ID from attributes. preg_match( '/class=["\'](.*?)["\']/', $attributes, $class_match ); preg_match( '/id=["\'](.*?)["\']/', $attributes, $id_match ); $class = isset( $class_match[1] ) ? '.' . str_replace( ' ', '.', $class_match[1] ) : ''; $id = isset( $id_match[1] ) ? '#' . $id_match[1] : ''; // Initialize or increment the count for this tag. if ( ! isset( $element_count[ $tag ] ) ) { $element_count[ $tag ] = 1; } else { ++$element_count[ $tag ]; } // Add a numeric postfix to distinguish duplicates. $postfix = $element_count[ $tag ]; $selector = "{$tag}{$id}{$class}:nth-of-type({$postfix})"; $rule_set = array(); foreach ( $styles as $style ) { if ( strpos( $style, ':' ) !== false ) { list( $property, $value ) = explode( ':', $style ); $rule_set[ trim( $property ) ] = trim( $value ); } } $css_rules[ $selector ] = $rule_set; } return $css_rules; } } // Hook into the 'save_post' action to generate accessibility reports on save. add_action( 'save_post', function ( $post_id ) { /** * Prevent saving during autosave or if it's a post revision. * * @param int $post_id The ID of the post being saved. */ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return; } if ( wp_is_post_revision( $post_id ) ) { return; } // Generate and save the report. AEnhancer_Reports::save_report( $post_id ); } );