Skip to content
Open
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
4 changes: 4 additions & 0 deletions includes/hcard/class-user.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ public static function extra_fields() {
'title' => \__( 'Honorific Prefix', 'indieweb' ),
'description' => \__( 'e.g. Mrs., Mr. Dr.', 'indieweb' ),
),
'pronouns' => array(
'title' => \__( 'Pronouns', 'indieweb' ),
'description' => \__( 'e.g. she/her, he/him, they/them', 'indieweb' ),
),
);
return \apply_filters( 'wp_user_extrafields', $extras );
}
Expand Down
5 changes: 5 additions & 0 deletions templates/h-card.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
<p class="hcard-name p-name n"><?php echo esc_html( $name ); ?></p>
<?php
}
if ( $user->has_prop( 'pronouns' ) && $user->get( 'pronouns' ) ) {
?>
<p class="hcard-pronouns p-pronouns"><?php echo esc_html( $user->get( 'pronouns' ) ); ?></p>
<?php
}
if ( $args['email'] ) {
?>
<p>
Expand Down
23 changes: 23 additions & 0 deletions tests/phpunit/tests/includes/hcard/class-test-user.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public function test_extra_fields_contains_expected_keys() {
$this->assertArrayHasKey( 'job_title', $fields );
$this->assertArrayHasKey( 'organization', $fields );
$this->assertArrayHasKey( 'honorific_prefix', $fields );
$this->assertArrayHasKey( 'pronouns', $fields );
}

/**
Expand Down Expand Up @@ -187,4 +188,26 @@ public function test_hcard_returns_string_for_valid_user() {
$this->assertIsString( $result );
$this->assertStringContainsString( 'h-card', $result );
}

/**
* Test hcard renders pronouns as p-pronouns.
*/
public function test_hcard_renders_pronouns() {
\update_user_meta( self::$user_id, 'pronouns', 'they/them' );

$result = \Indieweb\Hcard\User::hcard( self::$user_id );

$this->assertStringContainsString( '<p class="hcard-pronouns p-pronouns">they/them</p>', $result );

\delete_user_meta( self::$user_id, 'pronouns' );
}

/**
* Test hcard omits pronouns when not set.
*/
public function test_hcard_omits_empty_pronouns() {
$result = \Indieweb\Hcard\User::hcard( self::$user_id );

$this->assertStringNotContainsString( 'p-pronouns', $result );
}
}
Loading