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
版权声明:本文标题:woocommerce offtopic - Switch to user link shortcode 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741510121a2382558.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论