WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is my entire code. It doesn't save the data I enter on the plugin settings page. I don't have a clue on why this happens! Can somebody please help me?

<?php // add the admin options page
add_action('admin_menu', 'plugin_admin_add_page');
function plugin_admin_add_page() {
        'Revenue Share Plugin',
        'RSP Menu',

<?php // display the admin options page
function RSP_options_page() {
    <h2>Adsense Revenue Share Plugin</h2>
    Set the publication id and the position of the ad here!
    <form action="options.php" method="post">
    <?php settings_fields('RSP_options'); ?>
    <?php do_settings_sections('RSP_plugin'); ?>

    <input name="Submit" type="submit" value="<?php esc_attr_e('Save Changes'); ?>" />


    $options = get_option('RSP_options');
    echo '<br /><h4>Current Settings</h4><br>';
    echo 'Adsense Publisher Id';
    echo $options['RSP_text_string']; 


<?php // add the admin settings and such
add_action('admin_init', 'RSP_admin_init');
function RSP_admin_init(){
    register_setting( 'RSP_options', 'RSP_options', 'RSP_options_validate' );
    add_settings_section('RSP_main', 'Main Settings', 'RSP_section_text', 'RSP_plugin');
        'RSP Adsense Pub Id',

<?php // validate our options
function RSP_options_validate($input) {
    $options = get_option('RSP_options');
    $options['RSP_text_string'] = trim($input['RSP_text_string']);
    if(!preg_match('/^[a-z0-9]{32}$/i', $options['RSP_text_string'])) {
        $options['RSP_text_string'] = '';
    return $options;

function RSP_setting_string() {
    $options = get_option('RSP_options');
    echo "<input id='RSP_text_string' name='RSP_options[RSP_text_string]' size='40' type='text' value='{$options['RSP_text_string']}' />";

function RSP_section_text() {
    echo '<p>Main description of this section here.</p>';
share|improve this question
I think it is a better way you sue the settings API, it is easier and fast forward. You find excellent tutorials in the www – bueltge Jan 23 '13 at 13:01
I am using setting API! Can you help me find what I am doing wrong in this code? – defiant Jan 23 '13 at 13:08
Import on the settings API is the id, the string (like settings-group) there you use to identifier the data. see tutorial – bueltge Jan 23 '13 at 13:39
Please check, if you change the first value on register_settingsto 'RSP_options-group'. You have the same key for group and name. Use this also on settings_fields. – bueltge Jan 23 '13 at 13:45
Do I need to change it somewhere else, because still it doesn't work! :( – defiant Jan 23 '13 at 13:58
up vote 0 down vote accepted

The problem is your validate function RSP_options_validate(). This function always a empty string. Check your conditional statement with preg_match.

If you test your source without this functions, it works.

register_setting( 'RSP_options_group', 'RSP_options', 'RSP_options_validate' );


register_setting( 'RSP_options_group', 'RSP_options' );

share|improve this answer
That was it thanks ! :D – defiant Jan 23 '13 at 15:59
Welcome. Leave always good readable source, makes so much easier to check it. – bueltge Jan 23 '13 at 16:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.