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 (2)

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

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