向WP_OPTION表中的序列化数组添加新值

时间:2019-04-02 作者:monkeyman905

我正在寻找一些关于如何在WordPress中为sterialized数据添加新值的帮助。我正在尝试为已安装的插件添加一个新选项,以便为客户端添加额外功能,并且我需要将“price\\u higher\\u rates”添加到wp_estate_submission_page_fields 阵列输入wprentals_admin.

由于我是WordPress的新开发人员,我曾尝试将数据直接添加到数据库中,但后来出现了一些错误,这是因为我发现数据被序列化了。我已经看到了功能add_option()update_option() 但无法找到如何添加新值。

这是wprentals\\u管理员的一个片段wp_estate_submission_page_fields 大堆

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";}

全表值

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,
谢谢你

1 个回复
最合适的回答,由SO网友:Tom J Nowell 整理而成

选项存储值,而您尝试调整的插件犯了一个主要的错误,即在数据库中存储PHP序列化数据,以及随之而来的所有安全和维护问题。

您找不到任何WordPress API允许您更新或添加序列化值,但您可以对其进行反序列化,使用标准PHP语言进行修改,然后再次序列化。有点像把一个盒子移走,放进新的东西,然后把它放回你找到的地方。

$serialised = get_option( \'foobar\' );
$data = maybe_unserialize( $serialised );
// .. do something with $data
update_option( \'foobar\', serialize( $data ) );
您可以如何修改它?与任何其他PHP数组或对象的方式相同,例如:

// if this was $data
$data = [ 1,2,3,4,5];
// then lets add a 6th item to the array
$data[] = 6
至于这个插件/主题存储数据的细节,如果遇到问题或参考他们的文档,你必须联系他们

相关推荐

Testing Plugins for Multisite

我最近发布了一个WordPress插件,它在单个站点上非常有效。我被告知该插件在多站点安装上不能正常工作,我理解其中的一些原因。我已经更新了代码,现在需要一种方法来测试更新后的代码,然后才能转到实时客户的多站点安装。我有一个用于测试的WordPress安装程序的单站点安装,但需要在多站点安装上进行测试。根据我所能找到的唯一方法是在网络上至少有两个站点来安装整个多站点安装,以测试我的插件。设置WordPress的整个多站点安装是插件开发人员的唯一/首选方式,还是有更快的测试环境可用。