The syndicated_item_content
hook allows you to write filters which alter or act on the content of posts that are syndicated by FeedWordPress. The hook passes two parameters to any registered filter functions:
$content
, a string containing the content of the item (as taken from the syndication feed), and$post
, an object of class SyndicatedPost representing the syndicated item as a whole.
The return value for the filter function should be a string containing the filtered content to be imported into the WordPress database. The original content should be returned unchanged if the filter will not modify the content of the post.
Usage
<?php
add_filter('syndicated_item_content', $callback, $order, /*arguments=*/ 2);
// $callback should be the name of a callable function with two parameters, such as 'fwp_syndicated_item_content_filter'
// $order should be an integer value; a lower value means that the filter will be executed sooner; a higher value means later
function fwp_syndicated_item_content_filter ($content, $post) {
/* ... */
return $content;
}
Sample
This example filter will add information about the source of an article to the content of articles syndicated from that source, if the articles were authored by someone other a defined author.
<?php
/*
Plugin Name: FWP+: Add source to other people's content
Plugin URI: http://feedwordpress.radgeek.com/wiki/fwp-add-source-content
Description: alters the content of incoming syndicated posts to include the name of the syndication source, when the author is not "radgeek"
Version: 2010.0208
Author: Charles Johnson
Author URI: http://radgeek.com/
License: GPL
- /
// Change the value to look for different author names.
define('FWPASTOPC_AUTHOR_NAME', 'radgeek');
add_filter(
/*hook=*/ 'syndicated_item_content',
/*function=*/ 'fwp_add_source_to_content',
/*order=*/ 10,
/*arguments=*/ 2
);
/**
* fwp_add_source_to_content: Gets the content of the syndication source and
* includes it in the content of all syndicated posts
* that are not by the defined author (presumably, you).
*
* @param string $content The current content of the syndicated item.
* @param SyndicatedPost $post An object representing the syndicated post.
* The syndicated item data is contained in $post->item
* The syndication feed channel data is contained in $post->feed
* The subscription data is contained in $post->link
* @return string The new content to give the syndicated item.
*/
function fwp_add_source_to_content ($content, $post) {
// Use SyndicatedPost::author() to get author
// data in a convenient array
$author = $post->author();
// Authored by someone else
if (!preg_match('/^'.FWPASTOPC_AUTHOR_NAME.'$/', $author[1])) :
// Use SyndicatedLink::homepage() and
// SyndicatedLink::name() to get source
// data. Append to $content.
$content .= '<p>This is a syndicated
post, which originally appeared at <a
href="'.$post->link->homepage().'">'.
$post->link->name().'</a>.
Reprinted with permission.</p>';
endif;
// Send it back
return $content;
} /* fwp_add_source_to_content() */
Enrique Castro asks:
It’s possible create?
regexp filter
style=<span color="">
or<type text>
Please help me in this question.
(Sorry for my english)
I don’t understand … Where i should write the function? in syndicatedpost.class.php, below
function content () {
$ content = NULL;
if (isset ($ this-> item [‘atom_content’])): ….
Pingback: Let the Birds Sing (Feed WordPress Filter) | Bionic Teaching
How to filter duplicate post
Hi
I when using this function , next
Plugin not working
Why ?
Help me
Recently work but now not work