Well, I sort of got things working by adding a new filter which I called “widget-twitter-filter-tweets” to keep it in the same naming convention as the ones native to TWP.
Bear in mind that this is for version 2.5.3 and the line numbers could well be different in other versions.
Also remember that since this is modifying the plugin code, the modifications will be lost when you upgrade or reinstall TWP.
In the file wp-twitter-widget.php:
On line 264 I added:
add_filter( 'widget-twitter-filter-tweets', array( $this, 'filter_tweets' ) );
(this was after add_action( 'widgets_init', array( $this, 'register' ), 11 );
and before add_filter( 'widget_twitter_content', array( $this, 'linkTwitterUsers' ) );
)
On line 863 I added:
$tweets = apply_filters( 'widget-twitter-filter-tweets', $tweets);
(this was after $tweets = $this->_getTweets( $args );
and before if ( false === $tweets )
then in my functions.php I can write a bit of code to remove the required tweets from the displayed feed like so:
function mysite_filter_tweets($tweets) {
$filteredTweets = array();
foreach ($tweets as $tweet) {
/* Decide which tweets to keep/get rid of here.
* e.g. to exclude all tweets beginning with "RT ":
*/
$excludeThis = 'RT';
$result = substr_count($tweet->text, $excludeThis, 0, strlen($excludeThis));
if ($result == 0) {
$filteredTweets[] = $tweet;
}
}
return $filteredTweets;
}
add_filter('widget-twitter-filter-tweets', 'mysite_filter_tweets');
The “RT” stuff is just an example since TWP already provides an option to remove retweets, but hopefully it gives you the idea.
This works, however let’s say you’ve got TWP set to display 5 tweets, and this filter removes 2 of them – you will only see 3 tweets displayed, because the filtering is being doing after the tweets are retrieved from Twitter. I don’t know of a way to get Twitter to then retrieve an additional 2 tweets and add them onto the end of the array, to make up the difference for the filtered out tweets.
Hopefully this will help somebody anyway.