Custom Fields in WordPress RSS Feed – Code Error

I installed this WordPress plugin… http://wordpress.org/support/plugin/custom-fields-rss
which has this code…

/**
* Plugin Name: Custom Fields In RSS
* Plugin URI: http://www.webentwickler.de/wordpress/custom_fields_in_rss
* Description: Extends RSS by custom fields from an arbitrary post.
* Version: 1.0
* Author: Frank Seidel
* Author URI: http://www.webentwickler.de
* License: GPL2
*/

class Extend_RSS_By_Custom_Fields {
    function __construct() {
        add_action('rss2_item', 'Extend_RSS_By_Custom_Fields::add_my_custom_field_node');
    }

    function add_my_custom_field_node() {
    global $post;
    $custom_fields = get_post_custom();

        foreach($custom_fields AS $key => $value) {
            if(substr($key, 0, 1) != "_") {
                foreach($value AS $_value) {
                    $_value = trim($_value);
                    if($_value) {
                        echo("<$key>{$_value}</$key>rn");
                    }
                }
            }
        }
    }
}

$extended_rss = new Extend_RSS_By_Custom_Fields;

My issue is that the output in the RSS feed is this…

Read More
<b>Warning</b>
: call_user_func_array() [
<a href="function.call-user-func-array">function.call-user-func-array</a>
]: First argument is expected to be a valid callback,
'Extend_RSS_By_Custom_Fields::add_my_custom_field_node' was given in
<b>
/home/hcfcornw/public_html/home/wp-includes/plugin.php
</b>
on line
<b>470</b>

I have provided the entire code of the plugin and I trust I have provided enough of the output to show the issue.

Related posts

Leave a Reply

1 comment

  1. The hook is trying to call a static method:

    add_action('rss2_item', 'Extend_RSS_By_Custom_Fields::add_my_custom_field_node');
    

    And the method is missing public static. Untested, but modify this:

    public static function add_my_custom_field_node() {
    

    And the hook should be:

    add_action( 'rss2_item', array( self, 'add_my_custom_field_node' ) );