示例#1
0
文件: ajax.php 项目: slavic18/cats
 function update_user_setting()
 {
     // options
     $options = acf_parse_args($_POST, array('name' => '', 'value' => '', 'nonce' => ''));
     // validate
     if (!wp_verify_nonce($options['nonce'], 'acf_nonce') || empty($options['name'])) {
         die('0');
     }
     // upadte setting
     acf_update_user_setting($options['name'], $options['value']);
     // return
     die('1');
 }
示例#2
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 
        }
示例#3
0
function acf_is_row_collapsed($field_key = '', $row_index = 0)
{
    // 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);
        // update
        acf_update_user_setting('collapsed_' . $field_key, $collapsed);
    }
    // explode
    $collapsed = explode(',', $collapsed);
    $collapsed = array_filter($collapsed, 'is_numeric');
    // collapsed class
    return in_array($row_index, $collapsed);
}