WordPress 导入设置功能中 update_option() 出现问题

发布于 2024-11-05 03:39:51 字数 1571 浏览 1 评论 0原文

我在主题中构建的导入/导出选项遇到了一些麻烦。希望我能很好地解释这一点,让我从函数开始。

function ifeature_import_options() {
$options = get_option('ifeature');
$import = $options['if_import_code'];

if ($import != '');
    $options_array = (unserialize($import));
        foreach( $options_array as $option_name => $option_value ) {
        update_option( $option_name, $option_value );
        }
}

if_import_code 返回 $options 的序列化输出(用户将其输入到我的选项面板中的文本区域中),并且我已经测试了 $options_array 正确反序列化导入代码,因为它打印以下内容:

Array ( [if_menu_color] => 粉色 [if_font] => Arial [if_css_options] => [if_favicon] => [if_ga_code] => [if_import_code] =>; [if_export_code] => b:0; [if_logo] => [if_menuicon] =>; [if_header_contact] => [if_facebook] => [if_twitter] => [if_linkedin] => [if_youtube] => [if_googlemaps] => [if_email] => [if_rsslink] => [if_home_描述] => [if_home_keywords] => [if_home_title] => [if_callout_title] => [if_callout_text] => [if_callout_img] => [if_callout_image_link] => [if_slider_type] =>帖子 [if_slider_placement] =>特征 [if_slider_category] ​​=> [if_slider_posts_number] => [if_slider_height] => [if_slider_delay] => [if_slider_animation] =>随机的 [if_footer_text] => [if_hide_callout] => 0 [if_show_fb_like] => 0 [if_hide_slider] => 0 [if_hide_boxes] => 0 [if_hide_link] => 0 [if_slider_navigation] => 0)

所以我有需要写入我的选项的新数组,但我使用的 update_options 代码不起作用。我缺少什么?

I am having a bit of trouble with an import/export option I'm building into my theme. Hopefully I explain this well, let me start with the function.

function ifeature_import_options() {
$options = get_option('ifeature');
$import = $options['if_import_code'];

if ($import != '');
    $options_array = (unserialize($import));
        foreach( $options_array as $option_name => $option_value ) {
        update_option( $option_name, $option_value );
        }
}

if_import_code returns the serialized output of $options (which the user enters into a textarea in my options panel), and I've tested that $options_array is properly unserializing the import code as it prints the following:

Array ( [if_menu_color] => Pink [if_font] => Arial [if_css_options] =>
[if_favicon] => [if_ga_code] => [if_import_code] => [if_export_code]
=> b:0; [if_logo] => [if_menuicon] => [if_header_contact] =>
[if_facebook] => [if_twitter] => [if_linkedin] => [if_youtube] =>
[if_googlemaps] => [if_email] => [if_rsslink] => [if_home_description]
=> [if_home_keywords] => [if_home_title] => [if_callout_title] =>
[if_callout_text] => [if_callout_img] => [if_callout_image_link] =>
[if_slider_type] => posts [if_slider_placement] => feature
[if_slider_category] => [if_slider_posts_number] => [if_slider_height]
=> [if_slider_delay] => [if_slider_animation] => random
[if_footer_text] => [if_hide_callout] => 0 [if_show_fb_like] => 0
[if_hide_slider] => 0 [if_hide_boxes] => 0 [if_hide_link] => 0
[if_slider_navigation] => 0 )

So I have the new array that needs to be written to my options, but the update_options code I've used isn't working. What am I missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南渊 2024-11-12 03:39:51

$options_array = 反序列化($importOptions);

foreach ($options_array as $option_name=>$value) {
    if ($value != '') update_option( $key, $value );
}

$options_array = unserialize($importOptions);

foreach ($options_array as $option_name=>$value) {
    if ($value != '') update_option( $key, $value );
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文