Читать книгу Professional WordPress Plugin Development - Brad Williams - Страница 100
Adding a Section to an Existing Page
ОглавлениеYour previous plugin was adding a whole new section and its input field on a stand‐alone page. You now modify it to insert this content into WordPress’ Privacy Settings page.
<?php $args = array( 'type' => 'string', 'sanitize_callback' => 'pdev_plugin_validate_options', 'default' => NULL ); register_setting( 'reading', 'pdev_plugin_options', $args ); add_settings_section( 'pdev_plugin_options', 'PDEV Plugin Settings', 'pdev_plugin_section_text', 'reading' ); add_settings_field( 'pdev_plugin_text_string', 'Your Name', 'pdev_plugin_setting_name', 'reading', 'pdev_plugin_options' ); ?>
Notice that the first parameter passed in the register_setting()
function call is set to reading
. This function now adds your custom section into the reading
section, which is located within the Reading Settings page, as shown in Figure 3‐6. Replace all reading
instances with media
, and your section will be appended at the end of the Media Settings page.
FIGURE 3‐6: Section appended
You still need to whitelist this setting, with register_setting()
. Omitting this step would make WordPress ignore the setting when submitting the form.