diff --git a/src/wp-admin/includes/user.php b/src/wp-admin/includes/user.php
index 269d64fb26..f3efd1daf1 100644
a
|
b
|
function edit_user( $user_id = 0 ) { |
96 | 96 | $user->description = trim( $_POST['description'] ); |
97 | 97 | } |
98 | 98 | |
| 99 | if ( isset( $_POST['gender'] ) ) { |
| 100 | $user->gender = in_array( $_POST['gender'], array( 'unknown', 'female', 'male' ), true ) ? $_POST['gender'] : 'unknown'; |
| 101 | } |
| 102 | |
99 | 103 | foreach ( wp_get_user_contact_methods( $user ) as $method => $name ) { |
100 | 104 | if ( isset( $_POST[ $method ] ) ) { |
101 | 105 | $user->$method = sanitize_text_field( $_POST[ $method ] ); |
diff --git a/src/wp-admin/user-edit.php b/src/wp-admin/user-edit.php
index 7e443c42c3..2b50ae815d 100644
a
|
b
|
if ( is_multisite() && is_network_admin() && ! IS_PROFILE_PAGE && current_user_c |
638 | 638 | </tr> |
639 | 639 | <?php endif; ?> |
640 | 640 | |
| 641 | <tr class="user-gender-wrap"> |
| 642 | <th><label for="gender"><?php _e( 'What pronoun do you prefer?' ); ?></label></th> |
| 643 | <td> |
| 644 | <p> |
| 645 | <?php |
| 646 | $gender = get_user_meta( $user_id, 'gender', true ); |
| 647 | if ( ! $gender ) { |
| 648 | $gender = 'unknown'; |
| 649 | } |
| 650 | ?> |
| 651 | <label><input name="gender" type="radio" value="female" <?php checked( 'female', $gender ); ?> /> <?php _e( 'Female: She published a new post.' ); ?></label><br /> |
| 652 | <label><input name="gender" type="radio" value="male" <?php checked( 'male', $gender ); ?> /> <?php _e( 'Male: He published a new post.' ); ?></label><br /> |
| 653 | <label><input name="gender" type="radio" value="unknown" <?php checked( 'unknown', $gender ); ?> /> <?php _e( 'Other/Unknown: They published a new post.' ); ?></label> |
| 654 | </p> |
| 655 | <p class="description"> |
| 656 | <?php _e( 'This preference will allow translations of WordPress to address you and to mention you to others using the appropriate grammatical gender.' ); ?><br /> |
| 657 | <?php _e( 'If "Other/Unknown" is chosen, WordPress will use gender-neutral words whenever possible.' ); ?> |
| 658 | </p> |
| 659 | </td> |
| 660 | </tr> |
| 661 | |
641 | 662 | <?php |
642 | 663 | if ( IS_PROFILE_PAGE && count( $sessions->get_all() ) === 1 ) : |
643 | 664 | ?> |
diff --git a/src/wp-includes/class-wp-user.php b/src/wp-includes/class-wp-user.php
index f67780f1f4..4abbad63b8 100644
a
|
b
|
|
32 | 32 | * @property string $spam |
33 | 33 | * @property string $deleted |
34 | 34 | * @property string $locale |
| 35 | * @property string $gender |
35 | 36 | * @property string $rich_editing |
36 | 37 | * @property string $syntax_highlighting |
37 | 38 | */ |
diff --git a/src/wp-includes/l10n.php b/src/wp-includes/l10n.php
index 5f4ba59ec3..22c271ca37 100644
a
|
b
|
function get_user_locale( $user_id = 0 ) { |
104 | 104 | return $locale ? $locale : get_locale(); |
105 | 105 | } |
106 | 106 | |
| 107 | /** |
| 108 | * Retrieves the gender of a user for use in translations. |
| 109 | * |
| 110 | * If the user has a gender set to a valid non-empty string then it will be |
| 111 | * returned. Otherwise it returns 'unknown'. |
| 112 | * |
| 113 | * @since 5.0.0 |
| 114 | * |
| 115 | * @param int|WP_User $user_id User's ID or a WP_User object. Defaults to current user. |
| 116 | * @return string The gender of the user. |
| 117 | */ |
| 118 | function get_user_gender( $user_id = 0 ) { |
| 119 | $user = false; |
| 120 | if ( 0 === $user_id && function_exists( 'wp_get_current_user' ) ) { |
| 121 | $user = wp_get_current_user(); |
| 122 | } elseif ( $user_id instanceof WP_User ) { |
| 123 | $user = $user_id; |
| 124 | } elseif ( $user_id && is_numeric( $user_id ) ) { |
| 125 | $user = get_user_by( 'id', $user_id ); |
| 126 | } |
| 127 | |
| 128 | if ( ! $user ) { |
| 129 | return 'unknown'; |
| 130 | } |
| 131 | |
| 132 | $gender = $user->gender; |
| 133 | return $gender ? $gender : 'unknown'; |
| 134 | } |
| 135 | |
107 | 136 | /** |
108 | 137 | * Retrieve the translation of $text. |
109 | 138 | * |
diff --git a/src/wp-includes/user.php b/src/wp-includes/user.php
index 9a685b9b36..aad6026826 100644
a
|
b
|
function validate_username( $username ) { |
1469 | 1469 | * to build the second part of the user's display name |
1470 | 1470 | * if `$display_name` is not specified. |
1471 | 1471 | * @type string $description The user's biographical description. |
| 1472 | * @type string $gender The user's chosen gender. |
1472 | 1473 | * @type string|bool $rich_editing Whether to enable the rich-editor for the user. |
1473 | 1474 | * False if not empty. |
1474 | 1475 | * @type string|bool $syntax_highlighting Whether to enable the rich code editor for the user. |
… |
… |
function wp_insert_user( $userdata ) { |
1684 | 1685 | */ |
1685 | 1686 | $meta['description'] = apply_filters( 'pre_user_description', $description ); |
1686 | 1687 | |
| 1688 | $meta['gender'] = empty( $userdata['gender'] ) ? 'unknown' : $userdata['gender']; |
| 1689 | |
1687 | 1690 | $meta['rich_editing'] = empty( $userdata['rich_editing'] ) ? 'true' : $userdata['rich_editing']; |
1688 | 1691 | |
1689 | 1692 | $meta['syntax_highlighting'] = empty( $userdata['syntax_highlighting'] ) ? 'true' : $userdata['syntax_highlighting']; |
… |
… |
function wp_insert_user( $userdata ) { |
1774 | 1777 | * @type string $first_name The user's first name. |
1775 | 1778 | * @type string $last_name The user's last name. |
1776 | 1779 | * @type string $description The user's description. |
| 1780 | * @type string $gender The user's gender. |
1777 | 1781 | * @type bool $rich_editing Whether to enable the rich-editor for the user. False if not empty. |
1778 | 1782 | * @type bool $syntax_highlighting Whether to enable the rich code editor for the user. False if not empty. |
1779 | 1783 | * @type bool $comment_shortcuts Whether to enable keyboard shortcuts for the user. Default false. |