wpfts_irule/ (Filter)

The wpfts_irule/<ident> filter in WP Fast Total Search is a powerful tool for modifying post data before indexing. It’s used in conjunction with Indexing Rules and allows you to apply various transformations to post field values extracted according to these rules. <ident> in the filter name is the identifier of a specific filter, which must match the identifier specified in the indexing rule.

When Used

This filter is applied when you need to perform specific transformations on post data before indexing. Examples of use:

  • Data cleaning: removing HTML tags, special characters, extra spaces.
  • Data transformation: changing date format, converting to lowercase, highlighting keywords.
  • Combining data from multiple fields.
  • Extracting data from serialized arrays or objects.

Arguments

  • $s (string|array): The post field value to be processed. It can be a string or an array, depending on the data type.
  • $opts (array): An array of options passed to the filter. The set of options depends on the specific filter (identifier <ident>).
  • $post (object WP_Post): The WordPress post object. Allows access to any post data.
  • &$chunks (array): A reference to the array of data prepared for indexing. Important: This parameter is passed by reference, so any changes made to the $chunks array inside the filter handler will be saved.
  • $r (array): An array of parameters of the indexing rule in which this filter is used. Can be used to access other rule parameters.

Return Value

  • $s (string|array): The modified post field value.

Example

Suppose you have an indexing rule that extracts the value of the my_custom_field meta field. You want to remove all HTML tags from this value before indexing. You can create the wpfts_irule/strip_tags filter and use it in the rule:

// Filter to remove HTML tags.
add_filter('wpfts_irule/strip_tags', 'my_strip_tags_filter', 10, 5);
function my_strip_tags_filter($s, $opts, $post, &$chunks, $r) {
  return wp_strip_all_tags($s);
}
 
// Inside the indexing rule
'actions' => array(
		array(
			'src' => '.my_custom_field',
			'dest' => 'my_custom_field',
			'filters' => array(
				array('ident' => 'strip_tags')
			),
		)
	),

Built-in wpfts_irule/<ident> Filters

The following filters are already implemented in the plugin code:

  • wpfts_irule/content_open_shortcodes: Processes shortcodes in the content before indexing. Arguments: $s, $opts, $post, &$chunks, $rule. Returns: Processed content.
  • wpfts_irule/content_is_remove_nodes: Removes certain HTML nodes (e.g., <script> and <style>) from the content. Arguments: $s, $opts, $post, &$chunks, $rule. Returns: Cleaned content.
  • wpfts_irule/content_strip_tags: Removes all HTML tags from the content. Arguments: $s, $opts, $post, &$chunks, $rule. Returns: Text without HTML tags.

Important Notes

  • The wpfts_irule/<ident> filter is called only in the context of indexing rules.
  • The filter identifier <ident> must be unique within the plugin.
  • You can create your own filters with any identifiers and use them in your indexing rules.

The wpfts_irule/<ident> filter provides developers with a powerful and flexible mechanism for preprocessing data before indexing in WP Fast Total Search.