• Rene Hermenau

    (@renehermi)


    Hey guys,

    I noticed that your plugin is serializing the plugin settings twice. This makes it hard for search and replace plugins to proper unserialize and serialize the data of your plugin.

    Example file get_value.php line 6:

    dashboard_page = unserialize(get_option('Admin_custome_login_dashboard'));

    get_option() is already unserializing data when a string is serialized, so there is no need to do it multiple times.

    I am author of WP Staging (https://ww.wp.xz.cn/plugins/wp-staging/) and it would be great if you could fix that and bring the serialized array into a correct format by just serializing it properly one time so that its fully compatible with WP Staging and other search & replace scripts. For instance we need this when we want to move sites from one domain to another without losing the plugin settings.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thanks, Rene, we will consider it and let you know how can we go through.

    A problem, the plugin is actively installed on 60K+ sites. I think you are a database expert. So, can you suggest us a way to make it?

    Thanks

    Thread Starter Rene Hermenau

    (@renehermi)

    Best approach would be to create a small update routine. I notice there are only a few table rows which need to be updated so it should not be much of work:

    At first I would create a var which stores the current version. (You can use that one for future version specific things as well)

    add_option('acl_version', '2.5.9');

    Then use that version number to determine if the database should be updated when someone updates the plugin. This makes sure that the update routine is not running all the time:

    function acl_update(){
    if (false === get_option('acl_version') || 
    version_compare( get_option('acl_version'), '2.5.9', '<' ) ){
      acl_update_data();
    }
    }
    
    add_action('admin_init', 'acl_update');
    
    // Updates the database
    
    function acl_update_data(){
    $data1 = unserialize(get_option('Admin_custome_login_Slidshow'));
    update_option('Admin_custome_login_Slidshow_new', $data1);
    
    $data2 = unserialize(get_option('Admin_custome_login_Social'));
    update_option('Admin_custome_login_Social_new', $data2);
    
    $data3 = unserialize(get_option('Admin_custome_login_logo'));
    update_option('Admin_custome_login_logo_new', $data3);
    
    // and so on
    }

    As you can see I store the data as a new row so in case something goes wrong the original data row is not gone and can be restored easily.

    One heavy duty job then would be to remove all serialize() and unserialize() functions from your code. This seems to be much of initial work but in the end your code gets much easier to maintain and develope. So in the end you will save a lot of time in the future.

    Let me know if you have further questions.

    Cheers

    Thanks, Rene.

    Perfect solution and that make sense, we will do it ASAP. And make the plugin compatible with WP Staging.

    Great Day!!!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Do not serialize plugin settings twice!’ is closed to new replies.