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

时间:2011-05-06 06:48:06

标签: wordpress wordpress-theming

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

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的序列化输出(用户在我的选项面板中输入textarea),我测试$options_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] =>帖子[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代码不起作用。我错过了什么?

1 个答案:

答案 0 :(得分:1)

$ options_array = unserialize($ importOptions);

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