admin管理员组

文章数量:1291113

I am using the User Switching plugin in order to allow sales agents to place an order on behalf of a customer.

I have a page called My Customers which uses toolset to return a list of their customers. I'd like to add a link that allows them to switch to each user on this page.

I have tried adding the following code to functions.php and receive a critical error on the page, code is directly from the developer.

// Add Shortcode
function userswitch_shortcode() {

    if ( method_exists( 'user_switching', 'maybe_switch_url' ) ) {
        $url = user_switching::maybe_switch_url( $target_user );
        if ( $url ) {
            printf(
                '<a href="%1$s">Switch to %2$s</a>',
                esc_url( $url ),
                esc_html( $target_user->display_name )
            );
        }
    }

}
add_shortcode( 'userswitch', 'userswitch_shortcode' );
2021/06/11 05:16:14 [error] 46260#46260: *335027 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught TypeError: Argument 1 passed to user_switching::maybe_switch_url() must be an instance of WP_User, null given, called in /www/healthlightshop_532/public/wp-content/themes/wai-child/functions.php on line 35 and defined in /www/healthlightshop_532/public/wp-content/plugins/user-switching/user-switching.php:757
Stack trace:
#0 /www/healthlightshop_532/public/wp-content/themes/wai-child/functions.php(35): user_switching::maybe_switch_url(NULL)
#1 /www/healthlightshop_532/public/wp-includes/shortcodes.php(343): userswitch_shortcode('', '', 'userswitch')
#2 [internal function]: do_shortcode_tag(Array)
#3 /www/healthlightshop_532/public/wp-includes/shortcodes.php(218): preg_replace_callback('/\\[(\\[?)(usersw...', 'do_shortcode_ta...', '<div class="fl-...')
#4 /www/healthlightshop_532/public/wp-content/plugins/bb-plugin/classes/class-fl-builder.php(1844): do_shortcode('<div class="fl-...')
#5 /www/healthlightshop_532/public/wp-content/plugins/bb-plugin/classes/clas" while reading response header from upstream, client: 67.173.15.26, server: shop.healthlightllc, request: "GET /my-customers/?v=32aec8db952d HTTP/1.0", upstream: "fastcgi://unix:/var/run/php7.4-fpm-healthlightshop.sock:", host: "shop.healthlightllc"

本文标签: woocommerce offtopicSwitch to user link shortcode