[wp-trac] [WordPress Trac] #39223: Add a filter to edit $meta array in wpmu_signup_user

WordPress Trac noreply at wordpress.org
Tue Dec 27 17:56:54 UTC 2016


#39223: Add a filter to edit $meta array in wpmu_signup_user
-------------------------+------------------------------
 Reporter:  Mista-Flo    |       Owner:
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  Users        |     Version:  3.0
 Severity:  normal       |  Resolution:
 Keywords:  has-patch    |     Focuses:  multisite
-------------------------+------------------------------

Comment (by Mista-Flo):

 Without this patch merged in the core, in my plugin, I should do this
 (code from my last plugin release 24 december) :

 {{{#!php
 <?php
 add_action( 'after_signup_user', 'mu_add_roles_in_signup_meta', 10, 4 );
 public function mu_add_roles_in_signup_meta( $user, $user_email, $key,
 $meta ) {
         if ( isset( $_POST['md_multiple_roles_nonce'] ) && !
 wp_verify_nonce( $_POST['md_multiple_roles_nonce'], 'update-md-multiple-
 roles' ) ) {
                 return;
         }

         if ( ! $this->model->can_update_roles() ) {
                 return;
         }

         $new_roles = ( isset( $_POST['md_multiple_roles'] ) && is_array(
 $_POST['md_multiple_roles'] ) ) ? $_POST['md_multiple_roles'] : array();
         if ( empty( $new_roles ) ) {
                 return;
         }

         global $wpdb;

         // Get user signup
         // Suppress errors in case the table doesn't exist
         $suppress = $wpdb->suppress_errors();
         $signup   = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM
 {$wpdb->signups} WHERE user_email = %s", $user_email ) );
         $wpdb->suppress_errors( $suppress );

         if ( empty( $signup ) || is_wp_error( $signup ) ) {
                 return new WP_Error( 'md_get_user_signups_failed' );
         }

         // Add multiple roles to a new array in meta var
         $meta = maybe_unserialize( $meta );
         $meta['md_roles'] = $new_roles;
         $meta = maybe_serialize( $meta );

         // Update user signup with good meta
         $where        = array( 'signup_id' => (int) $signup->signup_id );
         $where_format = array( '%d' );
         $formats      = array( '%s' );
         $fields       = array( 'meta' => $meta );
         $result       = $wpdb->update( $wpdb->signups, $fields, $where,
 $formats, $where_format );

         // Check for errors
         if ( empty( $result ) && ! empty( $wpdb->last_error ) ) {
                 return new WP_Error( 'md_update_user_signups_failed' );
         }
 }
 }}}

 That means, get the signup from the database, update the meta array with
 the data I want to add, update the signup in the database.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/39223#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list