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


PHP switch_to_blog函数代码示例

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


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

示例1: uninstall

 static function uninstall()
 {
     global $wpdb;
     if (is_multisite()) {
         // Cleanup Network install
         foreach (wp_get_sites(array('limit' => apply_filters('gadwp_sites_limit', 100))) as $blog) {
             switch_to_blog($blog['blog_id']);
             $sqlquery = $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_gadash%%'");
             $sqlquery = $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_timeout_gadash%%'");
             $sqlquery = $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_ga_dash%%'");
             $sqlquery = $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_timeout_ga_dash%%'");
             delete_option('gadash_options');
             delete_transient('ga_dash_lasterror');
             delete_transient('ga_dash_refresh_token');
             delete_transient('ga_dash_gapi_errors');
             restore_current_blog();
         }
         delete_site_option('gadash_network_options');
         delete_site_transient('ga_dash_refresh_token');
     } else {
         // Cleanup Single install
         $sqlquery = $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_gadash%%'");
         $sqlquery = $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_timeout_gadash%%'");
         $sqlquery = $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_ga_dash%%'");
         $sqlquery = $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_timeout_ga_dash%%'");
         delete_option('gadash_options');
         delete_transient('ga_dash_lasterror');
         delete_transient('ga_dash_refresh_token');
         delete_transient('ga_dash_gapi_errors');
     }
 }
开发者ID:nickhype,项目名称:HackeyWalk-site-backup,代码行数:31,代码来源:uninstall.php

示例2: ajaxsearchpro_priorities_get_posts

function ajaxsearchpro_priorities_get_posts()
{
    global $wpdb;
    parse_str($_POST['options'], $o);
    if (isset($wpdb->base_prefix)) {
        $_prefix = $wpdb->base_prefix;
    } else {
        $_prefix = $wpdb->prefix;
    }
    $w_post_type = '';
    $w_filter = '';
    $w_limit = (int) $o['p_asp_limit'];
    if (isset($o['blog_id']) && $o['blog_id'] != 0 && is_multisite()) {
        switch_to_blog($o['p_asp_blog']);
    }
    if ($o['p_asp_filter'] != '') {
        $w_filter = "AND {$wpdb->posts}.post_title LIKE '%" . $o['p_asp_filter'] . "%'";
    }
    if ($o['p_asp_post_type'] != 'all') {
        $w_post_type = "AND {$wpdb->posts}.post_type = '" . $o['p_asp_post_type'] . "'";
    }
    $querystr = "\r\n    \t\tSELECT\r\n          {$wpdb->posts}.post_title as title,\r\n          {$wpdb->posts}.ID as id,\r\n          {$wpdb->posts}.post_date as date,\r\n          {$wpdb->users}.user_nicename as author,\r\n          {$wpdb->posts}.post_type as post_type,\r\n          CASE WHEN " . $_prefix . "ajaxsearchpro_priorities.priority IS NULL\r\n                   THEN 100\r\n                   ELSE " . $_prefix . "ajaxsearchpro_priorities.priority\r\n          END AS priority\r\n    \t\tFROM {$wpdb->posts}\r\n        LEFT JOIN {$wpdb->users} ON {$wpdb->users}.ID = {$wpdb->posts}.post_author\r\n        LEFT JOIN " . $_prefix . "ajaxsearchpro_priorities ON (" . $_prefix . "ajaxsearchpro_priorities.post_id = {$wpdb->posts}.ID AND " . $_prefix . "ajaxsearchpro_priorities.blog_id = " . get_current_blog_id() . ")\r\n    \tWHERE\r\n          {$wpdb->posts}.ID>0 AND\r\n          {$wpdb->posts}.post_status IN ('publish', 'pending') AND\r\n          {$wpdb->posts}.post_type NOT IN ('revision', 'attachment')\r\n          {$w_post_type}\r\n          {$w_filter}\r\n        GROUP BY\r\n          {$wpdb->posts}.ID\r\n        ORDER BY " . $o['p_asp_ordering'] . "\r\n        LIMIT {$w_limit}";
    echo "!!PASPSTART!!" . json_encode($wpdb->get_results($querystr, OBJECT)) . '!!PASPEND!!';
    if (is_multisite()) {
        restore_current_blog();
    }
    die;
}
开发者ID:Artgorae,项目名称:wp-artgorae,代码行数:28,代码来源:admin-ajax.php

示例3: widget

 /**
  * load widget
  *
  * @name    widget
  * @author  Cleber Santos <oclebersantos@gmail.com>
  * @since   2014-10-27
  * @updated 2014-10-27
  * @param   array $args - widget structure
  * @param   array $instance - widget data
  * @return  void
  */
 function widget($args, $instance)
 {
     global $wpdb, $post;
     $blog_id = !empty($instance['blog']) ? $instance['blog'] : 1;
     if (function_exists('switch_to_blog')) {
         switch_to_blog($blog_id);
     }
     // pega o link do blog
     $blog_url = get_bloginfo('url');
     print $args['before_widget'];
     if (!empty($instance['title'])) {
         print $args['before_head'];
         print "<a href='{$blog_url}' title='click para ver todas as tags'>" . $args['before_title'] . $instance['title'] . $args['after_title'] . "</a>";
         print $args['after_head'];
     }
     print $args['before_body'];
     if (function_exists('wp_tag_cloud')) {
         $tags = wp_tag_cloud('format=array&smallest=8&largest=25');
         // remove /blog/ do link
         foreach ($tags as $tag) {
             $tag = str_replace('/blog/', '/', $tag);
             echo $tag;
         }
     }
     print $args['after_body'];
     print $args['after_widget'];
     if (function_exists('restore_current_blog')) {
         restore_current_blog();
     }
 }
开发者ID:CoordCulturaDigital-Minc,项目名称:cdigital2014,代码行数:41,代码来源:widget-global-tags.php

示例4: get_blogs

 /**
  * Returns an array of all sites in the current network.
  * The array index is the blog-ID and the array value the blog title.
  *
  * @since  1.0.0
  * @param  bool $only_public By default only public sites are returned.
  * @return array
  */
 public static function get_blogs($only_public = true)
 {
     static $List = array();
     $key = $only_public ? 'public' : 'all';
     if (!isset($List['_cache'])) {
         $List['_cache'] = array();
     }
     if (!isset($List[$key])) {
         $args = array('limit' => 0, 'public' => true, 'spam' => false, 'deleted' => false);
         if ($only_public) {
             $args['archived'] = false;
             $args['mature'] = false;
         }
         $sites = wp_get_sites($args);
         $List[$key] = array();
         foreach ($sites as $site_data) {
             $blog_id = $site_data['blog_id'];
             if (isset($List['_cache'][$blog_id])) {
                 $title = $List['_cache'][$blog_id];
             } else {
                 switch_to_blog($blog_id);
                 $title = get_bloginfo('title');
                 $List['_cache'][$blog_id] = $title;
                 restore_current_blog();
             }
             $List[$key][$blog_id] = $title;
         }
     }
     return $List[$key];
 }
开发者ID:nayabbukhari,项目名称:circulocristiano,代码行数:38,代码来源:class-ms-helper-settings.php

示例5: propagate_default_global_css

 /**
  * insert default CSS into option
  */
 public static function propagate_default_global_css($networkwide = false)
 {
     $css = self::get_default_global_css();
     if (function_exists('is_multisite') && is_multisite() && $networkwide) {
         //do for each existing site
         global $wpdb;
         $old_blog = $wpdb->blogid;
         // Get all blog ids and create tables
         $blogids = $wpdb->get_col("SELECT blog_id FROM " . $wpdb->blogs);
         foreach ($blogids as $blog_id) {
             switch_to_blog($blog_id);
             if (get_option('tp_eg_custom_css_imported', 'false') == 'true') {
                 continue;
             }
             update_option('tp_eg_custom_css_imported', 'true');
             self::set_global_css_styles($css);
         }
         switch_to_blog($old_blog);
         //go back to correct blog
     } else {
         if (get_option('tp_eg_custom_css_imported', 'false') == 'false') {
             update_option('tp_eg_custom_css_imported', 'true');
             self::set_global_css_styles($css);
         }
     }
 }
开发者ID:Lumbe,项目名称:dev_servus,代码行数:29,代码来源:global-css.class.php

示例6: run_installer

 static function run_installer()
 {
     global $wpdb;
     if (function_exists('is_multisite') && is_multisite()) {
         // check if it is a network activation - if so, run the activation function for each blog id
         if (isset($_GET['networkwide']) && $_GET['networkwide'] == 1) {
             $old_blog = $wpdb->blogid;
             // Get all blog ids
             $blogids = $wpdb->get_col("SELECT blog_id FROM {$wpdb->blogs}");
             foreach ($blogids as $blog_id) {
                 switch_to_blog($blog_id);
                 AIOWPSecurity_Installer::create_db_tables();
                 AIOWPSecurity_Configure_Settings::add_option_values();
             }
             AIOWPSecurity_Installer::create_db_backup_dir();
             //Create a backup dir in the WP uploads directory
             switch_to_blog($old_blog);
             return;
         }
     }
     AIOWPSecurity_Installer::create_db_tables();
     AIOWPSecurity_Configure_Settings::add_option_values();
     AIOWPSecurity_Installer::create_db_backup_dir();
     //Create a backup dir in the WP uploads directory
     AIOWPSecurity_Installer::miscellaneous_tasks();
 }
开发者ID:yarylo,项目名称:cerkva.pp.ua,代码行数:26,代码来源:wp-security-installer.php

示例7: liquidizer_table_uninstall

function liquidizer_table_uninstall()
{
    if (!current_user_can('activate_plugins')) {
        return;
    }
    check_admin_referer('bulk-plugins');
    if (__FILE__ != WP_UNINSTALL_PLUGIN) {
        return;
    }
    if (!is_multisite()) {
        delete_option('liquidizer_lite_wp_table');
        delete_option('liquidizer_lite_wp_which_table_element');
        delete_option('liquidizer_lite_wp_table_width');
    } else {
        global $wpdb;
        $blog_ids = $wpdb->get_col("SELECT blog_id FROM {$wpdb->blogs}");
        $original_blog_id = get_current_blog_id();
        foreach ($blog_ids as $blog_id) {
            switch_to_blog($blog_id);
            delete_option('liquidizer_lite_wp_table');
            delete_option('liquidizer_lite_wp_which_table_element');
            delete_option('liquidizer_lite_wp_table_width');
        }
        switch_to_blog($original_blog_id);
    }
}
开发者ID:poderomedia,项目名称:narcodata-wp,代码行数:26,代码来源:uninstall.php

示例8: jquery_install_site

function jquery_install_site($site, $user)
{
    $sites = jquery_sites();
    $details = $sites[$site];
    if (strpos($site, '/')) {
        list($domain, $path) = explode('/', $site, 2);
        $path = '/' . trim($path, '/') . '/';
    } else {
        $domain = $site;
        $path = '/';
    }
    $default_options = jquery_default_site_options();
    $default_options['admin_email'] = $user->user_email;
    if (1 !== $details['blog_id']) {
        $blog_id = insert_blog(JQUERY_STAGING_PREFIX . $domain, $path, 1);
        if ($blog_id != $details['blog_id']) {
            wp_die("Something went very wrong when trying to install {$domain} as site {$blog_id}-{$details['blog_id']}. Find nacin.");
        }
        switch_to_blog($blog_id);
        install_blog($blog_id, $details['options']['blogname']);
        add_user_to_blog($blog_id, $user->ID, 'administrator');
    }
    $options = array_merge($default_options, $details['options']);
    foreach ($options as $option => $value) {
        update_option($option, $value);
    }
    delete_option('rewrite_rules');
    restore_current_blog();
}
开发者ID:hryniu555,项目名称:jquery-wp-content,代码行数:29,代码来源:install.php

示例9: test_wp_idea_stream_users_signup_child_blog

 /**
  * @group signup
  */
 public function test_wp_idea_stream_users_signup_child_blog()
 {
     if (!is_multisite()) {
         $this->markTestSkipped(__METHOD__ . ' is a multisite-only test.');
     }
     if (function_exists('buddypress')) {
         $this->markTestSkipped('wp_idea_stream_users_signup_user() is not used when BuddyPress is activated.');
     }
     $registration = get_site_option('registration');
     update_site_option('registration', 'user');
     $b = $this->factory->blog->create();
     switch_to_blog($b);
     add_filter('wp_idea_stream_allow_signups', '__return_true');
     $this->post_signup_form(array('user_login' => 'barfoo', 'user_email' => 'barfoo@mail.com'));
     wp_idea_stream_users_signup_user(false);
     remove_filter('wp_idea_stream_allow_signups', '__return_true');
     preg_match('/<(.+?)>/', $GLOBALS['phpmailer']->mock_sent[0]['body'], $match);
     $activate_url = explode('?', $match[1]);
     $this->assertSame(wp_login_url(), $activate_url[0], 'The activate url must be the one of the child blog');
     $user = get_user_by('email', 'barfoo@mail.com');
     $this->assertTrue(!empty($user->ID), 'The user must be created');
     restore_current_blog();
     update_site_option('registration', $registration);
     global $wpdb;
     $signup_data = $wpdb->get_row("SELECT activated, meta FROM {$wpdb->signups} WHERE user_email = 'barfoo@mail.com' AND active = 1");
     $this->assertTrue(!empty($signup_data->activated), 'The signup must be activated');
     $this->assertEquals(array('add_to_blog' => $b, 'new_role' => 'subscriber'), maybe_unserialize($signup_data->meta));
 }
开发者ID:BoweFrankema,项目名称:wp-idea-stream,代码行数:31,代码来源:functions.php

示例10: td

 /**
  * Table body
  * @param string $column_name
  * @param int $item_id
  */
 public function td($column_name, $item_id)
 {
     if ('mslscol' == $column_name) {
         $blogs = MslsBlogCollection::instance()->get();
         if ($blogs) {
             $mydata = MslsOptions::create($item_id);
             foreach ($blogs as $blog) {
                 switch_to_blog($blog->userblog_id);
                 $language = $blog->get_language();
                 $icon = MslsAdminIcon::create();
                 $icon->set_language($language);
                 if ($mydata->has_value($language)) {
                     $flag_url = MslsOptions::instance()->get_url('images/link_edit.png');
                     $icon->set_href($mydata->{$language})->set_src($flag_url);
                 } else {
                     $flag_url = MslsOptions::instance()->get_url('images/link_add.png');
                     $icon->set_src($flag_url);
                 }
                 echo $icon;
                 // xss ok
                 restore_current_blog();
             }
         }
     }
 }
开发者ID:laishidua,项目名称:laishidua.com,代码行数:30,代码来源:MslsCustomColumn.php

示例11: scoper_requested_file_rule_expire

function scoper_requested_file_rule_expire()
{
    if (scoper_get_option('file_filtering')) {
        if ($key = scoper_get_option('file_filtering_regen_key')) {
            if (!empty($_GET['key']) && $key == $_GET['key']) {
                // user must store their own non-null key before this will work
                global $wpdb;
                if (IS_MU_RS) {
                    $blog_ids = scoper_get_col("SELECT blog_id FROM {$wpdb->blogs} ORDER BY blog_id");
                    $orig_blog_id = $GLOBALS['blog_id'];
                    foreach ($blog_ids as $id) {
                        switch_to_blog($id);
                        scoper_query("DELETE FROM {$wpdb->postmeta} WHERE meta_key = '_rs_file_key'");
                    }
                } else {
                    scoper_query("DELETE FROM {$wpdb->postmeta} WHERE meta_key = '_rs_file_key'");
                }
                scoper_expire_file_rules();
                if (IS_MU_RS) {
                    _e("File attachment access keys and rewrite rules will be regenerated for each site at next access.", 'scoper');
                } else {
                    _e("File attachment access keys and rewrite rules were regenerated.", 'scoper');
                }
            } else {
                _e('Invalid argument.', 'scoper');
            }
        } else {
            _e('Please configure File Filtering options!', 'scoper');
        }
    } else {
        _e('The function is disabled.', 'scoper');
    }
    exit(0);
}
开发者ID:joostrijneveld,项目名称:cscircles-wp-content,代码行数:34,代码来源:attachment-helper_rs.php

示例12: _book

 /**
  * Create and switch to a new test book
  */
 private function _book()
 {
     $blog_id = $this->factory->blog->create();
     switch_to_blog($blog_id);
     switch_theme('donham');
     // Pick a theme with some built-in $supported_languages
 }
开发者ID:JackDougherty,项目名称:pressbooks,代码行数:10,代码来源:test-globaltypography.php

示例13: ajax_add_multisite_page

 public function ajax_add_multisite_page()
 {
     switch_to_blog($_POST['blogId']);
     $post = get_post($_POST['ids'][0]);
     $url = get_permalink($post->ID);
     restore_current_blog();
     $item_ids = wp_update_nav_menu_item(0, 0, array('menu-item-title' => esc_attr($post->post_title), 'menu-item-type' => 'custom', 'menu-item-url' => $url));
     foreach ((array) $item_ids as $menu_item_id) {
         $menu_obj = get_post($menu_item_id);
         if (!empty($menu_obj->ID)) {
             $menu_obj = wp_setup_nav_menu_item($menu_obj);
             // don't show "(pending)" in ajax-added items
             $menu_obj->label = $menu_obj->title;
             $menu_items[] = $menu_obj;
         }
     }
     // Needed to get the Walker up and running
     require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
     // This gets the HTML to returns it to the menu
     if (!empty($menu_items)) {
         $args = array('after' => '', 'before' => '', 'link_after' => '', 'link_before' => '', 'walker' => new Walker_Nav_Menu_Edit());
         echo walk_nav_menu_tree($menu_items, 0, (object) $args);
     }
     exit;
 }
开发者ID:ryan2407,项目名称:Vision,代码行数:25,代码来源:index.php

示例14: wpmuNewBlog

 /**
  * Runs activation function and sets up default WP options for new blog,
  * a.k.a. when a registered user creates a new blog
  *
  * @param int $blog_id
  * @param int $user_id
  *
  * @see add_action( 'wpmu_new_blog', ... )
  */
 function wpmuNewBlog($blog_id, $user_id)
 {
     $this->blog_id = (int) $blog_id;
     $this->user_id = (int) $user_id;
     switch_to_blog($this->blog_id);
     if (!$this->isBookSetup()) {
         $this->wpmuActivate();
         array_walk($this->opts, function ($v, $k) {
             if (empty($v)) {
                 delete_option($k);
             } else {
                 update_option($k, $v);
             }
         });
         wp_cache_flush();
     }
     // Set current metadata version to skip redundant upgrade routines
     update_option('pressbooks_metadata_version', \Pressbooks\Metadata::$currentVersion);
     flush_rewrite_rules(false);
     do_action('pressbooks_new_blog');
     restore_current_blog();
     if (is_user_logged_in()) {
         (new \Pressbooks\Catalog())->deleteCache();
         \Pressbooks\Redirect\location(get_admin_url($this->blog_id));
     }
 }
开发者ID:pressbooks,项目名称:pressbooks,代码行数:35,代码来源:class-pb-activation.php

示例15: change

 /**
  * Change the label of the blog
  */
 function change($blogs)
 {
     if (0 == count($blogs)) {
         return $blogs;
     }
     foreach ($blogs as &$blog) {
         $hash = md5(time());
         if ($hash === get_blog_option($blog->userblog_id, 'admin_label', $hash)) {
             /**
              * Allow superadmins to setup an admin label
              */
             switch_to_blog($blog->userblog_id);
             update_option('admin_label', '');
             restore_current_blog();
         } else {
             if ($admin_label = get_blog_option($blog->userblog_id, 'admin_label')) {
                 /**
                  * Set the admin label
                  */
                 $blog->blogname = $admin_label;
             }
         }
     }
     return $blogs;
 }
开发者ID:trendwerk,项目名称:multisite-labels,代码行数:28,代码来源:multisite-labels.php


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