网络容器仅用于在多站点网络管理中添加带有选项的页面。 字段数据存储为站点元数据。
由于网络容器扩展了主题选项容器,请参阅主题选项容器文档以获取更多信息。
示例容器
use Carbon_Fields\Container;
use Carbon_Fields\Field;
Container::make( 'network', 'crb_network_container', 'Network Settings' )
->add_fields( array(
Field::make( 'text', 'crb_title' ) ,
Field::make( 'checkbox', 'crb_disable_feature' )
)
);
访问字段值
要从网络选项容器中检索字段值,您需要使用函数,其中:carbon_get_network_option( $site_id, $name, $container_id )
参数 | 描述 |
---|---|
$site_id |
当前网络的站点 ID(例如:SITE_ID_CURRENT_SITE ) |
$name |
要检索的字段的字段名称模式。 |
$container_id |
包含字段的容器 ID。在上面的示例中,.crb_network_container |
<h1>This is my title: <?php echo carbon_get_network_option( SITE_ID_CURRENT_SITE, 'crb_title', 'carbon_fields_container_crb_network_container' ); ?></p>
保存后调用钩子,允许你在保存后钩子附加功能。carbon_fields_network_container_saved