Пример #1
0
        function get_field_groups()
        {
            // options
            $options = acf_parse_args($_POST, array('nonce' => '', 'post_id' => 0, 'ajax' => 1));
            // vars
            $r = array();
            $nonce = acf_extract_var($options, 'nonce');
            // verify nonce
            if (!wp_verify_nonce($nonce, 'acf_nonce')) {
                die;
            }
            // get field groups
            $field_groups = acf_get_field_groups($options);
            // loop through field groups and build $r
            if (!empty($field_groups)) {
                foreach ($field_groups as $field_group) {
                    // vars
                    $class = 'acf-postbox ' . $field_group['style'];
                    // load fields
                    $fields = acf_get_fields($field_group);
                    // get field HTML
                    ob_start();
                    // render
                    if ($field_group['label_placement'] == 'left') {
                        ?>
					<table class="acf-table">
						<tbody>
							<?php 
                        acf_render_fields($options['post_id'], $fields, 'tr', $field_group['instruction_placement']);
                        ?>
						</tbody>
					</table>
					<?php 
                    } else {
                        acf_render_fields($options['post_id'], $fields, 'div', $field_group['instruction_placement']);
                    }
                    $html = ob_get_clean();
                    // get style
                    $style = acf_get_field_group_style($field_group);
                    // append to $r
                    $r[] = array('key' => $field_group['key'], 'title' => $field_group['title'], 'html' => $html, 'style' => $style, 'class' => $class);
                }
            }
            // return
            wp_send_json_success($r);
        }
Пример #2
0
 function get_field_groups()
 {
     // options
     $options = acf_parse_args($_POST, array('nonce' => '', 'post_id' => 0, 'ajax' => 1, 'exists' => array()));
     // vars
     $json = array();
     $nonce = acf_extract_var($options, 'nonce');
     $exists = acf_extract_var($options, 'exists');
     // verify nonce
     if (!wp_verify_nonce($nonce, 'acf_nonce')) {
         die;
     }
     // get field groups
     $field_groups = acf_get_field_groups($options);
     // bail early if no field groups
     if (empty($field_groups)) {
         wp_send_json_success($json);
     }
     // loop through field groups
     foreach ($field_groups as $i => $field_group) {
         // vars
         $item = array('key' => $field_group['key'], 'title' => $field_group['title'], 'html' => '', 'style' => '');
         // style
         if ($i == 0) {
             $item['style'] = acf_get_field_group_style($field_group);
         }
         // html
         if (!in_array($field_group['key'], $exists)) {
             // load fields
             $fields = acf_get_fields($field_group);
             // get field HTML
             ob_start();
             // render
             acf_render_fields($options['post_id'], $fields, 'div', $field_group['instruction_placement']);
             $item['html'] = ob_get_clean();
         }
         // append
         $json[] = $item;
     }
     // return
     wp_send_json_success($json);
 }