<?php
/**
 * Enable functionality for the Edit Member Panel when saving user info.
 * Add this code to your site, follow this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
**/
function my_custom_ffl_fix_user_display_name() {
	
	// Make sure Force First and Last Name is installed.
	if ( ! function_exists( 'ffl_fix_user_display_name' ) ) {
		return;
	}
	
	// Update on specific panel update.
	$pmpro_page = empty( $_REQUEST['page'] ) ? '' : sanitize_text_field( $_REQUEST['page'] );
	if ( $pmpro_page !== 'pmpro-member' ) {
		return;
	}

	// Get the user ID from the request.
	$user_id = empty( $_REQUEST['user_id'] ) ? 0 : intval( $_REQUEST['user_id'] );

	if ( ! $user_id ) {
		return;
	}
	
	// Generate the display name.
	ffl_fix_user_display_name( $user_id );
	
}
add_action( 'admin_init', 'my_custom_ffl_fix_user_display_name', 99 );