【问题标题】:php - Fatal Error, Class not found, when Adding Wordpress Shortcodephp - 添加 Wordpress 简码时出现致命错误,找不到类
【发布时间】:2017-08-31 09:25:33
【问题描述】:

我从教程中获取了以下代码。它旨在创建一个简码,我可以使用它向我的 Wordpress 帖子添加一个按钮,该按钮直接向创建帖子的用户发送一条消息。

我收到 php 错误 -

致命错误:在第 755 行的 /homepages/22/d688271077/htdocs/clickandbuilds/VillaShare/wp-content/themes/listable/functions.php 中找不到类“wpchats”

请看下面的functions.php代码和简码:

add_shortcode('wpc-link-to-chat', function($atts) {

    $a = shortcode_atts( array(
        'user_id' => wp_get_current_user()->ID
    ), $atts );

    $user_id = (int) "{$a['user_id']}";
    $wpchats = new wpchats;
    return $wpchats->get_settings( 'messages_page' ) . "?recipient=$user_id";    
});

简码:

[wpc-link-to-chat user_id="3"]

【问题讨论】:

  • 猜测你的类没有被声明——你的类在哪里,它包含什么?

标签: php wordpress plugins shortcode


【解决方案1】:

尝试使用:

...
$wpchats = new wpChats;
return $wpchats->get_settings( 'messages_page' ) . "?recipient=$user_id";
});

【讨论】:

    【解决方案2】:

    也许这听起来很愚蠢,但如果 wpChats 是一个类,你应该用 () 声明它

    $wpchats = new wpchats();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-08
      • 2015-03-20
      • 2016-01-01
      • 2019-10-09
      • 1970-01-01
      • 1970-01-01
      • 2022-01-02
      • 2013-09-27
      相关资源
      最近更新 更多