-
Notifications
You must be signed in to change notification settings - Fork 6
Actions & Filters
- jarvis/themes
- jarvis/theme/{{theme-name}}
- jarvis/theme_default
- jarvis/instants
- jarvis/suggestions
- jarvis/suggestions/recent/query
- jarvis/recent/posts
- jarvis/include_post_types
- jarvis/exclude_post_stati
- jarvis/exclude_post_ids
- jarvis/results
- jarvis/model
- jarvis/model/{{model-name}}
Filter the list of themes to add custom themes or remove themes
add_filter( 'jarvis/themes', function( $themes ) {
$themes['my-brand'] = 'My Brand'; // add a custom theme
unset( $themes['solarized-light'] ); // remove a theme
return $themes;
} );
Provide a css uri for a theme
add_filter( 'jarvis/theme/my-brand', function( $uri ) {
return 'https://example.com/jarvis-theme-my-brand.css';
} );
Set the default theme for a user when they haven't made their own selection in the user profile page
add_filter( 'jarvis/theme_default', function( $default ) {
return 'my-brand';
} );
filter the list of instant classes that provide instant suggestions through their get
method
@see https://github.com/WDGDC/Jarvis/wiki/Extending-Jarvis
add_filter( 'jarvis/instants', function( $instants ) {
array_push( $instants, 'MyInstantsClass' );
return $instants;
} );
modify any of the prepopulated suggestions from instants
add_filter( 'jarvis/suggestions, function( $suggestions ) {
// this contrived example doesn't want any posts returned
$suggestions = array_filter( $suggestions, function( $suggestion ) {
return $suggestion->kind !== 'post';
} );
return $suggestions;
} );
Modify the WP_Query arguments for the recent posts instant
add_filter( 'jarvis/suggestions/recent/query', function( $args ) {
// this example makes it the 10 most recent edited by anyone, and not the current author
unset( $args['author'] );
return $args;
} );
modify the models of the recent posts after they have been queried and modeled
add_filter( 'jarvis/recent/posts', function( $models ) {
// this example changes the icons for recent posts to the clock dashicon
foreach( $models as &$model ) {
$model->iconType = 'dashicon';
$model->icon = 'dashicons-clock';
}
return $models;
} );
Modify the post types that are searched as part of the search query, by default this includes post_types that are registered with 'show_ui' => true
.
add_filter( 'jarvis/include_post_types', function( $post_types ) {
// this example excludes pages from being searched
$post_types = array_diff( $post_types, [ 'pages' ] );
return $post_types;
} );
Exclude any custom post_status that you do not want jarvis to search. Default is to exclude revision, auto-draft, and trash
add_filter( 'jarvis/exclude_post_stati', function( $stati ) {
array_push( $stati, 'my-custom-post-status' );
return $stati;
} );
Exclude any post ids you want excluded from searching
add_filter( 'jarvis/exclude_post_ids', function( $ids ) {
// this example excludes any posts by an author id
$exclude = get_posts( [
'author' => 1,
'fields' => $ids
] );
return array_merge( $ids, $exclude );
} )
This filter allows modification of search results
add_filter( 'jarvis/results', function( $results, $query ) {
// this contrived example removes posts from the results
if ( 'do_not_search_posts' === $query ) {
$results = array_filter( $results, function( $result ) {
return $result->kind !== 'post';
} );
}
return $results;
}, 10, 2 );
This action allows you to hook into any model that extends the base \Jarvis\Models\Model. Model is passed by reference.
add_action( 'jarvis/model', function( $model ) {
if ( preg_match( '/Top Secret/i', $model->title ) ) {
$model->title = '*********';
}
} );
This action allows you to hook into a specific model type.
add_action( 'jarvis/model/user', function( $model ) {
array_push( $model->attributes, get_user_meta( $model->id, 'my_custom_attribute', true ) );
} );