当前位置: 首页>>代码示例>>PHP>>正文


PHP wp_set_sidebars_widgets函数代码示例

本文整理汇总了PHP中wp_set_sidebars_widgets函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_set_sidebars_widgets函数的具体用法?PHP wp_set_sidebars_widgets怎么用?PHP wp_set_sidebars_widgets使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了wp_set_sidebars_widgets函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: retrieve_widgets

function retrieve_widgets()
{
    global $wp_registered_widget_updates, $wp_registered_sidebars, $sidebars_widgets, $wp_registered_widgets;
    $_sidebars_widgets = array();
    $sidebars = array_keys($wp_registered_sidebars);
    unset($sidebars_widgets['array_version']);
    $old = array_keys($sidebars_widgets);
    sort($old);
    sort($sidebars);
    if ($old == $sidebars) {
        return;
    }
    // Move the known-good ones first
    foreach ($sidebars as $id) {
        if (array_key_exists($id, $sidebars_widgets)) {
            $_sidebars_widgets[$id] = $sidebars_widgets[$id];
            unset($sidebars_widgets[$id], $sidebars[$id]);
        }
    }
    // if new theme has less sidebars than the old theme
    if (!empty($sidebars_widgets)) {
        foreach ($sidebars_widgets as $lost => $val) {
            if (is_array($val)) {
                $_sidebars_widgets['wp_inactive_widgets'] = array_merge((array) $_sidebars_widgets['wp_inactive_widgets'], $val);
            }
        }
    }
    // discard invalid, theme-specific widgets from sidebars
    $shown_widgets = array();
    foreach ($_sidebars_widgets as $sidebar => $widgets) {
        if (!is_array($widgets)) {
            continue;
        }
        $_widgets = array();
        foreach ($widgets as $widget) {
            if (isset($wp_registered_widgets[$widget])) {
                $_widgets[] = $widget;
            }
        }
        $_sidebars_widgets[$sidebar] = $_widgets;
        $shown_widgets = array_merge($shown_widgets, $_widgets);
    }
    $sidebars_widgets = $_sidebars_widgets;
    unset($_sidebars_widgets, $_widgets);
    // find hidden/lost multi-widget instances
    $lost_widgets = array();
    foreach ($wp_registered_widgets as $key => $val) {
        if (in_array($key, $shown_widgets, true)) {
            continue;
        }
        $number = preg_replace('/.+?-([0-9]+)$/', '$1', $key);
        if (2 > (int) $number) {
            continue;
        }
        $lost_widgets[] = $key;
    }
    $sidebars_widgets['wp_inactive_widgets'] = array_merge($lost_widgets, (array) $sidebars_widgets['wp_inactive_widgets']);
    wp_set_sidebars_widgets($sidebars_widgets);
}
开发者ID:klr2003,项目名称:sourceread,代码行数:59,代码来源:widgets.php

示例2: ht_sidebars_page

/**
 *
 * HighThemes Options Framework
 * twitter : http://twitter.com/theHighthemes
 *
 */
function ht_sidebars_page()
{
    global $sidehook, $sidebar_options, $wpdb;
    if (isset($_POST['Submit'])) {
        // getting the list of custom sidebars
        $get_sidebar_options = ht_sidebar_generator::get_sidebars();
        $sidebar_name = str_replace(array("\n", "\r", "\t"), '', $_POST['ht_sidebar_name']);
        $sidebar_id = sanitize_title($sidebar_name);
        if ($sidebar_id == '') {
            $options_sidebar = $get_sidebar_options;
        } else {
            if (isset($get_sidebar_options[$sidebar_id])) {
                header("Location: admin.php?page=sidebars&error=true{$hidden_anchor}");
                die;
            }
            if (is_array($get_sidebar_options)) {
                $new_sidebar_gen[$sidebar_id] = $sidebar_name;
                $options_sidebar = array_merge($get_sidebar_options, (array) $new_sidebar_gen);
            } else {
                $options_sidebar[$sidebar_id] = $sidebar_name;
            }
        }
        update_option('ht_sidebar_generator', $options_sidebar);
        header("Location: admin.php?page=sidebars{$send}&saved=true{$hidden_anchor}");
        die;
    }
    if (isset($_GET['sn'])) {
        $sidebar_id = $_GET['sn'];
        $get_sidebar_options = ht_sidebar_generator::get_sidebars();
        if (array_key_exists($sidebar_id, $get_sidebar_options)) {
            unset($get_sidebar_options[$sidebar_id]);
            update_option('ht_sidebar_generator', $get_sidebar_options);
            //
            $get_widgets = wp_get_sidebars_widgets();
            unset($get_widgets['array_version']);
            foreach ($get_widgets as $key => $value) {
                if ($key == 'ht_' . $sidebar_id) {
                    unset($get_widgets['ht_' . $sidebar_id]);
                }
            }
            wp_set_sidebars_widgets($get_widgets);
            $sidebar_meta = $wpdb->get_results("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_value = '{$sidebar_id}'", ARRAY_A);
            if ($sidebar_meta) {
                if (is_array($sidebar_meta)) {
                    foreach ($sidebar_meta as $key => $value) {
                        delete_post_meta($value['post_id'], '_selected_sidebar');
                    }
                }
            } else {
                header("Location: admin.php?page=sidebars");
            }
        }
    }
    wp_enqueue_script('common');
    wp_enqueue_script('wp-lists');
    wp_enqueue_script('postbox');
    add_meta_box('ht_add_sidebars', 'Add New Sidebars', 'ht_add_sidebars', $sidehook, 'normal', 'high');
}
开发者ID:naffan2014,项目名称:greenhomeland,代码行数:64,代码来源:sidebars.php

示例3: import_widgets

 function import_widgets($file)
 {
     $data = unserialize(base64_decode(file_get_contents($file)));
     $data['positions']['wp_inactive_widgets'] = array();
     wp_set_sidebars_widgets($data['positions']);
     foreach ($data['widgets'] as $class => $widget) {
         update_option($class, $widget);
     }
 }
开发者ID:amitmula,项目名称:amitandaastha.in,代码行数:9,代码来源:importer.php

示例4: clear_widgets

 private static function clear_widgets()
 {
     $sidebars = wp_get_sidebars_widgets();
     $inactive = isset($sidebars['wp_inactive_widgets']) ? $sidebars['wp_inactive_widgets'] : array();
     unset($sidebars['wp_inactive_widgets']);
     foreach ($sidebars as $sidebar => $widgets) {
         $inactive = array_merge($inactive, $widgets);
         $sidebars[$sidebar] = array();
     }
     $sidebars['wp_inactive_widgets'] = $inactive;
     wp_set_sidebars_widgets($sidebars);
 }
开发者ID:taeche,项目名称:SoDoEx,代码行数:12,代码来源:class-widget-data.php

示例5: on_ecwid_plugin_installed

 public function on_ecwid_plugin_installed()
 {
     $widgets = get_option('sidebars_widgets');
     if (strpos(implode(' ', $widgets['sidebar-1']), 'ecwidstorelink') === false) {
         array_unshift($widgets['sidebar-1'], 'ecwidstorelink-2');
         wp_set_sidebars_widgets($widgets);
         $options = get_option('widget_ecwidstorelink');
         if (!$options) {
             $options = array(2 => array('label' => __('Shop', 'ecwid-shopping-cart')), '_multiwidget' => 1);
         }
         update_option('widget_ecwidstorelink', $options);
     }
 }
开发者ID:digitaldevelopers,项目名称:ecwid-wordpress-plugin,代码行数:13,代码来源:class-ecwid-theme-twentyfifteen.php

示例6: import_sidebars_widgets

 public function import_sidebars_widgets($file)
 {
     $thememove_sidebars = get_option("sidebars_widgets");
     unset($thememove_sidebars['array_version']);
     $data = $this->file_options($file);
     if (is_array($data['sidebars'])) {
         $thememove_sidebars = array_merge((array) $thememove_sidebars, (array) $data['sidebars']);
         unset($thememove_sidebars['wp_inactive_widgets']);
         $thememove_sidebars = array_merge(array('wp_inactive_widgets' => array()), $thememove_sidebars);
         $thememove_sidebars['array_version'] = 2;
         wp_set_sidebars_widgets($thememove_sidebars);
     }
 }
开发者ID:novichkovv,项目名称:prlab,代码行数:13,代码来源:import.php

示例7: rotary_install_default_widgets

function rotary_install_default_widgets()
{
    //add default widgets to the home page side bar
    $sidebar = 'home-widget-area';
    $widget_name = 'text';
    $sidebars_widgets = wp_get_sidebars_widgets();
    if (empty($sidebars_widgets[$sidebar])) {
        $sidebar_options = get_option('widget_' . $widget_name);
        $startcount = $count = count($sidebar_options);
        $sidebar_options[$count] = array('title' => 'Rotary Vision', 'text' => '', 'filter' => '');
        $count++;
        $sidebar_options[$count] = array('title' => 'Rotary Mission', 'text' => '', 'filter' => '');
        $count++;
        $sidebar_options[$count] = array('title' => 'Project Filters', 'text' => '', 'filter' => '');
        $count++;
        $sidebar_options[$count] = array('title' => '4-Way Test', 'text' => '', 'filter' => '');
        update_option('widget_' . $widget_name, $sidebar_options);
        $sidebars_widgets[$sidebar] = array();
        for ($i = $startcount; $i <= $count; $i++) {
            $sidebars_widgets[$sidebar][] = $widget_name . '-' . $i;
        }
        //add the rotary blogroll
        $widget_name = 'rotarylinks';
        $sidebar_options = get_option('widget_' . $widget_name);
        $count = count($sidebar_options);
        $sidebar_options[$count] = array('images' => 0, 'name' => '', 'description' => '', 'rating' => 0, 'orderby' => 0, 'limit' => 0);
        update_option('widget_' . $widget_name, $sidebar_options);
        $sidebars_widgets[$sidebar][] = $widget_name . '-' . $count;
        wp_set_sidebars_widgets($sidebars_widgets);
    }
    //add default widgets to the secondary side bar
    $sidebar = 'secondary-widget-area';
    $widget_name = 'rotaryarchivewidget';
    $sidebars_widgets = wp_get_sidebars_widgets();
    if (empty($sidebars_widgets[$sidebar])) {
        $sidebar_options = get_option('widget_' . $widget_name);
        $count = count($sidebar_options);
        $sidebar_options[$count] = array('title' => 'Archives', 'showcount' => 0, 'linkcounter' => 0, 'truncmonth' => 0, 'jsexpand' => 1, 'groupbyyear' => 1, 'limitbycategory' => 0);
        $sidebars_widgets[$sidebar] = array();
        update_option('widget_' . $widget_name, $sidebar_options);
        $sidebars_widgets[$sidebar][] = $widget_name . '-' . $count;
        //add the tag cloud
        $widget_name = 'tag_cloud';
        $sidebar_options = get_option('widget_' . $widget_name);
        $count = count($sidebar_options);
        $sidebar_options[$count] = array('title' => 'Tags', 'taxonomy' => '');
        update_option('widget_' . $widget_name, $sidebar_options);
        $sidebars_widgets[$sidebar][] = $widget_name . '-' . $count;
        wp_set_sidebars_widgets($sidebars_widgets);
    }
}
开发者ID:bogdanbrudiu,项目名称:rotary,代码行数:51,代码来源:sidebar-init.php

示例8: set_ls_sidebar

 public function set_ls_sidebar()
 {
     $counter = $this->get_widget_index();
     $language_switcher_prefix = 'icl_lang_sel_widget-';
     $active_widgets = get_option('sidebars_widgets');
     foreach ($this->ls_sidebars as $target_sidebar_id => $add_widget) {
         $active_sidebar_widgets = $active_widgets[$target_sidebar_id];
         $widget_exists = $this->widget_exists($language_switcher_prefix, $active_sidebar_widgets);
         if ($add_widget && !$widget_exists) {
             $active_widgets = $this->add_to_sidebar($active_widgets, $target_sidebar_id, $language_switcher_prefix, $counter);
             $counter = $this->update_widget_options($counter);
         } elseif (!$add_widget && $widget_exists) {
             $active_widgets = $this->remove_widget($active_sidebar_widgets, $language_switcher_prefix, $active_widgets, $target_sidebar_id);
         }
     }
     wp_set_sidebars_widgets($active_widgets);
 }
开发者ID:edgarter,项目名称:wecare,代码行数:17,代码来源:wpml-language-switcher-settings.class.php

示例9: fastfood_upgrade

/**
 * Update some mods and options
 *
 * @since Fastfood 0.37
 */
function fastfood_upgrade()
{
    if (!is_admin()) {
        return;
    }
    $options_version = get_theme_mod('options_version', '0.36');
    if (version_compare($options_version, '0.37', '<')) {
        // footer widget area
        $sidebars_widgets = get_option('sidebars_widgets', array());
        $_sidebars_widgets = array();
        foreach (array('first-footer-widget-area', 'second-footer-widget-area', 'third-footer-widget-area') as $sidebar) {
            if (isset($sidebars_widgets[$sidebar])) {
                $_sidebars_widgets = array_merge($_sidebars_widgets, $sidebars_widgets[$sidebar]);
                unset($sidebars_widgets[$sidebar]);
            }
        }
        $sidebars_widgets['footer-widget-area'] = $_sidebars_widgets;
        wp_set_sidebars_widgets($sidebars_widgets);
        // header slider
        $header_image = get_theme_mod('header_image');
        if ($header_image === 'fastfood-slider-uploaded') {
            set_theme_mod('header_image', '');
            set_theme_mod('display_header_slider', 1);
        }
        // quickbar-navbar icons
        $background_color = get_theme_mod('background_color');
        $iconfont_color = get_theme_mod('background_icons_color');
        if ($background_color && !$iconfont_color) {
            $r = hexdec(substr($background_color, 0, 2));
            $g = hexdec(substr($background_color, 2, 2));
            $b = hexdec(substr($background_color, 4, 2));
            $yiq = ($r * 299 + $g * 587 + $b * 114) / 1000;
            $iconfont_color = $yiq >= 120 ? '#404040' : '#FFFFFF';
            set_theme_mod('background_icons_color', $iconfont_color);
        }
        // header text background
        $header_text_background = get_theme_mod('header_text_background');
        if ($header_text_background) {
            $match = array('transparent' => 'transparent', 'black' => '#000000', 'white' => '#FFFFFF');
            $header_text_background = isset($match[$header_text_background]) ? $match[$header_text_background] : 'transparent';
            set_theme_mod('header_text_background', $header_text_background);
        }
    }
    set_theme_mod('options_version', fastfood_get_info('version'));
}
开发者ID:TwoBeers,项目名称:fastfood,代码行数:50,代码来源:back-compat.php

示例10: wps_upgrade

function wps_upgrade($current_version)
{
    global $wpdb;
    $table_name = $wpdb->prefix . "category_subdomains";
    //--- Run upgrades based on current version
    switch ($current_version) {
        case '':
            $wpdb->query("UPDATE " . $table_name . " SET is_subdomain = 1 WHERE not_subdomain = 0");
            $wpdb->query("UPDATE " . $table_name . " SET not_subdomain = 0");
            // Change options from old SR ones to CSD ones.
            update_option('csd_sub_pages', get_option('sr_sub_pages') ? get_option('sr_sub_pages') : '');
            update_option('csd_themes_on', get_option('sr_themes_on') ? get_option('sr_themes_on') : '');
            update_option('csd_catarchives_on', get_option('sr_catarchives_on') ? get_option('sr_catarchives_on') : '');
            update_option('csd_pagefilter_on', get_option('sr_pagefilter_on') ? get_option('sr_pagefilter_on') : '');
        case '0.5.0':
            // Change options to new names and settings
            update_option('wps_sub_pages', get_option('csd_sub_pages') ? WPS_CHK_ON : '');
            update_option('wps_themes', get_option('csd_themes_on') ? WPS_CHK_ON : '');
            update_option('wps_catarchives', get_option('csd_catarchives_on') ? WPS_CHK_ON : '');
            update_option('wps_pagefilter', get_option('csd_pagefilter_on') ? WPS_CHK_ON : '');
            update_option('wps_subdomainall', get_option('csd_subdomainall_on') ? WPS_CHK_ON : '');
            // Delete Old CSD options, leave the SR options so they can go back to old plugin
            delete_option('csd_themes_on');
            delete_option('csd_catarchives_on');
            delete_option('csd_pagefilter_on');
            delete_option('csd_subdomainall_on');
            // Change page meta keys to new ones
            $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = 'wps_page_theme' WHERE meta_key = 'csd_page_theme'");
            $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = 'wps_page_subdomain' WHERE meta_key = 'csd_page_subdomain'");
            $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = 'wps_tie_to_category' WHERE meta_key = 'csd_tie_to_category'");
        case '0.5.1':
            // Change Widgets Names to the New Names
            $widgets = wp_get_sidebars_widgets();
            foreach (array_keys($widgets) as $sidebar) {
                if ($key = array_search('csd-site-list', $widgets[$sidebar])) {
                    $widgets[$sidebar][$key] = 'wps-sitelist';
                }
                if ($key = array_search('csd-categories', $widgets[$sidebar])) {
                    $widgets[$sidebar][$key] = 'wps-categories';
                }
            }
            wp_set_sidebars_widgets($widgets);
            break;
    }
}
开发者ID:hacklabr,项目名称:toquenobrasil,代码行数:45,代码来源:install.php

示例11: import_widgets

 function import_widgets($folder = '', $file = 'widgets.txt')
 {
     $file_path = get_template_directory() . '/library/import/files/' . $folder . '/' . $file;
     $file_data = $this->get_file_contents($file_path);
     $data = json_decode($file_data, true);
     foreach ((array) $data['widgets'] as $widget_id => $widget_data) {
         update_option('widget_' . $widget_id, $widget_data);
     }
     $slice_sidebars = get_option("sidebars_widgets");
     unset($slice_sidebars['array_version']);
     if (is_array($data['sidebars'])) {
         $slice_sidebars = array_merge((array) $slice_sidebars, (array) $data['sidebars']);
         unset($slice_sidebars['wp_inactive_widgets']);
         $slice_sidebars = array_merge(array('wp_inactive_widgets' => array()), $slice_sidebars);
         $slice_sidebars['array_version'] = 2;
         wp_set_sidebars_widgets($slice_sidebars);
     }
 }
开发者ID:love4code,项目名称:originalContracting,代码行数:18,代码来源:import.php

示例12: mr_upgrade_to_4_0

/**
 * Upgrade to 4.0
 */
function mr_upgrade_to_4_0()
{
    try {
        $sidebar_widgets = wp_get_sidebars_widgets();
        foreach ($sidebar_widgets as &$widgets) {
            foreach ($widgets as $widget_key => $widget_id) {
                if (strpos($widget_id, 'top_rating_results_widget') !== false) {
                    $instance = substr($widget_id, 26);
                    $widget_id = 'mr_rating_results_list-' . $instance;
                    $widget_options = get_option('widget_top_rating_results_widget');
                    $show_filter = $widget_options[$instance]['show_category_filter'];
                    $term_id = $widget_options[$instance]['category_id'];
                    unset($widget_options[$instance]['show_category_filter']);
                    $widget_options[$instance]['show_filter'] = $show_filter;
                    unset($widget_options[$instance]['category_id']);
                    $widget_options[$instance]['term_id'] = $term_id;
                    $widget_options[$instance]['taxonomy'] = 'category';
                    add_option('widget_mr_rating_results_list', $widget_options);
                    delete_option('widget_top_rating_results_widget');
                    $widgets[$widget_key] = $widget_id;
                }
            }
        }
        // custom settings
        $custom_text_settings = (array) get_option(Multi_Rating::CUSTOM_TEXT_SETTINGS);
        if (isset($custom_text_settings['mr_category_label_text'])) {
            $custom_text_settings[Multi_Rating::FILTER_LABEL_TEXT_OPTION] = $custom_text_settings['mr_category_label_text'];
            unset($custom_text_settings['mr_category_label_text']);
        }
        if (isset($custom_text_settings['mr_top_rating_results_title_text'])) {
            $custom_text_settings[Multi_Rating::RATING_RESULTS_LIST_TITLE_TEXT_OPTION] = $custom_text_settings['mr_top_rating_results_title_text'];
            unset($custom_text_settings['mr_top_rating_results_title_text']);
        }
        update_option(Multi_Rating::CUSTOM_TEXT_SETTINGS, $custom_text_settings);
        // PHP files
        if (file_exists(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'class-rating-result.php')) {
            unlink(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'class-rating-result.php');
        }
    } catch (Exception $e) {
        die(__('An error occured.', 'multi-rating'));
    }
    wp_set_sidebars_widgets($sidebar_widgets);
}
开发者ID:ratheeshpkr,项目名称:multi-rating,代码行数:46,代码来源:update-check.php

示例13: gk_set_sidebar_default

 function gk_set_sidebar_default()
 {
     global $_wp_sidebars_widgets;
     //初始化widget
     $widgets = gk_config('widget');
     foreach ($widgets as $name => $setting) {
         $id = 102;
         $option = get_option('widget_' . $name);
         if (!$option) {
             $option = array();
         }
         if (!isset($option[$id]) || gk_config('sidebar_debug')) {
             $option[$id] = $setting;
             update_option('widget_' . $name, $option);
         }
     }
     //初始化边栏
     $sidebars_option = wp_get_sidebars_widgets();
     $update_sidebar = true;
     $sidebars = gk_config('sidebar');
     foreach ($sidebars as $sidebar) {
         if (isset($sidebar['default']) && (!isset($sidebars_option[$sidebar['id']]) || gk_config('sidebar_debug'))) {
             $sidebars_option[$sidebar['id']] = array_map(create_function('$v', 'return $v.\'-102\';'), explode(',', $sidebar['default']));
             $update_sidebar = true;
         }
     }
     if ($update_sidebar) {
         $_wp_sidebars_widgets = $sidebars_option;
         wp_set_sidebars_widgets($sidebars_option);
     }
 }
开发者ID:G-g-beringei,项目名称:DChaser,代码行数:31,代码来源:functions.php

示例14: retrieve_widgets

function retrieve_widgets($theme_changed = false)
{
    global $wp_registered_widget_updates, $wp_registered_sidebars, $sidebars_widgets, $wp_registered_widgets;
    $registered_sidebar_keys = array_keys($wp_registered_sidebars);
    $orphaned = 0;
    $old_sidebars_widgets = get_theme_mod('sidebars_widgets');
    if (is_array($old_sidebars_widgets)) {
        // time() that sidebars were stored is in $old_sidebars_widgets['time']
        $_sidebars_widgets = $old_sidebars_widgets['data'];
        remove_theme_mod('sidebars_widgets');
        foreach ($_sidebars_widgets as $sidebar => $widgets) {
            if ('wp_inactive_widgets' == $sidebar || 'orphaned_widgets' == substr($sidebar, 0, 16)) {
                continue;
            }
            if (!in_array($sidebar, $registered_sidebar_keys)) {
                $_sidebars_widgets['orphaned_widgets_' . ++$orphaned] = $widgets;
                unset($_sidebars_widgets[$sidebar]);
            }
        }
    } else {
        if (empty($sidebars_widgets)) {
            return;
        }
        unset($sidebars_widgets['array_version']);
        $old = array_keys($sidebars_widgets);
        sort($old);
        sort($registered_sidebar_keys);
        if ($old == $registered_sidebar_keys) {
            return;
        }
        $_sidebars_widgets = array('wp_inactive_widgets' => !empty($sidebars_widgets['wp_inactive_widgets']) ? $sidebars_widgets['wp_inactive_widgets'] : array());
        unset($sidebars_widgets['wp_inactive_widgets']);
        foreach ($wp_registered_sidebars as $id => $settings) {
            if ($theme_changed) {
                $_sidebars_widgets[$id] = array_shift($sidebars_widgets);
            } else {
                // no theme change, grab only sidebars that are currently registered
                if (isset($sidebars_widgets[$id])) {
                    $_sidebars_widgets[$id] = $sidebars_widgets[$id];
                    unset($sidebars_widgets[$id]);
                }
            }
        }
        foreach ($sidebars_widgets as $val) {
            if (is_array($val) && !empty($val)) {
                $_sidebars_widgets['orphaned_widgets_' . ++$orphaned] = $val;
            }
        }
    }
    // discard invalid, theme-specific widgets from sidebars
    $shown_widgets = array();
    foreach ($_sidebars_widgets as $sidebar => $widgets) {
        if (!is_array($widgets)) {
            continue;
        }
        $_widgets = array();
        foreach ($widgets as $widget) {
            if (isset($wp_registered_widgets[$widget])) {
                $_widgets[] = $widget;
            }
        }
        $_sidebars_widgets[$sidebar] = $_widgets;
        $shown_widgets = array_merge($shown_widgets, $_widgets);
    }
    $sidebars_widgets = $_sidebars_widgets;
    unset($_sidebars_widgets, $_widgets);
    // find hidden/lost multi-widget instances
    $lost_widgets = array();
    foreach ($wp_registered_widgets as $key => $val) {
        if (in_array($key, $shown_widgets, true)) {
            continue;
        }
        $number = preg_replace('/.+?-([0-9]+)$/', '$1', $key);
        if (2 > (int) $number) {
            continue;
        }
        $lost_widgets[] = $key;
    }
    $sidebars_widgets['wp_inactive_widgets'] = array_merge($lost_widgets, (array) $sidebars_widgets['wp_inactive_widgets']);
    wp_set_sidebars_widgets($sidebars_widgets);
    return $sidebars_widgets;
}
开发者ID:CarterNelms,项目名称:www.engineeredcomfort.net,代码行数:82,代码来源:widgets.php

示例15: ob_start

        ob_start();
        call_user_func_array($control['callback'], $control['params']);
        ob_end_clean();
        break;
    }
    $sidebars_widgets[$sidebar_id] = $sidebar;
    // Remove old position.
    if (!isset($_POST['delete_widget'])) {
        foreach ($sidebars_widgets as $key => $sb) {
            if (is_array($sb)) {
                $sidebars_widgets[$key] = array_diff($sb, array($widget_id));
            }
        }
        array_splice($sidebars_widgets[$sidebar_id], $position, 0, $widget_id);
    }
    wp_set_sidebars_widgets($sidebars_widgets);
    wp_redirect(admin_url('widgets.php?message=0'));
    exit;
}
// Output the widget form without js
if (isset($_GET['editwidget']) && $_GET['editwidget']) {
    $widget_id = $_GET['editwidget'];
    if (isset($_GET['addnew'])) {
        // Default to the first sidebar
        $keys = array_keys($wp_registered_sidebars);
        $sidebar = array_shift($keys);
        if (isset($_GET['base']) && isset($_GET['num'])) {
            // multi-widget
            // Copy minimal info from an existing instance of this widget to a new instance
            foreach ($wp_registered_widget_controls as $control) {
                if ($_GET['base'] === $control['id_base']) {
开发者ID:luskyj89,项目名称:mt-wordpress,代码行数:31,代码来源:widgets.php


注:本文中的wp_set_sidebars_widgets函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。