Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try: add gravatar to quick edit author selector #8254

Draft
wants to merge 4 commits into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 52 additions & 4 deletions src/wp-admin/css/forms.css
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,12 @@ input[type="radio"].disabled:checked:before {
background-size: 16px 16px;
cursor: pointer;
vertical-align: middle;
appearance: base-select;

}

select::picker( .wp-core-ui ) {
appearance: base-select;
}

.wp-core-ui select:hover {
Expand Down Expand Up @@ -411,10 +417,52 @@ input[type="radio"].disabled:checked:before {
margin-top: 0;
}

.wp-core-ui select[multiple] {
height: auto;
padding-right: 8px;
background: #fff;
select,
::picker(select) {
appearance: base-select;
font-family: system-ui;
}

/* hide checkmark */
option::checkmark,
select.authors::picker-icon {
display: none;
}

::picker(select) {
max-height: 60dvh;
padding: 0;
}

select:has(:popover-open) {
border-radius: 0;
}

option,
selectedcontent {
display: grid;
grid-template-columns: 1.5rem 1fr;
gap: 1rem;
font-size: 1rem;
/* remove these two lines when patch is in */
align-items: center;
padding: .4rem;

& img,
& figure {
width: 100%;
}
}


[hidden] {
display: none;
}



body {
margin: 2rem 4rem;
}

.submit {
Expand Down
1 change: 1 addition & 0 deletions src/wp-admin/includes/class-wp-posts-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -1735,6 +1735,7 @@ public function inline_edit() {
'multi' => 1,
'echo' => 0,
'show' => 'display_name_with_login',
'show_gravatar' => true,
);

if ( $bulk ) {
Expand Down
18 changes: 17 additions & 1 deletion src/wp-includes/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -1604,6 +1604,7 @@ function setup_userdata( $for_user_id = 0 ) {
* @since 4.7.0 Added the 'role', 'role__in', and 'role__not_in' parameters.
* @since 5.9.0 Added the 'capability', 'capability__in', and 'capability__not_in' parameters.
* Deprecated the 'who' parameter.
* @since 6.8.0 Add the 'show_gravatar' parameter.
*
* @param array|string $args {
* Optional. Array or string of arguments to generate a drop-down of users.
Expand Down Expand Up @@ -1665,6 +1666,7 @@ function setup_userdata( $for_user_id = 0 ) {
* of these capabilities will not be included in results.
* Does NOT work for capabilities not in the database or filtered
* via {@see 'map_meta_cap'}. Default empty array.
* @type string $show_gravatar Whether to include the user's Gravatar. Accepts 'true' or 'false'. Default false.
* }
* @return string HTML dropdown list of users.
*/
Expand Down Expand Up @@ -1694,6 +1696,7 @@ function wp_dropdown_users( $args = '' ) {
'capability' => '',
'capability__in' => array(),
'capability__not_in' => array(),
'show_gravatar' => false,
);

$defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0;
Expand All @@ -1715,6 +1718,7 @@ function wp_dropdown_users( $args = '' ) {
'capability',
'capability__in',
'capability__not_in',
'show_gravatar',
)
);

Expand Down Expand Up @@ -1794,7 +1798,19 @@ function wp_dropdown_users( $args = '' ) {
}

$_selected = selected( $user->ID, $parsed_args['selected'], false );
$output .= "\t<option value='$user->ID'$_selected>" . esc_html( $display ) . "</option>\n";

// Add the gravatar image if enabled.
$gravatar = '';
if ( $parsed_args['show_gravatar'] ) {
$gravatar = get_avatar( $user->ID, 24 ) . ' ';
}
$output .= sprintf(
"\t<option value='%s'%s>%s%s</option>\n",
$user->ID,
$_selected,
$gravatar,
esc_html( $display )
);
}

$output .= '</select>';
Expand Down
25 changes: 25 additions & 0 deletions tests/phpunit/tests/user/wpDropdownUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,29 @@
$this->assertStringNotContainsString( $u1->user_login, $found );
$this->assertStringContainsString( $u2->user_login, $found );
}

/**
* Show display name with gravatar image.
*/
public function test_user_dropdown_with_gravatar() {
$u1 = self::factory()->user->create(array(

Check failure on line 209 in tests/phpunit/tests/user/wpDropdownUsers.php

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

Opening parenthesis of a multi-line function call must be the last content on the line
'user_login' => 'foo',
'display_name' => 'Foo Person',
) );

Check failure on line 212 in tests/phpunit/tests/user/wpDropdownUsers.php

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

Closing parenthesis of a multi-line function call must be on a line by itself

// Add some gravatars.
update_user_meta( $u1, 'wp_user_avatar', 'https://example.com/avatar1.jpg' );

$dropdown = wp_dropdown_users(
array(
'echo' => false,
'show_gravatar' => 'true',
)
);

$gravatar = get_avatar( $u1, 24 );
$expected = "<option value='$u1'>$gravatar Foo Person</option>";

$this->assertStringContainsString( $expected, $dropdown );
}
}
Loading