Automattic\WooCommerce\Internal\Admin\Logging\FileV2

SearchListTable::column_line()publicWC 1.0

Render the line column.

Method of the class: SearchListTable{}

No Hooks.

Return

String.

Usage

$SearchListTable = new SearchListTable();
$SearchListTable->column_line( $item ): string;
$item(array) (required)
The current search result being rendered.

SearchListTable::column_line() code WC 9.3.3

public function column_line( array $item ): string {
	$params = $this->page_controller->get_query_params( array( 'search' ) );
	$line   = $item['line'];

	// Highlight matches within the line.
	$pattern = preg_quote( $params['search'], '/' );
	preg_match_all( "/$pattern/i", $line, $matches, PREG_OFFSET_CAPTURE );
	if ( is_array( $matches[0] ) && count( $matches[0] ) >= 1 ) {
		$length_change = 0;

		foreach ( $matches[0] as $match ) {
			$replace        = '<span class="search-match">' . $match[0] . '</span>';
			$offset         = $match[1] + $length_change;
			$orig_length    = strlen( $match[0] );
			$replace_length = strlen( $replace );

			$line = substr_replace( $line, $replace, $offset, $orig_length );

			$length_change += $replace_length - $orig_length;
		}
	}

	return wp_kses_post( $line );
}