【问题标题】:Wordpress body_class issues, call some warningsWordpress body_class 问题,调用一些警告
【发布时间】:2021-09-14 21:13:13
【问题描述】:

打开wordpress调试模式后,发现有一些问题:

Warning: call_user_func_array() expects parameter 1 to be a valid callback, function '' not found or invalid function name in /home/kafijass/public_html/wp-includes/class-wp-hook.php on line 294

Warning: array_unique() expects parameter 1 to be array, null given in /home/kafijass/public_html/wp-includes/post-template.php on line 838

Warning: implode(): Invalid arguments passed in /home/kafijass/public_html/wp-includes/post-template.php on line 595
class="">

我在浏览器中打开页面源代码,发现警告来自 body_class。我从我的 html 正文标记中删除了 body_class 函数,警告消失了。为什么wordpress会这么乱?而且每次更新后都不要开始说 woocomerce 愚蠢的结构和错误......

【问题讨论】:

    标签: php wordpress class warnings


    【解决方案1】:

    这里有三个错误。由于我没有堆栈跟踪,因此很难准确找出问题的根源,但有很多事情是个别警告告诉我们的。

    1. Warning: call_user_func_array() expects parameter 1 to be a valid callback, function '' not found or invalid function name in /home/kafijass/public_html/wp-includes/class-wp-hook.php on line 294

    这通常发生在您使用任何钩子、过滤器或操作并且您将函数传递给它但未定义时。例如。

    add_action('wp_loaded', 'a_function_which_should_handle_it');
    function not_the_correct_function() {
    ...
    }
    

    如您所见,函数名称与a_function_which_should_handle_it 不匹配,或者它可能根本不存在。发生此类错误时就是这种情况。

    2.Warning: array_unique() expects parameter 1 to be array, null given in /home/kafijass/public_html/wp-includes/post-template.php on line 838

    当您在帖子模板上使用 wordpress 函数并且它接受数组时,通常会发生这种情况,但您没有提供数组,或者可能发生了一些边缘情况,其中值的类型与函数预期的不符。这需要开发人员查看才能修复。

    1. Warning: implode(): Invalid arguments passed in /home/kafijass/public_html/wp-includes/post-template.php on line 595 class="">

    PHP 中的 implode 函数用于“将数组的元素与字符串连接起来”。 implode() 函数从数组的元素中返回一个字符串。

    这再次意味着该函数需要一个数组,而您没有将数组传递给它。

    确保它的一个好方法是始终检查它。

    if (is_array($variable)) {
     // Then do something.
    }
    

    希望这些线索能帮助你找到错误的根源。

    【讨论】:

    • 谢谢。错误1突然出现,我没有添加,删除或编辑代码
    • 最近是否开启了调试模式?
    • 页面工作正常。客户给我发了一个截图,页面不工作(标准文本,那个 wordpress 有严重的问题......)在切换调试模式后 wc-cart-functions 出现了一些问题(更新后)。我下载了最新的 woocommerce 并替换该文件和页面开始工作,但有 thous 警告
    • 是的,这解释了很多。所以根据我的理解,你从一开始就遇到了问题,因为这些是Warnings 而不是Errors。请参阅差异here。现在,如果您打开调试模式,您会看到这些警告消失了,但是一旦您打开它,它们就会回来。要解决此问题,请先停用插件并以这种方式检查,您将能够查明负责它的插件,然后可以尝试通过支持或 stackoverflow 帮助修复它。 @aidron
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-17
    • 1970-01-01
    • 2016-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多