function render_form($args = array()) { // vars $url = acf_get_current_url(); // defaults $args = wp_parse_args($args, array('id' => 'acf-form', 'post_id' => false, 'new_post' => false, 'field_groups' => false, 'fields' => false, 'post_title' => false, 'post_content' => false, 'form' => true, 'form_attributes' => array(), 'return' => add_query_arg('updated', 'true', $url), 'html_before_fields' => '', 'html_after_fields' => '', 'submit_value' => __("Update", 'acf'), 'updated_message' => __("Post updated", 'acf'), 'label_placement' => 'top', 'instruction_placement' => 'label', 'field_el' => 'div', 'uploader' => 'wp', 'honeypot' => true)); $args['form_attributes'] = wp_parse_args($args['form_attributes'], array('id' => $args['id'], 'class' => 'acf-form', 'action' => '', 'method' => 'post')); // filter post_id $args['post_id'] = acf_get_valid_post_id($args['post_id']); // load values from this post $post_id = $args['post_id']; // new post? if ($post_id == 'new_post') { // dont load values $post_id = false; // new post defaults $args['new_post'] = wp_parse_args($args['new_post'], array('post_type' => 'post', 'post_status' => 'draft')); } // register local fields foreach ($this->fields as $k => $field) { acf_add_local_field($field); } // vars $field_groups = array(); $fields = array(); // post_title if ($args['post_title']) { // load local field $_post_title = acf_get_field('_post_title'); $_post_title['value'] = $post_id ? get_post_field('post_title', $post_id) : ''; // append $fields[] = $_post_title; } // post_content if ($args['post_content']) { // load local field $_post_content = acf_get_field('_post_content'); $_post_content['value'] = $post_id ? get_post_field('post_content', $post_id) : ''; // append $fields[] = $_post_content; } // specific fields if ($args['fields']) { foreach ($args['fields'] as $selector) { // append field ($strict = false to allow for better compatibility with field names) $fields[] = acf_maybe_get_field($selector, $post_id, false); } } elseif ($args['field_groups']) { foreach ($args['field_groups'] as $selector) { $field_groups[] = acf_get_field_group($selector); } } elseif ($args['post_id'] == 'new_post') { $field_groups = acf_get_field_groups($args['new_post']); } else { $field_groups = acf_get_field_groups(array('post_id' => $args['post_id'])); } //load fields based on field groups if (!empty($field_groups)) { foreach ($field_groups as $field_group) { $field_group_fields = acf_get_fields($field_group); if (!empty($field_group_fields)) { foreach (array_keys($field_group_fields) as $i) { $fields[] = acf_extract_var($field_group_fields, $i); } } } } // honeypot if ($args['honeypot']) { $fields[] = acf_get_field('_validate_email'); } // updated message if (!empty($_GET['updated']) && $args['updated_message']) { echo '<div id="message" class="updated"><p>' . $args['updated_message'] . '</p></div>'; } // uploader (always set incase of multiple forms on the page) acf_update_setting('uploader', $args['uploader']); // display form if ($args['form']) { ?> <form <?php acf_esc_attr_e($args['form_attributes']); ?> > <?php } // render post data acf_form_data(array('post_id' => $args['post_id'], 'nonce' => 'acf_form')); ?> <div class="acf-hidden"> <?php acf_hidden_input(array('name' => '_acf_form', 'value' => base64_encode(json_encode($args)))); ?> </div> <div class="acf-fields acf-form-fields -<?php echo $args['label_placement']; ?> "> <?php // html before fields echo $args['html_before_fields']; // render acf_render_fields($post_id, $fields, $args['field_el'], $args['instruction_placement']); // html after fields echo $args['html_after_fields']; ?> </div><!-- acf-form-fields --> <?php if ($args['form']) { ?> <div class="acf-form-submit"> <input type="submit" class="acf-button button button-primary button-large" value="<?php echo $args['submit_value']; ?> " /> <span class="acf-spinner"></span> </div> </form> <?php } }
<?php if (function_exists('acf_add_local_field_group')) { acf_add_local_field_group(array('key' => 'group_57393379a27d4', 'title' => 'ss', 'fields' => array(array('key' => 'field_simple_slideshow', 'label' => 'slidehsow', 'name' => 'slidehsow', 'type' => 'repeater', 'instructions' => '', 'layout' => 'table', 'button_label' => 'Add Slide', 'sub_fields' => array())), 'location' => array(array(array('param' => 'post_type', 'operator' => '==', 'value' => 'page'))), 'hide_on_screen' => array(0 => 'the_content'))); acf_add_local_field(array('key' => 'field_5739338826510', 'label' => 'content', 'name' => 'content', 'type' => 'wysiwyg', 'parent' => 'field_simple_slideshow', 'instructions' => '', 'required' => 0, 'conditional_logic' => 0, 'wrapper' => array('width' => '70'))); acf_add_local_field(array('key' => 'field_5739339d26511', 'label' => 'image', 'name' => 'image', 'type' => 'image', 'parent' => 'field_simple_slideshow', 'wrapper' => array('width' => '30'), 'return_format' => 'url')); }
function _acf_form_register_fields() { acf_add_local_field(array('prefix' => 'acf', 'name' => '_post_title', 'key' => '_post_title', 'label' => __('Title', 'acf'), 'type' => 'text', 'required' => true)); acf_add_local_field(array('prefix' => 'acf', 'name' => '_post_content', 'key' => '_post_content', 'label' => __('Content', 'acf'), 'type' => 'wysiwyg')); acf_add_local_field(array('prefix' => 'acf', 'name' => '_validate_email', 'key' => '_validate_email', 'label' => __('Validate Email', 'acf'), 'type' => 'text', 'value' => '', 'wrapper' => array('style' => 'display:none !important;'))); }