Пример #1
0
 /**
  * @param array $args
  *
  * @return WPLib_User_Model_Base|null
  */
 static function make_new($args)
 {
     $user = null;
     if (!empty($args['user'])) {
         $user = $args['user'];
     }
     if (!is_null($user) && !is_a($user, 'WP_User')) {
         if (is_numeric($user)) {
             $user = get_user_by('id', $user);
         } else {
             if (false !== strpos($user, '@')) {
                 $user = get_user_by('email', $user);
             } else {
                 if (!($user = get_user_by('slug', $user))) {
                     $user = get_user_by('login', $user);
                 }
             }
         }
     }
     return $user ? WPLib_Users::make_user($user) : null;
 }
Пример #2
0
    /**
     * User's role name as found in the WP_User object.
     *
     * @param WP_User $wp_user
     * @return string|null
     */
    static function get_assigned_role_slug($wp_user)
    {
        if (!property_exists($wp_user, 'roles') || !is_array($wp_user->roles)) {
            $role_slug = null;
        } else {
            $role_slug = reset($wp_user->roles);
        }
        return $role_slug ? $role_slug : WPLib_Subscriber::ROLE;
    }
    /**
     * @param string $user_role
     *
     * @return bool
     */
    static function current_user_is($user_role)
    {
        /**
         * @var WP_User $current_user
         */
        $current_user = wp_get_current_user();
        return isset($current_user->roles) && is_array($current_user->roles) && in_array($user_role, $current_user->roles);
    }
}
WPLib_Users::on_load();
Пример #3
0
 /**
  * @param object $user
  * @return mixed|object
  */
 function set_user($user)
 {
     if (WPLib_Users::is_user($user)) {
         $this->_user = $user;
     }
 }