Support » Plugins » [Plugin: scbFramework] admin page overwrites unreferenced options field

  • I am making admin page for plugin. Using Smart Archives Reloaded as reference, but simplifying here and there (less objects, omitting localization, etc).

    So I have scbOptions object as global $rds_options variable, setup in init function of plugin.

    One of the option fields is called known_sites, blank array by default, filled by function scheduled with WP Cron.

    I setup my AdminPage class RDS_Settings and put in init

    if ( is_admin() )
    		scbAdminPage::register('RDS_Settings', __FILE__, $rds_options);

    RDS_Settings is not referencing or expected to change known_sites field. But when I hit Save Changes on my settings page known_sites is changed to empty string.

    Am I doing everything right? Is this expected behavior? If it is – should options not expected to be changed by form stored separately or something?

    Thanks in advance.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The default scbAdminPage::form_handler() does indeed update the entire option. I’ve just made a commit that makes it update only the fields defined in the defaults array.

    So, you have two options:

    1. Make your own form_handler() method in your RDS_Settings class and use $this->options->set() instead of $this->options->update() to update only the fields you want.

    2. Use the development version of scbFramework and remove ‘known_sites’ from the default fields. You will also need to use the new scb_init() function – see the development version of Smart Archives Reloaded.

    Quick and dirty fix that worked for me, I copied form_handler() to my class and changed

    $new_data = array();
    		foreach ( array_keys($this->formdata) as $key )
    			$new_data[$key] = @$_POST[$key];


    $new_data = array();
    		foreach ( array_keys($this->formdata) as $key ) {
    			if ( isset( $_POST[$key] ) )
    				$new_data[$key] = @$_POST[$key];
    			elseif ( isset( $this->options->$key ) )
    				$new_data[$key] = $this->options->$key;
    				$new_data[$key] = '';

    Still updates all the fields, but those that aren’t in form are filled back with known values.

    Careful with that: you won’t be able to clear checkboxes (if you have any).

    Nope, no checkboxes… As I said – quick and dirty. 🙂 I need to get this thing working and pretty by Sunday.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Plugin: scbFramework] admin page overwrites unreferenced options field’ is closed to new replies.