1. Home
  2. Third-Party
  3. LifterLMS integration

LifterLMS integration

By default, LifterLMS uses his own logic to register, for example, the custom user meta as soon as a new user was added to WordPress. 
Down below you will find all possible integrations we offer for LifterLMS.

Add LifterLMS custom user meta on “Send Data On Register” trigger:
The following code offers you the possibility to add the LifterLMS user meta along to the Send Data On Register trigger. It supports the data that is added through the frontend logic for LifterLMS, as well as for the manually added user meta of adding a user from the backend.

To make it work, just copy and paste the code down below into your functions.php file into your child theme.

class WPWHPRO_LLM_Insert_User_Meta{

    public function __construct() {
        $this->user_data = array();
        $this->action = 'registration';

        add_filter( 'lifterlms_user_' . $this->action . '_insert_user', array( $this, 'wpwhpro_grab_frontend_user_data' ), 10, 3 );
	    add_action( 'user_register', array( $this, 'wpwhpro_add_llms_user_register' ), 5, 1 );
    }

	/**
     * This functionis only available for grabbing the data in case it is a frontend call
     *
	 * @param $insert_data - the user data
	 * @param $data - The data we want with the meta attributes
	 * @param $action - the current action (In this case "registration"
	 *
	 * @return mixed - the user data
	 */
    public function wpwhpro_grab_frontend_user_data( $insert_data, $data, $action ){

        $this->user_data = $data;

        return $insert_data;
    }


    public function wpwhpro_add_llms_user_register( $user_id ){

        //Make sure we also check the possibility to trigger after we add a user through the backend
        if( empty( $this->user_data ) ){
	        $this->user_data = $_POST;
        }

        $meta_prefix = 'llms_';

	    $possible_metas = apply_filters( 'llms_person_insert_data_possible_metas', array(
		    $meta_prefix . 'billing_address_1',
		    $meta_prefix . 'billing_address_2',
		    $meta_prefix . 'billing_city',
		    $meta_prefix . 'billing_state',
		    $meta_prefix . 'billing_zip',
		    $meta_prefix . 'billing_country',
		    $meta_prefix . 'ip_address',
		    $meta_prefix . 'phone',
	    ) );
	    $insert_metas = array();
	    foreach ( $possible_metas as $meta ) {
		    if ( isset( $this->user_data[ $meta ] ) ) {
			    $insert_metas[ $meta ] = $this->user_data[ $meta ];
		    }
	    }

	    $metas = apply_filters( 'lifterlms_user_' . $this->action . '_insert_user_meta', $insert_metas, $this->user_data, $this->action );
	    foreach ( $metas as $key => $val ) {
		    update_user_meta( $user_id, $key, $val );
	    }

    }

}
new WPWHPRO_LLM_Insert_User_Meta();
Updated on October 18, 2021

Was this article helpful?

Related Articles