0

我正在尝试创建一个 WP 短代码,它将为 Wordpress 用户插入个人资料表单。

我想调用以下操作: 正在显示的用户的 WP_User 对象<?php do_action( 'bbpnns_digest_show_profile_form', $user); ?> 在哪里。$user

这是我到目前为止所拥有的,但它不起作用(我收到“Bad User”消息):

function custom_shortcode_sc() {
  $current_user = wp_get_current_user (); 
  $user=$current_user->user_login;

  do_action( 'bbpnns_digest_show_profile_form', $user);        
}
add_shortcode( 'custom_shortcode', 'custom_shortcode_sc' );

我想我已经很接近了,但是在正确调用 $user 时遗漏了一些东西。谢谢你的帮助!

4

2 回答 2

1

感谢@yogesh 提供了一个简单的解决方案,让我的代码正常工作。这是最终的代码供参考:

function custom_shortcode_sc() {
  $current_user = wp_get_current_user (); 
  $user = $current_user->ID;

  do_action( 'bbpnns_digest_show_profile_form', $user);        
}
add_shortcode( 'custom_shortcode', 'custom_shortcode_sc' );
于 2018-08-02T14:14:24.400 回答
0

我已经测试了您的短代码,并且它在我的最终工作正常..

请尝试传递用户 ID 而不是用户登录。因为有时用户登录包含空格和特殊字符和函数参数可能不接受这个..所以尝试用户ID..

$user = $current_user->ID;

如果您需要更多帮助,请告诉我..

我很乐意帮助你..

谢谢你

于 2018-08-02T06:44:59.140 回答