WordPress/BuddyPress添加用户类型

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WordPress/BuddyPress添加用户类型相关的知识,希望对你有一定的参考价值。

I used this plugin to create new roles/capabilities: http://wordpress.org/extend/plugins/capsman/
  1. Put this in the BuddyPress theme /registration/register.php file:
  2. <label>Account Type:</label>
  3. <select>
  4. <option value="optiona">Option A</option>
  5. <option value="optionb">Option B</option>
  6. <option value="optionc">Option C</option>
  7. </select>
  8.  
  9.  
  10. Put the following code in your theme's functions.php
  11.  
  12. <?php
  13. /* Add sign-up field to BuddyPress sign-up array*/
  14. function bp_custom_user_signup_field( $usermeta ) {
  15. $usermeta['signup_type'] = $_POST['signup_type'];
  16.  
  17. return $usermeta;
  18. }
  19. add_filter( 'bp_signup_usermeta', 'bp_custom_user_signup_field' );
  20.  
  21. /* Add field_name from sign-up to usermeta on activation */
  22. function bp_user_activate_field( $signup ) {
  23.  
  24. update_usermeta( $signup['user_id'], 'signup_type', $signup['meta']['signup_type'] );
  25.  
  26. return $signup;
  27. }
  28. add_filter( 'bp_core_activate_account', 'bp_user_activate_field' );
  29.  
  30. function synchro_wp_usermeta($user_id, $password, $meta) {
  31. global $bp, $wpdb;
  32.  
  33. $type = $meta[signup_type];
  34.  
  35. update_usermeta( $user_id, 'signup_type', $type );
  36.  
  37. }
  38. add_action( 'wpmu_activate_user', 'synchro_wp_usermeta', 10, 3);
  39.  
  40. function synchro_wp_usermeta_blog($blog_id, $user_id, $domain, $path, $site_id, $meta) {
  41. global $bp, $wpdb;
  42.  
  43. $type = $meta[signup_type];
  44.  
  45. update_usermeta( $user_id, 'signup_type', $type );
  46.  
  47. }
  48.  
  49. add_action( 'wpmu_new_blog', 'synchro_wp_usermeta_blog', 10, 6 );
  50.  
  51. // change user role on registration
  52.  
  53. function register_role($user_id, $password, $meta) {
  54.  
  55. global $bp, $wpdb;
  56.  
  57. $userdata = array();
  58. $userdata['ID'] = $user_id;
  59. $userdata['role'] = $meta['signup_type'];
  60.  
  61. //only allow if user role is my_role
  62.  
  63. if ($userdata['role'] == 'optiona' || $userdata['role'] == 'optionb' || $userdata['role'] == 'optionc' ){
  64. wp_update_user($userdata);
  65. }
  66. }
  67.  
  68. add_action('wpmu_activate_user', 'register_role', 10, 3);
  69.  
  70. function register_role_blog($blog_id, $user_id, $domain, $path, $site_id, $meta) {
  71. global $bp, $wpdb;
  72.  
  73. $userdata = array();
  74. $userdata['ID'] = $user_id;
  75. $userdata['role'] = $meta['signup_type'];
  76.  
  77. //only allow if user role is my_role
  78.  
  79. if ($userdata['role'] == 'optiona' || $userdata['role'] == 'optionb' || $userdata['role'] == 'optionc' ){
  80. wp_update_user($userdata);
  81. }
  82.  
  83. }
  84.  
  85. add_action( 'wpmu_new_blog', 'register_role_blog', 101, 6 );
  86. ?>

以上是关于WordPress/BuddyPress添加用户类型的主要内容,如果未能解决你的问题,请参考以下文章

wordpress buddypress 2.6.1.1 激活邮件修改

Sencha Touch 和 WordPress BuddyPress API 之间的 JSON 解析问题

Joomla:根据用户组添加页面类

在添加身份对话框中禁用用户类条目

将用户选择的方法添加到 python 中的元基类

可拖动 | jQuery 用户界面。如何在拖动事件上添加类