1

I'm looking for some help on how to add a new value to steralized data in WordPress. I'm trying to add a new option to an already installed plugin so I can add extra functionality for the client and I need to add "price_higher_rates" to wp_estate_submission_page_fields array in wprentals_admin.

As I'm new to developing for WordPress I've tried adding the data directly into the database but I then I got some errors which is when I found that the data is seralized. I've seen the functions add_option() and update_option() but cant find how to add the new value.

This is a snippet on the wprentals_admin perceptually the wp_estate_submission_page_fields array

s:32:"wp_estate_submission_page_fields";a:40:{i:0;s:20:"prop_category_submit";i:1;s:27:"prop_action_category_submit";i:2;s:19:"property_city_front";i:3;s:19:"property_area_front";i:4;s:20:"property_description";i:5;s:14:"property_price";i:6;s:14:"property_taxes";i:7;s:23:"property_price_per_week";i:8;s:24:"property_price_per_month";i:9;s:18:"price_per_weekeend";i:10;s:12:"cleaning_fee";i:11;s:8:"city_fee";i:12;s:16:"min_days_booking";i:13;s:16:"security_deposit";i:14;s:18:"early_bird_percent";i:15;s:21:"extra_price_per_guest";i:16;s:19:"checkin_change_over";i:17;s:28:"checkin_checkout_change_over";i:18;s:13:"extra_options";i:19;s:13:"custom_prices";i:20;s:8:"attachid";i:21;s:14:"embed_video_id";i:22;s:16:"embed_video_type";i:23;s:13:"property_size";i:24;s:14:"property_rooms";i:25;s:18:"property_bathrooms";i:26;s:16:"property_address";i:27;s:12:"property_zip";i:28;s:15:"property_county";i:29;s:14:"property_state";i:30;s:12:"property_map";i:31;s:17:"property_latitude";i:32;s:18:"property_longitude";i:33;s:19:"google_camera_angle";i:34;s:15:"individual-work";i:35;s:14:"client-meeting";i:36;s:12:"team-meeting";i:37;s:4:"wifi";i:38;s:13:"flatscreen-tv";i:39;s:9:"flipchart";}

Full table value

a:411:{s:8:"last_tab";s:1:"1";s:25:"wp_estate_general_country";s:14:"United Kingdom";s:21:"wp_estate_measure_sys";s:2:"ft";s:26:"wp_estate_enable_user_pass";s:3:"yes";s:24:"wp_estate_separate_users";s:3:"yes";s:22:"wp_estate_publish_only";s:17:"Connect";s:23:"wp_estate_delete_orphan";s:3:"yes";s:19:"wp_estate_date_lang";s:5:"en-GB";s:29:"wp_estate_disable_theme_cache";s:2:"no";s:31:"wp_estate_google_analytics_code";s:0:"";s:21:"wp_estate_wide_status";s:1:"1";s:17:"wp_estate_prop_no";s:1:"6";s:22:"wp_estate_blog_sidebar";s:10:"no sidebar";s:27:"wp_estate_blog_sidebar_name";s:19:"primary-widget-area";s:28:"wp_estate_property_list_type";s:1:"1";s:32:"wp_estate_property_list_type_adv";s:1:"2";s:23:"wp_estate_favicon_image";a:5:{s:3:"url";s:81:"";s:2:"id";s:5:"30153";s:6:"height";s:2:"64";s:5:"width";s:2:"64";s:9:"thumbnail";s:81:"";}s:20:"wp_estate_logo_image";a:5:{s:3:"url";s:82:"";s:2:"id";s:5:"30179";s:6:"height";s:3:"109";s:5:"width";s:3:"441";s:9:"thumbnail";s:90:"";}s:32:"wp_estate_transparent_logo_image";a:5:{s:3:"url";s:82:";s:2:"id";s:5:"30179";s:6:"height";s:3:"109";s:5:"width";s:3:"441";s:9:"thumbnail";s:90:"";}s:27:"wp_estate_mobile_logo_image";a:5:{s:3:"url";s:82:"";s:2:"id";s:5:"30179";s:6:"height";s:3:"109";s:5:"width";s:3:"441";s:9:"thumbnail";s:90:"";}s:27:"wp_estate_logo_image_retina";a:5:{s:3:"url";s:0:"";s:2:"id";s:0:"";s:6:"height";s:0:"";s:5:"width";s:0:"";s:9:"thumbnail";s:0:"";}s:39:"wp_estate_transparent_logo_image_retina";a:5:{s:3:"url";s:0:"";s:2:"id";s:0:"";s:6:"height";s:0:"";s:5:"width";s:0:"";s:9:"thumbnail";s:0:"";}s:34:"wp_estate_mobile_logo_image_retina";a:5:{s:3:"url";s:0:"";s:2:"id";s:0:"";s:6:"height";s:0:"";s:5:"width";s:0:"";s:9:"thumbnail";s:0:"";}s:32:"wp_estate_show_top_bar_user_menu";s:2:"no";s:34:"wp_estate_show_top_bar_mobile_menu";s:2:"no";s:21:"wp_estate_show_submit";s:2:"no";s:33:"wp_estate_show_top_bar_user_login";s:3:"yes";s:29:"wp_estate_show_menu_dashboard";s:3:"yes";s:26:"wp_estate_logo_header_type";s:5:"type1";s:27:"wp_estate_logo_header_align";s:4:"left";s:21:"wp_estate_header_type";s:1:"4";s:26:"wp_estate_user_header_type";s:1:"0";s:34:"wp_estate_global_revolution_slider";s:0:"";s:23:"wp_estate_global_header";a:5:{s:3:"url";s:0:"";s:2:"id";s:0:"";s:6:"height";s:0:"";s:5:"width";s:0:"";s:9:"thumbnail";s:0:"";}s:24:"wp_estate_paralax_header";s:3:"yes";s:29:"wp_estate_use_upload_tax_page";s:3:"yes";s:21:"wp_estate_wide_header";s:3:"yes";s:26:"wp_estate_transparent_menu";s:2:"no";s:34:"wp_estate_transparent_menu_listing";s:2:"no";s:27:"wp_estate_footer_background";a:5:{s:3:"url";s:0:"";s:2:"id";s:0:"";s:6:"height";s:0:"";s:5:"width";s:0:"";s:9:"thumbnail";s:0:"";}s:28:"wp_estate_repeat_footer_back";s:9:"no repeat";s:21:"wp_estate_wide_footer";s:2:"no";s:27:"wp_estate_copyright_message";s:37:"COPYRIGHT © 2019 ALL RIGHTS RESERVED";s:29:"wp_estate_prices_th_separator";s:1:",";s:29:"wp_estate_currency_label_main";s:2:"£";s:31:"wp_estate_where_currency_symbol";s:6:"before";s:25:"wp_estate_currency_symbol";s:3:"GBP";s:22:"wp_estate_auto_curency";s:3:"yes";s:34:"wp_estate_currencyconverterapi_api";s:0:"";s:22:"wp_estate_booking_type";s:1:"3";s:23:"wp_estate_setup_weekend";s:1:"0";s:21:"wp_estate_date_format";s:1:"2";s:27:"wp_estate_guest_dropdown_no";s:2:"50";s:23:"wp_estate_month_no_show";s:2:"24";s:27:"wpestate_custom_fields_list";a:5:{s:14:"add_field_name";a:3:{i:0;s:15:"Individual Work";i:1;s:14:"Client Meeting";i:2;s:12:"Team Meeting";}s:15:"add_field_label";a:3:{i:0;s:24:"Good for Individual Work";i:1;s:14:"Client Meeting";i:2;s:12:"Team Meeting";}s:15:"add_field_order";a:3:{i:0;s:1:"1";i:1;s:1:"2";i:2;s:1:"4";}s:14:"add_field_type";a:3:{i:0;s:8:"dropdown";i:1;s:8:"dropdown";i:2;s:8:"dropdown";}s:18:"add_dropdown_order";a:3:{i:0;s:7:"Yes, No";i:1;s:7:"Yes, No";i:2;s:7:"Yes, No";}}s:22:"wp_estate_feature_list";s:155:"WiFi,

Thank You

  • 1
    Hey monkeyman, welcome to WordPress development. It's a bit unclear to me what exactly you are trying to achieve. Extend a contrib or premium or custom plugin? Have you already read about codex.wordpress.org/Function_Reference/add_option and scanned the core for the mentioned functions? – leymannx Apr 2 at 13:58
  • Does it have to be a part of the option and not a new additional option? – Tom J Nowell Apr 2 at 14:23
  • Hi, sorry, so i can use add_option() and create a new table row called wp_estate_submission_page_fields with the value "price_higher_rates" , What i want to do is add "price_higher_rates" to a row called wprentals_admin but i want to add "price_higher_rates" to an specific array already in wprentals_admin. – monkeyman905 Apr 2 at 14:24
  • @TomJNowell Hi Tom, It needs to be part of the the option and not a new one. Thanks – monkeyman905 Apr 2 at 14:30
3

Options store values, and the plugin you're trying to adjust has committed the cardinal sin of storing PHP serialised data in the database, complete with all the security and maintenance problems that come with it.

You won't find any WordPress APIs that let you update or add to that serialised value, but you can deserialise it, modify it with standard PHP language stuff, then serialise it again. A bit like removing a box, putting something new in it, then putting it back where you found it.

$serialised = get_option( 'foobar' );
$data = maybe_unserialize( $serialised );
// .. do something with $data
update_option( 'foobar', serialize( $data ) );

How might you modify it? The same way you would any other PHP array or object, e.g.:

// if this was $data
$data = [ 1,2,3,4,5];
// then lets add a 6th item to the array
$data[] = 6

As for the specifics of this plugin/themes stored data, you'd have to contact them if you encounter issues or refer to their documentation

  • Okay, thank you for pointing me in the right direction. I think its my lack of WordPress knowledge has tripped me up here. This should get me going again. Thanks again – monkeyman905 Apr 2 at 14:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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