Auto Populate Display Name and Profile Link
-
For those looking for an upgrade to user-only chat, the following code will:
1. Auto-populate the user’s display name in the username field
2. Auto-populate the user’s profile url in the URL field
3. Widen the chat box to 100% and put the message field on the bottom
4. Hide the name and url inputs
5. Hide the “Message” label and add a placeholder saying “Type your message here”
6. Change the Submit button text to “Send Message”Add to your functions.php file and use
[sac_populated]
as your shortcode instead:/** * Autopopulate chat room details using a new shortcode * Usage: [sac_populated] */ add_shortcode( 'sac_populated', 'sac_populated_function' ); function sac_populated_function() { $user_info = get_userdata( get_current_user_id()); $display_name = $user_info->display_name; $combined_name = str_replace(' ', '-', $display_name); if (function_exists('simple_ajax_chat')) simple_ajax_chat(); $results = '<style>fieldset#sac-user-info, fieldset#sac-user-url, #sac-user-chat label {display: none;} div#sac-output, input#sac_chat {width: 100% !important; margin-top: 10px !important;} div#sac-panel {float: left !important; width: 100% !important;} </style>'; $results .= '<div id="display-name-div" class="'.$combined_name.'"></div><div id="profile-url-div" class="'.um_user_profile_url().'"></div>'; $results .= '<script type="text/javascript">'; $results .= 'var combinedName = document.getElementById("display-name-div").className;'; $results .= 'var displayName = combinedName.replace(/-/g, " ");'; $results .= 'var nameInput = document.getElementById("sac_name");'; $results .= 'nameInput.value = displayName;'; $results .= 'var profileURL = document.getElementById("profile-url-div").className;'; $results .= 'var urlInput = document.getElementById("sac_url");'; $results .= 'urlInput.value = profileURL;'; $results .= 'var chatInput = document.getElementById("sac_chat");'; $results .= 'chatInput.placeholder = "Type your message here";'; $results .= 'var submitButton = document.getElementById("submitchat");'; $results .= 'submitButton.value = "Send Message";'; $results .= '</script>'; return $results; }
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Auto Populate Display Name and Profile Link’ is closed to new replies.