簡體   English   中英

使用WP_User對象的簡碼

[英]Shortcode using WP_User object

我正在嘗試創建WP短代碼,該代碼將為Wordpress用戶插入配置文件表單。

我想調用以下操作: <?php do_action( 'bbpnns_digest_show_profile_form', $user); ?> <?php do_action( 'bbpnns_digest_show_profile_form', $user); ?>其中$user是要顯示的用戶的WP_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時缺少了一些東西。 謝謝你的幫助!

感謝@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' );

我已經測試了您的短代碼及其正常工作。

請嘗試傳遞用戶ID,而不是用戶登錄名。 由於有時用戶登錄名包含空格,特殊字符和功能參數可能不接受此。.因此,請嘗試使用用戶ID。

$ user = $ current_user-> ID;

如果您需要更多幫助,請告訴我。

我很樂意為您提供幫助。

謝謝

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM