It is possible to restrict the importing of posts depending on their author when using Feed to Post.
This is done by hooking into wprss_insert_post_item_conditionals and checking the author for the feed item.
The below code demonstrates this by restricting importing to items that have the author “Jean Galea”.
add_filter( 'wprss_insert_post_item_conditionals', 'author_conditional', 10 , 3 );
function author_conditional( $item, $source, $permalink ) {
$wanted_author = "Jean Galea";
// Get the author, and proceed only if the author is present
if ( $author = $item->get_author() ) {
$name = trim( $author->get_name() );
// If no author, don't import. Return NULL
if ( $name === NULL || !is_string( $name ) || $name === '' ) {
return NULL;
}
// Check if author is the author we want
if ( strcasecmp( $name, $wanted_author ) === 0 ) {
return $item;
} else return NULL;
}
// If no author specified, do not import. Return NULL
return NULL;
}
How do I add this to my site?
Follow the step-by-step instructions below to add this filter to your WordPress site.
- Copy the code you need from above.
- Go to your WordPress site’s dashboard.
- Go to Plugins > Add New.
- Search for Code Snippets, then install and activate the plugin.
- Once installed and activated, go to Snippets in your dashboard menu.
- Click on Add New.
- Add a Title, which could be the title of this article.
- Paste the code you copied in step 1 to the Code section.
- Add a Description or Tags if you wish to do so. It is not required.
- Click on Save Changes and Activate to save the filter and activate it.
- Or click on Save Changes to save the filter and activate it later.
- Your action or filter is now stored and active on your site.