function wpec_members_remove_all_capabilities($user_id)
{
    global $wp_roles;
    $remove_user = new WP_User($user_id);
    $remove_user = sanitize_user_object($remove_user, 'display');
    foreach ($remove_user->caps as $cap => $value) {
        if (!$wp_roles->is_role($cap)) {
            $remove_user->remove_cap($cap);
        }
    }
    if (count($remove_user->caps) > 1) {
        $remove_user->remove_role('subscriber');
    } elseif (count($remove_user->caps) < 1) {
        $remove_user->add_role('subscriber');
    }
    delete_user_meta($user_id, '_subscription_ends');
    delete_user_meta($user_id, '_subscription_length');
    delete_user_meta($user_id, '_subscription_starts');
    delete_user_meta($user_id, '_has_current_subscription');
}
Пример #2
0
/**
 * Retrieve user data and filter it.
 *
 * @since unknown
 *
 * @param int $user_id User ID.
 * @return object WP_User object with user data.
 */
function get_user_to_edit($user_id)
{
    $user = new WP_User($user_id);
    $user_contactmethods = _wp_get_user_contactmethods();
    foreach ($user_contactmethods as $method => $name) {
        if (empty($user->{$method})) {
            $user->{$method} = '';
        }
    }
    if (empty($user->description)) {
        $user->description = '';
    }
    $user = sanitize_user_object($user, 'edit');
    return $user;
}
 /**
  * Generate HTML for a single row on the users.php admin panel.
  *
  * Slightly adapted version of function last seen in WP 3.0.6
  *
  * @since 2.5
  * (since WP 2.1)
  *
  * @param object $user_object User object.
  * @param string $style       Optional. Attributes added to the TR element. Must be sanitized.
  * @param string $role        Key for the $wp_roles array.
  * @param int    $numposts    Optional. Post count to display for this user. Defaults to zero, as in, a new user has made zero posts.
  * @return string
  */
 public function user_row($user_object, $style = '', $role = '', $numposts = 0)
 {
     global $wp_roles;
     if (!(is_object($user_object) && is_a($user_object, 'WP_User'))) {
         $user_object = new WP_User((int) $user_object);
     }
     if (property_exists($user_object, 'filter')) {
         $user_object->filter = 'display';
     } else {
         // pre-WP 3.3
         $user_object = sanitize_user_object($user_object, 'display');
     }
     $email = $user_object->user_email;
     $url = $user_object->user_url;
     $short_url = str_replace('http://', '', $url);
     $short_url = str_replace('www.', '', $short_url);
     if ('/' == substr($short_url, -1)) {
         $short_url = substr($short_url, 0, -1);
     }
     if (strlen($short_url) > 35) {
         $short_url = substr($short_url, 0, 32) . '...';
     }
     $checkbox = '';
     // Check if the user for this row is editable
     if (current_user_can('list_users')) {
         // Set up the user editing link
         // TODO: make profile/user-edit determination a separate function
         if (get_current_user_id() == $user_object->ID) {
             $edit_link = 'profile.php';
         } else {
             $edit_link = esc_url(add_query_arg('wp_http_referer', urlencode(esc_url(stripslashes($_SERVER['REQUEST_URI']))), "user-edit.php?user_id={$user_object->ID}"));
         }
         $edit = "<strong><a href=\"{$edit_link}\">{$user_object->user_login}</a></strong><br />";
         // Set up the hover actions for this user
         $actions = array();
         if (current_user_can('edit_user', $user_object->ID)) {
             $edit = "<strong><a href=\"{$edit_link}\">{$user_object->user_login}</a></strong><br />";
             $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
         } else {
             $edit = "<strong>{$user_object->user_login}</strong><br />";
         }
         if (!is_multisite() && get_current_user_id() != $user_object->ID && current_user_can('delete_user', $user_object->ID)) {
             $actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url("users.php?action=delete&amp;user={$user_object->ID}", 'bulk-users') . "'>" . __('Delete') . "</a>";
         }
         if (is_multisite() && get_current_user_id() != $user_object->ID && current_user_can('remove_user', $user_object->ID)) {
             $actions['remove'] = "<a class='submitdelete' href='" . wp_nonce_url("users.php?action=remove&amp;user={$user_object->ID}", 'bulk-users') . "'>" . __('Remove') . "</a>";
         }
         $actions = apply_filters('user_row_actions', $actions, $user_object);
         $action_count = count($actions);
         $i = 0;
         $edit .= '<div class="row-actions">';
         foreach ($actions as $action => $link) {
             ++$i;
             $i == $action_count ? $sep = '' : ($sep = ' | ');
             $edit .= "<span class='{$action}'>{$link}{$sep}</span>";
         }
         $edit .= '</div>';
         // Set up the checkbox (because the user is editable, otherwise its empty)
         $checkbox = "<input type='checkbox' name='users[]' id='user_{$user_object->ID}' class='{$role}' value='{$user_object->ID}' />";
     } else {
         $edit = '<strong>' . $user_object->user_login . '</strong>';
     }
     $role_name = isset($wp_roles->role_names[$role]) ? translate_user_role($wp_roles->role_names[$role]) : __('None');
     $r = "<tr id='user-{$user_object->ID}'{$style}>";
     $columns = array('cb' => '<input type="checkbox" />', 'username' => __('Username'), 'name' => __('Name'), 'email' => __('E-mail'), 'role' => __('Role'));
     $avatar = get_avatar($user_object->ID, 32);
     foreach ($columns as $column_name => $column_display_name) {
         $attributes = "class=\"{$column_name} column-{$column_name}\"";
         switch ($column_name) {
             case 'cb':
                 $r .= "<th scope='row' class='check-column'>{$checkbox}</th>";
                 break;
             case 'username':
                 $r .= "<td {$attributes}>{$avatar} {$edit}</td>";
                 break;
             case 'name':
                 $r .= "<td {$attributes}>{$user_object->first_name} {$user_object->last_name}</td>";
                 break;
             case 'email':
                 $r .= "<td {$attributes}><a href='mailto:{$email}' title='" . sprintf(__('Email: %s'), $email) . "'>{$email}</a></td>";
                 break;
             case 'role':
                 $r .= "<td {$attributes}>{$role_name}</td>";
                 break;
             case 'posts':
                 $attributes = 'class="posts column-posts num"' . $style;
                 $r .= "<td {$attributes}>";
                 if ($numposts > 0) {
                     $r .= "<a href='edit.php?author={$user_object->ID}' title='" . __('View posts by this author') . "' class='edit'>";
                     $r .= $numposts;
                     $r .= '</a>';
                 } else {
                     $r .= 0;
                 }
                 $r .= "</td>";
                 break;
             default:
                 $r .= "<td {$attributes}>";
                 $r .= apply_filters('manage_users_custom_column', '', $column_name, $user_object->ID);
                 $r .= "</td>";
         }
     }
     $r .= '</tr>';
     return $r;
 }
 /**
  * Generate HTML for a single row on the users.php admin panel.
  *
  * @since 2.1.0
  *
  * @param object $user_object
  * @param string $style Optional. Attributes added to the TR element.  Must be sanitized.
  * @param string $role Key for the $wp_roles array.
  * @param int $numposts Optional. Post count to display for this user.  Defaults to zero, as in, a new user has made zero posts.
  * @return string
  */
 function single_row($user_object, $style = '', $role = '', $numposts = 0)
 {
     global $wp_roles;
     if (!(is_object($user_object) && is_a($user_object, 'WP_User'))) {
         $user_object = new WP_User((int) $user_object);
     }
     $user_object = sanitize_user_object($user_object, 'display');
     $email = $user_object->user_email;
     if ($this->is_site_users) {
         $url = "site-users.php?id={$this->site_id}&amp;";
     } else {
         $url = 'users.php?';
     }
     $checkbox = '';
     // Check if the user for this row is editable
     if (current_user_can('list_users')) {
         // Set up the user editing link
         // TODO: make profile/user-edit determination a separate function
         if (get_current_user_id() == $user_object->ID) {
             $edit_link = 'profile.php';
         } else {
             $edit_link = esc_url(add_query_arg('wp_http_referer', urlencode(stripslashes($_SERVER['REQUEST_URI'])), "user-edit.php?user_id={$user_object->ID}"));
         }
         // Set up the hover actions for this user
         $actions = array();
         if (current_user_can('edit_user', $user_object->ID)) {
             $edit = "<strong><a href=\"{$edit_link}\">{$user_object->user_login}</a></strong><br />";
             $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
         } else {
             $edit = "<strong>{$user_object->user_login}</strong><br />";
         }
         if (!is_multisite() && get_current_user_id() != $user_object->ID && current_user_can('delete_user', $user_object->ID)) {
             $actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url("users.php?action=delete&amp;user={$user_object->ID}", 'bulk-users') . "'>" . __('Delete') . "</a>";
         }
         if (is_multisite() && get_current_user_id() != $user_object->ID && current_user_can('remove_user', $user_object->ID)) {
             $actions['remove'] = "<a class='submitdelete' href='" . wp_nonce_url($url . "action=remove&amp;user={$user_object->ID}", 'bulk-users') . "'>" . __('Remove') . "</a>";
         }
         $actions = apply_filters('user_row_actions', $actions, $user_object);
         $edit .= $this->row_actions($actions);
         // Set up the checkbox ( because the user is editable, otherwise its empty )
         $checkbox = "<input type='checkbox' name='users[]' id='user_{$user_object->ID}' class='{$role}' value='{$user_object->ID}' />";
     } else {
         $edit = '<strong>' . $user_object->user_login . '</strong>';
     }
     $role_name = isset($wp_roles->role_names[$role]) ? translate_user_role($wp_roles->role_names[$role]) : __('None');
     $avatar = get_avatar($user_object->ID, 32);
     $r = "<tr id='user-{$user_object->ID}'{$style}>";
     list($columns, $hidden) = $this->get_column_info();
     foreach ($columns as $column_name => $column_display_name) {
         $class = "class=\"{$column_name} column-{$column_name}\"";
         $style = '';
         if (in_array($column_name, $hidden)) {
             $style = ' style="display:none;"';
         }
         $attributes = "{$class}{$style}";
         switch ($column_name) {
             case 'cb':
                 $r .= "<th scope='row' class='check-column'>{$checkbox}</th>";
                 break;
             case 'username':
                 $r .= "<td {$attributes}>{$avatar} {$edit}</td>";
                 break;
             case 'name':
                 $r .= "<td {$attributes}>{$user_object->first_name} {$user_object->last_name}</td>";
                 break;
             case 'email':
                 $r .= "<td {$attributes}><a href='mailto:{$email}' title='" . esc_attr(sprintf(__('E-mail: %s'), $email)) . "'>{$email}</a></td>";
                 break;
             case 'role':
                 $r .= "<td {$attributes}>{$role_name}</td>";
                 break;
             case 'posts':
                 $attributes = 'class="posts column-posts num"' . $style;
                 $r .= "<td {$attributes}>";
                 if ($numposts > 0) {
                     $r .= "<a href='edit.php?author={$user_object->ID}' title='" . esc_attr__('View posts by this author') . "' class='edit'>";
                     $r .= $numposts;
                     $r .= '</a>';
                 } else {
                     $r .= 0;
                 }
                 $r .= "</td>";
                 break;
             default:
                 $r .= "<td {$attributes}>";
                 $r .= apply_filters('manage_users_custom_column', '', $column_name, $user_object->ID);
                 $r .= "</td>";
         }
     }
     $r .= '</tr>';
     return $r;
 }
Пример #5
0
/**
 * {@internal Missing Short Description}}
 *
 * @since unknown
 *
 * @param unknown_type $user_object
 * @param unknown_type $style
 * @param unknown_type $role
 * @return unknown
 */
function user_row( $user_object, $style = '', $role = '' ) {
	global $wp_roles;

	$current_user = wp_get_current_user();

	if ( !( is_object( $user_object) && is_a( $user_object, 'WP_User' ) ) )
		$user_object = new WP_User( (int) $user_object );
	$user_object = sanitize_user_object($user_object, 'display');
	$email = $user_object->user_email;
	$url = $user_object->user_url;
	$short_url = str_replace( 'http://', '', $url );
	$short_url = str_replace( 'www.', '', $short_url );
	if ('/' == substr( $short_url, -1 ))
		$short_url = substr( $short_url, 0, -1 );
	if ( strlen( $short_url ) > 35 )
		$short_url = substr( $short_url, 0, 32 ).'...';
	$numposts = get_usernumposts( $user_object->ID );
	$checkbox = '';
	// Check if the user for this row is editable
	if ( current_user_can( 'edit_user', $user_object->ID ) ) {
		// Set up the user editing link
		// TODO: make profile/user-edit determination a seperate function
		if ($current_user->ID == $user_object->ID) {
			$edit_link = 'profile.php';
		} else {
			$edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( esc_url( stripslashes( $_SERVER['REQUEST_URI'] ) ) ), "user-edit.php?user_id=$user_object->ID" ) );
		}
		$edit = "<strong><a href=\"$edit_link\">$user_object->user_login</a></strong><br />";

		// Set up the hover actions for this user
		$actions = array();
		$actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
		if ( $current_user->ID != $user_object->ID )
			$actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url("users.php?action=delete&amp;user=$user_object->ID", 'bulk-users') . "'>" . __('Delete') . "</a>";
		$actions = apply_filters('user_row_actions', $actions, $user_object);
		$action_count = count($actions);
		$i = 0;
		$edit .= '<div class="row-actions">';
		foreach ( $actions as $action => $link ) {
			++$i;
			( $i == $action_count ) ? $sep = '' : $sep = ' | ';
			$edit .= "<span class='$action'>$link$sep</span>";
		}
		$edit .= '</div>';

		// Set up the checkbox (because the user is editable, otherwise its empty)
		$checkbox = "<input type='checkbox' name='users[]' id='user_{$user_object->ID}' class='$role' value='{$user_object->ID}' />";

	} else {
		$edit = '<strong>' . $user_object->user_login . '</strong>';
	}
	$role_name = isset($wp_roles->role_names[$role]) ? translate_user_role($wp_roles->role_names[$role] ) : __('None');
	$r = "<tr id='user-$user_object->ID'$style>";
	$columns = get_column_headers('users');
	$hidden = get_hidden_columns('users');
	$avatar = get_avatar( $user_object->ID, 32 );
	foreach ( $columns as $column_name => $column_display_name ) {
		$class = "class=\"$column_name column-$column_name\"";

		$style = '';
		if ( in_array($column_name, $hidden) )
			$style = ' style="display:none;"';

		$attributes = "$class$style";

		switch ($column_name) {
			case 'cb':
				$r .= "<th scope='row' class='check-column'>$checkbox</th>";
				break;
			case 'username':
				$r .= "<td $attributes>$avatar $edit</td>";
				break;
			case 'name':
				$r .= "<td $attributes>$user_object->first_name $user_object->last_name</td>";
				break;
			case 'email':
				$r .= "<td $attributes><a href='mailto:$email' title='" . sprintf( __('e-mail: %s' ), $email ) . "'>$email</a></td>";
				break;
			case 'role':
				$r .= "<td $attributes>$role_name</td>";
				break;
			case 'posts':
				$attributes = 'class="posts column-posts num"' . $style;
				$r .= "<td $attributes>";
				if ( $numposts > 0 ) {
					$r .= "<a href='edit.php?author=$user_object->ID' title='" . __( 'View posts by this author' ) . "' class='edit'>";
					$r .= $numposts;
					$r .= '</a>';
				} else {
					$r .= 0;
				}
				$r .= "</td>";
				break;
			default:
				$r .= "<td $attributes>";
				$r .= apply_filters('manage_users_custom_column', '', $column_name, $user_object->ID);
				$r .= "</td>";
		}
	}
	$r .= '</tr>';

	return $r;
}