Hey tdmohr,
the ct_before_render_testimonial
action fires immediately when the render()
function runs to display a testimonial.
What method are you using to display the testimonial(s) on which the event is not firing?
If you aren’t using a shortcode, and instead are using a custom loop or something, then it won’t fire natively.
If you are using a custom loop, say with query_posts or get_posts and displaying them in succession, do $testimonial = new WP_Testimonial( $the_post_id ); $testimonial->render();
If you are using a shortcode, then let me know and we can eliminate that at least.
Feel free to paste me a link to a gist which contains the code that isn’t working (or any sort of link), and I can take a look. Normally I wouldn’t ask this, but you seem to be more on the developer side of things than most users.
Thread Starter
tdmohr
(@tdmohr)
Hi,
I am using the widget and I’ve also tried the shortcode. The testimonials render in the same default way using both methods.
I think there must be something wrong with my filter implementation. Does this look correct to you?
function render_my_testimonial ( $testimonial, $context ) {
return '<p>' . $testimonial->post_title . '</p>';
}
add_filter( 'ct_before_render_testimonial', 'render_my_testimonial', 10, 2);
The function is located half way through the functions.php file but I’ve tried moving it around with no change. I’ve put an exit(); tag within the function and the site continues loading so I believe the function render_my_testimonial is never called.
The website is currently located on my internal staging servers but if you don’t have any ideas I can upload to an external staging environment which might give you a better idea of what is going on.
Cheers,
Tim
Hi Tim,
ct_before_render_testimonial
is an action, not a filter. The filter I think you’re after is ct_pre_render_testimonial
.
Try this
function render_my_testimonial ( $testimonial, $context ) {
return '<p>' . $testimonial->post_title . '</p>';
}
add_filter( 'ct_pre_render_testimonial', 'render_my_testimonial', 10, 2);
If render_my_testimonial
returns anything at all, Clean Testimonials will just display that instead of using the default output. It is designed to override the output completely.
Let me know how that goes.
Thread Starter
tdmohr
(@tdmohr)
Hi Luke,
Thanks for the reply.
Adding the correct filter started interupting the rendering of the plugin but I still didn’t see the testimonial title I was expecting. After a big of extra debugging I found the var $testimonial was blank and $context actually contained the testimonial object. I’m not sure why its not coming through the first parameter… perhaps you can shed some light on this…?
So my working code to achieve a testimonial post title is:
function render_my_testimonial($testimonial, $context) {
return '<p>' . $context->post_title . '</p>';
}
add_filter( 'ct_pre_render_testimonial', 'render_my_testimonial', 10, 2);
I should be good to go from here.
Just FYI… The code I started working from was copied from your reply in the thread that I originally posted my question in…
Perhaps you should correct it so that others do not get confused, now that it has been tested.
Thanks for your help though, its good to not have to hack the plugin to get the output I need.
Cheers,
Tim
Hey Tim,
That appears to be a bug. Can you please confirm that you are using the widget so we can test and fix?
Thread Starter
tdmohr
(@tdmohr)
Hi Luke,
Sorry for the delay.
The problem exists with the widget and shortcodes.
Thanks,
TIm
Hi Tim,
Have identified a bug which will be fixed in version 1.6 very shortly. Thank you for bringing this to my attention.
Have milestoned this fix for version 1.6 which will be released shortly. Look out for the update!
Hey Tim,
Finally had a chance to look at this. The fix was simple, the code I supplied you wasn’t 100%. The below will work.
function render_my_testimonial( $default, $testimonial, $context ) {
return '<p>' . $testimonial->post_title . '</p>';
}
add_filter( 'ct_pre_render_testimonial', 'render_my_testimonial', 10, 3 );
Forgot about the first parameter which is passed down the filter chain. The testimonial object is the second parameter, with context being the third.