WordPress RSS Feed中的自定义字段 - 代码错误

时间:2014-05-29 02:34:31

标签: php wordpress rss

我安装了这个WordPress插件...... http://wordpress.org/support/plugin/custom-fields-rss 有这个代码......

/**
* 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>\r\n");
                    }
                }
            }
        }
    }
}

$extended_rss = new Extend_RSS_By_Custom_Fields;

我的问题是RSS源中的输出是这个......

<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>

我提供了插件的完整代码,我相信我提供了足够的输出来显示问题。

1 个答案:

答案 0 :(得分:1)

钩子试图调用静态方法:

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

该方法缺少public static。未经测试,但修改此:

public static function add_my_custom_field_node() {

钩子应该是:

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