wpfts_irules_call/ (Action)
The wpfts_irules_call/<call>
hook in WP Fast Total Search provides a powerful mechanism for extending indexing functionality by adding custom data processing logic before data is added to the index. <call>
in the hook name is an identifier (string) that defines a specific call within the indexing rules. This hook is called within the getPostChunks()
method of the WPFTS_Core
class when applying indexing rules.
When to Use
- When standard WPFTS filters are insufficient for data processing.
- For performing complex data processing logic before indexing.
- For integration with other plugins or services.
- For adding data to the index from non-standard sources.
Arguments
$chunks
(array): An array of data prepared for indexing. This array can be modified within the handler function.$post
(object): AWP_Post
object representing the post being indexed.$props
(array): An array of properties defined in the indexing rule for this call. This allows passing additional parameters to the handler function.$rule
(array): An array containing all the data of the indexing rule.
Return Value
$chunks
(array): The modified array of data for indexing. The handler function must return the$chunks
array.
Example
/**
* Adds the last modified date of the post to the index.
*/
add_filter('wpfts_irules_call/get_last_modified_date', 'my_get_last_modified_date_handler', 10, 4);
function my_get_last_modified_date_handler($chunks, $post, $props, $rule) {
$chunks['last_modified'] = $post->post_modified;
return $chunks;
}
// Example indexing rule using this call:
$my_rule = array(
'filter' => array( 'post_type' => 'post' ),
// The rule applies only to posts.
'actions' => array(
array(
'call' => 'get_last_modified_date',
),
// ... other actions ...
),
// ... other rule parameters ...
);
add_filter('wpfts_irules_before', 'add_my_rule');
function add_my_rule($rules) {
global $my_rule;
$rules[] = $my_rule;
return $rules;
}
Important Notes
- The identifier must be unique to avoid conflicts with other extensions.
- Properties passed in
$props
must be defined in the indexing rule. - This hook provides great flexibility but requires understanding of WPFTS indexing rules.
The wpfts_irules_call/<call>
hook allows developers to extend WPFTS indexing functionality and add their own data processing logic.