I am creating my first ever plugin, its purpose is to show a notice when some conditions are met, I created the function in jQuery and initially I had to manually edit the file everytime I wanted to change the notice message, so I decided to create a settings page so that the user could edit the message from the front end.

Thanks to another member on stackxchange I was able to use wp localize to show the custom message saved in the wp options instead. however, I now find my self having to structure the message being shown such as;




I don't want to create many options so I thought I could try and serialize the data but I dont know how to.

In the settings page I have a single textbox for the user to enter the message.

<textarea name="msg_data" id="msg_data" cols="40" rows="10" />
<?php echo get_option('notice_data'); ?>

Here is the localize

$custom_notice = get_option('notice_data', 'default_value');
  wp_localize_script( 'lu_ban', 'custom_notice', $custom_notice);

My goal is to create three different inputs, one for title, one for body message and one for image path, can anyone help me out please.


  • 1
    Like this?
    – fuxia
    Jul 11, 2013 at 1:38

1 Answer 1


To store Data use this Code : save the serialize values

$title    = 'Your Title Value';
$message  = 'Your message HTML..';
$image    = 'http://www.domain.com/yourimage.jpg';

$notice_data = array('title'   => $title, 
                     'message' => $message,
                     'image'   => $image

if(get_option('notice_data') === FALSE){
    add_option('notice_data',  $notice_data );
    update_option('notice_data', $notice_data );

Now you can get the serialize values and use in your code

$notice_data =   get_option('notice_data')  ;  

echo $notice_data['title'];

  • 6
    add/update option serializes data automatically, all you need to do is pass an array. using serialize/unserialize here is redundant.
    – Milo
    Jul 11, 2013 at 5:09
  • Yes that's TRUE. Jul 11, 2013 at 5:14
  • @ShahinulIslam please update you answer, remove serialize/unserialize Jul 11, 2013 at 7:17
  • My serialized data looks like a:2:{s:5:"Title";s:11:"custom message";s:7:"Message";s:20:"Hello testing testing";} how do I now return it to a form, I tried <?php echo get_option('notice_data[Title]'); ?> but it doesnt work Jul 11, 2013 at 17:16
  • Jose David Garcia Llanos - you can unserialize($notice_data) to make that serialize data into array. I update the answer. Jul 11, 2013 at 20:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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