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


PHP acf_parse_types函数代码示例

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


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

示例1: 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

示例2: acf_parse_type

function acf_parse_type($v)
{
    // test for array
    if (is_array($v)) {
        return acf_parse_types($v);
    }
    // bail early if not string
    if (!is_string($v)) {
        return $v;
    }
    // trim
    $v = trim($v);
    // numbers
    if (is_numeric($v) && strval((int) $v) === $v) {
        $v = intval($v);
    }
    // return
    return $v;
}
开发者ID:sdh100shaun,项目名称:pantheon,代码行数:19,代码来源:api-helpers.php

示例3: acf_update_field_group

function acf_update_field_group($field_group = array())
{
    // validate
    $field_group = acf_get_valid_field_group($field_group);
    // may have been posted. Remove slashes
    $field_group = wp_unslash($field_group);
    // parse types (converts string '0' to int 0)
    $field_group = acf_parse_types($field_group);
    // locations may contain 'uniquid' array keys
    $field_group['location'] = array_values($field_group['location']);
    foreach ($field_group['location'] as $k => $v) {
        $field_group['location'][$k] = array_values($v);
    }
    // store origional field group for return
    $data = $field_group;
    // extract some args
    $extract = acf_extract_vars($data, array('ID', 'key', 'title', 'menu_order', 'fields', 'active'));
    // vars
    $data = maybe_serialize($data);
    $post_status = $extract['active'] ? 'publish' : 'acf-disabled';
    // save
    $save = array('ID' => $extract['ID'], 'post_status' => $post_status, 'post_type' => 'acf-field-group', 'post_title' => $extract['title'], 'post_name' => $extract['key'], 'post_excerpt' => sanitize_title($extract['title']), 'post_content' => $data, 'menu_order' => $extract['menu_order']);
    // allow field groups to contain the same name
    add_filter('wp_unique_post_slug', 'acf_update_field_group_wp_unique_post_slug', 100, 6);
    // update the field group and update the ID
    if ($field_group['ID']) {
        wp_update_post($save);
    } else {
        $field_group['ID'] = wp_insert_post($save);
    }
    // action for 3rd party customization
    do_action('acf/update_field_group', $field_group);
    // clear cache
    acf_delete_cache("get_field_group/key={$field_group['key']}");
    // return
    return $field_group;
}
开发者ID:rmikeska,项目名称:ushipnetwork,代码行数:37,代码来源:api-field-group.php

示例4: acf_parse_args

function acf_parse_args($args, $defaults = array())
{
    // parse args
    $args = wp_parse_args($args, $defaults);
    // parse types
    $args = acf_parse_types($args);
    // return
    return $args;
}
开发者ID:Garth619,项目名称:Femi9,代码行数:9,代码来源:api-helpers.php

示例5: acf_parse_types

function acf_parse_types($var)
{
    // is value another array?
    if (is_array($var)) {
        // some keys are restricted
        $restricted = array('label', 'name', 'value', 'instructions', 'nonce');
        // loop through $var carful not to parse any restricted keys
        foreach (array_keys($var) as $k) {
            // bail early for restricted pieces
            if (in_array($k, $restricted, true)) {
                continue;
            }
            $var[$k] = acf_parse_types($var[$k]);
        }
    } else {
        // string
        if (is_string($var)) {
            $var = trim($var);
        }
        // numbers
        if (is_numeric($var)) {
            // check for non numeric characters
            if (preg_match('/[^0-9]/', $var)) {
                // leave value if it contains such characters: . + - e
                //$value = floatval( $value );
            } else {
                $var = intval($var);
            }
        }
    }
    // return
    return $var;
}
开发者ID:spiff888,项目名称:rockharbor,代码行数:33,代码来源:api-helpers.php


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