cf_custom_fields_form_as_metabox

Setup form in the admin.

Description

cf_custom_fields_form_as_metabox(); 

Usage

  1. if ( !function_exists( 'cf_custom_fields_form_as_metabox' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'caldera-custom-fields/includes/metabox.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = cf_custom_fields_form_as_metabox(); 
  7.  

Defined (1)

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

/includes/metabox.php  
  1. function cf_custom_fields_form_as_metabox() { 
  2. $forms = get_option( '_caldera_forms' ); 
  3. if(empty($forms)) { 
  4. return; 
  5. foreach($forms as $form) { 
  6.  
  7. if(!empty($form['is_metabox'])) { 
  8. $form = get_option($form['ID']); 
  9. // is metabox processor 
  10. if(!empty($form['processors'][$form['is_metabox']]['config']['posttypes'])) { 
  11.  
  12. // add filter to get details of entry 
  13.  
  14. // add filter to remove submit buttons 
  15.  
  16. foreach( $form['processors'][$form['is_metabox']]['config']['posttypes'] as $screen=>$enabled) { 
  17. add_meta_box( 
  18. $form['ID'],  
  19. $form['name'],  
  20. $screen,  
  21. $form['processors'][$form['is_metabox']]['config']['context'],  
  22. $form['processors'][$form['is_metabox']]['config']['priority'] 
  23. ); 
  24.  
  25. // has a form - get field type 
  26. if(!isset($field_types)) { 
  27. $field_types = apply_filters('caldera_forms_get_field_types', array() ); 
  28.  
  29. if(!empty($form['fields'])) { 
  30. foreach($form['fields'] as $field) { 
  31. //enqueue styles 
  32. if( !empty( $field_types[$field['type']]['styles'])) { 
  33. foreach($field_types[$field['type']]['styles'] as $style) { 
  34. if(filter_var($style, FILTER_VALIDATE_URL)) { 
  35. wp_enqueue_style( 'cf-' . sanitize_key( basename( $style ) ), $style, array()); 
  36. }else{ 
  37. wp_enqueue_style( $style ); 
  38.  
  39. //enqueue scripts 
  40. if( !empty( $field_types[$field['type']]['scripts'])) { 
  41. // check for jquery deps 
  42. $depts[] = 'jquery'; 
  43. foreach($field_types[$field['type']]['scripts'] as $script) { 
  44. if(filter_var($script, FILTER_VALIDATE_URL)) { 
  45. wp_enqueue_script( 'cf-' . sanitize_key( basename( $script ) ), $script, $depts); 
  46. }else{ 
  47. wp_enqueue_script( $script ); 
  48.  
  49. // if depts been set- scripts are used - 
  50. wp_enqueue_script( 'cf-frontend-fields', CFCORE_URL . 'assets/js/fields.min.js', array('jquery'), null, true); 
  51. wp_enqueue_script( 'cf-frontend-script-init', CFCORE_URL . 'assets/js/frontend-script-init.min.js', array('jquery'), null, true); 
  52.  
  53. // metabox & gridcss 
  54. wp_enqueue_style( 'cf-metabox-grid-styles', CCF_URL . 'css/metagrid.css'); 
  55. wp_enqueue_style( 'cf-metabox-field-styles', CFCORE_URL . 'assets/css/fields.min.css'); 
  56. wp_enqueue_style( 'cf-metabox-styles', CCF_URL . 'css/metabox.css'); 
  57.