I'm a relative beginner, so anything that points me in the right direction is appreciated.
I'm trying to whitelist options from the admin panel. I have an array in another file (item-whitelist.php) that contains the whitelisted items, and I would like to be able to add to that array by entering new items on a custom options page. I created an options page with a textarea field for the user to input new items, but I'm unsure of how to go about adding input options to the array in the other file.
I'm assuming I would post the input items to the database and read from the database in the other file, but I've spent a while trying to figure out how to do this and haven't had much success.
functions.php :
<?php
add_action( 'admin_menu', 'mp_add_admin_menu' );
add_action( 'admin_init', 'mp_settings_init' );
function mp_add_admin_menu( ) {
add_options_page( 'my-plugin', 'my-plugin', 'manage_options', 'my-plugin', 'mp_options_page' );
}
function mp_settings_init( ) {
register_setting( 'pluginPage', 'mp_settings' );
add_settings_section(
'mp_pluginPage_section',
__( 'Your section description', 'wordpress' ),
'mp_settings_section_callback',
'pluginPage'
);
add_settings_field(
'mp_textarea_field_0',
__( 'Settings field description', 'wordpress' ),
'mp_textarea_field_0_render',
'pluginPage',
'mp_pluginPage_section'
);
}
function mp_textarea_field_0_render( ) {
$options = get_option( 'mp_settings' );
?>
<textarea cols='40' rows='5' name='mp_settings[mp_textarea_field_0]'>
<?php echo $options['mp_textarea_field_0']; ?>
</textarea>
<?php
}
function mp_settings_section_callback( ) {
echo __( 'This section description', 'wordpress' );
}
function mp_options_page( ) {
?>
<div class="wrap">
<form action='options.php' method='post'>
<h1>my-plugin Settings</h1>
<?php
settings_fields( 'pluginPage' );
do_settings_sections( 'pluginPage' );
submit_button();
?>
</form>
</div>
<?php
}
?>