• Resolved 37

    (@mikegandy)


    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)
  • Plugin Author Jeff Starr

    (@specialk)

    Thanks for sharing this code snippet Michael ??

    @mikegandy Hello, thanks for sharing that feature, but i have a problem to move it after wpforo, SAC is always before forum when i use [sac_populated]. Can You help me move it to the bottom ?

    Thread Starter 37

    (@mikegandy)

    @misiek1294 , I apologize; my email gets flooded and I just realized your comment was here. I have since disabled the chat just because we didn’t end up needing a chat feature on our website. Therefore, I don’t have the code in front of me to look at a solution. Are you still trying to figure this out? If so, maybe you can give me a link to your chatroom and I can take a look.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Auto Populate Display Name and Profile Link’ is closed to new replies.