cmb_metabox_form

The BuddyPress Profile Tabs cmb metabox form function.

Description

cmb_metabox_form( $meta_box, $object_id, (bool) $echo = true ); 

Parameters (3)

0. $meta_box
The meta box.
1. $object_id
The object id.
2. $echo — Optional. (bool) => true
The echo.

Usage

  1. if ( !function_exists( 'cmb_metabox_form' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress-profile-tabs/admin/includes/CMBF/init.php'; 
  3.  
  4. // The meta box. 
  5. $meta_box = null; 
  6.  
  7. // The object id. 
  8. $object_id = null; 
  9.  
  10. // The echo. 
  11. $echo = true; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = cmb_metabox_form($meta_box, $object_id, $echo); 
  15.  

Defined (1)

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

/admin/includes/CMBF/init.php  
  1. function cmb_metabox_form( $meta_box, $object_id, $echo = true ) { 
  2.  
  3. $meta_box = cmb_Meta_Box::set_mb_defaults( $meta_box ); 
  4.  
  5. // Make sure form should be shown 
  6. if ( ! apply_filters( 'cmb_show_on', true, $meta_box ) ) 
  7. return ''; 
  8.  
  9. // Make sure that our object type is explicitly set by the metabox config 
  10. cmb_Meta_Box::set_object_type( cmb_Meta_Box::set_mb_type( $meta_box ) ); 
  11.  
  12. // Save the metabox if it's been submitted 
  13. // check permissions 
  14. // @todo more hardening? 
  15. if ( 
  16. // check nonce 
  17. isset( $_POST['submit-cmb'], $_POST['object_id'], $_POST['wp_meta_box_nonce'] ) 
  18. && wp_verify_nonce( $_POST['wp_meta_box_nonce'], cmb_Meta_Box::nonce() ) 
  19. && $_POST['object_id'] == $object_id 
  20. cmb_save_metabox_fields( $meta_box, $object_id ); 
  21.  
  22. // Show specific metabox form 
  23.  
  24. // Get cmb form 
  25. ob_start(); 
  26. cmb_print_metabox( $meta_box, $object_id ); 
  27. $form = ob_get_contents(); 
  28. ob_end_clean(); 
  29.  
  30. $form_format = apply_filters( 'cmb_frontend_form_format', '<form class="cmb-form" method="post" id="%s" enctype="multipart/form-data" encoding="multipart/form-data"><input type="hidden" name="object_id" value="%s">%s<input type="submit" name="submit-cmb" value="%s" class="button-primary"></form>', $object_id, $meta_box, $form ); 
  31.  
  32. $form = sprintf( $form_format, $meta_box['id'], $object_id, $form, __( 'Save' ) ); 
  33.  
  34. if ( $echo ) 
  35. echo $form; 
  36.  
  37. return $form;