Advertisements

user_row

Definition:
function user_row( $user_object, $style = '', $role = '', $numposts = 0 ) {}

Generate HTML for a single row on the users.php admin panel.

Parameters

  • object $user_object
  • string $style: Optional. Attributes added to the TR element. Must be sanitized.
  • string $role: Key for the $wp_roles array.
  • int $numposts: Optional. Post count to display for this user. Defaults to zero, as in, a new user has made zero posts.

Defined filters

  • user_row_actions
    apply_filters('user_row_actions', $actions, $user_object)

Source code

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 );

	$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}' />";

3301

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: