2

BuddyPress には、いくつかのプロファイル フィールドを非表示にするのに役立つメソッドがあることを知っています。

function bp_has_profile( $args = '' ) {
    global $profile_template;

    // Only show empty fields if we're on the Dashboard, or we're on a user's profile edit page,
    // or this is a registration page
    $hide_empty_fields_default = ( !is_network_admin() && !is_admin() && !bp_is_user_profile_edit() && !bp_is_register_page() );

    // We only need to fetch visibility levels when viewing your own profile
    if ( bp_is_my_profile() || bp_current_user_can( 'bp_moderate' ) || bp_is_register_page() ) {
        $fetch_visibility_level_default = true;
    } else {
        $fetch_visibility_level_default = false;
    }

    $defaults = array(
        'user_id'             => bp_displayed_user_id(),
        'profile_group_id'    => false,
        'hide_empty_groups'   => true,
        'hide_empty_fields'   => $hide_empty_fields_default,
        'fetch_fields'        => true,
        'fetch_field_data'    => true,
        'fetch_visibility_level' => $fetch_visibility_level_default,
        'exclude_groups'      => false, // Comma-separated list of profile field group IDs to exclude
        'exclude_fields'      => false  // Comma-separated list of profile field IDs to exclude
    );

    $r = wp_parse_args( $args, $defaults );
    extract( $r, EXTR_SKIP );

    $profile_template = new BP_XProfile_Data_Template( $user_id, $profile_group_id, $hide_empty_groups, $fetch_fields, $fetch_field_data, $exclude_groups, $exclude_fields, $hide_empty_fields, $fetch_visibility_level );
    return apply_filters( 'bp_has_profile', $profile_template->has_groups(), $profile_template );
}

このメソッドを呼び出して 'exclude_fields' => $IDs_to_hide を渡す方法がわかりません

4

4 に答える 4

0

テーマ関数でこれを行う方法があるかどうかはわかりませんが、編集ループで簡単に非表示にすることができます. /buddypress/members/single/profile/edit.php をテーマにコピーし、次の行を追加します。

<?php if ( 'Field Name' == bp_get_the_profile_field_name() ) continue; ?>

この行のすぐ下:

<?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?>

これは Chirag のアプローチに似ていますが、ラッパー div を含むフィールドに関連するすべてのものをスキップするため、不要な HTML はありません。

于 2013-07-08T17:09:08.520 に答える
0

はい、プロフィールページから一部のフィールドを非表示にすることができます。

最初に、テーマ フォルダーの edit.php に移動します。テキスト ボックスを非表示にする場合は、ここで名前を「フル ネーム」にします。

<?php if ( 'textbox' == bp_get_the_profile_field_type() ) : ?>
    <?php if ( 'Full Name' != bp_the_profile_field_name() ) : ?>
         <label for="<?php bp_the_profile_field_input_name(); ?>"><?php bp_the_profile_field_name(); ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( '(required)', 'buddypress' ); ?><?php endif; ?></label>
         <input type="text" name="<?php bp_the_profile_field_input_name(); ?>" id="<?php bp_the_profile_field_input_name(); ?>" value="<?php bp_the_profile_field_edit_value(); ?>" <?php if ( bp_get_the_profile_field_is_required() ) : ?>aria-required="true"<?php endif; ?>/>
      <?php endif; ?>
<?php endif; ?>

上記のコードは profile.php ファイルと同じですが、他の Radiobutton や Selectbox などに条件を配置するのと同じ if 条件のみを新規に配置します。

フルネーム プロフィール フィールドはプロフィールに表示されません。

于 2012-11-27T05:56:46.023 に答える