[wp-trac] [WordPress Trac] #43051: Documentation fix for wp_update_user function first parameter

WordPress Trac noreply at wordpress.org
Tue Jan 9 08:02:34 UTC 2018


#43051: Documentation fix for wp_update_user function first parameter
--------------------------+-----------------------------
 Reporter:  nextendweb    |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Comments      |    Version:  trunk
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 /wp-includes/users.php

 wp_update_user functions expects array, but it accepts object (which
 converted to array) and WP_User object (which converted to array).

 So I think the comment for the $userdata parameter should be improved.

 Current documentation
 {{{#!php
 <?php
 /**
  * Update a user in the database.
  *
  * It is possible to update a user's password by specifying the
 'user_pass'
  * value in the $userdata parameter array.
  *
  * If current user's password is being updated, then the cookies will be
  * cleared.
  *
  * @since 2.0.0
  *
  * @see wp_insert_user() For what fields can be set in $userdata.
  *
  * @param object|WP_User $userdata An array of user data or a user object
 of type stdClass or WP_User.
  * @return int|WP_Error The updated user's ID or a WP_Error object if the
 user could not be updated.
  */
 function wp_update_user($userdata) {
         if ( $userdata instanceof stdClass ) {
                 $userdata = get_object_vars( $userdata );
         } elseif ( $userdata instanceof WP_User ) {
                 $userdata = $userdata->to_array();
         }

         $ID = isset( $userdata['ID'] ) ? (int) $userdata['ID'] : 0;
         if ( ! $ID ) {
                 return new WP_Error( 'invalid_user_id', __( 'Invalid user
 ID.' ) );
         }
 }}}


 Improved documentation
 {{{#!php
 <?php
 /**
  * Update a user in the database.
  *
  * It is possible to update a user's password by specifying the
 'user_pass'
  * value in the $userdata parameter array.
  *
  * If current user's password is being updated, then the cookies will be
  * cleared.
  *
  * @since 2.0.0
  *
  * @see wp_insert_user() For what fields can be set in $userdata.
  *
  * @param array|object|WP_User $userdata An array of user data or a user
 object of type stdClass or WP_User.
  * @return int|WP_Error The updated user's ID or a WP_Error object if the
 user could not be updated.
  */
 function wp_update_user($userdata) {
         if ( $userdata instanceof stdClass ) {
                 $userdata = get_object_vars( $userdata );
         } elseif ( $userdata instanceof WP_User ) {
                 $userdata = $userdata->to_array();
         }

         $ID = isset( $userdata['ID'] ) ? (int) $userdata['ID'] : 0;
         if ( ! $ID ) {
                 return new WP_Error( 'invalid_user_id', __( 'Invalid user
 ID.' ) );
         }
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/43051>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list