Skip to content

Hooks: Actions and Filters ​

Change how Real Testimonials behaves with a little PHP: ready-to-paste snippets for the common jobs, then every public hook the plugin offers.

Real Testimonials comes with hooks. A hook is a spot in the plugin's code where WordPress lets you step in with a function of your own. There are two kinds:

  • A filter hands you a value (a piece of text, a list, a setting) right before the plugin uses it. You change it and hand it back.
  • An action is a moment, like "just before a testimonial card is drawn". You add your own output or code at that moment.

To use any snippet below, paste it into your theme's functions.php file. Use a child theme's functions.php if you can, not the parent theme's, so a theme update won't wipe out your changes. A code-snippets plugin works too.

For developers

This page assumes you're comfortable editing PHP. One typo in functions.php can take your site down, so try things on a staging site first and keep a backup.

Most output hooks belong to the classic version

Hooks that change what visitors see (texts, query arguments, card markup) run for classic Views and Testimonial Forms, the shortcode-based displays. The Gutenberg blocks draw their cards with their own templates and skip those hooks. If you're using blocks, change the text and design in the block's inspector instead. Each hook below tells you which side it affects.

Jump to a snippet:

  1. Grant Editors access to the plugin
  2. Remove Safe Web Fonts
  3. Add custom fonts
  4. Change the "No testimonials found" text
  5. Fix the WPML translation issue
  6. Change the "End of content" text
  7. Add custom social profile networks
  8. Add a missing Google Font to Typography
  9. Tune the AI summary and AI requests
  10. Switch off Build with AI from code

Or go straight to the full hook reference.

1. Grant Editors access to the plugin ​

Out of the box, only Administrators can manage the plugin. Want Editors to have access too? Hook onto sp_real_testimonial_ui_permission and return a capability Editors already have, like edit_others_posts.

Be aware that this one capability unlocks a lot. It covers the plugin dashboard and its settings, the Manage Views, Testimonial Forms and Groups screens, import and export, and who can use Build with AI in the block editor. This snippet opens all of that up to Editors.

php
// Plugin access to editors
function sp_real_testimonial_ui_permission_editor() {
	return 'edit_others_posts';
}
add_filter( 'sp_real_testimonial_ui_permission', 'sp_real_testimonial_ui_permission_editor' );

2. Remove Safe Web Fonts ​

The font picker on a classic View's Typography tab lists a group of Safe Web Fonts. Don't want some of them cluttering the list? Filter spftestimonial_field_typography_safewebfonts and take them out by name.

php
function my_rt_remove_safe_fonts( $fonts ) {
	// Remove fonts by name.
	return array_values( array_diff( $fonts, array( 'Comic Sans MS', 'Impact' ) ) );
}
add_filter( 'spftestimonial_field_typography_safewebfonts', 'my_rt_remove_safe_fonts' );

The list you get starts with inherit (use the theme's font), followed by Arial, Arial Black, Helvetica, Times New Roman, Courier New, Tahoma, Verdana, Impact, Trebuchet MS, Comic Sans MS, Lucida Console, Lucida Sans Unicode, Georgia, serif and Palatino Linotype. Don't remove inherit. Every element uses it as the default.

Affects: classic Views only.

3. Add custom fonts ​

Want your own fonts in a View's Typography tab? Filter spftestimonial_field_typography_customwebfonts and add the font names. They'll show up in a Custom Web Fonts group at the top of the picker.

php
function my_rt_custom_fonts( $fonts ) {
	$fonts[] = 'Jupiter SP';
	$fonts[] = 'Sonar Bangla';
	return $fonts;
}
add_filter( 'spftestimonial_field_typography_customwebfonts', 'my_rt_custom_fonts' );

Want the weight dropdown to list only the weights your font has? Use the font name as the key and a list of weights as the value, for example $fonts['Jupiter SP'] = array( 'normal', '700' );.

This only adds the names to the picker. The fonts themselves must already be loaded by your theme or site. If they aren't, visitors' browsers fall back to a default font.

Affects: classic Views only.

4. Change the "No testimonials found" text ​

When a View has no testimonials to show, the plugin prints "No testimonials found". To say something else, use sptpro_not_found_any_testimonial.

php
function sptpro_not_found_text() {
	return __( 'Sorry, no testimonials found', 'testimonial-pro' );
}
add_filter( 'sptpro_not_found_any_testimonial', 'sptpro_not_found_text' );

Affects: classic Views only. Blocks show their own message.

5. Fix the WPML translation issue ​

When a visitor clicks a live filter, Load More or another Ajax control on a View, the plugin fetches the next testimonials in the background. During those requests it switches off WordPress's query filters. Unfortunately, WPML relies on those filters to pick the right language, so after a click, testimonials in the wrong language can appear. Return false on spt_testimonial_pro_suppress_filters to keep the query filters on.

php
add_filter( 'spt_testimonial_pro_suppress_filters', '__return_false' );

The filter receives two arguments: the current value (true during Ajax requests, false otherwise) and the View's ID. That second one lets you limit the fix to a single View if you need to.

Affects: classic Views only.

6. Change the "End of content" text ​

When a View uses Ajax pagination, the plugin shows "End of content" once every testimonial has loaded. You can reword it with sp_testimonial_pro_pagination_end_content_text.

php
function sp_testimonial_pro_pagination_end_content_text_modified() {
	return __( 'No more testimonials', 'testimonial-pro' );
}
add_filter( 'sp_testimonial_pro_pagination_end_content_text', 'sp_testimonial_pro_pagination_end_content_text_modified' );

Its partner, sp_testimonial_pro_pagination_error_text, works the same way for the "No more testimonials to load" message.

Affects: classic Views only. The Ajax Pagination block has its own text settings.

7. Add custom social profile networks ​

The reviewer's Social Profiles list comes with 35 networks. Need one that isn't there? Filter sp_testimonial_social_profile_list and return an array of extra networks. Each entry needs a name and an icon (a Font Awesome 4 markup string). This example adds Email and Download.

php
function sp_testimonial_social_profile_list_custom() {
	$custom_icon_list = array(
		'email'    => array(
			'name' => esc_html__( 'Email', 'testimonial-pro' ),
			'icon' => '<i class="fa fa-envelope"></i>',
		),
		'download' => array(
			'name' => esc_html__( 'Download', 'testimonial-pro' ),
			'icon' => '<i class="fa fa-download"></i>',
		),
	);
	return $custom_icon_list;
}
add_filter( 'sp_testimonial_social_profile_list', 'sp_testimonial_social_profile_list_custom' );

Your entries go after the built-in ones. You'll see them in the Social Profiles dropdown on the testimonial edit screen and in a classic form's Select Social Profile(s) list.

Affects: classic Views draw your icon markup. Blocks use their own built-in icons, so a network they don't recognize shows a generic link icon there.

8. Add a missing Google Font to Typography ​

The Google Web Fonts group in a View's font picker comes from a list bundled with the plugin, so newer Google Fonts may not be in it. To add one, filter spftestimonial_field_typography_googlewebfonts. Add to the list you receive rather than replacing it, and give each font its weights and character sets:

php
function my_rt_add_google_font( $fonts ) {
	$fonts['Figtree'] = array(
		array( 'normal', '500', '600', '700' ), // Weights ('normal' is 400).
		array( 'latin', 'latin-ext' ),          // Character sets.
	);
	return $fonts;
}
add_filter( 'spftestimonial_field_typography_googlewebfonts', 'my_rt_add_google_font' );

The plugin loads Google Fonts straight from Google, so only add fonts that really exist on Google Fonts, spelled exactly as they appear there. If your theme hosts the font itself, use custom fonts instead. One more thing: a Google Font only loads when the element's Load … Font switch is on and Google Fonts is enabled under Settings → Performance.

Affects: classic Views only.

9. Tune the AI summary and AI requests ​

Three filters control how the AI Summary in the Review Summary block behaves. Most sites never need them. They're for when you're keeping an eye on cost or dealing with a slow AI provider. The timeout filter also applies to Build with AI, since both features talk to the provider the same way.

Change how long a summary is cached. Summaries are stored for 12 hours by default, so a busy page doesn't send a request for every visitor. Each provider, model and set of testimonials gets its own cached copy. If your reviews change often, shorten the time:

php
function sp_real_my_ai_cache_ttl( $ttl ) {
	return 2 * HOUR_IN_SECONDS;
}
add_filter( 'sp_real_ai_summary_ttl', 'sp_real_my_ai_cache_ttl' );

Return 0 (or anything lower) and nothing is cached. Every page load then asks the provider for a fresh summary. That gets expensive fast, so only do it while testing.

Change how many reviews are sent. A summary is built from at most 200 reviews. Lower that number to make each request cheaper:

php
function sp_real_my_ai_max_reviews( $max ) {
	return 50;
}
add_filter( 'sp_real_ai_summary_max_reviews', 'sp_real_my_ai_max_reviews' );

Change the request timeout. The plugin waits 60 seconds for a provider to answer. That applies to the AI Summary, Build with AI, and the key check when you save a key under Settings → AI Configuration. The filter also receives the endpoint being called, so you can set a different timeout per provider:

php
function sp_real_my_ai_timeout( $timeout, $url ) {
	return 30;
}
add_filter( 'sp_real_ai_request_timeout', 'sp_real_my_ai_timeout', 10, 2 );

Anything below 5 seconds is raised to 5. Think twice before going much lower than the default. Build with AI asks for a much longer answer than a summary does, and reasoning-heavy models can take a while to reply.

This timeout only covers requests the plugin sends with a key saved on the AI Configuration tab. If a provider's key comes from WordPress's own Settings → Connectors screen (WordPress 7.0 and later), the request goes through WordPress's AI client, which sets its own timeout.

10. Switch off Build with AI from code ​

Normally you turn Build with AI on and off with its card on the Modules page. Sometimes you want code to decide instead. Maybe it should stay off on a client's live site no matter what anyone clicks. For that, filter sp_real_ai_builder_enabled. It receives one argument, $enabled, and expects a boolean back. $enabled is true when the module is on and your site allows AI features (WordPress 7.0 adds a site-wide switch for that).

php
// Turn Build with AI off everywhere.
add_filter( 'sp_real_ai_builder_enabled', '__return_false' );

You can also make it conditional. This version keeps it off unless the site is running in a development or staging environment:

php
function sp_real_my_ai_builder_enabled( $enabled ) {
	return $enabled && 'production' !== wp_get_environment_type();
}
add_filter( 'sp_real_ai_builder_enabled', 'sp_real_my_ai_builder_enabled' );

Returning false removes the Build with AI button from the editor's top toolbar and the Refine with AI button from the block toolbar. The plugin also refuses any request to build a block.

This filter can only switch it off

The editor also checks the module's toggle on the Modules page. Returning true won't bring the buttons back while the module itself is off. To get them back, turn the module on.

No longer needed: loading styles in the header ​

Earlier versions documented sp_testimonial_style_load_in_header for moving the plugin's CSS into the page <head>. The plugin still runs that filter, but its value doesn't change anything anymore. The plugin now remembers which Views each page uses and loads their styles in the <head> by itself. (On the very first visit to a page, before it knows, the styles load alongside the View instead.) If you have that snippet, you can delete it.

Hook reference ​

Every hook below is public, so you can rely on it. You may spot other hooks in the code: ones starting with spftestimonial_ (apart from the font filters above) and a few license-check hooks. Those belong to the plugin's internal options framework and licensing. They aren't listed here because they can change without notice.

In each table, the Receives column lists the arguments your function gets, with the default value in brackets. A filter must always return its first argument, whether you changed it or not.

Access and AI ​

These work for both blocks and classic Views.

HookTypeReceivesWhat it controls
sp_real_testimonial_ui_permissionfilter$capability ('manage_options')Who can manage the plugin. See snippet 1.
sp_real_ai_builder_enabledfilter$enabledWhether Build with AI is available. See snippet 10.
sp_real_ai_summary_ttlfilter$ttl (43200, 12 hours in seconds)How long an AI summary is cached.
sp_real_ai_summary_max_reviewsfilter$max (200)How many reviews feed one AI summary.
sp_real_ai_request_timeoutfilter$timeout (60), $urlSeconds to wait for an AI provider. Minimum 5.

Testimonials and groups ​

These change how WordPress registers the plugin's content types, so they reach everywhere, blocks and classic alike.

HookTypeReceivesWhat it controls
sp_testimonial_post_type_argsfilter$argsThe register_post_type() arguments for testimonials (post type spt_testimonial).
sp_testimonial_post_type_labelsfilter$labelsThe admin labels for testimonials, such as All Testimonials or Set reviewer image. (If you only want to rename "Testimonial", use Settings → Classic Settings instead.)
sp_testimonial_cat_argsfilter$argsThe register_taxonomy() arguments for Groups (taxonomy testimonial_cat).
sp_testimonial_social_profile_listfilter$networks (empty array)Extra social networks. See snippet 7.
sp_tpro_text_field_allowed_htmlfilter$allowed_html (span with class/style, em, strong)The HTML allowed in a testimonial's Designation and Company Name fields.

Classic Views: which testimonials show ​

HookTypeReceivesWhat it controls
spt_testimonial_pro_query_all_post_argfilter$args, $view_idThe first query a View runs, which collects every matching testimonial ID (used for filters, counts and pagination).
spt_testimonial_pro_query_argsfilter$args, $view_idThe WP_Query arguments for the testimonials a View actually displays, right before the query runs.
spt_testimonial_pro_suppress_filtersfilter$suppress (false, true during Ajax requests), $view_idWhether the View's query skips WordPress query filters. See snippet 5.
sp_testimonial_cache_timefilter$secondsHow long a View's cached data is kept when Cache is on under Settings → Performance. The plugin hooks this itself to apply the Cache Time setting, and a callback you add later wins.

Here's an example. It limits the View with ID 123 to testimonials published in the last 12 months:

php
function my_rt_recent_only( $args, $view_id ) {
	if ( 123 === (int) $view_id ) {
		$args['date_query'] = array(
			array( 'after' => '12 months ago' ),
		);
	}
	return $args;
}
add_filter( 'spt_testimonial_pro_query_all_post_arg', 'my_rt_recent_only', 10, 2 );

To narrow the set, filter the first query (query_all_post_arg). The display query can only show IDs the first one found.

Classic Views: texts and labels ​

HookTypeReceivesWhat it controls
sptpro_not_found_any_testimonialfilter$text ('No testimonials found')The message when a View has nothing to show.
sp_testimonial_pro_pagination_end_content_textfilter$text ('End of content')Shown when Ajax pagination has loaded everything.
sp_testimonial_pro_pagination_error_textfilter$text ('No more testimonials to load')Shown when there's nothing more to load.
sp_testimonial_search_placeholder_textfilter$text ('Search Testimonial')The placeholder inside the Ajax Testimonial Search box.
testimonial_filter_sort_by_labelfilter$text ('Sort By')The label beside the star-rating dropdown in Ajax Live Filters.
testimonial_average_rating_textfilter$text ('Average Rating')The heading of the Average Rating section.
tpro_aggregate_ratingfilter$ratingThe number in "4.8 out of 5 stars".
tpro_total_testimonial_reviewfilter$countThe number in "Based on 12 Reviews".
testimonial_total_rating_textfilter$text ('Based on 12 Reviews')That whole "Based on … Reviews" line.

Classic Views: card content and markup ​

HookTypeReceivesWhat it controls
sp_testimonial_review_contentfilter$text, $testimonial_idThe testimonial text on a card (after trimming) and in the Read More popup.
sp_testimonial_read_more_linkfilter$html, $testimonial_idThe Read More link markup. Empty when the text wasn't trimmed.
testimonial_client_rating_full_star_iconfilter$html, $testimonial_idThe markup for one filled star.
testimonial_client_rating_empty_star_iconfilter$html, $testimonial_idThe markup for one empty star.
sp_testimonial_group_filter_sortfilter$groups, $view_idThe groups shown as filter buttons on an Isotope View or in Ajax Live Filters. Keyed by group name and sorted A to Z; each item has id, name and slug. Reorder or remove items here.
sp_testimonial_modify_filter_ratingsfilter$ratingsThe star-rating filter options, keyed five_star to one_star. Each value is the label or star markup.
sptestimonialpro_schema_typefilter$type ('Product')The schema.org type of the item being reviewed, in a View's schema markup.
sp_testimonial_pro_preloader_imagefilter$urlThe spinner image shown while a View with Preloader on is loading.
tpro_shortcodesfilter$tags (array( 'sp_single_testimonial' ))Shortcode tags that make the plugin load its stylesheet when it finds them in a page's content.

Classic Views: actions around each card ​

These actions fire while a View draws each testimonial. None of them pass arguments, but inside your function get_the_ID() returns the current testimonial's ID.

HookFires
sptpro_before_testimonial / sptpro_after_testimonialBefore and after each whole testimonial card.
sptpro_before_testimonial_title / sptpro_after_testimonial_titleAround the testimonial title.
sptpro_before_testimonial_content / sptpro_after_testimonial_contentAround the testimonial text.
sptpro_before_testimonial_client_image / sptpro_after_testimonial_client_imageAround the reviewer image.
sptpro_before_testimonial_client_name / sptpro_after_testimonial_client_nameAround the reviewer's full name.
sptpro_before_testimonial_client_designation_company / sptpro_after_testimonial_client_designation_companyAround the designation and company name.
sptpro_before_testimonial_client_location / sptpro_after_testimonial_client_locationAround the location.
sptpro_before_testimonial_client_phone / sptpro_after_testimonial_client_phoneAround the phone number.
sptpro_before_testimonial_email / sptpro_after_testimonial_emailAround the email address.
sptpro_before_testimonial_client_website / sptpro_after_testimonial_client_websiteAround the website.
sptpro_before_testimonial_date / sptpro_after_testimonial_dateAround the date.
sptpro_before_testimonial_client_rating / sptpro_after_testimonial_client_ratingAround the star rating.
sptpro_before_testimonial_social_profiles / sptpro_after_testimonial_social_profilesAround the social profile icons.
sptp_testimonial_before_testimonial_extra_fields / sptp_testimonial_after_testimonial_extra_fieldsInside the Additional Custom Fields area, before and after the fields.

An element's actions only fire when that element is switched on in the View's Display Settings. Here's one that adds a small "Verified" note after every reviewer name:

php
function my_rt_verified_note() {
	echo '<span class="my-verified-note">' . esc_html__( 'Verified customer', 'my-theme' ) . '</span>';
}
add_action( 'sptpro_after_testimonial_client_name', 'my_rt_verified_note' );

Single testimonial page ​

These affect the page a testimonial gets when Single Testimonial Template is on under Settings → Advanced Controls, and the [sp_single_testimonial] shortcode.

HookTypeReceivesWhat it controls
sp_tpro_single_template_pathfilter$pathThe template file used for a single testimonial page. Return the path to your own file to take over the layout.
tpro_single_testimonial_thumbnailfilter$html, $testimonial_idThe reviewer image markup.
sptp_show_client_addition_infofilter$show (true)Whether Additional Custom Fields show. Return false to hide them.

Classic Testimonial Forms ​

HookTypeReceivesWhat it controls
testimonial_pro_email_preview_template_tagsfilter$messageA notification email's body, after the template tags have been filled in. Use it to replace tags of your own.
tpro_upper_record_textfilter$text ('Record Review')The heading of the video recorder window.
tpro_no_camera_textfilter$text ('No camera available')Shown when the visitor has no camera.
tpro_start_recording_btn_textfilter$text ('Start Recording')The start button.
tpro_stop_recording_btn_textfilter$text ('Stop Recording')The stop button.
tpro_add_video_btn_textfilter$text ('Add this video')The button that attaches the recording to the form.
tpro_video_duration_textfilter$text ('Maximum recording duration')The text before the time limit.
tpro_video_duration_unitfilter$unit ('minute' or 'minutes')The unit after the time limit.

These hooks don't touch the Submission Form or Record Video blocks. Those set their texts and emails in their own inspector.

License notice and import ​

HookTypeReceivesWhat it controls
testimonial_pro_user_role_permissionfilter$capability ('manage_options')Who sees the "activate the license key" notice that replaces a View's output while the license isn't active. Everyone else sees nothing there.
testimonial_pro_shortcode_importedaction$view_idFires once for every View created by an import, with the new View's ID. Handy for adjusting imported Views.