call_user_func_array()期望参数1是有效的回调,第二个数组成员是无效的方法

时间:2018-04-12 20:46:18

标签: php wordpress

我在WordPress中创建自己的主题,尝试链接外部样式表。

我的代码是:

call_user_func_array( $the_['function'], array_slice( $args, 0, (int)$the_['accepted_args'] ) );

但它返回错误:

  

call_user_func_array()期望参数1是有效的回调,   

中的第二个数组成员不是有效的方法

我不知道出了什么问题。

2 个答案:

答案 0 :(得分:0)

包含外部样式表的正确方法如下:

function enqueue_custom_styles() {

    /*Enqueue The Styles*/
    wp_enqueue_style( 'themename', get_template_directory_uri() . '/css/custom.css' );

}

add_action( 'wp_enqueue_scripts', 'enqueue_custom_styles' );

答案 1 :(得分:0)

该错误意味着$the_['function']是一个数组,因此PHP试图将$the_['function'][0]解释为对象,将$the_['function'][1]解释为该对象的方法,以及该名称在该对象上不存在。来自manual回调:

  

实例化对象的方法作为数组传递,该数组包含索引为0的对象和索引为1的方法名称。

因此,您需要检查$the_['function']的内容,以确定其中的确切内容以及您应该如何调用call_user_func_array()