Skip to content

Actions and filters

Search: 12 hooks.

Every hook here has a description in the source.

3 actions9 filters

action

davo_register_search_sources

Register searchable content sources.

Fired once per request, on 'init'. Use $registry->register() to make a domain's content searchable.

Parameters of davo_register_search_sources
ParameterTypeDescription
$registrySearch_RegistryShared searchable-source registry.
add_action
add_action( 'davo_register_search_sources', 'my_action_callback', 10, 1 );

/**
 * @param Search_Registry $registry
 */
function my_action_callback( $registry ) {
	// Your code here.
}

src/domains/search/initializer.php:353

filter

davo_search_anonymous_avatar_url

Filters the avatar URL shown for an anonymous author in search results. Defaults to a generic person icon.

Parameters of davo_search_anonymous_avatar_url
ParameterTypeDescription
$urlstringAvatar image URL.

Returns string

add_filter
add_filter( 'davo_search_anonymous_avatar_url', 'my_filter_callback', 10, 1 );

/**
 * @param string $url
 */
function my_filter_callback( $url ) {
	// Change $url as needed, then return it.
	return $url;
}

src/domains/search/helpers.php:348

filter

davo_search_document_language

Filters the language a document is written in.

A resolver can set lang_code itself. Otherwise the active multilingual plugin is asked for the language of the post or term behind the document. An empty value marks it as not tied to a language.

Parameters of davo_search_document_language
ParameterTypeDescription
$codestringLanguage code, or empty.
$object_typestringRegistered source key.
$object_idintPost, term or user ID, matching the source's binding.
$sourcearray<string, mixed>The registered source.
add_filter
add_filter( 'davo_search_document_language', 'my_filter_callback', 10, 4 );

/**
 * @param string $code
 * @param string $object_type
 * @param int $object_id
 * @param array<string, mixed> $source
 */
function my_filter_callback( $code, $object_type, $object_id, $source ) {
	// Change $code as needed, then return it.
	return $code;
}

src/domains/search/repository.php:152

filter

davo_search_fallback_language

Filters the language untranslated documents are shown in.

Parameters of davo_search_fallback_language
ParameterTypeDescription
$codestringLanguage code. Empty for no fallback.
add_filter
add_filter( 'davo_search_fallback_language', 'my_filter_callback', 10, 1 );

/**
 * @param string $code
 */
function my_filter_callback( $code ) {
	// Change $code as needed, then return it.
	return $code;
}

src/domains/search/repository.php:118

filter

davo_search_language

Filters the language search results are restricted to.

Documents written in another language are left out; documents with no language (users, questions, anything a multilingual plugin does not translate) are always kept.

Parameters of davo_search_language
ParameterTypeDescription
$codestringLanguage code. Empty for no restriction.
add_filter
add_filter( 'davo_search_language', 'my_filter_callback', 10, 1 );

/**
 * @param string $code
 */
function my_filter_callback( $code ) {
	// Change $code as needed, then return it.
	return $code;
}

src/domains/search/repository.php:101

action

davo_search_performed

Fires after a full search ran for its first page.

Not fired for suggestions as the visitor types, for later pages, or for an invalid query.

Parameters of davo_search_performed
ParameterTypeDescription
$querystringTrimmed search text.
$totalintNumber of results found.
$argsarray<string, mixed>Search arguments as passed in.
add_action
add_action( 'davo_search_performed', 'my_action_callback', 10, 3 );

/**
 * @param string $query
 * @param int $total
 * @param array<string, mixed> $args
 */
function my_action_callback( $query, $total, $args ) {
	// Your code here.
}

src/domains/search/repository.php:716

filter

davo_search_redirect_native

Allow domain archives to retain their own search and filter context.

Parameters of davo_search_redirect_native
ParameterTypeDescription
$redirectboolWhether to redirect to global search.
add_filter
add_filter( 'davo_search_redirect_native', 'my_filter_callback', 10, 1 );

/**
 * @param bool $redirect
 */
function my_filter_callback( $redirect ) {
	// Change $redirect as needed, then return it.
	return $redirect;
}

src/domains/search/initializer.php:481

filter

davo_search_results_noindex

Filters whether a search results view is sent with a noindex directive.

Parameters of davo_search_results_noindex
ParameterTypeDescription
$noindexboolDefault true.
$querystringSearch query.
$pageintResults page.
$has_filtersboolWhether any filter is applied.
add_filter
add_filter( 'davo_search_results_noindex', 'my_filter_callback', 10, 4 );

/**
 * @param bool $noindex
 * @param string $query
 * @param int $page
 * @param bool $has_filters
 */
function my_filter_callback( $noindex, $query, $page, $has_filters ) {
	// Change $noindex as needed, then return it.
	return $noindex;
}

src/domains/search/helpers.php:195

filter

davo_search_scope_object_types

Registers the source keys a surface scope searches.

The default comes from each source's registered scopes. Unknown scopes remain empty. The result is intersected with the visible sources, so a scope can narrow a request but never widen it.

Parameters of davo_search_scope_object_types
ParameterTypeDescription
$object_typesarray<int, string>Source keys for the scope.
$scopestringSurface scope key.
add_filter
add_filter( 'davo_search_scope_object_types', 'my_filter_callback', 10, 2 );

/**
 * @param array<int, string> $object_types
 * @param string $scope
 */
function my_filter_callback( $object_types, $scope ) {
	// Change $object_types as needed, then return it.
	return $object_types;
}

src/domains/search/repository.php:1456, and 1 more place

filter

davo_search_scope_result

Filters one result row for a scoped request (suggest / recent).

Return null to omit the result, e.g. when the viewer may not open it.

Parameters of davo_search_scope_result
ParameterTypeDescription
$resultarray<string, mixed>|nullResponse row.
$scopestringSurface scope key.
$documentarray<string, mixed>Source document the row was built from.
add_filter
add_filter( 'davo_search_scope_result', 'my_filter_callback', 10, 3 );

/**
 * @param array<string, mixed>|null $result
 * @param string $scope
 * @param array<string, mixed> $document
 */
function my_filter_callback( $result, $scope, $document ) {
	// Change $result as needed, then return it.
	return $result;
}

src/domains/search/repository.php:1485

action

davo_search_source_registered

Fires after a search source is successfully registered.

Parameters of davo_search_source_registered
ParameterTypeDescription
$object_typestringNormalized object_type key.
$sourcearray<string, mixed>Normalized source definition.
add_action
add_action( 'davo_search_source_registered', 'my_action_callback', 10, 2 );

/**
 * @param string $object_type
 * @param array<string, mixed> $source
 */
function my_action_callback( $object_type, $source ) {
	// Your code here.
}

src/domains/search/search-registry.php:266

filter

davo_search_suggest_per_type

Filters how many suggestions each source contributes to the dropdown.

Parameters of davo_search_suggest_per_type
ParameterTypeDescription
$per_typeintMax results per source.
$scopestringSurface scope key ('' when unscoped).
add_filter
add_filter( 'davo_search_suggest_per_type', 'my_filter_callback', 10, 2 );

/**
 * @param int $per_type
 * @param string $scope
 */
function my_filter_callback( $per_type, $scope ) {
	// Change $per_type as needed, then return it.
	return $per_type;
}

src/domains/search/repository.php:1358

Note. Generated from the plugin source. Descriptions and parameters are the ones written in the code. The starter code uses the parameter names from those comments, or generic names where there are none, so check them against your use.

See it on your own site.

Davo is a WordPress theme and plugin by Exorex.

  • Runs on your own WordPress
  • Guided setup wizard
  • AI is off until you switch it on
  • Read the licence on the marketplace first