Created
February 28, 2024 21:10
-
-
Save wpmudev-sls/200ed07aef5a6a40a4f003d1f20b0705 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: THC Signup Autofill User Information. | |
* Description: Automatically fills in user information in Signup forms for logged-in users. | |
* Jira: SLS-5724 | |
* Author: Abdoljabbar Bakhshande | |
* Author URI: https://wpmudev.com | |
* License: GPLv2 or later | |
* | |
* @package WordPress | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { | |
// If the WordPress base file is not defined, halt execution. | |
exit; | |
} | |
if ( defined( 'WP_CLI' ) && WP_CLI ) { | |
// If the site is accessed via WP-CLI, do not run. | |
return; | |
} | |
function custom_hub_client_autofill_script() { | |
if ( is_user_logged_in() ) { | |
$current_user = wp_get_current_user(); | |
?> | |
<script type="text/javascript"> | |
window.onload = function() { | |
var form = document.querySelector('.dev-embed-hub-form'); // Check if the specific form class exists | |
if (!form) { | |
return; | |
} | |
var nameField = document.querySelector('input[name="registerName"]'); // Adjusted the selector based on the actual form field | |
var emailField = document.querySelector('input[name="registerEmail"]'); // Adjusted the selector based on the actual form field | |
if (nameField) { | |
nameField.value = "<?php echo esc_js( $current_user->display_name ); ?>"; | |
} | |
if (emailField) { | |
emailField.value = "<?php echo esc_js( $current_user->user_email ); ?>"; | |
} | |
}; | |
</script> | |
<?php | |
} | |
} | |
add_action( 'wpmudev_hub_template_footer', 'custom_hub_client_autofill_script' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment