• Resolved Jeffrey Cannon

    (@jacannon2)


    I have a multisite network, and I’m creating a custom registration page for new blogs.

    When the form is submitted I would like some of the info to be placed in the blog options table as serialized data.

    I’ve been able to do this successfully, but the serialized data is slightly different from that of what my theme’s options page creates, and even from what WordPress creates.

    Sample of WordPress format:
    a:2:{i:2;a:1:{s:5:"title";s:0:"";}s:12:"_multiwidget";i:1;}

    Sample of correct format as saved by theme options page:
    a:10:{s:10:"leadership";s:10:"John Smith";s:8:"address1";s:15:"123 Main Street";s:8:"address2";s:0:"";s:4:"city";s:6:"Dallas";s:14:"state_prov_reg";s:2:"TX";s:3:"zip";s:5:"76712";s:5:"phone";s:10:"8005551212";s:3:"fax";s:0:"";s:5:"email";s:21:"[email protected]";s:5:"state";s:2:"TX";}

    Sample of incorrect format as saved upon registration:
    s:321:"a:16:{i:0;s:10:"leadership";i:1;s:10:"John Smith";i:2;s:8:"address1";i:3;s:15:"123 Main Street";i:4;s:8:"address2";i:5;s:0:"";i:6;s:4:"city";i:7;s:6:"Dallas";i:8;s:14:"state_prov_reg";i:9;s:2:"TX";i:10;s:3:"zip";i:11;s:5:"76712";i:12;s:5:"phone";i:13;s:10:"8005551212";i:14;s:5:"email";i:15;s:21:"[email protected]";}";

    My theme options page was created from here:
    https://themeshaper.com/2010/06/03/sample-theme-options/

    This is the code I use on the registration form to put the options into the database:

    // Create array for options
    $theme_options = array(
    	'leadership' => $_REQUEST['leadership'],
    	'address1' => $_REQUEST['address1'],
    	'address2' => $_REQUEST['address2'],
    	'city' => $_REQUEST['city'],
    	'state_prov_reg' => $_REQUEST['state'],
    	'zip' => $_REQUEST['zip'],
    	'phone' => $_REQUEST['phone'],
    	'email' => $_REQUEST['email']
    );
    
    // serialize the array
    if(!is_serialized( $theme_options )) { $theme_options = maybe_serialize($theme_options); }
    
    // Save Leadership
    add_blog_option($id, 'theme_options', $theme_options);

    I see the difference. I just don’t know why it’s happening.

    Any ideas?

  • The topic ‘Adding Blog Option with Serialized Data’ is closed to new replies.