有一个过滤器:bp_xprofile_get_visibility_levels
. 它用于过滤可见性级别数组,初始化如下:
$this->visibility_levels = array(
\'public\' => array(
\'id\' => \'public\',
\'label\' => _x( \'Everyone\', \'Visibility level setting\', \'buddypress\' )
),
\'adminsonly\' => array(
\'id\' => \'adminsonly\',
\'label\' => _x( \'Only Me\', \'Visibility level setting\', \'buddypress\' )
),
\'loggedin\' => array(
\'id\' => \'loggedin\',
\'label\' => _x( \'All Members\', \'Visibility level setting\', \'buddypress\' )
)
);
if ( bp_is_active( \'friends\' ) ) {
$this->visibility_levels[\'friends\'] = array(
\'id\' => \'friends\',
\'label\' => _x( \'My Friends\', \'Visibility level setting\', \'buddypress\' )
);
}
(上述代码位于
bp-xprofile/bp-xprofile-loader.php
)
因此,在你的情况下,你会想:
add_filter(
\'bp_xprofile_get_visibility_levels\',
function($levels)
{
// remove "My Friends"
if(isset($levels[\'friends\'])) unset($levels[\'friends\']);
// remove "All Members"
if(isset($levels[\'loggedin\'])) unset($levels[\'loggedin\']);
// change "Everyone" to "Public"
if(isset($levels[\'public\']))
$levels[\'public\'][\'label\']=_x(\'Public\',\'Visibility level setting\',\'buddypress\');
// change "Only Me" to "Private"
if(isset($levels[\'adminsonly\']))
$levels[\'adminsonly\'][\'label\']=_x(\'Private\',\'Visibility level setting\',\'buddypress\');
return $levels;
}
);
请记住,它是一个过滤器,其他人可能已经在您之前钩住了它,因此请始终检查给定的数组元素
isset()
.
作为旁注,这里有一些翻译方面的考虑,但我想详细阐述这一点超出了范围。