コード例 #1
0
ファイル: menu-walkers.php プロジェクト: yarylo/cerkva.pp.ua
function wptouch_save_menu_changes($old_value, $new_value)
{
    if (isset($new_value['nav_menu_locations'])) {
        global $wptouch_pro;
        $menu_map = $new_value['nav_menu_locations'];
        if (is_array($menu_map) && count($menu_map > 0)) {
            foreach ($menu_map as $location => $menu_id) {
                if (strstr($location, 'wptouch_')) {
                    $menu_data = wp_get_nav_menu_object($menu_id);
                    $location = substr($location, 8);
                    global $wptouch_pro;
                    $menu_domain = false;
                    foreach ($wptouch_pro->theme_menus as $menu) {
                        if ($menu->setting_name == $location) {
                            $menu_domain = $menu->settings_domain;
                            continue;
                        }
                    }
                    if ($menu_domain) {
                        $settings = wptouch_get_settings($menu_domain);
                        $settings->{$location} = $menu_id;
                        $settings->save();
                    }
                }
            }
        }
        wptouch_customizer_begin_theme_override();
        set_theme_mod('nav_menu_locations', $menu_map);
        wptouch_customizer_end_theme_override();
    }
}
コード例 #2
0
function wptouch_customizer_save($object)
{
    wptouch_customizer_begin_theme_override();
    // Apply changes made in the customizer to the WPtouch settings objects.
    // Settings are prefixed with wptouch_ to avoid collision with other sources of theme mods & for clarity if viewing the database directly.
    global $wptouch_pro, $options_domains;
    // Colours are a special case in WPtouch, so they're handled separately
    $colors = foundation_get_theme_colors();
    foreach ($colors as $color) {
        $settings = wptouch_get_settings($color->domain);
        // Colours are stored by the customizer as theme mods
        $new_color = get_theme_mod('wptouch_' . $color->setting);
        if (!$new_color) {
            // The customizer allows users to save an null value for colours. Rather than allowing it to stay, we'll treat this as a 'reset to default' action.
            remove_theme_mod('wptouch_' . $color->setting);
            // Now replace the saved setting with the appropriate default
            $defaults = $wptouch_pro->get_setting_defaults($color->domain);
            $settings->{$color->setting} = $defaults->{$color->setting};
        } else {
            $settings->{$color->setting} = $new_color;
        }
        // Because colours could conceivably be in more than one domain we do a precautionary persist after each one.
        $settings->save();
    }
    $customizable_settings = wptouch_get_customizable_settings();
    // Now iterate over each of the domains with settings managed in the customizer and transfer their settings
    foreach ($customizable_settings as $domain => $domain_customizable_settings) {
        // Determine whether we should retrieve data from theme mods or a site option.
        if (in_array($domain, $options_domains)) {
            $domain_options = get_option('wptouch_customizer_options_' . $domain);
            $use_options = true;
        } else {
            $domain_options = false;
            $use_options = false;
        }
        // Load the current settings object for this domain
        $settings = wptouch_get_settings($domain);
        // Next, iterate over the settings that can be set for this domain using the customizer
        foreach ($domain_customizable_settings as $setting_name) {
            if ($use_options) {
                // Persist from site option
                $options_setting_name = str_replace('[', '-----', str_replace(']', '_____', $setting_name));
                if (isset($domain_options[$options_setting_name])) {
                    $new_setting = $domain_options[$options_setting_name];
                    $settings = apply_filters('wptouch_customizer_save__' . $domain . '__' . $setting_name, $settings, $new_setting);
                    $settings->{$setting_name} = $new_setting;
                }
            } else {
                // Persist from theme mod
                if ($new_setting = get_theme_mod('wptouch_' . $setting_name)) {
                    $settings = apply_filters('wptouch_customizer_save__' . $domain . '__' . $setting_name, $settings, $new_setting);
                    $settings->{$setting_name} = $new_setting;
                }
            }
        }
        $settings->save();
    }
    wptouch_customizer_end_theme_override();
}