假设我有一堆设置部分。我用以下方式将这些部分添加到我的插件页面。
$sections = array(\'notifcations\', \'updates\');
foreach ($sections as $section)
{
add_settings_section(
$section .\'_section\',
$section,
array( $this, \'disable_callback_warnings\' ),
\'sgnc\'
);
}
一切如期进行,但我想知道如何本地化该部分的标题?据我所知,我无法将任何变量传递给语言环境函数
_e()
和
__()
. 所以这行不通:
$sections = array(\'notifcations\', \'updates\');
foreach ($sections as $section)
{
add_settings_section(
$section .\'_section\',
__($section),
array( $this, \'disable_callback_warnings\' ),
\'sgnc\'
);
}
http://codex.wordpress.org/Function_Reference/add_settings_section
最合适的回答,由SO网友:fuxia 整理而成
本地化初始数组中的标题:
$sections = array(
\'notifcations\' => __( \'Notifications\', \'your_text_domain\' ),
\'updates\' => __( \'Updates\', \'your_text_domain\' )
);
foreach ($sections as $section => $header )
{
add_settings_section(
$section .\'_section\',
$header,
array( $this, \'disable_callback_warnings\' ),
\'sgnc\'
);
}