使用bp-custom.php在BuddyPress(Wordpress)的额外选项卡中显示配置文件字段


Display profile fields in an extra tab in BuddyPress (Wordpress) using bp-custom.php

我在用户的个人资料页面上创建了一个额外的选项卡,我想在其中显示个人资料字段。

这就是我首先创建额外选项卡的方式,我创建了一个新的 bp-custom.php里面有这个

function profile_new_nav_item() {
    global $bp;
    bp_core_new_nav_item(
        array(
            'name'                => 'About',
            'slug'                => 'about',
          'default_subnav_slug' => 'extra_sub_tab', // We add this submenu item below
            'screen_function'     => 'view_manage_tab_main'
        )
    );
}
add_action( 'bp_setup_nav', 'profile_new_nav_item', 10 );
function view_manage_tab_main() {
    add_action( 'bp_template_content', 'bp_template_content_main_function' );
    bp_core_load_template( 'template_content' );
}
function bp_template_content_main_function() {
    if ( ! is_user_logged_in() ) {
        wp_login_form( array( 'echo' => true ) );
    }
}
function profile_new_subnav_item() {
    global $bp;
    bp_core_new_subnav_item( array(
        'name'            => 'Extra Sub Tab',
        'slug'            => 'extra_sub_tab',
        'parent_url'      => $bp->loggedin_user->domain . $bp->bp_nav[ 'about' ][ 'slug' ] . '/',
        'parent_slug'     => $bp->bp_nav[ 'about' ][ 'slug' ],
        'position'        => 10,
        'screen_function' => 'view_manage_sub_tab_main'
    ) );
}
add_action( 'bp_setup_nav', 'profile_new_subnav_item', 10 );
function view_manage_sub_tab_main() {
    add_action( 'bp_template_content', 'bp_template_content_sub_function' );
    bp_core_load_template( 'template_content' );
}
function bp_template_content_sub_function() {
    if ( is_user_logged_in() ) {
        echo 'you are here';
    } else {
        wp_login_form( array( 'echo' => true ) );
    }
}

看看它在最后一个函数中说echo 'you are here';的地方,我想在那里显示配置文件字段。我有下面的代码,但我不知道如何将它嵌入在那里。

如果我echo bp_the_profile_field(),我收到以下错误

致命错误:在 null 上调用成员函数 the_profile_field((

下面的代码在另一个页面上完美运行,它获取所有可用字段。

<div class="bp-widget <?php bp_the_profile_group_slug(); ?>">
<h4><?php bp_the_profile_group_name(); ?></h4>
<table class="profile-fields">
    <?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?>
        <?php if ( bp_field_has_data() ) : ?>
            <tr<?php bp_field_css_class(); ?>>
                <td class="label"><?php bp_the_profile_field_name(); ?></td>
                <td class="data"><?php bp_the_profile_field_value(); ?></td>
            </tr>
        <?php endif; ?>
        <?php
        do_action( 'bp_profile_field_item' ); ?>
    <?php endwhile; ?>
</table></div>

替换这个:

echo 'you are here';

有了这个:

bp_get_template_part( 'members/single/profile/profile-loop' );