/** * Prepared from data for edit post. * * @since 1.1.0 * * @uses "caldera_forms_render_pre_get_entry" filter * * @param array $data Form data. * @param array $form Form config. * @param $entry_id * * @return array */ function cf_custom_fields_populate_form_edit($data, $form, $entry_id) { $processors = Caldera_Forms::get_processor_by_type('post_type', $form); if (!empty($processors)) { foreach ($processors as $processor) { if (!empty($processor['config']['ID'])) { // ooo ID!!! $ID = Caldera_Forms::do_magic_tags($processor['config']['ID'], $entry_id); if (!empty($ID)) { $post = get_post($ID); } if (empty($post)) { return $data; } $data[$processor['config']['post_title']] = $post->post_title; $data[$processor['config']['post_content']] = $post->post_content; foreach ($form['fields'] as $field_id => $field) { if ($post->{$field['slug']}) { $data[$field_id] = $post->{$field['slug']}; } } } } } return $data; }
function pods_populate_edit_data($data, $form) { $processors = Caldera_Forms::get_processor_by_type('pods', $form); if (!empty($processors)) { foreach ($processors as $processor) { if (empty($processor['config']['pod_id'])) { continue; } $pod = pods($processor['config']['pod'], Caldera_Forms::do_magic_tags($processor['config']['pod_id'])); foreach ($processor['config']['fields'] as $field => $field_id) { if (empty($field_id)) { continue; } $line = $pod->field($field); if (is_array($line)) { foreach ($line as $line_item) { if (isset($line_item['ID'])) { $data[$field_id][$line_item['ID']] = $line_item['ID']; } elseif (isset($line_item['id'])) { $data[$field_id][$line_item['id']] = $line_item['id']; } else { $data[$field_id][] = $line_item; } } } else { $data[$field_id] = $line; } } } } return $data; }
/** * Pre-populate options for bound fields * * @since 1.0.0 * * @param array $field Field config * * @return array Field config */ function pods_cf_populate_options($field) { global $form; $processors = Caldera_Forms::get_processor_by_type('pods', $form); if (empty($processors)) { return $field; } foreach ($processors as $processor) { // is configured $fields = array(); if (!empty($processor['config']['fields'])) { $fields = array_merge($fields, $processor['config']['fields']); } if (!empty($processor['config']['object_fields'])) { $fields = array_merge($fields, $processor['config']['object_fields']); } if ($bound_field = array_search($field['ID'], $fields)) { // now lets see if this is a pick field $pod = pods($processor['config']['pod'], null, false); $pod_field = $pod->fields($bound_field); if (!empty($pod_field['options']['required'])) { $field['required'] = 1; } if ($pod_field['type'] === 'pick') { $options = PodsForm::options($pod_field['type'], $pod_field); include_once PODS_DIR . 'classes/fields/pick.php'; $fieldtype = new PodsField_Pick(); $choices = $fieldtype->data($bound_field, null, $options, $pod); $field['config']['option'] = array(); foreach ($choices as $choice_value => $choice_label) { $field['config']['option'][] = array('value' => $choice_value, 'label' => $choice_label); } } } } return $field; }
/** * If needed sets up dropdown options for EDD field. * * @since 0.1.0 * * @param array $form Form config */ function cf_edd_maybe_setup_licensed_field($field, $form) { // does this form have the processor? if ($processors = Caldera_Forms::get_processor_by_type('edd-licensed-downloads', $form)) { foreach ($processors as $processor) { if ($field['ID'] === $processor['config']['edd_licensed_downloads']) { // ye this a bound EDD field // over engineerd using that CF_EDD_License_Field class can do it here since we now have the whole config of an active processor. $user_id = null; if (!empty($config['config']['edd_licensed_downloads_user']) && 0 < absint($config['config']['edd_licensed_downloads_user'])) { $user_id = $config['config']['edd_licensed_downloads_user']; } $downloads = cf_edd_get_downloads_by_licensed_user($user_id); $field['config']['option'] = array(); if (!empty($downloads)) { foreach ($downloads as $id => $title) { $field['config']['option'][] = array('label' => esc_html($title), 'value' => (int) $id); } } } } } return $field; }
/** * Setup form in the admin * * @uses "add_meta_boxes" action * * @since 1.?.? */ function cf_custom_fields_form_as_metabox() { $forms = cf_custom_fields_get_forms(); if (empty($forms)) { return; } foreach ($forms as $form) { $form = cf_custom_fields_get_form($form['ID']); if (!is_array($form)) { continue; } $processors = Caldera_Forms::get_processor_by_type('cf_asmetabox', $form); if (!empty($processors)) { $processor = $processors[0]; // is metabox processor if (!empty($form['processors'][$processor['ID']]['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 add_filter('caldera_forms_render_setup_field', 'cf_custom_fields_submit_button_removal'); foreach ($form['processors'][$processor['ID']]['config']['posttypes'] as $screen => $enabled) { add_meta_box($form['ID'], $form['name'], 'cf_custom_fields_render', $screen, $form['processors'][$processor['ID']]['config']['context'], $form['processors'][$processor['ID']]['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); } } } } } wp_enqueue_script('cf-validator'); wp_enqueue_script('cf-validator-i18n'); // 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'); } } }