So I have a moderately successful plugin that appends or prepends an enhanced author biography to the content of a page/post/custom post type.
It does this by hooking to either the_content or the_excerpt and appending/prepending content according to the plugin's configuration.
I've started getting support queries where the author biography is appearing in the sidebar of a site via a widget, for example via the Category Posts widget. The widget is using the_excerpt() within a custom query Loop, to pull posts according to a configured category and show the post excerpt within the context of the sidebar.
As a direct effect of this, my plugin's the_excerpt filter hook is being called. What I'd like to do is be able to detect whether my filter hook is being invoked within the context of the sidebar or a widget and conditionally decide whether to append my plugin's content to the post content passed to the filter hook. The pseudo-code would look something like this ...
add_filter ('the_excerpt', array ($this, 'insert_biography_box'));
function insert_biography_box ($content) {
if (in_sidebar ()) {
return $content;
}
// do code stuff to append/prepend biography content
return $content;
}
... but after a lot of searching through the WordPress core source, on these forums and on the WordPress Answers Stack Exchange forum it doesn't look like a function along the lines of is_sidebar or is_widget (or some other variation on the name) exists.
Is it even possible to determine whether a filter hook function is being called within the context of the sidebar or within a widget?
-Gary