WordPress.org

Make WordPress Core

Ticket #42725: gender-to-user-profile.diff

File gender-to-user-profile.diff, 5.0 KB (added by yoavf, 3 years ago)

User profile gender field, and get_current_user_gender()

  • src/wp-includes/user.php

     
    435435}
    436436
    437437/**
     438 * Get the current user's gender
     439 *
     440 * @since MU (5.0.0)
     441 *
     442 * @return string The current user's gender, or 'unknown' if no user is logged in, or unset.
     443 */
     444function get_current_user_gender() {
     445        if ( ! function_exists( 'wp_get_current_user' ) )
     446                return 'unknown';
     447
     448        $user = wp_get_current_user();
     449        return ( isset( $user->gender ) ? $user->gender : 'unknown' );
     450}
     451
     452/**
    438453 * Retrieve user option that can be either per Site or per Network.
    439454 *
    440455 * If the user ID is not given, then the current user will be used instead. If
     
    14141429 *                                             to build the second part of the user's display name
    14151430 *                                             if `$display_name` is not specified.
    14161431 *     @type string      $description          The user's biographical description.
     1432 *     @type string      $gender               The user's chosen gender.
    14171433 *     @type string|bool $rich_editing         Whether to enable the rich-editor for the user.
    14181434 *                                             False if not empty.
    14191435 *     @type string|bool $syntax_highlighting  Whether to enable the rich code editor for the user.
     
    16291645         */
    16301646        $meta['description'] = apply_filters( 'pre_user_description', $description );
    16311647
     1648        $meta['gender'] = empty( $userdata['gender'] ) ? 'unknown' : $userdata['gender'];
     1649
    16321650        $meta['rich_editing'] = empty( $userdata['rich_editing'] ) ? 'true' : $userdata['rich_editing'];
    16331651
    16341652        $meta['syntax_highlighting'] = empty( $userdata['syntax_highlighting'] ) ? 'true' : $userdata['syntax_highlighting'];
     
    17191737         *     @type string   $first_name           The user's first name.
    17201738         *     @type string   $last_name            The user's last name.
    17211739         *     @type string   $description          The user's description.
     1740         *     @type string   $gender               The user's gender.
    17221741         *     @type bool     $rich_editing         Whether to enable the rich-editor for the user. False if not empty.
    17231742         *     @type bool     $syntax_highlighting  Whether to enable the rich code editor for the user. False if not empty.
    17241743         *     @type bool     $comment_shortcuts    Whether to enable keyboard shortcuts for the user. Default false.
  • src/wp-includes/class-wp-user.php

     
    3232 * @property string $spam
    3333 * @property string $deleted
    3434 * @property string $locale
     35 * @property string $gender
    3536 * @property string $rich_editing
    3637 * @property string $syntax_highlighting
    3738 */
  • src/wp-admin/includes/user.php

     
    8585        if ( isset( $_POST['description'] ) )
    8686                $user->description = trim( $_POST['description'] );
    8787
     88        if ( isset( $_POST['gender'] ) ) {
     89                $user->gender = in_array( $_POST['gender'], array( 'unknown', 'female', 'male' ), true ) ? $_POST['gender'] : 'unknown';
     90        }
     91
    8892        foreach ( wp_get_user_contact_methods( $user ) as $method => $name ) {
    8993                if ( isset( $_POST[$method] ))
    9094                        $user->$method = sanitize_text_field( $_POST[$method] );
  • src/wp-admin/user-edit.php

     
    551551</tr>
    552552<?php endif; ?>
    553553
     554<tr class="user-gender-wrap">
     555    <th><label for="gender"><?php _e( 'What pronoun do you prefer?' ); ?></label></th>
     556    <td>
     557        <p>
     558            <?php
     559                $gender = get_user_meta( $user_id, 'gender', true );
     560                if ( ! $gender ) {
     561                    $gender = 'unknown';
     562                }
     563            ?>
     564            <label><input name="gender" type="radio" value="female" <?php checked( 'female', $gender ); ?> /> <?php _e( 'Female: She published a new post.' ); ?></label><br />
     565            <label><input name="gender" type="radio" value="male" <?php checked( 'male', $gender ); ?> /> <?php _e( 'Male: He published a new post.' ); ?></label><br />
     566            <label><input name="gender" type="radio" value="unknown" <?php checked( 'unknown', $gender ); ?> /> <?php _e( 'Other/Unknown: They published a new post.' ); ?></label>
     567        </p>
     568        <p class="description">
     569            <?php _e( 'This preference will allow WordPress to address you and to mention you to others using the appropriate grammatical gender.'); ?><br />
     570            <?php _e( 'If "Other/Unknown" is chosen, WordPress will use gender-neutral words whenever possible.' ); ?>
     571        </p>
     572    </td>
     573</tr>
     574
    554575<?php
    555576/**
    556577 * Filters the display of the password fields.