[wp-trac] [WordPress Trac] #27047: add a wp_save_user pluggable api for plugin to choose where to save user

WordPress Trac noreply at wordpress.org
Fri Feb 7 08:48:28 UTC 2014


#27047: add a wp_save_user pluggable  api for plugin to  choose where to save user
-----------------------------+-----------------------------
 Reporter:  fatihwk          |      Owner:
     Type:  feature request  |     Status:  new
 Priority:  normal           |  Milestone:  Awaiting Review
Component:  Users            |    Version:  3.8.1
 Severity:  normal           |   Keywords:
  Focuses:                   |
-----------------------------+-----------------------------
 Index: user.php
 ===================================================================
 --- user.php    (revision 26748)
 +++ user.php    (working copy)
 @@ -1409,11 +1409,13 @@
         $data = wp_unslash( $data );

         if ( $update ) {
 -               $wpdb->update( $wpdb->users, $data, compact( 'ID' ) );
 -               $user_id = (int) $ID;
 +               //$wpdb->update( $wpdb->users, $data, compact( 'ID' ) );
 +               //$user_id = (int) $ID;
 +               $user_id = (int)wp_save_user($data, compact( 'ID' ));
         } else {
 -               $wpdb->insert( $wpdb->users, $data + compact( 'user_login'
 ) );
 -               $user_id = (int) $wpdb->insert_id;
 +               //$wpdb->insert( $wpdb->users, $data + compact(
 'user_login' ) );
 +               //$user_id = (int) $wpdb->insert_id;
 +               $user_id = (int)wp_save_user($data + compact( 'user_login'
 ));
         }

         $user = new WP_User( $user_id );
 Index: pluggable.php
 ===================================================================
 --- pluggable.php       (revision 26748)
 +++ pluggable.php       (working copy)
 @@ -6,6 +6,30 @@
   * @package WordPress
   */

 +
 +
 +/**
 + * Save or update user to database
 + */
 +if (! function_exists('wp_save_user')):
 +        function wp_save_user($data, $format = null)
 +{
 +        extract( $format, EXTR_SKIP );
 +        global $wpdb;
 +        if ( !empty($ID) )
 +        {
 +                $wpdb->update($wpdb->users, $data, $format);
 +                return $ID;
 +        }
 +        else
 +        {
 +                $wpdb->insert($wpdb->users, $data );
 +                return $wpdb->insert_id;
 +        }
 +}
 +endif;
 +
 +
  if ( !function_exists('wp_set_current_user') ) :
  /**
   * Changes the current user by ID or name.

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


More information about the wp-trac mailing list