yourprefix_register_user_profile_metabox

Hook in and add a metabox to add fields to the user profile pages.

Description

yourprefix_register_user_profile_metabox(); 

Usage

  1. if ( !function_exists( 'yourprefix_register_user_profile_metabox' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'cmb2/example-functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = yourprefix_register_user_profile_metabox(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/example-functions.php  
  1. function yourprefix_register_user_profile_metabox() { 
  2. $prefix = 'yourprefix_user_'; 
  3.  
  4. /** 
  5. * Metabox for the user profile screen 
  6. */ 
  7. $cmb_user = new_cmb2_box( array( 
  8. 'id' => $prefix . 'edit',  
  9. 'title' => esc_html__( 'User Profile Metabox', cmb2 ), // Doesn't output for user boxes 
  10. 'object_types' => array( 'user' ), // Tells CMB2 to use user_meta vs post_meta 
  11. 'show_names' => true,  
  12. 'new_user_section' => 'add-new-user', // where form will show on new user page. 'add-existing-user' is only other valid option. 
  13. ) ); 
  14.  
  15. $cmb_user->add_field( array( 
  16. 'name' => esc_html__( 'Extra Info', cmb2 ),  
  17. 'desc' => esc_html__( 'field description (optional)', cmb2 ),  
  18. 'id' => $prefix . 'extra_info',  
  19. 'type' => 'title',  
  20. 'on_front' => false,  
  21. ) ); 
  22.  
  23. $cmb_user->add_field( array( 
  24. 'name' => esc_html__( 'Avatar', cmb2 ),  
  25. 'desc' => esc_html__( 'field description (optional)', cmb2 ),  
  26. 'id' => $prefix . 'avatar',  
  27. 'type' => 'file',  
  28. ) ); 
  29.  
  30. $cmb_user->add_field( array( 
  31. 'name' => esc_html__( 'Facebook URL', cmb2 ),  
  32. 'desc' => esc_html__( 'field description (optional)', cmb2 ),  
  33. 'id' => $prefix . 'facebookurl',  
  34. 'type' => 'text_url',  
  35. ) ); 
  36.  
  37. $cmb_user->add_field( array( 
  38. 'name' => esc_html__( 'Twitter URL', cmb2 ),  
  39. 'desc' => esc_html__( 'field description (optional)', cmb2 ),  
  40. 'id' => $prefix . 'twitterurl',  
  41. 'type' => 'text_url',  
  42. ) ); 
  43.  
  44. $cmb_user->add_field( array( 
  45. 'name' => esc_html__( 'Google+ URL', cmb2 ),  
  46. 'desc' => esc_html__( 'field description (optional)', cmb2 ),  
  47. 'id' => $prefix . 'googleplusurl',  
  48. 'type' => 'text_url',  
  49. ) ); 
  50.  
  51. $cmb_user->add_field( array( 
  52. 'name' => esc_html__( 'Linkedin URL', cmb2 ),  
  53. 'desc' => esc_html__( 'field description (optional)', cmb2 ),  
  54. 'id' => $prefix . 'linkedinurl',  
  55. 'type' => 'text_url',  
  56. ) ); 
  57.  
  58. $cmb_user->add_field( array( 
  59. 'name' => esc_html__( 'User Field', cmb2 ),  
  60. 'desc' => esc_html__( 'field description (optional)', cmb2 ),  
  61. 'id' => $prefix . 'user_text_field',  
  62. 'type' => 'text',  
  63. ) ); 
  64.