如果“total_of_groups”不为 0,我想将以下选项添加到现有的选择框中。
<option value="groupmembers" <?php echo selected('groupmembers',bp_profile_visibility_get_settings($user_id,'bp_profile_visibility' ));?>><?php _e('Group Members Only','bp-profile-visibility');?></option>
不幸的是,它不起作用。我已经在选择之外测试了代码片段,它运行良好。
<select name="bp_profile_visibility">
<option value="public" <?php echo selected('public',bp_profile_visibility_get_settings($user_id,'bp_profile_visibility' ));?>><?php _e('Everyone','bp-profile-visibility');?></option>
<option value="friends" <?php echo selected('friends',bp_profile_visibility_get_settings($user_id,'bp_profile_visibility' ));?>><?php _e('Friends Only','bp-profile-visibility');?></option>
// the new option //
<?php
$is_groupmember = BP_Groups_Member::get_group_ids( bp_displayed_user_id() );
$total_of_groups = $is_groupmember[total];
if( $total_of_groups != 0 )
echo <option value="groupmembers" <?php echo selected('groupmembers',bp_profile_visibility_get_settings($user_id,'bp_profile_visibility' ));?>><?php _e('Group Members Only','bp-profile-visibility');?></option>
?>
<option value="self" <?php echo selected('self',bp_profile_visibility_get_settings($user_id,'bp_profile_visibility' ));?>><?php _e('Only Me (private)','bp-profile-visibility');?></option>
</select>