Pushing data into the $options array from the settings page
-
Hi all,
I’m currently developing a testimonial plugin. The testimonials are to be stored in an array.
I have an settings page where the admin is to add new testimonials. However it saves the form as an array into $option. I cant seem to find a way to push new data in that array it just save one array.He is the code for the setting page:
`
function JWidget_settings_init( ) {register_setting( ‘pluginPage’, ‘JWidget_settings’ );
add_settings_section(
‘JWidget_pluginPage_section’,
__( ‘Add a widget’, ‘wordpress’ ),
‘JWidget_settings_section_callback’,
‘pluginPage’
);add_settings_field(
‘img’,
__( ‘Image URL:’, ‘wordpress’ ),
‘JWidget_text_field_0_render’,
‘pluginPage’,
‘JWidget_pluginPage_section’
);add_settings_field(
‘url’,
__( ‘Name’, ‘wordpress’ ),
‘JWidget_text_field_1_render’,
‘pluginPage’,
‘JWidget_pluginPage_section’
);add_settings_field(
‘rev’,
__( ‘Rating:’, ‘wordpress’ ),
‘JWidget_select_field_2_render’,
‘pluginPage’,
‘JWidget_pluginPage_section’
);add_settings_field(
‘txt’,
__( ‘Review’, ‘wordpress’ ),
‘JWidget_textarea_field_3_render’,
‘pluginPage’,
‘JWidget_pluginPage_section’
);}
function JWidget_text_field_0_render( ) {
$options = get_option( ‘JWidget_settings’ );
?>
<input type=’text’ name=’JWidget_settings[img]’ value='<?php echo $options[‘img’]; ?>’>
<?php}
function JWidget_text_field_1_render( ) {
$options = get_option( ‘JWidget_settings’ );
?>
<input type=’text’ name=’JWidget_settings[url]’ value='<?php echo $options[‘url’]; ?>’>
<?php}
function JWidget_select_field_2_render( ) {
$options = get_option( ‘JWidget_settings’ );
?>
<select name=’JWidget_settings[rev]’>
<option value=’1′ <?php selected( $options[‘rev’], 1 ); ?>>4/5</option>
<option value=’2′ <?php selected( $options[‘rev’], 2 ); ?>>5/5/option>
</select><?php
}
function JWidget_textarea_field_3_render( ) {
$options = get_option( ‘JWidget_settings’ );
?>
<textarea cols=’40’ rows=’5′ name=’JWidget_settings[txt]’>
<?php echo $options[‘txt’]; ?>
</textarea>
<?php}
function JWidget_settings_section_callback( ) {
echo __( ‘Add a new plugin to be randomly generated. All fields must be filled out before submiting.’, ‘wordpress’ );
}
function JWidget_options_page( ) {
?>
<form action=’options.php’ method=’post’><h2>JWidget</h2>
<?php
settings_fields( ‘pluginPage’ );
do_settings_sections( ‘pluginPage’ );
submit_button();
?></form>
<?php}
?>
- The topic ‘Pushing data into the $options array from the settings page’ is closed to new replies.