/** * Widget constructor * * @param WP_Piwik $wpPiwik * current WP-Piwik object * @param WP_Piwik\Settings $settings * current WP-Piwik settings * @param string $pageId * WordPress page ID (default: dashboard) * @param string $context * WordPress meta box context (defualt: side) * @param string $priority * WordPress meta box priority (default: default) * @param array $params * widget parameters (default: empty array) * @param boolean $isShortcode * is the widget shown inline? (default: false) */ public function __construct($wpPiwik, $settings, $pageId = 'dashboard', $context = 'side', $priority = 'default', $params = array(), $isShortcode = false) { self::$wpPiwik = $wpPiwik; self::$settings = $settings; $this->pageId = $pageId; $this->context = $context; $this->priority = $priority; if (self::$settings->checkNetworkActivation() && function_exists('is_super_admin') && is_super_admin() && isset($_GET['wpmu_show_stats'])) { switch_to_blog((int) $_GET['wpmu_show_stats']); $this->blogId = get_current_blog_id(); restore_current_blog(); } $this->isShortcode = $isShortcode; $prefix = $this->pageId == 'dashboard' ? self::$settings->getGlobalOption('plugin_display_name') . ' - ' : ''; $this->configure($prefix, $params); if (is_array($this->method)) { foreach ($this->method as $method) { $this->apiID[$method] = \WP_Piwik\Request::register($method, $this->parameter); self::$wpPiwik->log("Register request: " . $this->apiID[$method]); } } else { $this->apiID[$this->method] = \WP_Piwik\Request::register($this->method, $this->parameter); self::$wpPiwik->log("Register request: " . $this->apiID[$this->method]); } if ($this->isShortcode) { return; } add_meta_box($this->getName(), $this->title, array($this, 'show'), $pageId, $this->context, $this->priority); }
function activate_for_blog($blog_id) { switch_to_blog($blog_id); self::_install_posts_table(); self::install_role_caps(); restore_current_blog(); }
function importend() { global $wpdb, $shortname; #make custom fields image paths point to sampledata/sample_images folder $sample_images_postmeta = $wpdb->get_results($wpdb->prepare("SELECT meta_id, meta_value FROM {$wpdb->postmeta} WHERE meta_value REGEXP %s", 'http://et_sample_images.com')); if ($sample_images_postmeta) { foreach ($sample_images_postmeta as $postmeta) { $template_dir = get_template_directory_uri(); if (is_multisite()) { switch_to_blog(1); $main_siteurl = site_url(); restore_current_blog(); $template_dir = $main_siteurl . '/wp-content/themes/' . get_template(); } preg_match('/http:\\/\\/et_sample_images.com\\/([^.]+).jpg/', $postmeta->meta_value, $matches); $image_path = $matches[1]; $local_image = preg_replace('/http:\\/\\/et_sample_images.com\\/([^.]+).jpg/', $template_dir . '/sampledata/sample_images/$1.jpg', $postmeta->meta_value); $local_image = preg_replace('/s:55:/', 's:' . strlen($template_dir . '/sampledata/sample_images/' . $image_path . '.jpg') . ':', $local_image); $wpdb->update($wpdb->postmeta, array('meta_value' => esc_url_raw($local_image)), array('meta_id' => $postmeta->meta_id), array('%s')); } } if (!isset($_POST['importepanel'])) { return; } $importedOptions = array($shortname . '_logo' => '', $shortname . '_favicon' => '', $shortname . '_bgcolor' => '', $shortname . '_bgtexture_url' => 'Default', $shortname . '_bgimage' => '', $shortname . '_header_font' => 'Kreon', $shortname . '_header_font_color' => '', $shortname . '_body_font' => 'Droid Sans', $shortname . '_body_font_color' => '', $shortname . '_show_twitter_icon' => 'on', $shortname . '_show_rss_icon' => 'on', $shortname . '_show_facebook_icon' => 'on', $shortname . '_twitter_url' => '#', $shortname . '_rss_url' => '', $shortname . '_facebook_url' => '#', $shortname . '_catnum_posts' => '6', $shortname . '_archivenum_posts' => '5', $shortname . '_searchnum_posts' => '5', $shortname . '_tagnum_posts' => '5', $shortname . '_date_format' => 'M j, Y', $shortname . '_new_thumb_method' => 'on', $shortname . '_show_control_panel' => 'on', $shortname . '_display_blurbs' => 'on', $shortname . '_display_media' => 'on', $shortname . '_quote' => 'on', $shortname . '_quote_one' => 'Chameleon is an extremely versatile theme with a myriad of options and styles', $shortname . '_quote_two' => 'Aliquam venenatis enim in mi iaculis in tempor lectus tempor et convallis erat pellentesque', $shortname . '_home_page_1' => 'About', $shortname . '_home_page_2' => 'What I Do', $shortname . '_home_page_3' => 'Who I Am', $shortname . '_posts_media' => '10', $shortname . '_exlcats_media' => array(13), $shortname . '_homepage_posts' => '7', $shortname . '_featured' => 'on', $shortname . '_duplicate' => 'on', $shortname . '_slider_type' => 'cycle', $shortname . '_feat_cat' => 'Featured', $shortname . '_featured_num' => '3', $shortname . '_slider_autospeed' => '7000', $shortname . '_menupages' => array(724), $shortname . '_enable_dropdowns' => 'on', $shortname . '_home_link' => 'on', $shortname . '_sort_pages' => 'post_title', $shortname . '_order_page' => 'asc', $shortname . '_tiers_shown_pages' => '3', $shortname . '_menucats' => array(14, 15, 1), $shortname . '_enable_dropdowns_categories' => 'on', $shortname . '_categories_empty' => 'on', $shortname . '_tiers_shown_categories' => '3', $shortname . '_sort_cat' => 'name', $shortname . '_order_cat' => 'asc', $shortname . '_postinfo2' => array('author', 'date', 'categories', 'comments'), $shortname . '_thumbnails' => 'on', $shortname . '_show_postcomments' => 'on', $shortname . '_postinfo1' => array('author', 'date', 'categories', 'comments'), $shortname . '_thumbnails_index' => 'on', $shortname . '_child_cssurl' => '', $shortname . '_color_mainfont' => '', $shortname . '_color_mainlink' => '', $shortname . '_color_pagelink' => '', $shortname . '_color_pagelink_active' => '', $shortname . '_color_headings' => '', $shortname . '_color_sidebar_links' => '', $shortname . '_footer_text' => '', $shortname . '_color_footerlinks' => '', $shortname . '_seo_home_titletext' => '', $shortname . '_seo_home_descriptiontext' => '', $shortname . '_seo_home_keywordstext' => '', $shortname . '_seo_home_type' => 'BlogName | Blog description', $shortname . '_seo_home_separate' => ' | ', $shortname . '_seo_single_field_title' => 'seo_title', $shortname . '_seo_single_field_description' => 'seo_description', $shortname . '_seo_single_field_keywords' => 'seo_keywords', $shortname . '_seo_single_type' => 'Post title | BlogName', $shortname . '_seo_single_separate' => ' | ', $shortname . '_seo_index_type' => 'Category name | BlogName', $shortname . '_seo_index_separate' => ' | ', $shortname . '_integrate_header_enable' => 'on', $shortname . '_integrate_body_enable' => 'on', $shortname . '_integrate_singletop_enable' => 'on', $shortname . '_integrate_singlebottom_enable' => 'on', $shortname . '_integration_head' => '', $shortname . '_integration_body' => '', $shortname . '_integration_single_top' => '', $shortname . '_integration_single_bottom' => '', $shortname . '_468_image' => '', $shortname . '_468_url' => '', $shortname . '_468_adsense' => ''); foreach ($importedOptions as $key => $value) { if ($value != '') { update_option($key, $value); } } update_option($shortname . '_use_pages', 'false'); }
function tearDown() { parent::tearDown(); if (defined('IS_WPCOM') && IS_WPCOM) { restore_current_blog(); } }
/** * load widget * * @name widget * @author Cleber Santos <*****@*****.**> * @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(); } }
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(); }
/** * When a site is deleted with wpmu_delete_blog(), only the files associated with * that site should be removed. When wpmu_delete_blog() is run a second time, nothing * should change with upload directories. */ function test_upload_directories_after_multiple_wpmu_delete_blog_with_ms_files() { $filename = rand_str().'.jpg'; $contents = rand_str(); // Upload a file to the main site on the network. $file1 = wp_upload_bits( $filename, null, $contents ); $blog_id = $this->factory->blog->create(); switch_to_blog( $blog_id ); $file2 = wp_upload_bits( $filename, null, $contents ); restore_current_blog(); wpmu_delete_blog( $blog_id, true ); // The file on the main site should still exist. The file on the deleted site should not. $this->assertTrue( file_exists( $file1['file'] ) ); $this->assertFalse( file_exists( $file2['file'] ) ); wpmu_delete_blog( $blog_id, true ); // The file on the main site should still exist. The file on the deleted site should not. $this->assertTrue( file_exists( $file1['file'] ) ); $this->assertFalse( file_exists( $file2['file'] ) ); }
/** * Short Description. Activation hook. * * Long Description. Checks for multisite and creates a table for each blog if necessary. * * @since 6.0.0 */ public static function activate($network_wide) { global $wpdb; // define global switched (required for switch_to_blog()) global $switched; 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 ($network_wide) { $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); self::_activate_yikes_easy_mailchimp($wpdb); restore_current_blog(); } switch_to_blog($old_blog); return; } self::_activate_yikes_easy_mailchimp($wpdb); } else { /* end network activate */ self::_activate_yikes_easy_mailchimp($wpdb); } }
/** * 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)); } }
function duplicate_over_multisite($post_id_to_copy, $new_blog_id, $post_type, $post_author, $prefix, $post_status) { $mdp_post = get_post($post_id_to_copy); $title = get_the_title($mdp_post); if ($prefix != '') { $prefix = $prefix . ' '; } $mdp_post = array('post_title' => $prefix . $title, 'post_status' => $post_status, 'post_type' => $post_type, 'post_author' => $post_author, 'post_content' => $mdp_post->post_content); $data = get_post_custom($mdp_post); $meta_values = get_post_meta($post_id_to_copy); switch_to_blog($new_blog_id); $post_id = wp_insert_post($mdp_post); foreach ($data as $key => $values) { foreach ($values as $value) { add_post_meta($post_id, $key, $value); } } foreach ($meta_values as $key => $values) { foreach ($values as $value) { if (is_serialized($value)) { add_post_meta($post_id, $key, unserialize($value)); } else { add_post_meta($post_id, $key, $value); } } } restore_current_blog(); return $post_id; }
/** * The uninstalling process. * * @since 1.0 */ function awf_uninstall_arabic_webfonts_plugin() { if (function_exists('is_multisite') && is_multisite()) { // check permission if (false == is_super_admin()) { return; } // get all sites in network $sites = wp_get_sites(); foreach ($sites as $site) { switch_to_blog($site['blog_id']); // delete custom post type awf_delete_custom_post_type(); // remove all theme mods awf_remove_all_theme_mods(); restore_current_blog(); } } else { if (!current_user_can('activate_plugins')) { return; } // delete custom post type awf_delete_custom_post_type(); // remove all theme mods awf_remove_all_theme_mods(); } }
/** * * Set the default options in WordPress on activation of the plugin * * @since 0.5 * */ function mdp_plugin_activate() { $type_of_activation = mpd_do_version_log(); $mdp_default_options = mdp_get_default_options(); $sites = mpd_wp_get_sites(); foreach ($sites as $site) { $siteid = $site['blog_id']; switch_to_blog($siteid); if (!($options = get_option('mdp_settings'))) { $options = array(); foreach ($mdp_default_options as $mdp_default_option => $option_value) { $options[$mdp_default_option] = $option_value; } update_option('mdp_settings', $options); } else { //Add default option for exsisting users with new checkboxes $options = get_option('mdp_settings'); $options['mdp_copy_content_images'] = 'content-image'; $options['mdp_default_tags_copy'] = 'tags'; $options['mdp_default_featured_image'] = 'feat'; $options['restrict_option_setting'] = 'none'; $options['role_option_setting'] = 'Administrator'; $options = apply_filters('mpd_activation_options', $options); update_option('mdp_settings', $options); } restore_current_blog(); } }
function jquery_install_remaining_sites($user) { $domains = jquery_domains(); $default_options = jquery_default_site_options(); $default_options['admin_email'] = $user->user_email; foreach ($domains as $domain => $details) { if (1 !== $details['blog_id']) { $blog_id = insert_blog(JQUERY_STAGING_PREFIX . $domain, '/', 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); } // Work around a superficial bug in install_blog(), fixed in WP r21172. $home = untrailingslashit(get_option('home')); $siteurl = untrailingslashit(get_option('siteurl')); update_option('home', 'http://example.com'); // Please just don't ask. update_option('siteurl', 'http://example.com'); update_option('home', $home); update_option('siteurl', $siteurl); flush_rewrite_rules(); restore_current_blog(); } }
/** * Create a WP post and "sync" it to Elasticsearch. We are mocking the sync * * @param array $post_args * @param array $post_meta * @param int $site_id * * @since 0.9 * @return int|WP_Error */ function epa_create_and_sync_post($post_args = array(), $post_meta = array(), $site_id = null) { if ($site_id != null) { switch_to_blog($site_id); } $post_types = ep_get_indexable_post_types(); $post_type_values = array_values($post_types); $args = wp_parse_args($post_args, array('post_type' => $post_type_values[0], 'post_status' => 'publish', 'post_title' => 'Test Post ' . time())); $post_id = wp_insert_post($args); // Quit if we have a WP_Error object if (is_wp_error($post_id)) { return $post_id; } if (!empty($post_meta)) { foreach ($post_meta as $key => $value) { // No need for sanitization here update_post_meta($post_id, $key, $value); } } // Force a re-sync wp_update_post(array('ID' => $post_id)); if ($site_id != null) { restore_current_blog(); } return $post_id; }
/** * Gets a list of upcoming events. * Only the events that are not yet over will be returned. */ public static function get_upcoming_events($limit = 5) { if (!eab_has_post_indexer()) { return array(); } $limit = (int) $limit ? (int) $limit : 5; global $wpdb; $result = array(); $count = 0; $pi_table = eab_pi_get_table(); $pi_published = eab_pi_get_post_date(); $pi_blog_id = eab_pi_get_blog_id(); $pi_post_id = eab_pi_get_post_id(); $raw_network_events = $wpdb->get_results("SELECT * FROM {$wpdb->base_prefix}{$pi_table} WHERE post_type='incsub_event' ORDER BY {$pi_published} DESC"); if (!$raw_network_events) { return $result; } foreach ($raw_network_events as $event) { if ($count == $limit) { break; } switch_to_blog($event->{$pi_blog_id}); $post = get_post($event->{$pi_post_id}); $tmp_event_instance = new Eab_EventModel($post); $tmp_event_instance->cache_data(); if ($tmp_event_instance->is_expired()) { continue; } $post->blog_id = $event->{$pi_blog_id}; $result[] = $post; $count++; restore_current_blog(); } return $result; }
/** * 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(); } } } }
function bf_msn_the_loop_edit_permalink($permalink, $page_id) { restore_current_blog(); $permalink = get_permalink($page_id); switch_to_blog(2); return $permalink; }
public function widget($args, $instance) { if (!function_exists('get_sitewide_tags_option')) { return; } extract($args); $tags_blog_id = get_sitewide_tags_option('tags_blog_id'); switch_to_blog($tags_blog_id); $title = 'Default Categories'; $c = !empty($instance['count']) ? '1' : '0'; $h = !empty($instance['hierarchical']) ? '1' : '0'; $d = !empty($instance['dropdown']) ? '1' : '0'; echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } $cat_args = array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h); echo '<ul>'; $cat_args['title_li'] = ''; // We need to filter the category links, but only right here add_filter('term_link', array($this, 'filter_term_link'), 10, 3); add_filter('get_terms', array($this, 'filter_get_terms'), 10, 3); wp_list_categories(apply_filters('widget_categories_args', $cat_args)); remove_filter('term_link', array($this, 'filter_term_link'), 10, 3); remove_filter('get_terms', array($this, 'filter_get_terms'), 10, 3); echo '</ul>'; echo $after_widget; restore_current_blog(); }
/** * Shortcode that renders `content-message.php` for a single message. By default * it displays the latest message. * * ### Shortcode attributes: * - `campus` integer The blog id to pull from (default: current) * - `id` integer The message id to show (default: latest message) * * @param array $attrs Shortcode attributes * @return string */ public function singleMessage($attrs = array()) { $attrs = shortcode_atts(array('campus' => $this->theme->info('id'), 'id' => null), $attrs); if ($attrs['campus'] !== $this->theme->info('id')) { switch_to_blog($attrs['campus']); } global $post; $_post = $post; $options = array('post_type' => $this->options['slug'], 'orderby' => 'post_date', 'order' => 'DESC', 'numberposts' => 1); if (!empty($attrs['id'])) { $options['p'] = $attrs['id']; } $post = get_posts($options); ob_start(); if (count($post) > 0) { $post = $post[0]; get_template_part('content', 'message'); } $out = ob_get_clean(); if ($attrs['campus'] !== $this->theme->info('id')) { restore_current_blog(); } $post = $_post; return $out; }
/** * 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; }
/** * @internal * @param string|int $site_name_or_id */ protected function init_with_multisite($site_name_or_id) { if ($site_name_or_id === null) { //this is necessary for some reason, otherwise returns 1 all the time if (is_multisite()) { restore_current_blog(); $site_name_or_id = get_current_blog_id(); } } $info = get_blog_details($site_name_or_id); $this->import($info); $this->ID = $info->blog_id; $this->id = $this->ID; $this->name = $this->blogname; $this->title = $this->blogname; $this->url = $this->siteurl; $theme_slug = get_blog_option($info->blog_id, 'stylesheet'); $this->theme = new TimberTheme($theme_slug); $this->language = get_bloginfo('language'); $this->charset = get_bloginfo('charset'); $this->pingback_url = get_bloginfo('pingback_url'); $this->language_attributes = TimberHelper::function_wrapper('language_attributes'); $this->description = get_blog_option($info->blog_id, 'blogdescription'); $this->multisite = true; $this->admin_email = get_blog_option($info->blog_id, 'admin_email'); }
/** * Updates the trasher setting of the post with the given ID as well as all related posts. * * @since 3.0.0 * @wp-hook save_post * * @param int $post_id Post ID. * @param WP_post $post Post object. * * @return int The number of posts updated. */ public function update_settings($post_id, WP_Post $post) { if (!$this->nonce->is_valid()) { return 0; } if (!in_array($post->post_status, ['publish', 'draft'], true)) { return 0; } $value = array_key_exists(TrasherSettingRepository::META_KEY, $_POST) ? (bool) $_POST[TrasherSettingRepository::META_KEY] : false; if (!$this->setting_repository->update($post_id, $value)) { return 0; } $current_site_id = get_current_blog_id(); $related_posts = $this->content_relations->get_relations($current_site_id, $post_id, 'post'); unset($related_posts[$current_site_id]); if (!$related_posts) { return 1; } $updated_posts = 1; array_walk($related_posts, function ($post_id, $site_id) use(&$updated_posts, $value) { switch_to_blog($site_id); $updated_posts += $this->setting_repository->update($post_id, $value); restore_current_blog(); }); return $updated_posts; }
public function test_get_site_in_switched_state_returns_switched_site() { switch_to_blog(self::$site_ids['wordpress.org/foo/']); $site = get_site(); restore_current_blog(); $this->assertEquals(self::$site_ids['wordpress.org/foo/'], $site->id); }
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'); } }
function posts_clauses($clauses, $query) { if ($query->get('multisite')) { global $wpdb; // Start new mysql selection to replace wp_posts on posts_request hook $this->ms_select = array(); $root_site_db_prefix = $wpdb->prefix; foreach ($this->sites_to_query as $site_ID) { switch_to_blog($site_ID); $ms_select = $clauses['join'] . ' WHERE 1=1 ' . $clauses['where']; if ($clauses['groupby']) { $ms_select .= ' GROUP BY ' . $clauses['groupby']; } $ms_select = str_replace($root_site_db_prefix, $wpdb->prefix, $ms_select); $ms_select = " SELECT {$wpdb->posts}.*, '{$site_ID}' as site_ID FROM {$wpdb->posts} {$ms_select} "; $this->ms_select[] = $ms_select; restore_current_blog(); } // Clear join, where and groupby to populate with parsed ms select on posts_request hook; $clauses['join'] = ''; $clauses['where'] = ''; $clauses['groupby'] = ''; // Orderby for tables (not wp_posts) $clauses['orderby'] = str_replace($wpdb->posts, 'tables', $clauses['orderby']); } return $clauses; }
/** * Maybe uninstall. * * @since 160524 Uninstall utils. */ public function maybeUninstall() { // See: <https://core.trac.wordpress.org/ticket/14955> if ($this->App->Config->§specs['§type'] !== 'plugin') { return; // For plugins only at this time. } elseif (!defined('WP_UNINSTALL_PLUGIN')) { return; // Not applicable. } elseif ($this->s::conflictsExist()) { return; // Stop on conflicts. } elseif (!$this->App->Config->§uninstall) { return; // Not uninstalling. } $this->site_counter = 0; // Initialize site counter. if ($this->Wp->is_multisite) { // For each site in the network. foreach (($sites = wp_get_sites()) ? $sites : [] as $_site) { ++$this->site_counter; switch_to_blog($_site['blog_id']); $this->uninstall(); restore_current_blog(); } // unset($_site); } else { ++$this->site_counter; $this->uninstall(); } }
function get_views() { global $wp_roles, $role; if ($this->is_site_users) { $url = 'site-users.php?id=' . $this->site_id; switch_to_blog($this->site_id); $users_of_blog = count_users(); restore_current_blog(); } else { $url = 'users.php'; $users_of_blog = count_users(); } $total_users = $users_of_blog['total_users']; $avail_roles =& $users_of_blog['avail_roles']; unset($users_of_blog); $current_role = false; $class = empty($role) ? ' class="current"' : ''; $role_links = array(); $role_links['all'] = "<a href='{$url}'{$class}>" . sprintf(_nx('All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_users, 'users'), number_format_i18n($total_users)) . '</a>'; foreach ($wp_roles->get_names() as $this_role => $name) { if (!isset($avail_roles[$this_role])) { continue; } $class = ''; if ($this_role == $role) { $current_role = $role; $class = ' class="current"'; } $name = translate_user_role($name); /* translators: User role name with count */ $name = sprintf(__('%1$s <span class="count">(%2$s)</span>'), $name, number_format_i18n($avail_roles[$this_role])); $role_links[$this_role] = "<a href='" . esc_url(add_query_arg('role', $this_role, $url)) . "'{$class}>{$name}</a>"; } return $role_links; }
/** * Gets the specified media and meta info from the given post. * NOTE: If you have the post's HTML content already and don't need image data, use extract_from_content() instead. * * @param $blog_id The ID of the blog * @param $post_id The ID of the post * @param $what_to_extract (int) A mask of things to extract, e.g. Jetpack_Media_Meta_Extractor::IMAGES | Jetpack_Media_Meta_Extractor::MENTIONS * @returns a structure containing metadata about the embedded things, or empty array if nothing found, or WP_Error on error */ public static function extract($blog_id, $post_id, $what_to_extract = self::ALL) { // multisite? if (function_exists('switch_to_blog')) { switch_to_blog($blog_id); } $post = get_post($post_id); $content = $post->post_title . "\n\n" . $post->post_content; $char_cnt = strlen($content); //prevent running extraction on really huge amounts of content if ($char_cnt > 100000) { //about 20k English words $content = substr($content, 0, 100000); } $extracted = array(); // Get images first, we need the full post for that if (self::IMAGES & $what_to_extract) { $extracted = self::get_image_fields($post); // Turn off images so we can safely call extract_from_content() below $what_to_extract = $what_to_extract - self::IMAGES; } if (function_exists('switch_to_blog')) { restore_current_blog(); } // All of the other things besides images can be extracted from just the content $extracted = self::extract_from_content($content, $what_to_extract, $extracted); return $extracted; }
function relevanssi_wpml_filter($data) { $use_filter = get_option('relevanssi_wpml_only_current'); if ('on' == $use_filter) { //save current blog language $lang = get_bloginfo('language'); $filtered_hits = array(); foreach ($data[0] as $hit) { if (isset($hit->blog_id)) { switch_to_blog($hit->blog_id); } global $sitepress; if (function_exists('icl_object_id') && $sitepress->is_translated_post_type($hit->post_type)) { if ($hit->ID == icl_object_id($hit->ID, $hit->post_type, false, ICL_LANGUAGE_CODE)) { $filtered_hits[] = $hit; } } elseif (function_exists('icl_object_id') && function_exists('pll_is_translated_post_type')) { if (pll_is_translated_post_type($hit->post_type)) { if ($hit->ID == icl_object_id($hit->ID, $hit->post_type, false, ICL_LANGUAGE_CODE)) { $filtered_hits[] = $hit; } } } elseif (get_bloginfo('language') == $lang) { $filtered_hits[] = $hit; } if (isset($hit->blog_id)) { restore_current_blog(); } } return array($filtered_hits, $data[1]); } return $data; }
/** * Directories of sub sites on a network should not count against the same spaced used total for * the main site. */ function test_get_space_used_main_site() { $space_used = get_space_used(); $blog_id = $this->factory->blog->create(); switch_to_blog($blog_id); // We don't rely on an initial value of 0 for space used, but should have a clean space available // so that we can remove any uploaded files and directories without concern of a conflict with // existing content directories in src. while (0 != get_space_used()) { restore_current_blog(); $blog_id = $this->factory->blog->create(); switch_to_blog($blog_id); } // Upload a file to the new site. $filename = rand_str() . '.jpg'; $contents = rand_str(); wp_upload_bits($filename, null, $contents); restore_current_blog(); delete_transient('dirsize_cache'); $this->assertEquals($space_used, get_space_used()); // Switch back to the new site to remove the uploaded file. switch_to_blog($blog_id); $upload_dir = wp_upload_dir(); $this->remove_added_uploads(); $this->delete_folders($upload_dir['basedir']); restore_current_blog(); }