How do I write add-ons for FeedWordPress

Contents

[ hide ]

    How do I write add-ons for FeedWordPress? How do I write custom filters for keyword searches, rewriting syndicated post content, filtering incoming posts by categories, tags, or other meta-data, etc.?

    A. FeedWordPress add-ons and filters allow for extensive and precise control over how feeds, syndicated posts, and related data are brought in and handled by FeedWordPress. They are written as PHP modules, which follow the common format for WordPress plugins and which take advantage of event hooks specially provided by FeedWordPress. To get started on creating an add-on module, try following these steps and then modify the resulting code to meet your needs.

    1. Create a new text file with the .php extension and add the WordPress plugin headers. For example, let’s create an add-on that adds information about the source of an article to syndicated articles, if the articles were written by someone other than a defined author. To begin, we’ll create a file named fwp-add-source-content.php, with the following headers:

        <?php
        /*
        Plugin Name: FWP+: Add source to other people's content
        Plugin URI: http://feedwordpress.radgeek.com/wiki/fwp-add-source-content
        Description: includes 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
        */
      
    2. Add FeedWordPress filter and action hooks. Use the WordPress Plugin API functions (mainly filters and events that FeedWordPress defines. For example, here we use add_filter to set up a filter function on the syndicated_item_content hook:

        <?php
        /*
        Plugin Name: FWP+: Add source to other people's content
        Plugin URI: http://feedwordpress.radgeek.com/wiki/fwp-add-source-content
        Description: includes 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
        */
      

      add_filter( /*hook=*/ 'syndicated_item_content', /*function=*/ 'fwp_add_source_to_content', /*order=*/ 10, /*arguments=*/ 2 );

      function fwp_add_source_to_content ($content, $post) {

      // ... do filtering here using FeedWordPress API, WordPress API, // and standard PHP functions.

      // Send it back return $content; } /* fwp_add_source_to_content() */
    3. Fill in the code for the filter function using the methods provided by FeedWordPress, WordPress, and the PHP standard libraries.

        <?php
        /*
        Plugin Name: FWP+: Add source to other people's content
        Plugin URI: http://feedwordpress.radgeek.com/wiki/fwp-add-source-content
        Description: includes 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() */
    4. Save your module and upload it to the WordPress plugin directory at wp-content/plugins.

    5. Log in to the WordPress admin interface and activate the add-on using the standard WordPress plugins page. Once your new filter is activated, it will begin processing new syndicated posts as they come in.

    For a fuller discussion and reference for FeedWordPress filter hooks, see Add-ons and Filters.

    This page is a Wiki! Log in or register an account to edit.

    Leave a Reply

    Your email address will not be published. Required fields are marked *