/** *添加自定义表单 */ function Bing_add_extra_social_links( $user ){ ?> <table class="form-table"> <tr> <th><label for="weibo">新浪微博</label></th> <td><input type="text" name="weibo" value="<?php echo esc_attr( get_the_author_meta( 'weibo', $user->ID ) ); ?>" class="regular-text" /></td> </tr> <tr> <th><label for="qq">QQ 号码</label></th> <td> <input type="text" name="qq" value="<?php echo esc_attr( get_the_author_meta( 'qq', $user->ID ) ); ?>" class="regular-text" /> <br> <span class="description" for="qq">请输入您的 QQ 号码。</span> </td> </tr> </table> <?php } add_action( 'show_user_profile', 'Bing_add_extra_social_links' ); add_action( 'edit_user_profile', 'Bing_add_extra_social_links' ); /** *保存自定义表单 */ function Bing_save_extra_social_links( $user_id ){ update_user_meta( $user_id, 'weibo', sanitize_text_field( $_POST['weibo'] ) ); update_user_meta( $user_id, 'qq', sanitize_text_field( $_POST['qq'] ) ); } add_action( 'personal_options_update', 'Bing_save_extra_social_links' ); add_action( 'edit_user_profile_update', 'Bing_save_extra_social_links' );
如果想获取保存的资料可以使用 get_the_author_meta() 函数,比如:
<?php echo the_author_meta( 'weibo' ); ?>
转载请注明:有客帮 » WordPress 在个人资料页面添加额外的字段