php - Wordpress settings page options not updating backend -
i'm developing wordpress plugin, , have been basing admin page development off of codex's custom settings page example. have been unable update setting in wp_options db, , can't seem find explanation i've done wrong. when click 'save settings', page refreshes , bar pops @ top saying settings saved properly, nothing shows in wp_options, , text input box isn't populated updated value.
here's have:
admin init section:
function secg_settings_init() { register_setting( 'secg', 'secg_options' ); add_settings_section( 'secg_section_developers', __( 'api keys.', 'secg' ), 'secg_section_developers_cb', 'secg' ); add_settings_field( 'secg_field_test_secret_key', __( 'test-secret-key', 'secg' ), 'secg_field_test_secret_key_cb', 'secg', 'secg_section_developers', [ 'label_for' => 'secg_field_test_secret_key', 'id' => 'test-secret-key' ] ); } add_action( 'admin_init', 'secg_settings_init' );
section , field callbacks:
function secg_section_developers_cb( $args ) { ?> <p id="<?php echo esc_attr( $args['id'] ); ?>"><?php esc_html_e( 'section developers cb.', 'secg' ); ?></p> <?php } function secg_field_test_secret_key_cb( $args ) { $options = secg_option(); ?> <input type="text" name="secg_options[<?php echo esc_attr( $args['label_for'] ); ?>]" id="<?php echo esc_attr( $args['label_for'] ); ?>" value="<?php $options[ $args['label_for'] ] ?>" /> <?php }
add page:
function secg_options_page() { add_menu_page( 'my plugin', 'plugin options', 'manage_options', 'secg', 'secg_options_page_html' ); } add_action( 'admin_menu', 'secg_options_page' );
handler setting default values:
function secg_option() { $default = array( 'secg_field_test_secret_key' => 'test secret key' ); return get_option('secg_options', $default); }
and finally, page itself:
function secg_options_page_html() { if ( ! current_user_can( 'manage_options' ) ) { return; } if ( isset( $_get['settings-updated'] ) ) { add_settings_error( 'secg_messages', 'secg_message', __( 'settings saved', 'secg' ), 'updated' ); } settings_errors( 'secg_messages' ); ?> <div class="wrap"> <h1><?php echo esc_html( get_admin_page_title() ); ?></h1> <form action="options.php" method="post"> <?php settings_fields( 'secg' ); do_settings_sections( 'secg' ); submit_button( 'save settings' ); ?> </form> </div> <?php }
thanks!
Comments
Post a Comment