Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.
LLMS_Person_Handler::insert_data( array $data = array(), string $action = 'registration' )
Insert user data during registrations and updates
Description Description
Parameters Parameters
- $data
-
(array) (Optional) array of user data to be passed to WP core functions
Default value: array()
- $action
-
(string) (Optional) either registration or update
Default value: 'registration'
Return Return
(WP_Error|int) WP_Error on error or the WP User ID
Source Source
File: includes/class.llms.person.handler.php
private static function insert_data( $data = array(), $action = 'registration' ) { if ( 'registration' === $action ) { $insert_data = array( 'role' => 'student', 'show_admin_bar_front' => false, 'user_email' => $data['email_address'], 'user_login' => $data['user_login'], 'user_pass' => $data['password'], ); $extra_data = array( 'first_name', 'last_name', ); $insert_func = 'wp_insert_user'; $meta_func = 'add_user_meta'; } elseif ( 'update' === $action ) { $insert_data = array( 'ID' => $data['user_id'], ); // email address if set if ( isset( $data['email_address'] ) ) { $insert_data['user_email'] = $data['email_address']; } // update password if both are set if ( isset( $data['password'] ) && isset( $data['password_confirm'] ) ) { $insert_data['user_pass'] = $data['password']; } $extra_data = array( 'first_name', 'last_name', ); $insert_func = 'wp_update_user'; $meta_func = 'update_user_meta'; } else { return new WP_Error( 'invalid', __( 'Invalid action', 'lifterlms' ) ); }// End if(). foreach ( $extra_data as $field ) { if ( isset( $data[ $field ] ) ) { $insert_data[ $field ] = $data[ $field ]; } } // attempt to insert the data $person_id = $insert_func( apply_filters( 'lifterlms_user_' . $action . '_insert_user', $insert_data, $data, $action ) ); // return the error object if registration fails if ( is_wp_error( $person_id ) ) { return apply_filters( 'lifterlms_user_' . $action . '_failure', $person_id, $data, $action ); } // add user ip address $data[ self::$meta_prefix . 'ip_address' ] = llms_get_ip_address(); // metas $possible_metas = apply_filters( 'llms_person_insert_data_possible_metas', array( self::$meta_prefix . 'billing_address_1', self::$meta_prefix . 'billing_address_2', self::$meta_prefix . 'billing_city', self::$meta_prefix . 'billing_state', self::$meta_prefix . 'billing_zip', self::$meta_prefix . 'billing_country', self::$meta_prefix . 'ip_address', self::$meta_prefix . 'phone', ) ); $insert_metas = array(); foreach ( $possible_metas as $meta ) { if ( isset( $data[ $meta ] ) ) { $insert_metas[ $meta ] = $data[ $meta ]; } } // record all meta values $metas = apply_filters( 'lifterlms_user_' . $action . '_insert_user_meta', $insert_metas, $data, $action ); foreach ( $metas as $key => $val ) { $meta_func( $person_id, $key, $val ); } // if agree to terms data is present, record the agreement date if ( isset( $data[ self::$meta_prefix . 'agree_to_terms' ] ) && 'yes' === $data[ self::$meta_prefix . 'agree_to_terms' ] ) { $meta_func( $person_id, self::$meta_prefix . 'agree_to_terms', current_time( 'mysql' ) ); } return $person_id; }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
3.0.0 | Introduced. |
User Contributed Notes User Contributed Notes
Permalink: