MrApplejuice / wp-autologin-links

Development branch of the WordPress Autologin-Links plugin
https://www.wordpress.org/plugins/autologin-links/
21 stars 5 forks source link

Anchor link in User Profile #29

Open jarodthornton opened 3 years ago

jarodthornton commented 3 years ago

I've forked your repo and we have done some workarounds I will outline below, but first, would you consider adding an anchor to the user profile link that is created?

https://github.com/Adopt-the-Web/wp-autologin-links/commit/ba68207ac92016b472c16c9aaa9f0ed97f909837#diff-0c30edbc52e942dd89a0bd37793f811b2b099509c7ef90c6a492bb5cf48c6dfd

Now, I wanted to share this because it has been incredibly useful, and may be something you'd be interested to learn we are doing.

Autologin to client order from admin

Screenshot: https://drive.google.com/file/d/18p78_5CMGy-Yfc9DmcE-lga7XOgMxx9G/view?usp=sharing

function custom_metabox_content_customer_data( $order ){
    ?>
    <script>
        function copyToClipboard(textToCopy) {

            urlInput = document.createElement( "input" );
        document.body.appendChild( urlInput );
        urlInput.setAttribute( "value", textToCopy );
        if ( navigator.userAgent.match( /ipad|ipod|iphone/i ) ) {
            let contentEditable      = urlInput.contentEditable,
                readOnly             = urlInput.readOnly,
                range                = document.createRange(),
                windowSelection      = window.getSelection();
            urlInput.contentEditable = !0;
            urlInput.readOnly        = !1;
            range.selectNodeContents( urlInput );
            windowSelection.removeAllRanges();
            windowSelection.addRange( range );
            urlInput.setSelectionRange( 0, 999999 );
            urlInput.contentEditable = contentEditable;
            urlInput.readOnly        = readOnly
        } else urlInput.select();
        document.execCommand( "copy" );
        document.body.removeChild( urlInput );
        alert( "Successfully copied to clipboard" );
    }
    </script>
    <?php
    $order = new WC_Order( $order );
    $user_id = $order->user_id;
    $user_id = $order->get_customer_id();
    if($user_id){
        $user = get_user_by( 'ID', $user_id );
        $auto_login = $user->pkg_autologin_code;    
        $auto_login = $order->get_checkout_payment_url() . '&autologin_code=' . $auto_login;
        ?>
            <style>
            .auto-login-links {color: #fff;font-weight: normal;text-decoration: none;background: #1e85be;padding: 5px 10px;border-radius: 2px;}
            </style>            
            <p>View as Client Links: Open in Incognito / Private browser session for internal reference (right-click on link). <br/><strong>Use "Copy to clipboard" for sending relevant autologin links to client.</p>
            <input style="display:none;" readonly='true' style='width:100%' type='text' value='<?=$auto_login?>'>
            <a class="auto-login-links" href="<?=$auto_login?>'>" target="_blank">View Order as Client</a><button type="button" style="float:right" onclick="copyToClipboard('<?=$auto_login?>')">Copy to clipboard</button>

        <?php
    }else{
        echo "No user associated with this order.";
    }
}

Auto login button in order emails

Screenshot: https://drive.google.com/file/d/1xfReI9a6BE2t-FBlAckbqRhu5Sp8eMfE/view?usp=sharing

<?php
$user_id = $order->get_customer_id();
$user = get_user_by( 'ID', $user_id );
$auto_login = $user->pkg_autologin_code;    
printf(
    wp_kses(
        /* translators: %1$s Site title, %2$s Order pay link */
        __( 'An order has been created for you on %1$s. Your invoice is below, with a link to make payment when you’re ready: %2$s', 'woocommerce' ),
        array(
            'a' => array(
                'href' => array(),
            ),
        )
    ),
    esc_html( get_bloginfo( 'name', 'display' ) ),
    '<br/><br/><br/><br/><a style="color: #fff;font-weight: normal;font-size: 1.5em;text-decoration: none;background: #1e85be;padding: 10px 15px;border-radius: 2px;" href="' . esc_url( $order->get_checkout_payment_url() ) . '&autologin_code=' . $auto_login . '">' . esc_html__( 'Pay for this order', 'woocommerce' ) . '</a><br/><br/><br/><br/>'
);
?>  
MrApplejuice commented 3 years ago

Hey there!

Wow that screenshot looks pretty sweet! A very nice way of integrating everything and creative use of the feature. I can see the specific usecase. Seems handy indeed.

To import the idea as a generic feature, it needs to a bit more thought, but maybe something like a button-tag would be possible. A big question of course would be how to safe-guard such a generic button so that regular authors cannot simply mine for autologin keys of other users.

I will keep this open for now and let is settle a bit. Thanks for sharing the code. Maybe it can be imported as a generic feature in the future.

sezerkaratas commented 3 years ago

Hello there When the user is created, I should automatically create a link and save it to the metadata. I tried a few times but I couldn't get it to work at all. can you help please