Exemplo n.º 1
0
function get_assignable_caps()
{
    bb_log_deprecated('function', __FUNCTION__, 'bb_get_assignable_caps');
    return bb_get_assignable_caps();
}
Exemplo n.º 2
0
// I don't know how this would ever get triggered
if (!bb_is_profile()) {
    $sendto = get_profile_tab_link($bb_current_id, 'edit');
    nxt_redirect($sendto);
    exit;
}
// Set some low capabilities if the current user has none
if (!isset($user->capabilities)) {
    $user->capabilities = array('inactive' => true);
}
// Store the profile info keys
$profile_info_keys = bb_get_profile_info_keys('profile-edit');
// Store additional keys if the current user has access to them
if (bb_current_user_can('edit_users')) {
    $profile_admin_keys = bb_get_profile_admin_keys('profile-edit');
    $assignable_caps = bb_get_assignable_caps();
}
// Instantiate the error object
$errors = new nxt_Error();
if ('post' == strtolower($_SERVER['REQUEST_METHOD'])) {
    $_POST = stripslashes_deep($_POST);
    bb_check_admin_referer('edit-profile_' . $user_id);
    // Fix the URL before sanitizing it
    $user_url = bb_fix_link($_POST['user_url']);
    // Sanitize the profile info keys and check for missing required data
    foreach ($profile_info_keys as $key => $label) {
        ${$key} = apply_filters('sanitize_profile_info', $_POST[$key], $key, $_POST[$key]);
        if (!${$key} && $label[0] == 1) {
            $errors->add($key, sprintf(__('%s is required.'), esc_html($label[1])));
            ${$key} = false;
        }
function bb_profile_admin_form($id = 0)
{
    global $wp_roles, $errors;
    if (!($user = bb_get_user(bb_get_user_id($id)))) {
        return;
    }
    if (!bb_current_user_can('edit_user', $user->ID)) {
        return;
    }
    $error_codes = $errors->get_error_codes();
    $bb_current_id = bb_get_current_user_info('id');
    $profile_admin_keys = bb_get_profile_admin_keys();
    $assignable_caps = bb_get_assignable_caps();
    $required = false;
    $roles = $wp_roles->role_names;
    $can_keep_gate = bb_current_user_can('keep_gate');
    // Keymasters can't demote themselves
    if ($bb_current_id == $user->ID && $can_keep_gate || isset($user->capabilities) && is_array($user->capabilities) && array_key_exists('keymaster', $user->capabilities) && !$can_keep_gate) {
        $roles = array('keymaster' => $roles['keymaster']);
    } elseif (!$can_keep_gate) {
        // only keymasters can promote others to keymaster status
        unset($roles['keymaster']);
    }
    $selected = array('inactive' => ' selected="selected"');
    ?>
<table id="admininfo">
<tr class='form-field<?php 
    if (in_array('role', $error_codes)) {
        echo ' form-invalid error';
    }
    ?>
'>
	<th scope="row">
		<label for="admininfo_role"><?php 
    _e('User Type');
    ?>
</label>
		<?php 
    if (in_array('role', $error_codes)) {
        echo '<em>' . $errors->get_error_message('role') . '</em>';
    }
    ?>
	</th>
	<td>
		<select id="admininfo_role" name="role">
<?php 
    foreach ($roles as $r => $n) {
        if (isset($user->capabilities) && is_array($user->capabilities) && array_key_exists($r, $user->capabilities)) {
            $selected['inactive'] = '';
            $selected[$r] = ' selected="selected"';
        } elseif ($r !== 'inactive') {
            $selected[$r] = '';
        }
        ?>
			<option value="<?php 
        echo $r;
        ?>
"<?php 
        echo $selected[$r];
        ?>
><?php 
        echo $n;
        ?>
</option>
<?php 
    }
    ?>
		</select>
	</td>
</tr>
<?php 
    if (count($assignable_caps)) {
        ?>
<tr class="extra-caps-row">
	<th scope="row"><?php 
        _e('Allow this user to');
        ?>
</th>
	<td>
<?php 
        foreach ($assignable_caps as $cap => $label) {
            $name = esc_attr($cap);
            $checked = '';
            if (isset($user->capabilities) && is_array($user->capabilities) && array_key_exists($cap, $user->capabilities)) {
                $checked = ' checked="checked"';
            }
            $label = esc_html($label);
            ?>

		<label><input name="<?php 
            echo $name;
            ?>
" value="1" type="checkbox"<?php 
            echo $checked;
            ?>
 /> <?php 
            echo $label;
            ?>
</label><br />

<?php 
        }
        ?>

	</td>
</tr>

<?php 
    }
    if (is_array($profile_admin_keys)) {
        foreach ($profile_admin_keys as $key => $label) {
            if ($label[0]) {
                $class = 'form-field form-required required';
                $required = true;
            } else {
                $class = 'form-field';
            }
            $title = esc_attr($label[1]);
            $name = esc_attr($key);
            $type = isset($label[2]) ? esc_attr($label[2]) : 'text';
            $checked = false;
            if (in_array($key, $error_codes)) {
                $class .= ' form-invalid error';
                $data = $errors->get_error_data($key);
                if ('checkbox' == $type) {
                    if (isset($data['data'])) {
                        $checked = $data['data'];
                    } else {
                        $checked = $_POST[$key];
                    }
                    $value = $label[3];
                    $checked = $checked == $value;
                } else {
                    if (isset($data['data'])) {
                        $value = $data['data'];
                    } else {
                        $value = $_POST[$key];
                    }
                }
                $message = esc_html($errors->get_error_message($key));
                $message = "<em>{$message}</em>";
            } else {
                if ('checkbox' == $type) {
                    $checked = $user->{$key} == $label[3] || $label[4] == $label[3];
                    $value = $label[3];
                } else {
                    $value = isset($user->{$key}) ? $user->{$key} : '';
                }
                $message = '';
            }
            $checked = $checked ? ' checked="checked"' : '';
            $value = esc_attr($value);
            ?>

<tr class="<?php 
            echo $class;
            ?>
">
	<th scope="row">
		<label for="<?php 
            echo $name;
            ?>
"><?php 
            echo $title;
            ?>
</label>
		<?php 
            echo $message;
            ?>
	</th>
	<td>
		<?php 
            if ('checkbox' == $type && isset($label[5])) {
                echo "<label for='{$name}'>";
            }
            ?>
		<input name="<?php 
            echo $name;
            ?>
" id="<?php 
            echo $name;
            ?>
" type="<?php 
            echo $type;
            ?>
"<?php 
            echo $checked;
            ?>
 value="<?php 
            echo $value;
            ?>
" />
		<?php 
            if ('checkbox' == $type && isset($label[5])) {
                echo esc_html($label[5]) . "</label>";
            }
            ?>
	</td>
</tr>

<?php 
        }
    }
    // $profile_admin_keys; $profile_admin_keys
    ?>

</table>

<?php 
    if ($required) {
        ?>
<p class="required-message"><?php 
        _e('These items are <span class="required">required</span>.');
        ?>
</p>

<?php 
    }
    ?>
<p><?php 
    _e('Inactive users can login and look around but not do anything. Blocked users just see a simple error message when they visit the site.');
    ?>
</p>
<p><?php 
    _e('<strong>Note</strong>: Blocking a user does <em>not</em> block any IP addresses.');
    ?>
</p>
<?php 
}