示例#1
0
        function edit_attachment($form_fields, $post)
        {
            // vars
            $el = 'tr';
            $post_id = $post->ID;
            $args = array('attachment' => 'All');
            // $el
            if ($this->validate_page()) {
                //$el = 'div';
            }
            // get field groups
            $field_groups = acf_get_field_groups($args);
            // render
            if (!empty($field_groups)) {
                // get acf_form_data
                ob_start();
                acf_form_data(array('post_id' => $post_id, 'nonce' => 'attachment'));
                if ($this->validate_page()) {
                    echo '<style type="text/css">
					.compat-attachment-fields,
					.compat-attachment-fields > tbody,
					.compat-attachment-fields > tbody > tr,
					.compat-attachment-fields > tbody > tr > th,
					.compat-attachment-fields > tbody > tr > td {
						display: block;
					}
					tr.acf-field {
						display: block;
						margin: 0 0 13px;
					}
					tr.acf-field td.acf-label {
						display: block;
						margin: 0;
					}
					tr.acf-field td.acf-input {
						display: block;
						margin: 0;
					}
				</style>';
                }
                // $el
                //if( $el == 'tr' ) {
                echo '</td></tr>';
                //}
                foreach ($field_groups as $field_group) {
                    $fields = acf_get_fields($field_group);
                    acf_render_fields($post_id, $fields, $el, 'field');
                }
                // $el
                //if( $el == 'tr' ) {
                echo '<tr class="compat-field-acf-blank"><td>';
                //}
                $html = ob_get_contents();
                ob_end_clean();
                $form_fields['acf-form-data'] = array('label' => '', 'input' => 'html', 'html' => $html);
            }
            // return
            return $form_fields;
        }
示例#2
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);
        }
示例#3
0
        function edit_term($term, $taxonomy)
        {
            // vars
            $post_id = "{$taxonomy}_{$term->term_id}";
            $args = array('taxonomy' => $taxonomy);
            // update vars
            $this->form = '#edittag';
            // get field groups
            $field_groups = acf_get_field_groups($args);
            // render
            if (!empty($field_groups)) {
                acf_form_data(array('post_id' => $post_id, 'nonce' => 'taxonomy'));
                foreach ($field_groups as $field_group) {
                    $fields = acf_get_fields($field_group);
                    ?>
				<?php 
                    if ($field_group['style'] == 'default') {
                        ?>
					<h3><?php 
                        echo $field_group['title'];
                        ?>
</h3>
				<?php 
                    }
                    ?>
				<table class="form-table">
					<tbody>
						<?php 
                    acf_render_fields($post_id, $fields, 'tr', 'field');
                    ?>
					</tbody>
				</table>
				<?php 
                }
            }
        }
示例#4
0
        function add_comment()
        {
            // vars
            $post_id = "comment_0";
            // get field groups
            $field_groups = acf_get_field_groups(array('comment' => 'new'));
            if (!empty($field_groups)) {
                // render post data
                acf_form_data(array('post_id' => $post_id, 'nonce' => 'comment'));
                foreach ($field_groups as $field_group) {
                    $fields = acf_get_fields($field_group);
                    ?>
				<table class="form-table">
					<tbody>
						<?php 
                    acf_render_fields($post_id, $fields, 'tr', 'field');
                    ?>
					</tbody>
				</table>
				<?php 
                }
            }
        }
示例#5
0
    function render_meta_box($post, $args)
    {
        // extract args
        extract($args);
        // all variables from the add_meta_box function
        extract($args);
        // all variables from the args argument
        // vars
        $o = array('id' => $id, 'key' => $field_group['key'], 'style' => $field_group['style'], 'edit_url' => '', 'edit_title' => __('Edit field group', 'acf'), 'visibility' => true);
        // vars
        $post_id = acf_get_valid_post_id('options');
        // load fields
        $fields = acf_get_fields($field_group);
        // render
        if ($field_group['label_placement'] == 'left') {
            ?>
			<table class="acf-table">
				<tbody>
					<?php 
            acf_render_fields($post_id, $fields, 'tr', $field_group['instruction_placement']);
            ?>
				</tbody>
			</table>
			<?php 
        } else {
            acf_render_fields($post_id, $fields, 'div', $field_group['instruction_placement']);
        }
        // edit_url
        if ($field_group['ID'] && acf_current_user_can_admin()) {
            $o['edit_url'] = admin_url('post.php?post=' . $field_group['ID'] . '&action=edit');
        }
        ?>
<script type="text/javascript">
if( typeof acf !== 'undefined' ) {
		
	acf.postbox.render(<?php 
        echo json_encode($o);
        ?>
);	

}
</script>
<?php 
    }
function acf_form($args = array())
{
    // vars
    $url = home_url($_SERVER['REQUEST_URI']);
    // 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'));
    $args['form_attributes'] = wp_parse_args($args['form_attributes'], array('id' => 'post', 'class' => '', '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'] = acf_parse_args($args['new_post'], array('post_type' => 'post', 'post_status' => 'draft'));
    }
    // attributes
    $args['form_attributes']['class'] .= ' acf-form';
    // vars
    $field_groups = array();
    $fields = array();
    // post_title
    if ($args['post_title']) {
        $fields[] = acf_get_valid_field(array('name' => '_post_title', 'label' => 'Title', 'type' => 'text', 'value' => $post_id ? get_post_field('post_title', $post_id) : '', 'required' => true));
    }
    // post_content
    if ($args['post_content']) {
        $fields[] = acf_get_valid_field(array('name' => '_post_content', 'label' => 'Content', 'type' => 'wysiwyg', 'value' => $post_id ? get_post_field('post_content', $post_id) : ''));
    }
    // specific fields
    if (!empty($args['fields'])) {
        foreach ($args['fields'] as $selector) {
            $fields[] = acf_get_field($selector);
        }
    } elseif (!empty($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(array('post_type' => $args['new_post']['post_type']));
    } 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) {
            $fields = array_merge($fields, acf_get_fields($field_group));
        }
    }
    // updated message
    if (!empty($_GET['updated']) && $args['updated_message']) {
        echo '<div id="message" class="updated"><p>' . $args['updated_message'] . '</p></div>';
    }
    // 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-form-fields">
	
		<?php 
    // html before fields
    echo $args['html_before_fields'];
    // start table
    if ($args['label_placement'] == 'left') {
        $args['field_el'] = 'tr';
        ?>
<table class="acf-table"><tbody><?php 
    }
    acf_render_fields($post_id, $fields, $args['field_el'], $args['instruction_placement']);
    // end table
    if ($args['label_placement'] == 'left') {
        ?>
</tbody></table><?php 
    }
    // html after fields
    echo $args['html_after_fields'];
    ?>
	
	</div><!-- acf-form-fields -->
	
	<?php 
    if ($args['form']) {
        ?>
	
	<!-- Submit -->
	<div class="acf-form-submit">
	
		<input type="submit" class="button button-primary button-large" value="<?php 
        echo $args['submit_value'];
        ?>
" />
		
	</div>
	<!-- / Submit -->
	
	</form>
	
	<?php 
    }
}
示例#7
0
文件: user.php 项目: Garth619/Femi9
 function render($user_id, $user_form, $el = 'tr')
 {
     // vars
     $post_id = "user_{$user_id}";
     $show_title = true;
     // show title
     if ($user_form === 'register') {
         $show_title = false;
     }
     // args
     $args = array('user_id' => 'new', 'user_form' => $user_form);
     if ($user_id) {
         $args['user_id'] = $user_id;
     }
     // get field groups
     $field_groups = acf_get_field_groups($args);
     // bail early if no field groups
     if (empty($field_groups)) {
         return;
     }
     // form data
     acf_form_data(array('post_id' => $post_id, 'nonce' => 'user'));
     // loop
     foreach ($field_groups as $field_group) {
         // vars
         $fields = acf_get_fields($field_group);
         // title
         if ($show_title && $field_group['style'] === 'default') {
             echo '<h2>' . $field_group['title'] . '</h2>';
         }
         // table start
         if ($el == 'tr') {
             echo '<table class="form-table"><tbody>';
         }
         // render fields
         acf_render_fields($post_id, $fields, $el, $field_group['instruction_placement']);
         // table end
         if ($el == 'tr') {
             echo '</tbody></table>';
         }
     }
 }
示例#8
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);
 }
示例#9
0
function acf_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'));
    $args['form_attributes'] = wp_parse_args($args['form_attributes'], array('id' => 'post', 'class' => '', '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'] = acf_parse_args($args['new_post'], array('post_type' => 'post', 'post_status' => 'draft'));
    }
    // attributes
    $args['form_attributes']['class'] .= ' acf-form';
    // vars
    $field_groups = array();
    $fields = array();
    // post_title
    if ($args['post_title']) {
        $fields[] = acf_get_valid_field(array('name' => '_post_title', 'label' => 'Title', 'type' => 'text', 'value' => $post_id ? get_post_field('post_title', $post_id) : '', 'required' => true));
    }
    // post_content
    if ($args['post_content']) {
        $fields[] = acf_get_valid_field(array('name' => '_post_content', 'label' => 'Content', 'type' => 'wysiwyg', 'value' => $post_id ? get_post_field('post_content', $post_id) : ''));
    }
    // specific fields
    if (!empty($args['fields'])) {
        foreach ($args['fields'] as $selector) {
            $fields[] = get_field_object($selector, $post_id, false, false);
        }
    } elseif (!empty($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(array('post_type' => $args['new_post']['post_type']));
    } 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);
                }
            }
        }
    }
    // updated message
    if (!empty($_GET['updated']) && $args['updated_message']) {
        echo '<div id="message" class="updated"><p>' . $args['updated_message'] . '</p></div>';
    }
    // 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 
    // html before fields
    echo $args['html_before_fields'];
    // start table
    if ($args['label_placement'] == 'left') {
        $args['field_el'] = 'tr';
        ?>
<table class="acf-table"><tbody><?php 
    }
    acf_render_fields($post_id, $fields, $args['field_el'], $args['instruction_placement']);
    // end table
    if ($args['label_placement'] == 'left') {
        ?>
</tbody></table><?php 
    }
    // html after fields
    echo $args['html_after_fields'];
    ?>
	
	</div><!-- acf-form-fields -->
	<?php 
    if ($args['form']) {
        ?>
	
	<!-- Submit -->
	<div class="acf-form-submit">
	
		<input type="submit" class="button button-primary button-large" value="<?php 
        echo $args['submit_value'];
        ?>
" />
		<span class="acf-loading" style="display: none;"></span>
		
	</div>
	<!-- / Submit -->
	
	</form>
	<script type="text/javascript">
	(function($) {
		
		// vars
		var $spinner = $('#<?php 
        echo $args['form_attributes']['id'];
        ?>
 .acf-form-submit .acf-loading');
		
		
		// show spinner on submit
		$(document).on('submit', '#<?php 
        echo $args['form_attributes']['id'];
        ?>
', function(){
			
			// show spinner
			$spinner.css('display', 'inline-block');
			
		});
		
		
		// hide spinner after validation
		acf.add_filter('validation_complete', function( json, $form ){
			
			// hide spinner
			$spinner.css('display', 'none');
			
			
			// return
			return json;
					
		});
		
	})(jQuery);	
	</script>
	<?php 
    }
}
示例#10
0
 /**
  * Get form HTML for a set of fields
  *
  * @param array $fields ACF fields
  * @return string Form HTML
  */
 public static function get_form_html($fields)
 {
     ob_start();
     if (self::is_pro_installed()) {
         acf_render_fields(0, $fields);
         // 0 = post_id
     } else {
         do_action('acf/create_fields', $fields, 0);
         // 0 = post_id
     }
     return ob_get_clean();
 }
示例#11
0
        function render($user_id, $user_form, $el = 'tr')
        {
            // vars
            $post_id = "user_{$user_id}";
            $show_title = true;
            // show title
            if ($user_form == 'register') {
                $show_title = false;
            }
            // args
            $args = array('user_id' => 'new', 'user_form' => $user_form);
            if ($user_id) {
                $args['user_id'] = $user_id;
            }
            // get field groups
            $field_groups = acf_get_field_groups($args);
            // render
            if (!empty($field_groups)) {
                acf_form_data(array('post_id' => $post_id, 'nonce' => 'user'));
                foreach ($field_groups as $field_group) {
                    $fields = acf_get_fields($field_group);
                    ?>
				<?php 
                    if ($show_title && $field_group['style'] == 'default') {
                        ?>
					<h3><?php 
                        echo $field_group['title'];
                        ?>
</h3>
				<?php 
                    }
                    ?>
				
				<?php 
                    if ($el == 'tr') {
                        ?>
					<table class="form-table">
						<tbody>
				<?php 
                    }
                    ?>
				
					<?php 
                    acf_render_fields($post_id, $fields, $el, 'field');
                    ?>
				
				<?php 
                    if ($el == 'tr') {
                        ?>
						</tbody>
					</table>
				<?php 
                    }
                    ?>
				<?php 
                }
            }
        }
示例#12
0
 function comment_form_field_comment($html)
 {
     // global
     global $post;
     // vars
     $post_id = false;
     // get field groups
     $field_groups = acf_get_field_groups(array('comment' => $post->post_type));
     // bail early if no field groups
     if (!$field_groups) {
         return $html;
     }
     // ob
     ob_start();
     // render post data
     acf_form_data(array('post_id' => $post_id, 'nonce' => 'comment'));
     foreach ($field_groups as $field_group) {
         $fields = acf_get_fields($field_group);
         acf_render_fields($post_id, $fields, 'p', $field_group['instruction_placement']);
     }
     // append
     $html .= ob_get_contents();
     ob_end_clean();
     // return
     return $html;
 }
示例#13
0
        function add_comment()
        {
            // vars
            $post_id = "comment_0";
            // get field groups
            $field_groups = acf_get_field_groups(array('comment' => 'new'));
            if (!empty($field_groups)) {
                // render post data
                acf_form_data(array('post_id' => $post_id, 'nonce' => 'comment'));
                foreach ($field_groups as $field_group) {
                    $fields = acf_get_fields($field_group);
                    ?>
				<div class="acf-fields -<?php 
                    echo $field_group['label_placement'];
                    ?>
">
					<?php 
                    acf_render_fields($post_id, $fields, 'div', $field_group['instruction_placement']);
                    ?>
				</div>
				<?php 
                }
            }
        }
示例#14
0
    function postbox_acf($post, $args)
    {
        // extract args
        extract($args);
        // all variables from the add_meta_box function
        extract($args);
        // all variables from the args argument
        // vars
        $o = array('id' => $id, 'key' => $field_group['key'], 'style' => $field_group['style'], 'label' => $field_group['label_placement'], 'edit_url' => '', 'edit_title' => __('Edit field group', 'acf'), 'visibility' => true);
        // get post_id (allow lang modification)
        $post_id = acf_get_valid_post_id($this->page['post_id']);
        // edit_url
        if ($field_group['ID'] && acf_current_user_can_admin()) {
            $o['edit_url'] = admin_url('post.php?post=' . $field_group['ID'] . '&action=edit');
        }
        // load fields
        $fields = acf_get_fields($field_group);
        // render
        acf_render_fields($post_id, $fields, 'div', $field_group['instruction_placement']);
        ?>
<script type="text/javascript">
if( typeof acf !== 'undefined' ) {
		
	acf.postbox.render(<?php 
        echo json_encode($o);
        ?>
);	

}
</script>
<?php 
    }
示例#15
0
function acf_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'));
    $args['form_attributes'] = wp_parse_args($args['form_attributes'], array('id' => 'post', 'class' => '', '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'] = acf_parse_args($args['new_post'], array('post_type' => 'post', 'post_status' => 'draft'));
    }
    // attributes
    $args['form_attributes']['class'] .= ' acf-form';
    // vars
    $field_groups = array();
    $fields = array();
    // post_title
    if ($args['post_title']) {
        $fields[] = acf_get_valid_field(array('name' => '_post_title', 'label' => 'Title', 'type' => 'text', 'value' => $post_id ? get_post_field('post_title', $post_id) : '', 'required' => true));
    }
    // post_content
    if ($args['post_content']) {
        $fields[] = acf_get_valid_field(array('name' => '_post_content', 'label' => 'Content', 'type' => 'wysiwyg', 'value' => $post_id ? get_post_field('post_content', $post_id) : ''));
    }
    // 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(array('post_type' => $args['new_post']['post_type']));
    } 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);
                }
            }
        }
    }
    // 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']) {
        ?>

	
	<!-- Submit -->
	<div class="acf-form-submit">
	
		<input type="submit" class="button button-primary button-large" value="<?php 
        echo $args['submit_value'];
        ?>
" />
		<span class="acf-spinner"></span>
		
	</div>
	<!-- / Submit -->
	
	</form>
	<?php 
    }
}
示例#16
0
    function render_meta_box($post, $args)
    {
        // extract args
        extract($args);
        // all variables from the add_meta_box function
        extract($args);
        // all variables from the args argument
        // classes
        $class = 'acf-postbox ' . $field_group['style'];
        $toggle_class = 'acf-postbox-toggle';
        // load fields
        $fields = acf_get_fields($field_group);
        // render
        if ($field_group['label_placement'] == 'left') {
            ?>
			<table class="acf-table">
				<tbody>
					<?php 
            acf_render_fields('options', $fields, 'tr', $field_group['instruction_placement']);
            ?>
				</tbody>
			</table>
			<?php 
        } else {
            acf_render_fields('options', $fields, 'div', $field_group['instruction_placement']);
        }
        // inline script
        ?>
		<div class="acf-hidden">
			<script type="text/javascript">
			(function($) {
				
				$('#<?php 
        echo $id;
        ?>
').addClass('<?php 
        echo $class;
        ?>
').removeClass('hide-if-js');
				$('#adv-settings label[for="<?php 
        echo $id;
        ?>
-hide"]').addClass('<?php 
        echo $toggle_class;
        ?>
');
				
			})(jQuery);	
			</script>
		</div>
		<?php 
    }
示例#17
0
        function edit_widget($widget, $return, $instance)
        {
            // vars
            $post_id = 0;
            if ($widget->number !== '__i__') {
                $post_id = "widget_{$widget->id}";
            }
            // get field groups
            $field_groups = acf_get_field_groups(array('widget' => $widget->id_base));
            // render
            if (!empty($field_groups)) {
                // render post data
                acf_form_data(array('post_id' => $post_id, 'nonce' => 'widget'));
                foreach ($field_groups as $field_group) {
                    $fields = acf_get_fields($field_group);
                    acf_render_fields($post_id, $fields, 'div', 'field');
                }
                if ($widget->updated) {
                    ?>
			<script type="text/javascript">
			(function($) {
				
				acf.do_action('append', $('[id^="widget"][id$="<?php 
                    echo $widget->id;
                    ?>
"]') );
				
			})(jQuery);	
			</script>
			<?php 
                }
            }
        }
示例#18
0
        function edit_attachment($form_fields, $post)
        {
            // vars
            $is_page = $this->validate_page();
            $post_id = $post->ID;
            $el = 'tr';
            $args = array('attachment' => $post_id);
            // get field groups
            $field_groups = acf_get_field_groups($args);
            // render
            if (!empty($field_groups)) {
                // get acf_form_data
                ob_start();
                acf_form_data(array('post_id' => $post_id, 'nonce' => 'attachment'));
                if ($this->validate_page()) {
                    echo '<style type="text/css">
					
					.compat-attachment-fields,
					.compat-attachment-fields > tbody,
					.compat-attachment-fields > tbody > tr,
					.compat-attachment-fields > tbody > tr > th,
					.compat-attachment-fields > tbody > tr > td {
						display: block;
					}
					
					.compat-attachment-fields > tbody > tr.acf-field {
						margin: 0 0 15px;
					}
					
					.compat-attachment-fields > tbody > tr.acf-field > td.acf-label {
						margin: 0;
					}
					
					.compat-attachment-fields > tbody > tr.acf-field > td.acf-label label {
						margin: 0;
						padding: 0;
					}
					
					.compat-attachment-fields > tbody > tr.acf-field > td.acf-label p {
						margin: 0 0 3px !important;
					}
					
					.compat-attachment-fields > tbody > tr.acf-field > td.acf-input {
						margin: 0;
					}
					
				</style>';
                }
                // open
                echo '</td></tr>';
                // loop
                foreach ($field_groups as $field_group) {
                    // load fields
                    $fields = acf_get_fields($field_group);
                    // override instruction placement for modal
                    if (!$is_page) {
                        $field_group['instruction_placement'] = 'field';
                    }
                    // render
                    acf_render_fields($post_id, $fields, $el, $field_group['instruction_placement']);
                }
                // close
                echo '<tr class="compat-field-acf-blank"><td>';
                $html = ob_get_contents();
                ob_end_clean();
                $form_fields['acf-form-data'] = array('label' => '', 'input' => 'html', 'html' => $html);
            }
            // return
            return $form_fields;
        }