进入高级插件开发阶段,我一直在关注Plugin Handbook 但我没有看到它提到如何引用已添加到设置页面的内容。例如,当您访问sample settings page 创建的菜单为:
function wporg_options_page() {
// add top level menu page
add_menu_page(
\'WPOrg\',
\'WPOrg Options\',
\'manage_options\',
\'wporg\',
\'wporg_options_page_html\'
);
}
在此页面上有一个字段:function wporg_field_pill_cb($args) {
// get the value of the setting we\'ve registered with register_setting()
$options = get_option(\'wporg_options\');
// output the field
?>
<select id="<?= esc_attr($args[\'label_for\']); ?>"
data-custom="<?= esc_attr($args[\'wporg_custom_data\']); ?>"
name="wporg_options[<?= esc_attr($args[\'label_for\']); ?>]"
>
<option value="red" <?= isset($options[$args[\'label_for\']]) ? (selected($options[$args[\'label_for\']], \'red\', false)) : (\'\'); ?>>
<?= esc_html(\'red pill\', \'wporg\'); ?>
</option>
<option value="blue" <?= isset($options[$args[\'label_for\']]) ? (selected($options[$args[\'label_for\']], \'blue\', false)) : (\'\'); ?>>
<?= esc_html(\'blue pill\', \'wporg\'); ?>
</option>
</select>
<p class="description">
<?= esc_html(\'You take the blue pill and the story ends. You wake in your bed and you believe whatever you want to believe.\', \'wporg\'); ?>
</p>
<p class="description">
<?= esc_html(\'You take the red pill and you stay in Wonderland and I show you how deep the rabbit-hole goes.\', \'wporg\'); ?>
</p>
<?php
}
如果我想创建一个小部件来引用wporg_field_pill_cb
功能我浏览了标签add-menu-page 和add-submenu-page 但我看不到什么坚实的东西。当我引用时- Add a sub-menu 它确实指向
add_submenu_page()
功能相同for add_menu_page()
函数我查看了add_setting_field
codex声明它是设置API的一部分,但没有任何内容
wporg_options
在里面widget()
?如果不清楚,我深表歉意,但我的目标是学习如何在子菜单或顶部菜单中创建一个表单,其中的设置将由小部件引用或由小部件呈现。我以上面的设置插件为例,查看在设置页面中我将使用什么来获取所选的选项值。