【问题标题】:Custom Fields in WordPress RSS Feed - Code ErrorWordPress RSS 源中的自定义字段 - 代码错误
【发布时间】:2014-05-29 02:34:30
【问题描述】:

我安装了这个 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>

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

【问题讨论】:

    标签: php wordpress rss


    【解决方案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' ) );
    

    【讨论】:

      猜你喜欢
      • 2011-11-09
      • 1970-01-01
      • 1970-01-01
      • 2012-12-13
      • 1970-01-01
      • 1970-01-01
      • 2014-12-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多