Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php WordPress RSS源中的自定义字段-代码错误_Php_Wordpress_Rss - Fatal编程技术网

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

Php WordPress RSS源中的自定义字段-代码错误,php,wordpress,rss,Php,Wordpress,Rss,我安装了这个WordPress插件。。。 它有这个代码 /** * 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 * A

我安装了这个WordPress插件。。。 它有这个代码

/**
* 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中的自定义字段
*插件URI:http://www.webentwickler.de/wordpress/custom_fields_in_rss
*描述:通过自定义字段从任意帖子扩展RSS。
*版本:1.0
*作者:弗兰克·塞德尔
*作者URI:http://www.webentwickler.de
*许可证:GPL2
*/
类按自定义字段扩展\u RSS\u{
函数_u构造(){
添加操作('rss2_项','Extend_RSS_By_Custom_Fields::add_my_Custom_field_node');
}
函数添加\我的\自定义\字段\节点(){
全球$员额;
$custom_fields=get_post_custom();
foreach($key=>$value的自定义字段){
if(substr($key,0,1)!=“uquo”){
foreach($作为$的值){
$\u值=修剪($\u值);
如果($\u值){
echo(“{$\u value}\r\n”);
}
}
}
}
}
}
$extended_rss=新的extended_rss_By_自定义_字段;
我的问题是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>
警告
:调用用户函数数组()[
]:第一个参数应为有效回调,
中给出了“通过自定义字段扩展RSS字段::添加我的自定义字段节点”
/home/hcfcornw/public_html/home/wp includes/plugin.php
在线
470

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

钩子正在尝试调用静态方法:

add_action('rss2_item', 'Extend_RSS_By_Custom_Fields::add_my_custom_field_node');
并且该方法缺少公共静态。未经测试,但请修改以下内容:

public static function add_my_custom_field_node() {
钩子应该是:

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