当前位置: 首页>>代码示例>>PHP>>正文


PHP acf_get_valid_field函数代码示例

本文整理汇总了PHP中acf_get_valid_field函数的典型用法代码示例。如果您正苦于以下问题:PHP acf_get_valid_field函数的具体用法?PHP acf_get_valid_field怎么用?PHP acf_get_valid_field使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了acf_get_valid_field函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: array

<?php

// vars
// Note: $args is always passed to this view from above
$fields = array();
$layout = false;
$parent = 0;
// use fields if passed in
extract($args);
// add clone
$fields[] = acf_get_valid_field(array('ID' => 'acfcloneindex', 'key' => 'acfcloneindex', 'label' => __('New Field', 'acf'), 'name' => 'new_field', 'type' => 'text', 'parent' => $parent));
?>
<div class="acf-field-list-wrap">
	
	<ul class="acf-hl acf-thead">
		<li class="li-field-order"><?php 
_e('Order', 'acf');
?>
</li>
		<li class="li-field-label"><?php 
_e('Label', 'acf');
?>
</li>
		<li class="li-field-name"><?php 
_e('Name', 'acf');
?>
</li>
		<li class="li-field-type"><?php 
_e('Type', 'acf');
?>
</li>
开发者ID:esjosemartinez,项目名称:PrototestWP,代码行数:31,代码来源:field-group-fields.php

示例2: ajax_move_field

 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;
 }
开发者ID:eea76,项目名称:hammer,代码行数:48,代码来源:field-group.php

示例3: add_field

 function add_field($field)
 {
     // validate
     $field = acf_get_valid_field($field);
     // add parent reference
     $this->add_parent_reference($field['parent'], $field['key']);
     // add in menu order
     $field['menu_order'] = count($this->parents[$field['parent']]) - 1;
     // add field
     $this->fields[$field['key']] = $field;
     // clear cache
     wp_cache_delete("get_field/key={$field['key']}", 'acf');
     wp_cache_delete("get_fields/parent={$field['parent']}", 'acf');
 }
开发者ID:slavic18,项目名称:cats,代码行数:14,代码来源:local.php

示例4: acf_update_field

function acf_update_field($field = false, $specific = false)
{
    // $field must be an array
    if (!is_array($field)) {
        return false;
    }
    // validate
    $field = acf_get_valid_field($field);
    // may have been posted. Remove slashes
    $field = wp_unslash($field);
    // parse types (converts string '0' to int 0)
    $field = acf_parse_types($field);
    // clean up conditional logic keys
    if (!empty($field['conditional_logic'])) {
        // extract groups
        $groups = acf_extract_var($field, 'conditional_logic');
        // clean array
        $groups = array_filter($groups);
        $groups = array_values($groups);
        // clean rules
        foreach (array_keys($groups) as $i) {
            $groups[$i] = array_filter($groups[$i]);
            $groups[$i] = array_values($groups[$i]);
        }
        // reset conditional logic
        $field['conditional_logic'] = $groups;
    }
    // parent may be a field key
    // - lookup parent ID
    if (acf_is_field_key($field['parent'])) {
        $field['parent'] = acf_get_field_id($field['parent']);
    }
    // filter for 3rd party customization
    $field = apply_filters("acf/update_field", $field);
    $field = apply_filters("acf/update_field/type={$field['type']}", $field);
    $field = apply_filters("acf/update_field/name={$field['name']}", $field);
    $field = apply_filters("acf/update_field/key={$field['key']}", $field);
    // store origional field for return
    $data = $field;
    // extract some args
    $extract = acf_extract_vars($data, array('ID', 'key', 'label', 'name', 'prefix', 'value', 'menu_order', 'id', 'class', 'parent', '_name', '_input', '_valid'));
    // serialize for DB
    $data = maybe_serialize($data);
    // save
    $save = array('ID' => $extract['ID'], 'post_status' => 'publish', 'post_type' => 'acf-field', 'post_title' => $extract['label'], 'post_name' => $extract['key'], 'post_excerpt' => $extract['name'], 'post_content' => $data, 'post_parent' => $extract['parent'], 'menu_order' => $extract['menu_order']);
    // $specific
    if (!empty($specific)) {
        // prepend ID
        array_unshift($specific, 'ID');
        // vars
        $_save = $save;
        // reset
        $save = array();
        // appen data
        foreach ($specific as $key) {
            $save[$key] = $_save[$key];
        }
    }
    // allow fields to contain the same name
    add_filter('wp_unique_post_slug', 'acf_update_field_wp_unique_post_slug', 100, 6);
    // update the field and update the ID
    if ($field['ID']) {
        wp_update_post($save);
    } else {
        $field['ID'] = wp_insert_post($save);
    }
    // clear cache
    acf_delete_cache("get_field/key={$field['key']}");
    // return
    return $field;
}
开发者ID:coreymargulis,项目名称:karenmargulis,代码行数:71,代码来源:api-field.php

示例5: update_sub_field

function update_sub_field($selector, $value, $post_id = false)
{
    // filter post_id
    $post_id = acf_get_valid_post_id($post_id);
    // vars
    $field = false;
    // within a have_rows loop
    if (is_string($selector)) {
        // get current row
        $row = acf_get_row();
        // override $post_id
        $post_id = $row['post_id'];
        // get sub field
        $field = get_sub_field_object($selector, false, false);
        // create dummy field
        if (!$field) {
            $field = acf_get_valid_field(array('name' => $selector, 'key' => '', 'type' => ''));
        }
        // update name
        $field['name'] = "{$row['name']}_{$row['i']}_{$field['name']}";
    } elseif (is_array($selector)) {
        // validate
        if (count($selector) < 3) {
            return false;
        }
        // vars
        $parent_name = acf_extract_var($selector, 0);
        // load parent
        $field = acf_maybe_get_field($parent_name, $post_id);
        // add to name
        $name = "{$field['name']}";
        // sub fields
        foreach ($selector as $s) {
            if (is_numeric($s)) {
                $row_i = intval($s) - 1;
                // add to name
                $name .= "_{$row_i}";
            } else {
                // update parent
                $field = acf_get_sub_field($s, $field);
                // create dummy field
                if (!$field) {
                    $field = acf_get_valid_field(array('name' => $s, 'key' => '', 'type' => ''));
                }
                // add to name
                $name .= "_{$field['name']}";
            }
            // if
        }
        // foreach
        // update name
        $field['name'] = $name;
    }
    // delete
    if ($value === null) {
        return acf_delete_value($post_id, $field);
    }
    // update
    return acf_update_value($value, $post_id, $field);
}
开发者ID:de190909,项目名称:WPTest,代码行数:60,代码来源:api-template.php

示例6: psp_update_sub_field

function psp_update_sub_field($selector, $value, $post_id = false)
{
    // filter post_id
    // $post_id = acf_get_valid_post_id( $post_id );
    // vars
    $field = false;
    $name = '';
    // within a have_rows loop
    if (is_string($selector)) {
        // loop over global data
        if (!empty($GLOBALS['acf_field'])) {
            foreach ($GLOBALS['acf_field'] as $row) {
                // add to name
                $name .= "{$row['name']}_{$row['i']}_";
                // override $post_id
                $post_id = $row['post_id'];
            }
        }
        // get sub field
        $field = get_sub_field_object($selector);
        // create dummy field
        if (!$field) {
            $field = acf_get_valid_field(array('name' => $selector, 'key' => '', 'type' => ''));
        }
        // append name
        $name .= $field['name'];
        // update name
        $field['name'] = $name;
    } elseif (is_array($selector)) {
        // validate
        if (count($selector) < 3) {
            return false;
        }
        // vars
        $parent_name = acf_extract_var($selector, 0);
        // load parent
        $field = get_field_object($parent_name, $post_id, false, false);
        // add to name
        $name .= "{$field['name']}";
        // sub fields
        foreach ($selector as $s) {
            if (is_numeric($s)) {
                $row_i = intval($s) - 1;
                // add to name
                $name .= "_{$row_i}";
            } else {
                // update parent
                $field = acf_get_sub_field($s, $field);
                // create dummy field
                if (!$field) {
                    $field = acf_get_valid_field(array('name' => $s, 'key' => '', 'type' => ''));
                }
                // add to name
                $name .= "_{$field['name']}";
            }
            // if
        }
        // foreach
        // update name
        $field['name'] = $name;
    }
    // save
    return acf_update_value($value, $post_id, $field);
}
开发者ID:VLabsInc,项目名称:WordPressPlatforms,代码行数:64,代码来源:transition.php

示例7: acf_render_field_setting

function acf_render_field_setting($field, $setting, $global = false)
{
    // vars
    $atts = array();
    // 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');
}
开发者ID:mariussunde,项目名称:Sn-hetta-Designmanual-WP-Theme,代码行数:19,代码来源:api-helpers.php

示例8: _migrate_field_500

function _migrate_field_500($field)
{
    // orig
    $orig = $field;
    // order_no is now menu_order
    $field['menu_order'] = acf_extract_var($field, 'order_no');
    // correct very old field keys
    if (substr($field['key'], 0, 6) !== 'field_') {
        $field['key'] = 'field_' . str_replace('field', '', $field['key']);
    }
    // get valid field
    $field = acf_get_valid_field($field);
    // save field
    $field = acf_update_field($field);
    // sub fields
    if ($field['type'] == 'repeater') {
        // get sub fields
        $sub_fields = acf_extract_var($orig, 'sub_fields');
        // save sub fields
        if (!empty($sub_fields)) {
            $keys = array_keys($sub_fields);
            foreach ($keys as $key) {
                $sub_field = acf_extract_var($sub_fields, $key);
                $sub_field['parent'] = $field['ID'];
                _migrate_field_500($sub_field);
            }
        }
    } elseif ($field['type'] == 'flexible_content') {
        // get layouts
        $layouts = acf_extract_var($orig, 'layouts');
        // update layouts
        $field['layouts'] = array();
        // save sub fields
        if (!empty($layouts)) {
            foreach ($layouts as $layout) {
                // vars
                $layout_key = uniqid();
                // append layotu key
                $layout['key'] = $layout_key;
                // extract sub fields
                $sub_fields = acf_extract_var($layout, 'sub_fields');
                // save sub fields
                if (!empty($sub_fields)) {
                    $keys = array_keys($sub_fields);
                    foreach ($keys as $key) {
                        $sub_field = acf_extract_var($sub_fields, $key);
                        $sub_field['parent'] = $field['ID'];
                        $sub_field['parent_layout'] = $layout_key;
                        _migrate_field_500($sub_field);
                    }
                    // foreach
                }
                // if
                // append layout
                $field['layouts'][] = $layout;
            }
            // foreach
        }
        // if
        // save field again with less sub field data
        $field = acf_update_field($field);
    }
    // return
    return $field;
}
开发者ID:rousnay,项目名称:lighthouse,代码行数:65,代码来源:5.0.0.php

示例9: add_field

 function add_field($field)
 {
     // validate
     $field = acf_get_valid_field($field);
     // don't allow overrides
     // edit: some manually created fields (via .php) used duplicate keys (copy of origional field).
     /*
     if( acf_is_local_field($field['key']) ) {
     			
     			return;	
     			
     		}
     */
     // vars
     $parent = $field['parent'];
     // append $parents
     $this->parents[$parent][] = $field['key'];
     // add in menu order
     $field['menu_order'] = count($this->parents[$parent]) - 1;
     // find ancestors
     //$field['ancestors'] = array();
     while (acf_is_local_field($parent)) {
         //$field['ancestors'][] = $parent;
         $parent = acf_get_local_field($parent);
         $parent = $parent['parent'];
     }
     //$field['ancestors'][] = $field['field_group'];
     // add field
     $this->fields[$field['key']] = $field;
 }
开发者ID:mariussunde,项目名称:Sn-hetta-Designmanual-WP-Theme,代码行数:30,代码来源:local.php

示例10: _e

    }
}
?>
		
	</div>
	
	<ul class="acf-hl acf-tfoot">
		<li class="acf-fr">
			<a href="#" class="button button-primary button-large add-field"><?php 
_e('+ Add Field', 'acf');
?>
</a>
		</li>
	</ul>
	
<?php 
if (!$parent) {
    // get clone
    $clone = acf_get_valid_field(array('ID' => 'acfcloneindex', 'key' => 'acfcloneindex', 'label' => __('New Field', 'acf'), 'name' => 'new_field', 'type' => 'text'));
    ?>
	<script type="text/html" id="tmpl-acf-field">
	<?php 
    acf_get_view('field-group-field', array('field' => $clone));
    ?>
	</script>
<?php 
}
?>
	
</div>
开发者ID:rmikeska,项目名称:ushipnetwork,代码行数:30,代码来源:field-group-fields.php

示例11: acf_render_field_wrap

function acf_render_field_wrap($field, $el = 'div', $instruction = 'label', $atts = array())
{
    // get valid field
    $field = acf_get_valid_field($field);
    // prepare field for input
    $field = acf_prepare_field($field);
    // el
    $elements = apply_filters('acf/render_field_wrap/elements', array('div' => 'div', 'tr' => 'td', 'ul' => 'li', 'ol' => 'li', 'dl' => 'dt', 'td' => 'div'));
    // validate $el
    if (!array_key_exists($el, $elements)) {
        $el = 'div';
    }
    // atts
    $atts = acf_parse_args($atts, array('class' => '', 'data-name' => $field['name'], 'data-type' => $field['type']));
    // add to atts
    $atts['class'] .= " acf-field field_type-{$field['type']}";
    // add key
    if ($field['key']) {
        $atts['class'] .= " field_key-{$field['key']}";
        $atts['data-key'] = $field['key'];
    }
    // add required
    if ($field['required']) {
        $atts['data-required'] = 1;
    }
    // vars
    $show_label = true;
    if ($el == 'td') {
        $show_label = false;
    }
    ?>
<<?php 
    echo $el;
    ?>
 <?php 
    echo acf_esc_attr($atts);
    ?>
>
		<?php 
    if ($show_label) {
        ?>
		<<?php 
        echo $elements[$el];
        ?>
 class="acf-label">
			
			<label for="<?php 
        echo $field['id'];
        ?>
"><?php 
        echo acf_get_field_label($field);
        ?>
</label>
			
			<?php 
        if ($instruction == 'label' && $field['instructions']) {
            ?>
				<p class="description"><?php 
            echo $field['instructions'];
            ?>
</p>
			<?php 
        }
        ?>
			
		</<?php 
        echo $elements[$el];
        ?>
>
		<?php 
    }
    ?>
		<<?php 
    echo $elements[$el];
    ?>
 class="acf-input">
		
			<?php 
    acf_render_field($field);
    ?>
			
			<?php 
    if ($instruction == 'field' && $field['instructions']) {
        ?>
				<p class="description"><?php 
        echo $field['instructions'];
        ?>
</p>
			<?php 
    }
    ?>
			
			<?php 
    if (!empty($field['conditional_logic'])) {
        ?>
			<script type="text/javascript">
			(function($) {
				
			if( typeof acf !== 'undefined' )
			{
//.........这里部分代码省略.........
开发者ID:spiff888,项目名称:rockharbor,代码行数:101,代码来源:api-helpers.php

示例12: update_field

function update_field($selector, $value, $post_id = false)
{
    // filter post_id
    $post_id = acf_get_valid_post_id($post_id);
    // get field
    $field = acf_maybe_get_field($selector, $post_id, false);
    // create dummy field
    if (!$field) {
        $field = acf_get_valid_field(array('name' => $selector, 'key' => '', 'type' => ''));
    }
    // save
    return acf_update_value($value, $post_id, $field);
}
开发者ID:rmikeska,项目名称:ushipnetwork,代码行数:13,代码来源:api-template.php

示例13: render

    public function render()
    {
        acf_enqueue_scripts();
        do_action('acf/view', $this->args, $this);
        $post_id = $this->post_id;
        $args = $this->args;
        // 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);
                    }
                }
            }
        }
        ?>
		<div class="acf-fields acf-form-fields -<?php 
        echo $args['label_placement'];
        ?>
">

		<?php 
        // html before fields
        echo $args['html_before_fields'];
        // render
        acf_views_render_fields($post_id, $fields, $args['field_el'], $args['instruction_placement']);
        // html after fields
        echo $args['html_after_fields'];
        ?>

		</div><!-- acf-form-fields -->
		<?php 
    }
开发者ID:NikolaGrdanjski,项目名称:acf-views,代码行数:61,代码来源:acf-views-view.php

示例14: ajax_move_field

 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;
 }
开发者ID:developmentDM2,项目名称:Whohaha,代码行数:57,代码来源:field-group.php

示例15: acf_views_render_field

function acf_views_render_field($field = false)
{
    // get valid field
    $field = acf_get_valid_field($field);
    // prepare field for input
    $field = acf_prepare_field($field);
    // update $field['name']
    $field['name'] = $field['_input'];
    // create field specific html
    do_action("acf/views_render_field", $field);
    do_action("acf/views_render_field/type={$field['type']}", $field);
}
开发者ID:NikolaGrdanjski,项目名称:acf-views,代码行数:12,代码来源:acf-views-api.php


注:本文中的acf_get_valid_field函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。