• Hello All,

    I am new to this forum and for the same reason I apologize if I have posted this topic in some other category then its own.

    Currently I am developing my first plugin and created all the UI stuff. Now I am trying to save the plugin options user choose but it isn’t working.

    I have registered the settings hook, settings group and options variable but it still redirects the page to options.php

    Here is a code snippet I have written to register the settings hook and the settings initialization:

    // Adding settings group and variable
    function MY_settings() {
    	register_setting('Mygroup','Mysettings');
    }
    // Registering settings hook
    add_action('admin_init','MY_settings');

    Now to get the data from variable, I am using

    global $My_Settings
    <input name="Mysettings[id]" type="text" id="id" value="' . $My_Settings[id] . '" class="regular-text" />

    And at the top of MyPlugin.php file, I have this code:

    $My_Settings = get_option('Mysettings');
    if( ! $My_Settings ) {
    	$My_Settings = array(
    		'id' => 'Enter you ID here'
    	);
    	update_option('Mysettings',$My_Settings);
    }

    Any help will be really appreciated, and a small code snippet if you can provide will be great too. I know I am missing a very small check or something but I am unable to figure it out.

    Thanks,
    Osama

  • The topic ‘[Plugin Developement – My 1st Plugin ] Plugin enable to save its data’ is closed to new replies.