// prevent repeater field from creating multiple conditional logic items for each row
    if ($i !== 'acfcloneindex') {
        $sub_field['conditional_logic'] = 0;
    }
    // add value
    if (isset($row[$sub_field['key']])) {
        // this is a normal value
        $sub_field['value'] = $row[$sub_field['key']];
    } elseif (isset($sub_field['default_value'])) {
        // no value, but this sub field has a default value
        $sub_field['value'] = $sub_field['default_value'];
    }
    // update prefix to allow for nested values
    $sub_field['prefix'] = "{$field['name']}[{$i}]";
    // render input
    acf_render_field_wrap($sub_field, $el);
    ?>

				<?php 
}
?>

				<?php 
echo $after_fields;
?>


			</tr>
		</tbody>
	</table>
</div>
示例#2
0
        function render_layout($field, $layout, $i, $value)
        {
            // vars
            $order = 0;
            // atts
            $layout_atts = array('class' => 'layout', 'data-layout' => $layout['name'], 'data-toggle' => 'open');
            $table_atts = array('class' => "acf-table acf-input-table {$layout['display']}-layout");
            // collapsed
            if (!empty($_COOKIE["acf_collapsed_{$field['key']}"])) {
                $collapsed = $_COOKIE["acf_collapsed_{$field['key']}"];
                $collapsed = explode('|', $collapsed);
                if (in_array($i, $collapsed)) {
                    $layout_atts['data-toggle'] = 'closed';
                    $table_atts['style'] = 'display:none;';
                }
            }
            // clone
            if (is_numeric($i)) {
                $order = $i + 1;
            } else {
                $layout_atts['class'] .= ' acf-clone';
            }
            // field wrap
            $el = 'td';
            $before_fields = '';
            $after_fields = '';
            if ($layout['display'] == 'row') {
                $el = 'tr';
                $before_fields = '<td class="acf-table-wrap"><table class="acf-table">';
                $after_fields = '</table></td>';
            } elseif ($layout['display'] == 'block') {
                $el = 'div';
                $before_fields = '<td class="acf-fields">';
                $after_fields = '</td>';
            }
            ?>
<div <?php 
            acf_esc_attr_e($layout_atts);
            ?>
>
			
	<div style="display:none">
		<?php 
            acf_hidden_input(array('name' => "{$field['name']}[{$i}][acf_fc_layout]", 'value' => $layout['name']));
            ?>
	</div>
	
	<div class="acf-fc-layout-handle">
		<span class="fc-layout-order"><?php 
            echo $order;
            ?>
</span> <?php 
            echo $layout['label'];
            ?>
	</div>
	
	<ul class="acf-fc-layout-controlls acf-hl acf-clearfix">
		<li>
			<a class="acf-icon acf-icon-plus small acf-fc-add" href="#" data-before="1" title="<?php 
            _e('Add layout', 'acf');
            ?>
"></a>
		</li>
		<li>
			<a class="acf-icon acf-icon-minus small acf-fc-remove" href="#" title="<?php 
            _e('Remove layout', 'acf');
            ?>
"></a>
		</li>
	</ul>
	
<?php 
            if (!empty($layout['sub_fields'])) {
                ?>
		
	<table <?php 
                acf_esc_attr_e($table_atts);
                ?>
>
		
		<?php 
                if ($layout['display'] == 'table') {
                    ?>
		
			<thead>
				<tr>
				
					<?php 
                    foreach ($layout['sub_fields'] as $sub_field) {
                        $atts = array('class' => "acf-th acf-th-{$sub_field['name']}", 'data-key' => $sub_field['key']);
                        // Add custom width
                        if ($sub_field['wrapper']['width']) {
                            $atts['data-width'] = $sub_field['wrapper']['width'];
                        }
                        ?>
						
						<th <?php 
                        acf_esc_attr_e($atts);
                        ?>
>
							<?php 
                        acf_the_field_label($sub_field);
                        ?>
							<?php 
                        if ($sub_field['instructions']) {
                            ?>
								<p class="description"><?php 
                            echo $sub_field['instructions'];
                            ?>
</p>
							<?php 
                        }
                        ?>
						</th>
						
					<?php 
                    }
                    ?>
 

				</tr>
			</thead>
			
		<?php 
                }
                ?>
		
		<tbody>
			<tr>
			<?php 
                echo $before_fields;
                // loop though sub fields
                foreach ($layout['sub_fields'] as $sub_field) {
                    // prevent repeater field from creating multiple conditional logic items for each row
                    if ($i !== 'acfcloneindex') {
                        $sub_field['conditional_logic'] = 0;
                    }
                    // add value
                    if (isset($value[$sub_field['key']])) {
                        // this is a normal value
                        $sub_field['value'] = $value[$sub_field['key']];
                    } elseif (isset($sub_field['default_value'])) {
                        // no value, but this sub field has a default value
                        $sub_field['value'] = $sub_field['default_value'];
                    }
                    // update prefix to allow for nested values
                    $sub_field['prefix'] = "{$field['name']}[{$i}]";
                    // render input
                    acf_render_field_wrap($sub_field, $el);
                }
                // layout: Row
                echo $after_fields;
                ?>
							
			</tr>
		</tbody>
		
	</table>

<?php 
            }
            ?>

</div>
<?php 
        }
示例#3
0
        function ajax_add_term()
        {
            // vars
            $args = acf_parse_args($_POST, array('nonce' => '', 'field_key' => '', 'term_name' => '', 'term_parent' => ''));
            // verify nonce
            if (!wp_verify_nonce($args['nonce'], 'acf_nonce')) {
                die;
            }
            // load field
            $field = acf_get_field($args['field_key']);
            if (!$field) {
                die;
            }
            // vars
            $taxonomy_obj = get_taxonomy($field['taxonomy']);
            $taxonomy_label = $taxonomy_obj->labels->singular_name;
            // validate cap
            // note: this situation should never occur due to condition of the add new button
            if (!current_user_can($taxonomy_obj->cap->manage_terms)) {
                echo '<p><strong>' . __("Error", 'acf') . '.</strong> ' . sprintf(__('User unable to add new %s', 'acf'), $taxonomy_label) . '</p>';
                die;
            }
            // save?
            if ($args['term_name']) {
                // exists
                if (term_exists($args['term_name'], $field['taxonomy'])) {
                    wp_send_json_error(array('error' => sprintf(__('%s already exists', 'acf'), $taxonomy_label)));
                }
                // insert
                $extra = array();
                if ($args['term_parent']) {
                    $extra['parent'] = $args['term_parent'];
                }
                $data = wp_insert_term($args['term_name'], $field['taxonomy'], $extra);
                // error?
                if (is_wp_error($data)) {
                    wp_send_json_error(array('error' => $data->get_error_message()));
                }
                // ancestors
                $prefix = '';
                $ancestors = get_ancestors($data['term_id'], $field['taxonomy']);
                if (!empty($ancestors)) {
                    $prefix = str_repeat('- ', count($ancestors));
                }
                // success
                wp_send_json_success(array('message' => sprintf(__('%s added', 'acf'), $taxonomy_label), 'term_id' => $data['term_id'], 'term_name' => $args['term_name'], 'term_label' => $prefix . $args['term_name'], 'term_parent' => $args['term_parent']));
            }
            ?>
<form method="post"><?php 
            acf_render_field_wrap(array('label' => 'Name', 'name' => 'term_name', 'type' => 'text'));
            if (is_taxonomy_hierarchical($field['taxonomy'])) {
                $choices = array();
                $choices2 = $this->get_choices(array('field_key' => $field['key']));
                if ($choices2) {
                    foreach ($choices2 as $v) {
                        $choices[$v['id']] = $v['text'];
                    }
                }
                acf_render_field_wrap(array('label' => 'Parent', 'name' => 'term_parent', 'type' => 'select', 'allow_null' => 1, 'ui' => 0, 'choices' => $choices));
            }
            ?>
<p class="acf-submit"><button class="acf-button blue" type="submit"><?php 
            _e("Add", 'acf');
            ?>
</button><i class="acf-loading"></i><span></span></p></form><?php 
            // die
            die;
        }
示例#4
0
// type
acf_render_field_wrap(array('label' => __('Field Type', 'acf'), 'instructions' => '', 'required' => 1, 'type' => 'select', 'name' => 'type', 'prefix' => $field['prefix'], 'value' => $field['type'], 'choices' => acf_get_field_types()), 'tr');
// instructions
acf_render_field_wrap(array('label' => __('Instructions', 'acf'), 'instructions' => __('Instructions for authors. Shown when submitting data', 'acf'), 'type' => 'textarea', 'name' => 'instructions', 'prefix' => $field['prefix'], 'value' => $field['instructions'], 'rows' => 5), 'tr');
// required
acf_render_field_wrap(array('label' => __('Required?', 'acf'), 'instructions' => '', 'type' => 'radio', 'name' => 'required', 'prefix' => $field['prefix'], 'value' => $field['required'], 'choices' => array(1 => __("Yes", 'acf'), 0 => __("No", 'acf')), 'layout' => 'horizontal'), 'tr');
// type specific settings
do_action("acf/render_field_settings/type={$field['type']}", $field);
// 3rd party settings
do_action('acf/render_field_settings', $field);
// conditional logic
acf_get_view('field-group-field-conditional-logic', array('field' => $field));
// wrapper
acf_render_field_wrap(array('label' => __('Wrapper Attributes', 'acf'), 'instructions' => '', 'type' => 'text', 'name' => 'width', 'prefix' => $field['prefix'] . '[wrapper]', 'value' => $field['wrapper']['width'], 'prepend' => __('width', 'acf'), 'append' => '%', 'wrapper' => array('data-name' => 'wrapper')), 'tr');
acf_render_field_wrap(array('label' => '', 'instructions' => '', 'type' => 'text', 'name' => 'class', 'prefix' => $field['prefix'] . '[wrapper]', 'value' => $field['wrapper']['class'], 'prepend' => __('class', 'acf'), 'wrapper' => array('data-append' => 'wrapper')), 'tr');
acf_render_field_wrap(array('label' => '', 'instructions' => '', 'type' => 'text', 'name' => 'id', 'prefix' => $field['prefix'] . '[wrapper]', 'value' => $field['wrapper']['id'], 'prepend' => __('id', 'acf'), 'wrapper' => array('data-append' => 'wrapper')), 'tr');
?>
				<tr class="acf-field acf-field-save">
					<td class="acf-label"></td>
					<td class="acf-input">
						<ul class="acf-hl">
							<li>
								<a class="edit-field acf-button grey" title="<?php 
_e("Close Field", 'acf');
?>
" href="#"><?php 
_e("Close Field", 'acf');
?>
</a>
							</li>
						</ul>
示例#5
0
        function render_field($field)
        {
            // vars
            $sub_fields = $field['sub_fields'];
            $value = acf_get_array($field['value']);
            $show_order = true;
            $show_add = true;
            $show_remove = true;
            // bail early if no sub fields
            if (empty($sub_fields)) {
                return;
            }
            // div
            $div = array('class' => 'acf-repeater', 'data-min' => $field['min'], 'data-max' => $field['max']);
            // empty
            if (empty($value)) {
                $div['class'] .= ' -empty';
            }
            // If there are less values than min, populate the extra values
            if ($field['min']) {
                $value = array_pad($value, $field['min'], array());
            }
            // If there are more values than man, remove some values
            if ($field['max']) {
                $value = array_slice($value, 0, $field['max']);
                // if max 1 row, don't show order
                if ($field['max'] == 1) {
                    $show_order = false;
                }
                // if max == min, don't show add or remove buttons
                if ($field['max'] <= $field['min']) {
                    $show_remove = false;
                    $show_add = false;
                }
            }
            // setup values for row clone
            $value['acfcloneindex'] = array();
            // button label
            if ($field['button_label'] === '') {
                $field['button_label'] = __('Add Row', 'acf');
            }
            // field wrap
            $el = 'td';
            $before_fields = '';
            $after_fields = '';
            if ($field['layout'] == 'row') {
                $el = 'div';
                $before_fields = '<td class="acf-fields -left">';
                $after_fields = '</td>';
            } elseif ($field['layout'] == 'block') {
                $el = 'div';
                $before_fields = '<td class="acf-fields">';
                $after_fields = '</td>';
            }
            // layout
            $div['class'] .= ' -' . $field['layout'];
            // hidden input
            acf_hidden_input(array('type' => 'hidden', 'name' => $field['name']));
            // collapsed
            if ($field['collapsed']) {
                // add target class
                foreach ($sub_fields as $i => $sub_field) {
                    // bail early if no match
                    if ($sub_field['key'] !== $field['collapsed']) {
                        continue;
                    }
                    // class
                    $sub_field['wrapper']['class'] .= ' -collapsed-target';
                    // update
                    $sub_fields[$i] = $sub_field;
                }
            }
            ?>
<div <?php 
            acf_esc_attr_e($div);
            ?>
>
<table class="acf-table">
	
	<?php 
            if ($field['layout'] == 'table') {
                ?>
		<thead>
			<tr>
				<?php 
                if ($show_order) {
                    ?>
					<th class="acf-row-handle"></th>
				<?php 
                }
                ?>
				
				<?php 
                foreach ($sub_fields as $sub_field) {
                    // prepare field (allow sub fields to be removed)
                    $sub_field = acf_prepare_field($sub_field);
                    // bail ealry if no field
                    if (!$sub_field) {
                        continue;
                    }
                    // vars
                    $atts = array();
                    $atts['class'] = 'acf-th';
                    $atts['data-name'] = $sub_field['_name'];
                    $atts['data-type'] = $sub_field['type'];
                    $atts['data-key'] = $sub_field['key'];
                    // Add custom width
                    if ($sub_field['wrapper']['width']) {
                        $atts['data-width'] = $sub_field['wrapper']['width'];
                        $atts['style'] = 'width: ' . $sub_field['wrapper']['width'] . '%;';
                    }
                    ?>
					<th <?php 
                    echo acf_esc_attr($atts);
                    ?>
>
						<?php 
                    echo acf_get_field_label($sub_field);
                    ?>
						<?php 
                    if ($sub_field['instructions']) {
                        ?>
							<p class="description"><?php 
                        echo $sub_field['instructions'];
                        ?>
</p>
						<?php 
                    }
                    ?>
					</th>
				<?php 
                }
                ?>

				<?php 
                if ($show_remove) {
                    ?>
					<th class="acf-row-handle"></th>
				<?php 
                }
                ?>
			</tr>
		</thead>
	<?php 
            }
            ?>
	
	<tbody>
		<?php 
            foreach ($value as $i => $row) {
                $row_class = 'acf-row';
                if ($i === 'acfcloneindex') {
                    $row_class .= ' acf-clone';
                } elseif (acf_is_row_collapsed($field['key'], $i)) {
                    $row_class .= ' -collapsed';
                }
                ?>
			<tr class="<?php 
                echo $row_class;
                ?>
" data-id="<?php 
                echo $i;
                ?>
">
				
				<?php 
                if ($show_order) {
                    ?>
					<td class="acf-row-handle order" title="<?php 
                    _e('Drag to reorder', 'acf');
                    ?>
">
						<?php 
                    if ($field['collapsed']) {
                        ?>
						<a class="acf-icon -collapse small" href="#" data-event="collapse-row" title="<?php 
                        _e('Click to toggle', 'acf');
                        ?>
"></a>
						<?php 
                    }
                    ?>
						<span><?php 
                    echo intval($i) + 1;
                    ?>
</span>
					</td>
				<?php 
                }
                ?>
				
				<?php 
                echo $before_fields;
                ?>
				
				<?php 
                foreach ($sub_fields as $sub_field) {
                    // prevent repeater field from creating multiple conditional logic items for each row
                    if ($i !== 'acfcloneindex') {
                        $sub_field['conditional_logic'] = 0;
                    }
                    // add value
                    if (isset($row[$sub_field['key']])) {
                        // this is a normal value
                        $sub_field['value'] = $row[$sub_field['key']];
                    } elseif (isset($sub_field['default_value'])) {
                        // no value, but this sub field has a default value
                        $sub_field['value'] = $sub_field['default_value'];
                    }
                    // update prefix to allow for nested values
                    $sub_field['prefix'] = $field['name'] . '[' . $i . ']';
                    // render input
                    acf_render_field_wrap($sub_field, $el);
                    ?>
					
				<?php 
                }
                ?>
				
				<?php 
                echo $after_fields;
                ?>
				
				<?php 
                if ($show_remove) {
                    ?>
					<td class="acf-row-handle remove">
						<a class="acf-icon -plus small" href="#" data-event="add-row" title="<?php 
                    _e('Add row', 'acf');
                    ?>
"></a>
						<a class="acf-icon -minus small" href="#" data-event="remove-row" title="<?php 
                    _e('Remove row', 'acf');
                    ?>
"></a>
					</td>
				<?php 
                }
                ?>
				
			</tr>
		<?php 
            }
            ?>
	</tbody>
</table>
<?php 
            if ($show_add) {
                ?>
	
	<ul class="acf-actions acf-hl">
		<li>
			<a class="acf-button button button-primary" data-event="add-row"><?php 
                echo $field['button_label'];
                ?>
</a>
		</li>
	</ul>
			
<?php 
            }
            ?>
</div>
<?php 
        }
示例#6
0
        function render_field($field)
        {
            // ensure value is an array
            if (empty($field['value'])) {
                $field['value'] = array();
            }
            // rows
            $field['min'] = empty($field['min']) ? 0 : $field['min'];
            $field['max'] = empty($field['max']) ? 0 : $field['max'];
            // populate the empty row data (used for acfcloneindex and min setting)
            $empty_row = array();
            foreach ($field['sub_fields'] as $f) {
                $empty_row[$f['key']] = isset($f['default_value']) ? $f['default_value'] : false;
            }
            // If there are less values than min, populate the extra values
            if ($field['min']) {
                for ($i = 0; $i < $field['min']; $i++) {
                    // continue if already have a value
                    if (array_key_exists($i, $field['value'])) {
                        continue;
                    }
                    // populate values
                    $field['value'][$i] = $empty_row;
                }
            }
            // If there are more values than man, remove some values
            if ($field['max']) {
                for ($i = 0; $i < count($field['value']); $i++) {
                    if ($i >= $field['max']) {
                        unset($field['value'][$i]);
                    }
                }
            }
            // setup values for row clone
            $field['value']['acfcloneindex'] = $empty_row;
            // show columns
            $show_order = true;
            $show_add = true;
            $show_remove = true;
            if ($field['max']) {
                if ($field['max'] == 1) {
                    $show_order = false;
                }
                if ($field['max'] <= $field['min']) {
                    $show_remove = false;
                    $show_add = false;
                }
            }
            // field wrap
            $el = 'td';
            $before_fields = '';
            $after_fields = '';
            if ($field['layout'] == 'row') {
                $el = 'tr';
                $before_fields = '<td class="acf-table-wrap"><table class="acf-table">';
                $after_fields = '</table></td>';
            } elseif ($field['layout'] == 'block') {
                $el = 'div';
                $before_fields = '<td class="acf-fields">';
                $after_fields = '</td>';
            }
            // hidden input
            acf_hidden_input(array('type' => 'hidden', 'name' => $field['name']));
            ?>
<div <?php 
            acf_esc_attr_e(array('class' => 'acf-repeater', 'data-min' => $field['min'], 'data-max' => $field['max']));
            ?>
>
<table <?php 
            acf_esc_attr_e(array('class' => "acf-table acf-input-table {$field['layout']}-layout"));
            ?>
>
	
	<?php 
            if ($field['layout'] == 'table') {
                ?>
		<thead>
			<tr>
				<?php 
                if ($show_order) {
                    ?>
					<th class="order"><span class="order-spacer"></span></th>
				<?php 
                }
                ?>
				
				<?php 
                foreach ($field['sub_fields'] as $sub_field) {
                    $atts = array('class' => "acf-th acf-th-{$sub_field['name']}", 'data-key' => $sub_field['key']);
                    // Add custom width
                    if ($sub_field['wrapper']['width']) {
                        $atts['data-width'] = $sub_field['wrapper']['width'];
                    }
                    ?>
					
					<th <?php 
                    acf_esc_attr_e($atts);
                    ?>
>
						<?php 
                    acf_the_field_label($sub_field);
                    ?>
						<?php 
                    if ($sub_field['instructions']) {
                        ?>
							<p class="description"><?php 
                        echo $sub_field['instructions'];
                        ?>
</p>
						<?php 
                    }
                    ?>
					</th>
					
				<?php 
                }
                ?>

				<?php 
                if ($show_remove) {
                    ?>
					<th class="remove"><span class="remove-spacer"></span></th>
				<?php 
                }
                ?>
			</tr>
		</thead>
	<?php 
            }
            ?>
	
	<tbody>
		<?php 
            foreach ($field['value'] as $i => $row) {
                ?>
			<tr class="acf-row<?php 
                echo $i === 'acfcloneindex' ? ' acf-clone' : '';
                ?>
">
				
				<?php 
                if ($show_order) {
                    ?>
					<td class="order" title="<?php 
                    _e('Drag to reorder', 'acf');
                    ?>
"><?php 
                    echo intval($i) + 1;
                    ?>
</td>
				<?php 
                }
                ?>
				
				<?php 
                echo $before_fields;
                ?>
				
				<?php 
                foreach ($field['sub_fields'] as $sub_field) {
                    // prevent repeater field from creating multiple conditional logic items for each row
                    if ($i !== 'acfcloneindex') {
                        $sub_field['conditional_logic'] = 0;
                    }
                    // add value
                    if (isset($row[$sub_field['key']])) {
                        // this is a normal value
                        $sub_field['value'] = $row[$sub_field['key']];
                    } elseif (isset($sub_field['default_value'])) {
                        // no value, but this sub field has a default value
                        $sub_field['value'] = $sub_field['default_value'];
                    }
                    // update prefix to allow for nested values
                    $sub_field['prefix'] = "{$field['name']}[{$i}]";
                    // render input
                    acf_render_field_wrap($sub_field, $el);
                    ?>
					
				<?php 
                }
                ?>
				
				<?php 
                echo $after_fields;
                ?>
				
				<?php 
                if ($show_remove) {
                    ?>
					<td class="remove">
						<a class="acf-icon small acf-repeater-add-row" href="#" data-before="1" title="<?php 
                    _e('Add row', 'acf');
                    ?>
"><i class="acf-sprite-add"></i></a>
						<a class="acf-icon small acf-repeater-remove-row" href="#" title="<?php 
                    _e('Remove row', 'acf');
                    ?>
"><i class="acf-sprite-remove"></i></a>
					</td>
				<?php 
                }
                ?>
				
			</tr>
		<?php 
            }
            ?>
	</tbody>
</table>
<?php 
            if ($show_add) {
                ?>
	
	<ul class="acf-hl acf-clearfix">
		<li class="acf-fr">
			<a href="#" class="acf-button blue acf-repeater-add-row"><?php 
                echo $field['button_label'];
                ?>
</a>
		</li>
	</ul>
			
<?php 
            }
            ?>
</div>
<?php 
        }
示例#7
0
        function render_layout($field, $layout, $i, $value)
        {
            // vars
            $order = 0;
            $el = 'div';
            $div = array('class' => 'layout', 'data-id' => $i, 'data-layout' => $layout['name']);
            // collapsed
            $collapsed = acf_get_user_setting('collapsed_' . $field['key'], '');
            // cookie fallback ( version < 5.3.2 )
            if ($collapsed === '') {
                $collapsed = acf_extract_var($_COOKIE, "acf_collapsed_{$field['key']}", '');
                $collapsed = str_replace('|', ',', $collapsed);
                acf_update_user_setting('collapsed_' . $field['key'], $collapsed);
            }
            // explode
            $collapsed = explode(',', $collapsed);
            $collapsed = array_filter($collapsed, 'is_numeric');
            // collapsed class
            if (in_array($i, $collapsed)) {
                $div['class'] .= ' -collapsed';
            }
            // clone
            if (is_numeric($i)) {
                $order = $i + 1;
            } else {
                $div['class'] .= ' acf-clone';
            }
            ?>
<div <?php 
            acf_esc_attr_e($div);
            ?>
>
			
	<div class="acf-hidden">
		<?php 
            acf_hidden_input(array('name' => "{$field['name']}[{$i}][acf_fc_layout]", 'value' => $layout['name']));
            ?>
	</div>
	
	<div class="acf-fc-layout-handle">
		<span class="fc-layout-order"><?php 
            echo $order;
            ?>
</span> <?php 
            echo $layout['label'];
            ?>
	</div>
	
	<ul class="acf-fc-layout-controlls acf-hl">
		<li class="acf-fc-show-on-hover">
			<a class="acf-icon -plus small" href="#" data-event="add-layout" title="<?php 
            _e('Add layout', 'acf');
            ?>
"></a>
		</li>
		<li class="acf-fc-show-on-hover">
			<a class="acf-icon -minus small" href="#" data-event="remove-layout" title="<?php 
            _e('Remove layout', 'acf');
            ?>
"></a>
		</li>
		<li>
			<a class="acf-icon -collapse small" href="#" data-event="collapse-layout" title="<?php 
            _e('Click to toggle', 'acf');
            ?>
"></a>
		</li>
	</ul>
	
<?php 
            if (!empty($layout['sub_fields'])) {
                ?>
	
	<?php 
                if ($layout['display'] == 'table') {
                    // update vars
                    $el = 'td';
                    ?>
	<table class="acf-table">
		
		<thead>
			<tr>
				<?php 
                    foreach ($layout['sub_fields'] as $sub_field) {
                        $atts = array('class' => "acf-th acf-th-{$sub_field['name']}", 'data-key' => $sub_field['key']);
                        // Add custom width
                        if ($sub_field['wrapper']['width']) {
                            $atts['data-width'] = $sub_field['wrapper']['width'];
                        }
                        ?>
					<th <?php 
                        acf_esc_attr_e($atts);
                        ?>
>
						<?php 
                        acf_the_field_label($sub_field);
                        ?>
						<?php 
                        if ($sub_field['instructions']) {
                            ?>
							<p class="description"><?php 
                            echo $sub_field['instructions'];
                            ?>
</p>
						<?php 
                        }
                        ?>
					</th>
					
				<?php 
                    }
                    ?>
 
			</tr>
		</thead>
		
		<tbody>
	<?php 
                } else {
                    ?>
	<div class="acf-fields <?php 
                    if ($layout['display'] == 'row') {
                        ?>
-left<?php 
                    }
                    ?>
">
	<?php 
                }
                ?>
	
		<?php 
                // loop though sub fields
                foreach ($layout['sub_fields'] as $sub_field) {
                    // prevent repeater field from creating multiple conditional logic items for each row
                    if ($i !== 'acfcloneindex') {
                        $sub_field['conditional_logic'] = 0;
                    }
                    // add value
                    if (isset($value[$sub_field['key']])) {
                        // this is a normal value
                        $sub_field['value'] = $value[$sub_field['key']];
                    } elseif (isset($sub_field['default_value'])) {
                        // no value, but this sub field has a default value
                        $sub_field['value'] = $sub_field['default_value'];
                    }
                    // update prefix to allow for nested values
                    $sub_field['prefix'] = "{$field['name']}[{$i}]";
                    // render input
                    acf_render_field_wrap($sub_field, $el);
                }
                ?>
			
	<?php 
                if ($layout['display'] == 'table') {
                    ?>
		</tbody>
	</table>
	<?php 
                } else {
                    ?>
	</div>
	<?php 
                }
                ?>

<?php 
            }
            ?>

</div>
<?php 
        }
// active
acf_render_field_wrap(array('label' => __('Status', 'acf'), 'instructions' => '', 'type' => 'select', 'name' => 'active', 'prefix' => 'acf_field_group', 'value' => $field_group['active'], 'choices' => array(1 => __("Active", 'acf'), 0 => __("Disabled", 'acf'))));
// style
acf_render_field_wrap(array('label' => __('Style', 'acf'), 'instructions' => '', 'type' => 'select', 'name' => 'style', 'prefix' => 'acf_field_group', 'value' => $field_group['style'], 'choices' => array('default' => __("Standard (WP metabox)", 'acf'), 'seamless' => __("Seamless (no metabox)", 'acf'))));
// position
acf_render_field_wrap(array('label' => __('Position', 'acf'), 'instructions' => '', 'type' => 'select', 'name' => 'position', 'prefix' => 'acf_field_group', 'value' => $field_group['position'], 'choices' => array('acf_after_title' => __("High (after title)", 'acf'), 'normal' => __("Normal (after content)", 'acf'), 'side' => __("Side", 'acf')), 'default_value' => 'normal'));
// label_placement
acf_render_field_wrap(array('label' => __('Label placement', 'acf'), 'instructions' => '', 'type' => 'select', 'name' => 'label_placement', 'prefix' => 'acf_field_group', 'value' => $field_group['label_placement'], 'choices' => array('top' => __("Top aligned", 'acf'), 'left' => __("Left Aligned", 'acf'))));
// instruction_placement
acf_render_field_wrap(array('label' => __('Instruction placement', 'acf'), 'instructions' => '', 'type' => 'select', 'name' => 'instruction_placement', 'prefix' => 'acf_field_group', 'value' => $field_group['instruction_placement'], 'choices' => array('label' => __("Below labels", 'acf'), 'field' => __("Below fields", 'acf'))));
// menu_order
acf_render_field_wrap(array('label' => __('Order No.', 'acf'), 'instructions' => __('Field groups with a lower order will appear first', 'acf'), 'type' => 'number', 'name' => 'menu_order', 'prefix' => 'acf_field_group', 'value' => $field_group['menu_order']));
// description
acf_render_field_wrap(array('label' => __('Description', 'acf'), 'instructions' => __('Shown in field group list', 'acf'), 'type' => 'text', 'name' => 'description', 'prefix' => 'acf_field_group', 'value' => $field_group['description']));
// hide on screen
acf_render_field_wrap(array('label' => __('Hide on screen', 'acf'), 'instructions' => __('<b>Select</b> items to <b>hide</b> them from the edit screen.', 'acf') . '<br /><br />' . __("If multiple field groups appear on an edit screen, the first field group's options will be used (the one with the lowest order number)", 'acf'), 'type' => 'checkbox', 'name' => 'hide_on_screen', 'prefix' => 'acf_field_group', 'value' => $field_group['hide_on_screen'], 'toggle' => true, 'choices' => array('permalink' => __("Permalink", 'acf'), 'the_content' => __("Content Editor", 'acf'), 'excerpt' => __("Excerpt", 'acf'), 'custom_fields' => __("Custom Fields", 'acf'), 'discussion' => __("Discussion", 'acf'), 'comments' => __("Comments", 'acf'), 'revisions' => __("Revisions", 'acf'), 'slug' => __("Slug", 'acf'), 'author' => __("Author", 'acf'), 'format' => __("Format", 'acf'), 'page_attributes' => __("Page Attributes", 'acf'), 'featured_image' => __("Featured Image", 'acf'), 'categories' => __("Categories", 'acf'), 'tags' => __("Tags", 'acf'), 'send-trackbacks' => __("Send Trackbacks", 'acf'))));
// 3rd party settings
do_action('acf/render_field_group_settings', $field_group);
?>
<div class="acf-hidden">
	<input type="hidden" name="acf_field_group[key]" value="<?php 
echo $field_group['key'];
?>
" />
</div>
<script type="text/javascript">
if( typeof acf !== 'undefined' ) {
		
	acf.postbox.render({
		'id': 'acf-field-group-options',
		'label': 'left'
	</ul>
	
	<div class="field-settings">			
		<table class="acf-table">
			<tbody>
				<?php 
// label
acf_render_field_wrap(array('label' => __('Field Label', 'acf'), 'instructions' => __('This is the name which will appear on the EDIT page', 'acf'), 'required' => 1, 'type' => 'text', 'name' => 'label', 'prefix' => $field['prefix'], 'value' => $field['label']), 'tr');
// name
acf_render_field_wrap(array('label' => __('Field Name', 'acf'), 'instructions' => __('Single word, no spaces. Underscores and dashes allowed', 'acf'), 'required' => 1, 'type' => 'text', 'name' => 'name', 'prefix' => $field['prefix'], 'value' => $field['name']), 'tr');
// type
acf_render_field_wrap(array('label' => __('Field Type', 'acf'), 'instructions' => '', 'required' => 1, 'type' => 'select', 'name' => 'type', 'prefix' => $field['prefix'], 'value' => $field['type'], 'choices' => acf_get_field_types()), 'tr');
// instructions
acf_render_field_wrap(array('label' => __('Instructions', 'acf'), 'instructions' => __('Instructions for authors. Shown when submitting data', 'acf'), 'type' => 'textarea', 'name' => 'instructions', 'prefix' => $field['prefix'], 'value' => $field['instructions']), 'tr');
// required
acf_render_field_wrap(array('label' => __('Required?', 'acf'), 'instructions' => '', 'type' => 'radio', 'name' => 'required', 'prefix' => $field['prefix'], 'value' => $field['required'], 'choices' => array(1 => __("Yes", 'acf'), 0 => __("No", 'acf')), 'layout' => 'horizontal'), 'tr');
// custom field options
acf_render_field_settings($field);
// load view
acf_get_view('field-group-field-conditional-logic', array('field' => $field));
?>
				<tr class="field_save">
					<td class="acf-label"></td>
					<td class="acf-input">
						<ul class="acf-hl acf-clearfix">
							<li>
								<a class="edit-field acf-button grey" title="<?php 
_e("Close Field", 'acf');
?>
" href="#"><?php 
_e("Close Field", 'acf');
示例#10
0
function acf_render_field_setting($field, $setting, $global = false)
{
    // vars
    $atts = array();
    // if this setting is not global, add a data attribute
    if (!$global) {
        $atts['data-setting'] = $field['type'];
    }
    // copy across prefix
    $setting['prefix'] = $field['prefix'];
    // copy across the $setting value
    // Note: tab field contains no name for it's $setting (its just a message)
    if (isset($setting['name'], $field[$setting['name']])) {
        $setting['value'] = $field[$setting['name']];
    }
    // render
    acf_render_field_wrap($setting, 'tr', 'label', $atts);
}
示例#11
0
        function render_layout($field, $layout, $i, $value)
        {
            // vars
            $order = 0;
            $el = 'div';
            $sub_fields = $layout['sub_fields'];
            $prefix = $field['name'] . '[' . $i . ']';
            // div
            $div = array('class' => 'layout', 'data-id' => $i, 'data-layout' => $layout['name']);
            // collapsed class
            if (acf_is_row_collapsed($field['key'], $i)) {
                $div['class'] .= ' -collapsed';
            }
            // clone
            if (is_numeric($i)) {
                $order = $i + 1;
            } else {
                $div['class'] .= ' acf-clone';
            }
            // display
            if ($layout['display'] == 'table') {
                $el = 'td';
            }
            // title
            $title = $this->get_layout_title($field, $layout, $i, $value);
            // remove row
            reset_rows();
            ?>
<div <?php 
            echo acf_esc_attr($div);
            ?>
>
			
	<div class="acf-hidden">
		<?php 
            acf_hidden_input(array('name' => $prefix . '[acf_fc_layout]', 'value' => $layout['name']));
            ?>
	</div>
	
	<div class="acf-fc-layout-handle" title="<?php 
            _e('Drag to reorder', 'acf');
            ?>
"><?php 
            echo $title;
            ?>
</div>
	
	<div class="acf-fc-layout-controlls">
		<a class="acf-icon -plus small" href="#" data-event="add-layout" title="<?php 
            _e('Add layout', 'acf');
            ?>
"></a>
		<a class="acf-icon -minus small" href="#" data-event="remove-layout" title="<?php 
            _e('Remove layout', 'acf');
            ?>
"></a>
		<a class="acf-icon -collapse small" href="#" data-event="collapse-layout" title="<?php 
            _e('Click to toggle', 'acf');
            ?>
"></a>
	</div>
	
<?php 
            if (!empty($sub_fields)) {
                ?>
	
	<?php 
                if ($layout['display'] == 'table') {
                    ?>
	<table class="acf-table">
		
		<thead>
			<tr>
				<?php 
                    foreach ($sub_fields as $sub_field) {
                        // prepare field (allow sub fields to be removed)
                        $sub_field = acf_prepare_field($sub_field);
                        // bail ealry if no field
                        if (!$sub_field) {
                            continue;
                        }
                        // vars
                        $atts = array();
                        $atts['class'] = 'acf-th';
                        $atts['data-name'] = $sub_field['_name'];
                        $atts['data-type'] = $sub_field['type'];
                        $atts['data-key'] = $sub_field['key'];
                        // Add custom width
                        if ($sub_field['wrapper']['width']) {
                            $atts['data-width'] = $sub_field['wrapper']['width'];
                            $atts['style'] = 'width: ' . $sub_field['wrapper']['width'] . '%;';
                        }
                        ?>
					<th <?php 
                        echo acf_esc_attr($atts);
                        ?>
>
						<?php 
                        echo acf_get_field_label($sub_field);
                        ?>
						<?php 
                        if ($sub_field['instructions']) {
                            ?>
							<p class="description"><?php 
                            echo $sub_field['instructions'];
                            ?>
</p>
						<?php 
                        }
                        ?>
					</th>
					
				<?php 
                    }
                    ?>
 
			</tr>
		</thead>
		
		<tbody>
	<?php 
                } else {
                    ?>
	<div class="acf-fields <?php 
                    if ($layout['display'] == 'row') {
                        ?>
-left<?php 
                    }
                    ?>
">
	<?php 
                }
                ?>
	
		<?php 
                // loop though sub fields
                foreach ($sub_fields as $sub_field) {
                    // prevent repeater field from creating multiple conditional logic items for each row
                    if ($i !== 'acfcloneindex') {
                        $sub_field['conditional_logic'] = 0;
                    }
                    // add value
                    if (isset($value[$sub_field['key']])) {
                        // this is a normal value
                        $sub_field['value'] = $value[$sub_field['key']];
                    } elseif (isset($sub_field['default_value'])) {
                        // no value, but this sub field has a default value
                        $sub_field['value'] = $sub_field['default_value'];
                    }
                    // update prefix to allow for nested values
                    $sub_field['prefix'] = $prefix;
                    // render input
                    acf_render_field_wrap($sub_field, $el);
                }
                ?>
			
	<?php 
                if ($layout['display'] == 'table') {
                    ?>
		</tbody>
	</table>
	<?php 
                } else {
                    ?>
	</div>
	<?php 
                }
                ?>

<?php 
            }
            ?>

</div>
<?php 
        }
示例#12
0
        function render_field_table($field)
        {
            ?>
<table class="acf-table">
	<thead>
		<tr>
		<?php 
            foreach ($field['sub_fields'] as $sub_field) {
                // prepare field (allow sub fields to be removed)
                $sub_field = acf_prepare_field($sub_field);
                // bail ealry if no field
                if (!$sub_field) {
                    continue;
                }
                // vars
                $atts = array();
                $atts['class'] = 'acf-th';
                $atts['data-name'] = $sub_field['_name'];
                $atts['data-type'] = $sub_field['type'];
                $atts['data-key'] = $sub_field['key'];
                // Add custom width
                if ($sub_field['wrapper']['width']) {
                    $atts['data-width'] = $sub_field['wrapper']['width'];
                    $atts['style'] = 'width: ' . $sub_field['wrapper']['width'] . '%;';
                }
                ?>
			<th <?php 
                acf_esc_attr_e($atts);
                ?>
>
				<?php 
                echo acf_get_field_label($sub_field);
                ?>
				<?php 
                if ($sub_field['instructions']) {
                    ?>
					<p class="description"><?php 
                    echo $sub_field['instructions'];
                    ?>
</p>
				<?php 
                }
                ?>
			</th>
		<?php 
            }
            ?>
		</tr>
	</thead>
	<tbody>
		<tr class="acf-row">
		<?php 
            foreach ($field['sub_fields'] as $sub_field) {
                acf_render_field_wrap($sub_field, 'td');
            }
            ?>
		</tr>
	</tbody>
</table>
<?php 
        }
 public function render_field($field)
 {
     global $wp_widget_factory;
     $widget = isset($field['value']) && isset($field['value']['the_widget']) ? $field['value']['the_widget'] : $field['widget'];
     $the_widget = !empty($wp_widget_factory->widgets[$widget]) ? $wp_widget_factory->widgets[$widget] : false;
     if (empty($the_widget)) {
         return;
     }
     $the_widget->number = isset($field['value']) && isset($field['value']['number']) ? $field['value']['number'] : uniqid();
     $the_widget->id = isset($field['value']) && isset($field['value']['widget_id']) ? $field['value']['widget_id'] : $the_widget->id_base . '-' . $the_widget->number;
     $instance = apply_filters('widget_form_callback', isset($field['value']) && isset($field['value']['instance']) ? $field['value']['instance'] : array(), $the_widget);
     if (false !== $instance) {
         ob_start();
         $the_widget->form($instance);
         //do_action_ref_array( 'in_widget_form', array( &$the_widget, &$return, $instance ) );
         $form = ob_get_clean();
         // Convert the widget field naming into ones that Page Builder uses
         $exp = preg_quote($the_widget->get_field_name('____'));
         $exp = str_replace('____', '(.*?)', $exp);
         $final = preg_replace('/' . $exp . '/', $field['name'] . '[widget_fields][$1]', $form);
         echo $final;
     }
     //Now the regular widget fields are rendered.
     //Render any additional fields that were added to the widget using advanced custom fields widget fields.
     $el = 'div';
     foreach ($field['sub_fields'] as $sub_field) {
         // add value
         if (isset($field['value'][$sub_field['key']])) {
             // this is a normal value
             $sub_field['value'] = $field['value'][$sub_field['key']];
         } elseif (isset($sub_field['default_value'])) {
             // no value, but this sub field has a default value
             $sub_field['value'] = $sub_field['default_value'];
         }
         //Setup a field prefix so in our update value function we can grab the correct info.
         $sub_field['prefix'] = "{$field['name']}";
         acf_render_field_wrap($sub_field, $el);
     }
 }
示例#14
0
 function ajax_move_field()
 {
     // disable filters to ensure ACF loads raw data from DB
     acf_disable_filters();
     $args = acf_parse_args($_POST, array('nonce' => '', 'post_id' => 0, 'field_id' => 0, 'field_group_id' => 0));
     // verify nonce
     if (!wp_verify_nonce($args['nonce'], 'acf_nonce')) {
         die;
     }
     // confirm?
     if ($args['field_id'] && $args['field_group_id']) {
         // vars
         $field = acf_get_field($args['field_id']);
         $field_group = acf_get_field_group($args['field_group_id']);
         // update parent
         $field['parent'] = $field_group['ID'];
         // remove conditional logic
         $field['conditional_logic'] = 0;
         // update field
         acf_update_field($field);
         $v1 = $field['label'];
         $v2 = '<a href="' . admin_url("post.php?post={$field_group['ID']}&action=edit") . '" target="_blank">' . $field_group['title'] . '</a>';
         echo '<p><strong>' . __('Move Complete.', 'acf') . '</strong></p>';
         echo '<p>' . sprintf(__('The %s field can now be found in the %s field group', 'acf'), $v1, $v2) . '</p>';
         echo '<a href="#" class="button button-primary acf-close-popup">' . __("Close Window", 'acf') . '</a>';
         die;
     }
     // get all field groups
     $field_groups = acf_get_field_groups();
     $choices = array();
     // check
     if (!empty($field_groups)) {
         // loop
         foreach ($field_groups as $field_group) {
             // bail early if no ID
             if (!$field_group['ID']) {
                 continue;
             }
             // bail ealry if is current
             if ($field_group['ID'] == $args['post_id']) {
                 continue;
             }
             // append
             $choices[$field_group['ID']] = $field_group['title'];
         }
     }
     // render options
     $field = acf_get_valid_field(array('type' => 'select', 'name' => 'acf_field_group', 'choices' => $choices));
     echo '<p>' . __('Please select the destination for this field', 'acf') . '</p>';
     echo '<form id="acf-move-field-form">';
     // render
     acf_render_field_wrap($field);
     echo '<button type="submit" class="button button-primary">' . __("Move Field", 'acf') . '</button>';
     echo '</form>';
     // die
     die;
 }
			<p><?php 
_e('Select the field groups you would like to export and then select your export method. Use the download button to export to a .json file which you can then import to another ACF installation. Use the generate button to export to PHP code which you can place in your theme.', 'acf');
?>
</p>
			
			<form method="post" action="">
			<div class="acf-hidden">
				<input type="hidden" name="_acfnonce" value="<?php 
echo wp_create_nonce('export');
?>
" />
			</div>
			<table class="form-table">
                <tbody>
	                <?php 
acf_render_field_wrap($field, 'tr');
?>
					<tr>
						<th></th>
						<td>
							<input type="submit" name="download" class="acf-button blue" value="<?php 
_e('Download export file', 'acf');
?>
" />
							<input type="submit" name="generate" class="acf-button blue" value="<?php 
_e('Generate export code', 'acf');
?>
" />
						</td>
					</tr>
				</tbody>
示例#16
0
文件: repeater.php 项目: Aqro/NewDWM
        function render_field($field)
        {
            // vars
            $div = array('class' => 'acf-repeater', 'data-min' => $field['min'], 'data-max' => $field['max']);
            // ensure value is an array
            if (empty($field['value'])) {
                $field['value'] = array();
                $div['class'] .= ' -empty';
            }
            // rows
            $field['min'] = empty($field['min']) ? 0 : $field['min'];
            $field['max'] = empty($field['max']) ? 0 : $field['max'];
            // populate the empty row data (used for acfcloneindex and min setting)
            $empty_row = array();
            // If there are less values than min, populate the extra values
            if ($field['min']) {
                for ($i = 0; $i < $field['min']; $i++) {
                    // continue if already have a value
                    if (array_key_exists($i, $field['value'])) {
                        continue;
                    }
                    // populate values
                    $field['value'][$i] = $empty_row;
                }
            }
            // If there are more values than man, remove some values
            if ($field['max']) {
                for ($i = 0; $i < count($field['value']); $i++) {
                    if ($i >= $field['max']) {
                        unset($field['value'][$i]);
                    }
                }
            }
            // setup values for row clone
            $field['value']['acfcloneindex'] = $empty_row;
            // show columns
            $show_order = true;
            $show_add = true;
            $show_remove = true;
            if ($field['max']) {
                if ($field['max'] == 1) {
                    $show_order = false;
                }
                if ($field['max'] <= $field['min']) {
                    $show_remove = false;
                    $show_add = false;
                }
            }
            // field wrap
            $el = 'td';
            $before_fields = '';
            $after_fields = '';
            if ($field['layout'] == 'row') {
                $el = 'div';
                $before_fields = '<td class="acf-fields -left">';
                $after_fields = '</td>';
            } elseif ($field['layout'] == 'block') {
                $el = 'div';
                $before_fields = '<td class="acf-fields">';
                $after_fields = '</td>';
            }
            // layout
            $div['class'] .= ' -' . $field['layout'];
            // hidden input
            acf_hidden_input(array('type' => 'hidden', 'name' => $field['name']));
            // collapsed
            $collapsed = array();
            if ($field['collapsed']) {
                // get user setting
                $collapsed = acf_get_user_setting('collapsed_' . $field['key'], '');
                $collapsed = explode(',', $collapsed);
                $collapsed = array_filter($collapsed, 'is_numeric');
                // add target class
                foreach (array_keys($field['sub_fields']) as $i) {
                    if ($field['sub_fields'][$i]['key'] === $field['collapsed']) {
                        $field['sub_fields'][$i]['wrapper']['class'] .= ' -collapsed-target';
                    }
                }
            }
            ?>
<div <?php 
            acf_esc_attr_e($div);
            ?>
>
<table class="acf-table">
	
	<?php 
            if ($field['layout'] == 'table') {
                ?>
		<thead>
			<tr>
				<?php 
                if ($show_order) {
                    ?>
					<th class="acf-row-handle"><span></span></th>
				<?php 
                }
                ?>
				
				<?php 
                foreach ($field['sub_fields'] as $sub_field) {
                    $atts = array('class' => 'acf-th', 'data-key' => $sub_field['key']);
                    // add type
                    $atts['class'] .= ' acf-th-' . $sub_field['type'];
                    // Add custom width
                    if ($sub_field['wrapper']['width']) {
                        $atts['data-width'] = $sub_field['wrapper']['width'];
                    }
                    ?>
					<th <?php 
                    acf_esc_attr_e($atts);
                    ?>
>
						<?php 
                    acf_the_field_label($sub_field);
                    ?>
						<?php 
                    if ($sub_field['instructions']) {
                        ?>
							<p class="description"><?php 
                        echo $sub_field['instructions'];
                        ?>
</p>
						<?php 
                    }
                    ?>
					</th>
					
				<?php 
                }
                ?>

				<?php 
                if ($show_remove) {
                    ?>
					<th class="acf-row-handle"><span></span></th>
				<?php 
                }
                ?>
			</tr>
		</thead>
	<?php 
            }
            ?>
	
	<tbody>
		<?php 
            foreach ($field['value'] as $i => $row) {
                $row_class = 'acf-row';
                if ($i === 'acfcloneindex') {
                    $row_class .= ' acf-clone';
                } elseif (in_array($i, $collapsed)) {
                    $row_class .= ' -collapsed';
                }
                ?>
			<tr class="<?php 
                echo $row_class;
                ?>
" data-id="<?php 
                echo $i;
                ?>
">
				
				<?php 
                if ($show_order) {
                    ?>
					<td class="acf-row-handle order" title="<?php 
                    _e('Drag to reorder', 'acf');
                    ?>
">
						<?php 
                    if ($field['collapsed']) {
                        ?>
						<a class="acf-icon -collapse small" href="#" data-event="collapse-row" title="<?php 
                        _e('Click to toggle', 'acf');
                        ?>
"></a>
						<?php 
                    }
                    ?>
						<span><?php 
                    echo intval($i) + 1;
                    ?>
</span>
					</td>
				<?php 
                }
                ?>
				
				<?php 
                echo $before_fields;
                ?>
				
				<?php 
                foreach ($field['sub_fields'] as $sub_field) {
                    // prevent repeater field from creating multiple conditional logic items for each row
                    if ($i !== 'acfcloneindex') {
                        $sub_field['conditional_logic'] = 0;
                    }
                    // add value
                    if (isset($row[$sub_field['key']])) {
                        // this is a normal value
                        $sub_field['value'] = $row[$sub_field['key']];
                    } elseif (isset($sub_field['default_value'])) {
                        // no value, but this sub field has a default value
                        $sub_field['value'] = $sub_field['default_value'];
                    }
                    // update prefix to allow for nested values
                    $sub_field['prefix'] = "{$field['name']}[{$i}]";
                    // render input
                    acf_render_field_wrap($sub_field, $el);
                    ?>
					
				<?php 
                }
                ?>
				
				<?php 
                echo $after_fields;
                ?>
				
				<?php 
                if ($show_remove) {
                    ?>
					<td class="acf-row-handle remove">
						<a class="acf-icon -plus small" href="#" data-event="add-row" title="<?php 
                    _e('Add row', 'acf');
                    ?>
"></a>
						<a class="acf-icon -minus small" href="#" data-event="remove-row" title="<?php 
                    _e('Remove row', 'acf');
                    ?>
"></a>
					</td>
				<?php 
                }
                ?>
				
			</tr>
		<?php 
            }
            ?>
	</tbody>
</table>
<?php 
            if ($show_add) {
                ?>
	
	<ul class="acf-hl">
		<li class="acf-fr">
			<a href="#" class="acf-button blue" data-event="add-row"><?php 
                echo $field['button_label'];
                ?>
</a>
		</li>
	</ul>
			
<?php 
            }
            ?>
</div>
<?php 
        }
示例#17
0
        function render_field_table($field)
        {
            ?>
<table class="acf-table">
	<thead>
		<tr>
		<?php 
            foreach ($field['sub_fields'] as $sub_field) {
                $atts = array('class' => 'acf-th', 'data-key' => $sub_field['key']);
                // add type
                $atts['class'] .= ' acf-th-' . $sub_field['type'];
                // Add custom width
                if ($sub_field['wrapper']['width']) {
                    $atts['data-width'] = $sub_field['wrapper']['width'];
                }
                ?>
			<th <?php 
                acf_esc_attr_e($atts);
                ?>
>
				<?php 
                echo acf_get_field_label($sub_field);
                ?>
				<?php 
                if ($sub_field['instructions']) {
                    ?>
					<p class="description"><?php 
                    echo $sub_field['instructions'];
                    ?>
</p>
				<?php 
                }
                ?>
			</th>
		<?php 
            }
            ?>
		</tr>
	</thead>
	<tbody>
		<tr class="acf-row">
		<?php 
            foreach ($field['sub_fields'] as $sub_field) {
                acf_render_field_wrap($sub_field, 'td');
            }
            ?>
		</tr>
	</tbody>
</table>
<?php 
        }
示例#18
0
        function render_attachment($id = 0, $field)
        {
            $attachment = wp_prepare_attachment_for_js($id);
            $prefix = "attachments[{$id}]";
            $compat = get_compat_media_markup($id);
            ?>
		<div class="acf-gallery-side-info acf-cf">
			<img src="<?php 
            echo $attachment['sizes']['thumbnail']['url'];
            ?>
" alt="<?php 
            echo $attachment['alt'];
            ?>
" />
			<p class="filename"><strong><?php 
            _e('Attachment Details', 'acf');
            ?>
</strong></p>
			<p class="uploaded"><?php 
            echo $attachment['dateFormatted'];
            ?>
</p>
			<p class="dimensions"><?php 
            echo $attachment['width'];
            ?>
 × <?php 
            echo $attachment['height'];
            ?>
</p>
		</div>
		<table class="form-table">
			<tbody>
				<?php 
            acf_render_field_wrap(array('name' => 'title', 'prefix' => $prefix, 'type' => 'text', 'label' => 'Title', 'value' => $attachment['title']), 'tr');
            acf_render_field_wrap(array('name' => 'caption', 'prefix' => $prefix, 'type' => 'textarea', 'label' => 'Caption', 'value' => $attachment['caption']), 'tr');
            acf_render_field_wrap(array('name' => 'alt', 'prefix' => $prefix, 'type' => 'text', 'label' => 'Alt Text', 'value' => $attachment['alt']), 'tr');
            acf_render_field_wrap(array('name' => 'description', 'prefix' => $prefix, 'type' => 'textarea', 'label' => 'Description', 'value' => $attachment['description']), 'tr');
            ?>
			</tbody>
		</table>
		<?php 
            echo $compat['item'];
            ?>
		
		<?php 
        }
示例#19
0
文件: gallery.php 项目: TMBR/johnjohn
        function render_attachment($id = 0, $field)
        {
            // vars
            $attachment = wp_prepare_attachment_for_js($id);
            $thumb = '';
            $prefix = "attachments[{$id}]";
            $compat = get_compat_media_markup($id);
            $dimentions = '';
            // thumb
            if (isset($attachment['thumb']['src'])) {
                // video
                $thumb = $attachment['thumb']['src'];
            } elseif (isset($attachment['sizes']['thumbnail']['url'])) {
                // image
                $thumb = $attachment['sizes']['thumbnail']['url'];
            } elseif ($attachment['type'] === 'image') {
                // svg
                $thumb = $attachment['url'];
            } else {
                // fallback (perhaps attachment does not exist)
                $thumb = $attachment['icon'];
            }
            // dimentions
            if ($attachment['type'] === 'audio') {
                $dimentions = __('Length', 'acf') . ': ' . $attachment['fileLength'];
            } elseif (!empty($attachment['width'])) {
                $dimentions = $attachment['width'] . ' x ' . $attachment['height'];
            }
            if ($attachment['filesizeHumanReadable']) {
                $dimentions .= ' (' . $attachment['filesizeHumanReadable'] . ')';
            }
            ?>
		<div class="acf-gallery-side-info acf-cf">
			<img src="<?php 
            echo $thumb;
            ?>
" alt="<?php 
            echo $attachment['alt'];
            ?>
" />
			<p class="filename"><strong><?php 
            echo $attachment['filename'];
            ?>
</strong></p>
			<p class="uploaded"><?php 
            echo $attachment['dateFormatted'];
            ?>
</p>
			<p class="dimensions"><?php 
            echo $dimentions;
            ?>
</p>
			<p class="actions"><a href="#" class="edit-attachment" data-id="<?php 
            echo $id;
            ?>
"><?php 
            _e('Edit', 'acf');
            ?>
</a> <a href="#" class="remove-attachment" data-id="<?php 
            echo $id;
            ?>
"><?php 
            _e('Remove', 'acf');
            ?>
</a></p>
		</div>
		<table class="form-table">
			<tbody>
				<?php 
            acf_render_field_wrap(array('name' => 'title', 'prefix' => $prefix, 'type' => 'text', 'label' => 'Title', 'value' => $attachment['title']), 'tr');
            acf_render_field_wrap(array('name' => 'caption', 'prefix' => $prefix, 'type' => 'textarea', 'label' => 'Caption', 'value' => $attachment['caption']), 'tr');
            acf_render_field_wrap(array('name' => 'alt', 'prefix' => $prefix, 'type' => 'text', 'label' => 'Alt Text', 'value' => $attachment['alt']), 'tr');
            acf_render_field_wrap(array('name' => 'description', 'prefix' => $prefix, 'type' => 'textarea', 'label' => 'Description', 'value' => $attachment['description']), 'tr');
            ?>
			</tbody>
		</table>
		<?php 
            echo $compat['item'];
            ?>
		
		<?php 
        }
 function render_field($field)
 {
     global $post, $self;
     if (is_object($post)) {
         $current_id = $post->ID;
     } elseif ($self === "profile.php") {
         $current_id = "user_" . $_GET["user_id"];
     } elseif ($self === "comment.php") {
         $current_id = "comment_" . $_GET["c"];
     } else {
         $current_id = "options";
     }
     $name_prefix = '';
     // Geniem addition: get field group to get the visibility settings
     $field_groups = acf_get_field_groups();
     foreach ($field_groups as $group) {
         if ($group["key"] == $field["group_key"]) {
             $contents = $group;
             break;
         }
     }
     $contents["active"] = true;
     // Geniem addition: set a variable that we are including the field group
     // this variable will be checked in the visibility condition check
     $this->included = "true";
     // Geniem addition: check the visibility rules and return false if not visible
     if (!acf_get_field_group_visibility($contents)) {
         return false;
     }
     if (isset($field['parent'])) {
         preg_match_all('/\\[(field_\\w+)\\](\\[(\\d+)\\])?/', $field['prefix'], $parent_fields);
         if (isset($parent_fields[0])) {
             foreach ($parent_fields[0] as $parent_field_index => $parent_field) {
                 $field_name = $parent_fields[1][$parent_field_index];
                 $index = $parent_fields[3][$parent_field_index];
                 $parent_field_object = acf_get_field($field_name);
                 $parent_prefix = $parent_field_object['name'];
                 if ($index !== '') {
                     $parent_prefix .= '_' . $index;
                 }
                 $name_prefix .= $parent_prefix . '_';
             }
         }
         $name_prefix .= $field['_name'] . '_';
     }
     foreach ($field['sub_fields'] as $sub_field) {
         $sub_name_prefix = $name_prefix;
         $sub_field_name = $sub_field['name'];
         // update prefix to allow for nested values
         $sub_field['prefix'] = $field["name"];
         $sub_field['name'] = "{$name_prefix}{$sub_field_name}";
         // load value
         if ($sub_field['value'] === null) {
             $sub_field['value'] = acf_get_value($current_id, $sub_field);
         }
         // render input
         acf_render_field_wrap($sub_field);
     }
 }
示例#21
0
function acf_render_field_setting($field, $setting, $global = false)
{
    // validate
    $setting = acf_get_valid_field($setting);
    // if this setting is not global, add a data attribute
    if (!$global) {
        $setting['wrapper']['data-setting'] = $field['type'];
    }
    // copy across prefix
    $setting['prefix'] = $field['prefix'];
    // copy across the $setting value
    if (isset($field[$setting['name']])) {
        $setting['value'] = $field[$setting['name']];
    } elseif (isset($setting['default_value'])) {
        // use the default value
        $setting['value'] = $setting['default_value'];
    }
    // vars
    $instructions_placement = acf_extract_var($setting, 'instructions_placement', 'label');
    // render
    acf_render_field_wrap($setting, 'tr', $instructions_placement);
}
示例#22
0
function acf_render_field_setting($field, $setting, $global = false)
{
    // validate
    $setting = acf_get_valid_field($setting);
    // if this setting is not global, add a data attribute
    if (!$global) {
        $setting['wrapper']['data-setting'] = $field['type'];
    }
    // copy across prefix
    $setting['prefix'] = $field['prefix'];
    // copy across the $setting value
    if (isset($field[$setting['name']])) {
        $setting['value'] = $field[$setting['name']];
    }
    // render
    acf_render_field_wrap($setting, 'tr', 'label');
}
示例#23
0
 function ajax_move_field()
 {
     // disable JSON to avoid conflicts between DB and JSON
     acf_disable_local();
     $args = acf_parse_args($_POST, array('nonce' => '', 'field_id' => 0, 'field_group_id' => 0));
     // verify nonce
     if (!wp_verify_nonce($args['nonce'], 'acf_nonce')) {
         die;
     }
     // confirm?
     if ($args['field_id'] && $args['field_group_id']) {
         // vars
         $field = acf_get_field($args['field_id']);
         $field_group = acf_get_field_group($args['field_group_id']);
         // update parent
         $field['parent'] = $field_group['ID'];
         // remove conditional logic
         $field['conditional_logic'] = 0;
         // update field
         acf_update_field($field);
         $v1 = $field['label'];
         $v2 = '<a href="' . admin_url("post.php?post={$field_group['ID']}&action=edit") . '" target="_blank">' . $field_group['title'] . '</a>';
         echo '<p><strong>' . __('Move Complete.', 'acf') . '</strong></p>';
         echo sprintf(__('The %s field can now be found in the %s field group', 'acf'), $v1, $v2) . '</p>';
         echo '<a href="#" class="acf-button blue acf-close-popup">' . __("Close Window", 'acf') . '</a>';
         die;
     }
     // get all field groups
     $field_groups = acf_get_field_groups();
     $choices = array();
     if (!empty($field_groups)) {
         foreach ($field_groups as $field_group) {
             if ($field_group['ID']) {
                 $choices[$field_group['ID']] = $field_group['title'];
             }
         }
     }
     // render options
     $field = acf_get_valid_field(array('type' => 'select', 'name' => 'acf_field_group', 'choices' => $choices));
     echo '<p>' . __('Please select the destination for this field', 'acf') . '</p>';
     echo '<form id="acf-move-field-form">';
     // render
     acf_render_field_wrap($field);
     echo '<button type="submit" class="acf-button blue">' . __("Move Field", 'acf') . '</button>';
     echo '</form>';
     // die
     die;
 }
示例#24
0
function acf_render_field_setting($field, $setting, $global = false)
{
    // validate
    $setting = acf_get_valid_field($setting);
    // specific
    if (!$global) {
        $setting['wrapper']['data-setting'] = $field['type'];
    }
    // class
    $setting['wrapper']['class'] .= ' acf-field-setting-' . $setting['name'];
    // copy across prefix
    $setting['prefix'] = $field['prefix'];
    // attempt find value
    if ($setting['value'] === null) {
        // name
        if (isset($field[$setting['name']])) {
            $setting['value'] = $field[$setting['name']];
            // default
        } elseif (isset($setting['default_value'])) {
            $setting['value'] = $setting['default_value'];
        }
    }
    // append (used by JS to join settings)
    if (isset($setting['_append'])) {
        $setting['wrapper']['data-append'] = $setting['_append'];
    }
    // render
    acf_render_field_wrap($setting, 'tr', 'label');
}