首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >返回要在我的自定义仪表板短代码中显示的用户成员资格。

返回要在我的自定义仪表板短代码中显示的用户成员资格。
EN

Stack Overflow用户
提问于 2020-04-21 07:43:22
回答 1查看 142关注 0票数 0

这是我第一次尝试添加一个短代码。我想在我的自定义仪表板中显示用户成员资格。因此,在构建Woocommerce成员区域(/wp-content/plugins/woocommerce-memberships/includes/frontend/class-wc-memberships-members-area.php),的PHP中,我发现:

代码语言:javascript
复制
/**
     * Returns the user membership to display in members area.
     *
     * @since 1.7.4
     *
     * @return false|\WC_Memberships_User_Membership current user membership object
     */
    public function get_members_area_user_membership() {
        return wc_memberships_get_user_membership( get_current_user_id(), $this->get_members_area_membership_plan_id() );
    }

使用这个想法,我尝试创建my_function,将其添加到my_shortcode中,并将片段粘贴到模板的function.php上:

代码语言:javascript
复制
    // function that runs when shortcode is called
function my_function() { 

// Things that you want to do. 
public function get_members_area_user_membership() {
        return wc_memberships_get_user_membership( get_current_user_id(), $this->get_members_area_membership_plan_id() );
    }

// register shortcode
add_shortcode('my_shortcode', 'my_function'); 

当然,作为所有良好的第一次尝试,它是行不通的。

有人能帮我弄清楚怎么回事吗?

错误:解析错误:第1340行/home4/waksli0agozc/public_html/wp-content/themes/twentyseventeen/functions.php中的语法错误,意外的'public‘(T_PUBLIC)

提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2020-04-21 08:07:09

在另一个函数中有一个函数,错误是显式的,在public之前删除function ;)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61338352

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档