cf_custom_fields_form_as_metabox
Setup form in the admin.
Description
cf_custom_fields_form_as_metabox();
Usage
if ( !function_exists( 'cf_custom_fields_form_as_metabox' ) ) { require_once ABSPATH . PLUGINDIR . 'caldera-custom-fields/includes/metabox.php'; } // NOTICE! Understand what this does before running. $result = cf_custom_fields_form_as_metabox();
Defined (1)
The function is defined in the following location(s).
- /includes/metabox.php
- function cf_custom_fields_form_as_metabox() {
- $forms = get_option( '_caldera_forms' );
- if(empty($forms)) {
- return;
- }
- foreach($forms as $form) {
- if(!empty($form['is_metabox'])) {
- $form = get_option($form['ID']);
- // is metabox processor
- if(!empty($form['processors'][$form['is_metabox']]['config']['posttypes'])) {
- // add filter to get details of entry
- add_filter('caldera_forms_get_entry_detail', 'cf_custom_fields_get_post_details', 10, 3);
- // add filter to remove submit buttons
- foreach( $form['processors'][$form['is_metabox']]['config']['posttypes'] as $screen=>$enabled) {
- add_meta_box(
- $form['ID'],
- $form['name'],
- $screen,
- $form['processors'][$form['is_metabox']]['config']['context'],
- $form['processors'][$form['is_metabox']]['config']['priority']
- );
- }
- }
- // has a form - get field type
- if(!isset($field_types)) {
- $field_types = apply_filters('caldera_forms_get_field_types', array() );
- }
- if(!empty($form['fields'])) {
- foreach($form['fields'] as $field) {
- //enqueue styles
- if( !empty( $field_types[$field['type']]['styles'])) {
- foreach($field_types[$field['type']]['styles'] as $style) {
- if(filter_var($style, FILTER_VALIDATE_URL)) {
- wp_enqueue_style( 'cf-' . sanitize_key( basename( $style ) ), $style, array());
- }else{
- wp_enqueue_style( $style );
- }
- }
- }
- //enqueue scripts
- if( !empty( $field_types[$field['type']]['scripts'])) {
- // check for jquery deps
- $depts[] = 'jquery';
- foreach($field_types[$field['type']]['scripts'] as $script) {
- if(filter_var($script, FILTER_VALIDATE_URL)) {
- wp_enqueue_script( 'cf-' . sanitize_key( basename( $script ) ), $script, $depts);
- }else{
- wp_enqueue_script( $script );
- }
- }
- }
- }
- }
- // if depts been set- scripts are used -
- wp_enqueue_script( 'cf-frontend-fields', CFCORE_URL . 'assets/js/fields.min.js', array('jquery'), null, true);
- wp_enqueue_script( 'cf-frontend-script-init', CFCORE_URL . 'assets/js/frontend-script-init.min.js', array('jquery'), null, true);
- // metabox & gridcss
- wp_enqueue_style( 'cf-metabox-grid-styles', CCF_URL . 'css/metagrid.css');
- wp_enqueue_style( 'cf-metabox-field-styles', CFCORE_URL . 'assets/css/fields.min.css');
- wp_enqueue_style( 'cf-metabox-styles', CCF_URL . 'css/metabox.css');
- }
- }
- }