| |
| <?php
|
| add_filter( 'edd_report_customer_columns', 'gv_edd_report_customer_columns_add_user_switching' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| function gv_edd_report_customer_columns_add_user_switching( $columns ) {
|
|
|
| if ( ! class_exists( 'user_switching' ) ) {
|
| return $columns;
|
| }
|
|
|
| $columns['user_switching'] = esc_html__( 'Switch To', 'edd-user-switching' );
|
|
|
| return $columns;
|
| }
|
|
|
| add_filter( 'edd_customers_column_user_switching', 'gv_edd_customers_column_user_switching', 10, 2 );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| function gv_edd_customers_column_user_switching( $value, $item_id = 0 ) {
|
|
|
| $customer = new EDD_Customer( $item_id );
|
|
|
| return gv_edd_user_switching_link( $customer );
|
| }
|
|
|
| add_filter( 'edd_payments_table_column', 'gv_edd_payments_table_column_user_switching', 10, 3 );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| function gv_edd_payments_table_column_user_switching( $value, $payment_id = 0, $column_name = '' ) {
|
|
|
| if ( ! class_exists( 'user_switching' ) ) {
|
| return $value;
|
| }
|
|
|
| if ( 'user' === $column_name ) {
|
| $payment = new EDD_Payment( $payment_id );
|
| $customer = new EDD_Customer( $payment->customer_id );
|
| if ( $link = gv_edd_user_switching_link( $customer, __( 'Switch To', 'edd-user-switching' ) ) ) {
|
| $value .= ' (' . $link . ')';
|
| }
|
| }
|
|
|
| return $value;
|
| }
|
|
|
| add_action( 'edd_payment_view_details', 'gv_edd_payment_view_details_user_switching' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| function gv_edd_payment_view_details_user_switching( $payment_id ) {
|
|
|
| $payment = new EDD_Payment( $payment_id );
|
|
|
| if ( ! $payment ) {
|
| return;
|
| }
|
|
|
| $customer = new EDD_Customer( $payment->customer_id );
|
|
|
| if ( ! $customer ) {
|
| return;
|
| }
|
|
|
| $link = gv_edd_user_switching_link( $customer );
|
|
|
| if( empty( $link ) ) {
|
| return;
|
| }
|
|
|
|
|
| ?>
|
| <script>
|
| jQuery( document ).ready( function( $ ) {
|
| $('.edd-switch-customer').appendTo('#edd-customer-details h3').addClass('alignright').css('font-size', '13px');
|
| });
|
| </script>
|
| <?php
|
| echo $link;
|
| }
|
|
|
| add_action( 'edd_customer_before_stats', 'gv_edd_customer_user_switching_link' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| function gv_edd_customer_user_switching_link( $customer ) {
|
|
|
| $link = gv_edd_user_switching_link( $customer );
|
|
|
| if ( $link ) {
|
| echo '<div class="customer-note-wrapper" id="customer-edit-actions">';
|
| echo $link;
|
| echo '</div >';
|
| }
|
| }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| function gv_edd_user_switching_link( $customer, $text = '' ) {
|
|
|
| if ( ! class_exists( 'user_switching' ) ) {
|
| return '';
|
| }
|
|
|
| $user = get_user_by( 'id', $customer->user_id );
|
|
|
| if ( ! $user ) {
|
| return '';
|
| }
|
|
|
| if ( ! $link = user_switching::maybe_switch_url( $user ) ) {
|
| return '';
|
| }
|
|
|
| if ( empty( $text ) ) {
|
| $text = __( 'Switch To Customer', 'edd-user-switching' );
|
| }
|
|
|
| return sprintf( '<a href="%s" class="edd-switch-customer">%s</a>', esc_url( $link ), esc_html( $text ) );
|
| }
|
| |
| |
Comments