Пример #1
0
 function pre_can_user($verdict, $args)
 {
     if (!class_exists('BP_Roles')) {
         require_once BACKPRESS_PATH . 'class.bp-roles.php';
     }
     if (!class_exists('BP_User')) {
         require_once BACKPRESS_PATH . 'class.bp-user.php';
     }
     $user = new BP_User($args['user_id']);
     // 78 = global.wordpress.org. Administrators on this site are considered global admins in GlotPress.
     if (!empty($user->ros_78_capabilities) && is_array($user->ros_78_capabilities) && !empty($user->ros_78_capabilities['administrator'])) {
         return true;
     }
     if ($args['action'] !== 'approve' || !in_array($args['object_type'], array('project|locale|set-slug', 'translation-set'))) {
         return false;
     }
     if (!($locale_slug = $this->get_locale_slug($args['object_type'], $args['object_id']))) {
         return false;
     }
     if (!($maybe_cap_key = $this->get_cap_key($locale_slug))) {
         return false;
     }
     $user->cap_key = $maybe_cap_key;
     $user->caps =& $user->{$user->cap_key};
     if (!is_array($user->caps)) {
         $user->caps = array();
     }
     $user->get_role_caps();
     foreach (array('administrator', 'editor', 'author', 'contributor', 'validator') as $role) {
         if ($user->has_cap($role)) {
             return true;
         }
     }
     return false;
 }
Пример #2
0
function bb_can_access_tab($profile_tab, $viewer_id, $owner_id)
{
    global $bb_current_user;
    $viewer_id = (int) $viewer_id;
    $owner_id = (int) $owner_id;
    if ($viewer_id == bb_get_current_user_info('id')) {
        $viewer =& $bb_current_user;
    } else {
        $viewer = new BP_User($viewer_id);
    }
    if (!$viewer) {
        return '' === $profile_tab[2];
    }
    if ($owner_id == $viewer_id) {
        if ('' === $profile_tab[1]) {
            return true;
        } else {
            return $viewer->has_cap($profile_tab[1]);
        }
    } else {
        if ('' === $profile_tab[2]) {
            return true;
        } else {
            return $viewer->has_cap($profile_tab[2]);
        }
    }
}
/**
 * Handles the resetting of users' passwords
 *
 * Handles resetting a user's password, prompted by an email sent by
 * {@see bb_reset_email()}
 *
 * @since 0.7.2
 * @global bbdb $bbdb
 *
 * @param string $key
 * @return unknown
 */
function bb_reset_password($key)
{
    global $bbdb;
    $key = sanitize_user($key, true);
    if (empty($key)) {
        return new WP_Error('key_not_found', __('Key not found.'));
    }
    if (!($user_id = $bbdb->get_var($bbdb->prepare("SELECT user_id FROM {$bbdb->usermeta} WHERE meta_key = 'newpwdkey' AND meta_value = %s", $key)))) {
        return new WP_Error('key_not_found', __('Key not found.'));
    }
    if ($user = new BP_User($user_id)) {
        if (bb_has_broken_pass($user->ID)) {
            bb_block_current_user();
        }
        if (!$user->has_cap('change_user_password', $user->ID)) {
            return new WP_Error('permission_denied', __('You are not allowed to change your password.'));
        }
        $newpass = bb_generate_password();
        bb_update_user_password($user->ID, $newpass);
        if (!bb_send_pass($user->ID, $newpass)) {
            return new WP_Error('sending_mail_failed', __('The email containing the new password could not be sent.'));
        } else {
            bb_update_usermeta($user->ID, 'newpwdkey', '');
            return true;
        }
    } else {
        return new WP_Error('key_not_found', __('Key not found.'));
    }
}