Amazon_S3_And_CloudFront::switch_to_blog PHP Method

switch_to_blog() public method

Helper to switch to a Multisite blog - If the site is MS - If the blog is not the current blog defined
public switch_to_blog ( integer | boolean $blog_id = false )
$blog_id integer | boolean
    public function switch_to_blog($blog_id = false)
    {
        if (!is_multisite()) {
            return;
        }
        if (!$blog_id) {
            $blog_id = defined('BLOG_ID_CURRENT_SITE') ? BLOG_ID_CURRENT_SITE : 1;
        }
        if ($blog_id !== get_current_blog_id()) {
            switch_to_blog($blog_id);
        }
    }

Usage Example

 /**
  * Purge URL from cache
  *
  * @param string   $url
  * @param bool|int $blog_id
  */
 public function purge_from_cache($url, $blog_id = false)
 {
     global $wpdb;
     if (false !== $blog_id) {
         $this->as3cf->switch_to_blog($blog_id);
     }
     // Purge postmeta cache
     $sql = $wpdb->prepare("\n \t\t\tDELETE FROM {$wpdb->postmeta}\n \t\t\tWHERE meta_key = %s\n \t\t\tAND meta_value LIKE %s;\n \t\t", 'amazonS3_cache', '%"' . $url . '"%');
     $wpdb->query($sql);
     // Purge option cache
     $sql = $wpdb->prepare("\n \t\t\tDELETE FROM {$wpdb->options}\n \t\t\tWHERE option_name = %s\n \t\t\tAND option_value LIKE %s;\n \t\t", 'amazonS3_cache', '%"' . $url . '"%');
     $wpdb->query($sql);
     if (false !== $blog_id) {
         $this->as3cf->restore_current_blog();
     }
 }
All Usage Examples Of Amazon_S3_And_CloudFront::switch_to_blog
Amazon_S3_And_CloudFront