Created
January 28, 2020 23:11
-
-
Save renventura/17866244f33a016e0ebb99b886ecb80e to your computer and use it in GitHub Desktop.
Adds a "Switch To" link to EDD Customer Details page --> Profile tab.
This file contains hidden or 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 | |
add_action( 'edd_customer_before_stats', 'edd_customer_switch_to_link' ); | |
/** | |
* Adds a "Switch To" link to EDD Customer Details page --> Profile tab. | |
* Requires User Switching plugin. | |
* | |
* @author Ren Ventura <renventura.com> | |
* | |
* @param object $customer EDD_Customer | |
* | |
* @return mixed False if no switch link, else void | |
*/ | |
function edd_customer_switch_to_link( $customer ) { | |
$user = new WP_User( $customer->user_id ); | |
$switch_to_link = class_exists( 'user_switching' ) && ! empty( $user->ID ) ? user_switching::maybe_switch_url( $user ) : false; | |
if ( false === $switch_to_link ) { | |
return; | |
} | |
?> | |
<p id="switch_to_customer_link"> | |
<a href="<?php echo $switch_to_link; ?>">Switch To</a> | |
</p> | |
<script> | |
jQuery(document).ready(function($) { | |
// Stick the link below the customer avatar image | |
$('#edit-customer').after($('#switch_to_customer_link')); | |
}); | |
</script> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment