mtv\wp\models\SiteCollection::for_user PHP Method

for_user() public static method

public static for_user ( $kwargs )
    public static function for_user($kwargs)
    {
        if (isset($kwargs['user_id'])) {
            $userid = $kwargs['user_id'];
        } else {
            if (isset($kwargs['user_email'])) {
                $userid = get_user_id_from_string($kwargs['user_email']);
                if ($userid === 0) {
                    throw new JsonableException(__("I don't know that email address", 'mtv'));
                }
            } else {
                if (isset($kwargs['user_login'])) {
                    $userid = get_user_id_from_string($kwargs['user_login']);
                    if ($userid === 0) {
                        throw new JsonableException(__("I don't know that username", 'mtv'));
                    }
                } else {
                    throw new NotImplementedException();
                }
            }
        }
        $class = get_called_class();
        $blogdata = get_blogs_of_user($userid);
        $sites = new $class();
        if (!empty($blogdata)) {
            foreach ($blogdata as $b) {
                $site = new static::$model();
                $site->reload($b);
                $sites->add($site);
            }
        }
        return $sites;
    }

Usage Example

Example #1
0
 /**
  * sites
  * Returns a SiteCollection containing all the sites this user is connected to.
  **/
 public function sites()
 {
     if (empty($this->_sites)) {
         $this->_sites = SiteCollection::for_user(array('user_id' => $this->id));
     }
     return $this->_sites;
 }
SiteCollection