WP如何爲用戶添加資料選項

  1. /////Add User Profile item   
  2. add_action( 'show_user_profile', 'sl_profile_fields' );   
  3. add_action( 'edit_user_profile', 'sl_profile_fields' );   
  4.   
  5. function sl_profile_fields( $user ) {   
  6. ?>   
  7.   
  8.     <h3>社交網絡</h3>   
  9.   
  10.     <table class="form-table">   
  11.   
  12.         <tr>   
  13.             <th><label for="weibo">SINA-WEIBO</label></th>   
  14.   
  15.             <td>   
  16.                 <input type="text" name="weibo" id="weibo" value="<?php echo esc_attr( get_the_author_meta( 'weibo', $user->ID ) ); ?>" /><br />   
  17.                 <span class="description">新浪微博鏈接</span>   
  18.             </td>   
  19.         </tr>   
  20.     </table>   
  21.   
  22. <?php   
  23. }   
  24. add_action( 'personal_options_update', 'sl_save_profile_fields' );   
  25. add_action( 'edit_user_profile_update', 'sl_save_profile_fields' );   
  26.   
  27. function sl_save_profile_fields( $user_id ) {   
  28.     if ( !current_user_can( 'edit_user', $user_id ) )   
  29.         return false;   
  30.     update_user_meta( $user_id, 'weibo', $_POST['weibo'] );   
  31.   用戶打開Wordpress後臺-->用戶-->我的資料的時候,會在“更新個人資料“按鈕上方出現新增的微博設置項
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章