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


PHP acf_is_field_key函数代码示例

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


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

示例1: getField

 public function getField($fieldId, $format = true)
 {
     if (!function_exists('acf_is_field_key')) {
         throw new \Exception('Advanced Custom Fields must be installed to use ' . __METHOD__);
     }
     $value = maybe_unserialize($this->getMeta($fieldId));
     $fieldId = $this->getMeta('_' . $fieldId);
     if (!acf_is_field_key($fieldId)) {
         return null;
     }
     $field = get_field_object($fieldId, $this->ID, false, false);
     $value = apply_filters("acf/load_value", $value, $this->ID, $field);
     $value = apply_filters("acf/load_value/type={$field['type']}", $value, $this->ID, $field);
     $value = apply_filters("acf/load_value/name={$field['name']}", $value, $this->ID, $field);
     $value = apply_filters("acf/load_value/key={$field['key']}", $value, $this->ID, $field);
     if ($format) {
         $value = acf_format_value($value, $this->ID, $field);
     }
     return $value;
 }
开发者ID:lara-press,项目名称:framework,代码行数:20,代码来源:Post.php

示例2: update_field

 function update_field($field)
 {
     // bail ealry if not relevant
     if (!$field['parent'] || !acf_is_field_key($field['parent'])) {
         return $field;
     }
     // vars
     $ref = 0;
     // create reference
     if (empty($this->ref)) {
         $this->ref = array();
     }
     if (isset($this->ref[$field['parent']])) {
         $ref = $this->ref[$field['parent']];
     } else {
         // get parent without caching (important not to cache as parent $field will now contain new sub fields)
         $parent = acf_get_field($field['parent'], true);
         // bail ealry if no parent
         if (!$parent) {
             return $field;
         }
         // get ref
         $ref = $parent['ID'] ? $parent['ID'] : $parent['key'];
         // update ref
         $this->ref[$field['parent']] = $ref;
     }
     // update field's parent
     $field['parent'] = $ref;
     // return
     return $field;
 }
开发者ID:bmavus,项目名称:wp-theme-blank,代码行数:31,代码来源:acf-pro.php

示例3: acf_get_field_ancestors

function acf_get_field_ancestors($field)
{
    // get field
    $ancestors = array();
    // loop
    while ($field && acf_is_field_key($field['parent'])) {
        $ancestors[] = $field['parent'];
        $field = acf_get_field($field['parent']);
    }
    // return
    return $ancestors;
}
开发者ID:coreymargulis,项目名称:karenmargulis,代码行数:12,代码来源:api-field.php

示例4: wp_restore_post_revision

 function wp_restore_post_revision($post_id, $revision_id)
 {
     // global
     global $wpdb;
     // get field objects
     $custom_fields = get_post_custom($revision_id);
     // populate vars
     if (!empty($custom_fields)) {
         foreach ($custom_fields as $k => $v) {
             // value is always an array
             $v = $v[0];
             // bail early if $value is not is a field_key
             if (!acf_is_field_key($v)) {
                 continue;
             }
             // remove prefix '_' field from reference
             $field_name = substr($k, 1);
             // bail early if value could not be found
             if (!isset($custom_fields[$field_name][0])) {
                 continue;
             }
             update_post_meta($post_id, $field_name, $custom_fields[$field_name][0]);
         }
     }
 }
开发者ID:harrisonsmith,项目名称:active-progression,代码行数:25,代码来源:revisions.php

示例5: acf_copy_postmeta

function acf_copy_postmeta($from_post_id, $to_post_id)
{
    // get all postmeta
    $meta = get_post_meta($from_post_id);
    // bail early if no meta
    if (!$meta) {
        return;
    }
    // loop
    foreach ($meta as $name => $value) {
        // attempt to find key value
        $key = acf_maybe_get($meta, '_' . $name);
        // bail ealry if no key
        if (!$key) {
            continue;
        }
        // update vars
        $value = $value[0];
        $key = $key[0];
        // bail early if $key is a not a field_key
        if (!acf_is_field_key($key)) {
            continue;
        }
        // get_post_meta will return array before running maybe_unserialize
        $value = maybe_unserialize($value);
        // add in slashes
        // - update_post_meta will unslash the value, so we must first slash it to avoid losing backslashes
        // - https://codex.wordpress.org/Function_Reference/update_post_meta#Character_Escaping
        if (is_string($value)) {
            $value = wp_slash($value);
        }
        // update value
        acf_update_metadata($to_post_id, $name, $value);
        acf_update_metadata($to_post_id, $name, $key, true);
    }
}
开发者ID:Garth619,项目名称:Femi9,代码行数:36,代码来源:api-value.php

示例6: get_clone_setting_choice

 function get_clone_setting_choice($selector = '')
 {
     // bail early no selector
     if (!$selector) {
         return '';
     }
     // ajax_fields
     if (isset($_POST['fields'][$selector])) {
         return $this->get_clone_setting_field_choice($_POST['fields'][$selector]);
     }
     // field
     if (acf_is_field_key($selector)) {
         return $this->get_clone_setting_field_choice(acf_get_field($selector));
     }
     // group
     if (acf_is_field_group_key($selector)) {
         return $this->get_clone_setting_group_choice(acf_get_field_group($selector));
     }
     // return
     return $selector;
 }
开发者ID:developmentDM2,项目名称:Whohaha,代码行数:21,代码来源:clone.php

示例7: is_protected_meta

 function is_protected_meta($protected, $meta_key, $meta_type)
 {
     // if acf_get_field_reference returns a valid key, this is an acf value, so protect it!
     if (!$protected) {
         $reference = acf_get_field_reference($meta_key, $this->post_id);
         if (acf_is_field_key($reference)) {
             $protected = true;
         }
     }
     // return
     return $protected;
 }
开发者ID:tofubuddha,项目名称:example,代码行数:12,代码来源:post.php

示例8: acf_get_field

function acf_get_field($selector = null)
{
    // vars
    $field = false;
    $k = 'ID';
    $v = 0;
    // $post_id or $key
    if (is_numeric($selector)) {
        $v = $selector;
    } elseif (is_string($selector)) {
        if (acf_is_field_key($selector)) {
            $k = 'key';
        } else {
            $k = 'name';
        }
        $v = $selector;
    } elseif (is_object($selector)) {
        $v = $selector->ID;
    } else {
        return false;
    }
    // get cache key
    $cache_key = "load_field/{$k}={$v}";
    // get cache
    $found = false;
    $cache = wp_cache_get($cache_key, 'acf', false, $found);
    if ($found) {
        return $cache;
    }
    // get field group from ID or key
    if ($k == 'ID') {
        $field = _acf_get_field_by_id($v);
    } elseif ($k == 'name') {
        $field = _acf_get_field_by_name($v);
    } else {
        $field = _acf_get_field_by_key($v);
    }
    // filter for 3rd party customization
    $field = apply_filters('acf/load_field', $field);
    // If a field has been found, apply filters
    if ($field) {
        $field = apply_filters("acf/load_field/type={$field['type']}", $field);
        $field = apply_filters("acf/load_field/name={$field['name']}", $field);
        $field = apply_filters("acf/load_field/key={$field['key']}", $field);
    }
    // set cache
    wp_cache_set($cache_key, $field, 'acf');
    // return
    return $field;
}
开发者ID:spiff888,项目名称:rockharbor,代码行数:50,代码来源:api-field.php

示例9: get_field_object

function get_field_object($selector, $post_id = false, $format_value = true, $load_value = true)
{
    // complete loading
    acf()->complete();
    // compatibilty
    if (is_array($format_value)) {
        extract($format_value);
    }
    // vars
    $field_name = false;
    // get valid post_id
    $post_id = acf_get_valid_post_id($post_id);
    // load field reference if not a field_key
    if (!acf_is_field_key($selector)) {
        // save selector as field_name (could be sub field name)
        $field_name = $selector;
        // get reference
        $selector = acf_get_field_reference($selector, $post_id);
        // bail early if no reference for this field
        if (!$selector) {
            return false;
        }
    }
    // get field key
    $field = acf_get_field($selector);
    // bail early if no field found
    if (!$field) {
        return false;
    }
    // Override name - allows the $selector to be a sub field (images_0_image)
    if ($field_name) {
        $field['name'] = $field_name;
    }
    // load value
    if ($load_value) {
        $field['value'] = acf_get_value($post_id, $field);
    }
    // format value
    if ($format_value) {
        // get value for field
        $field['value'] = acf_format_value($field['value'], $post_id, $field);
    }
    // return
    return $field;
}
开发者ID:bself,项目名称:nuimage-wp,代码行数:45,代码来源:api-template.php

示例10: acf_maybe_get_field

function acf_maybe_get_field($selector, $post_id = false, $strict = true)
{
    // complete loading
    // this function may be used in a theme file before the init action has been run
    acf()->complete();
    // vars
    $field_name = false;
    // get valid post_id
    $post_id = acf_get_valid_post_id($post_id);
    // load field reference if not a field_key
    if (!acf_is_field_key($selector)) {
        // save selector as field_name (could be sub field name)
        $field_name = $selector;
        // get reference
        $field_key = acf_get_field_reference($selector, $post_id);
        if ($field_key) {
            $selector = $field_key;
        } elseif ($strict) {
            return false;
        }
    }
    // get field key
    $field = acf_get_field($selector);
    // bail early if no field
    if (!$field) {
        return false;
    }
    // Override name - allows the $selector to be a sub field (images_0_image)
    if ($field_name) {
        $field['name'] = $field_name;
    }
    // return
    return $field;
}
开发者ID:jorgesoulness,项目名称:mexifilter,代码行数:34,代码来源:api-field.php

示例11: 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);
    // 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;
    }
    // find correct parent
    if (acf_is_field_key($field['parent'])) {
        // get parent
        $parent = acf_get_field($field['parent']);
        // update to ID
        $field['parent'] = acf_maybe_get($parent, 'ID', 0);
    }
    // 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
    wp_cache_delete("get_field/ID={$field['ID']}", 'acf');
    wp_cache_delete("get_field/key={$field['key']}", 'acf');
    wp_cache_delete("get_fields/parent={$field['parent']}", 'acf');
    // return
    return $field;
}
开发者ID:rousnay,项目名称:lighthouse,代码行数:73,代码来源:api-field.php

示例12: get_field_object

function get_field_object($selector, $post_id = false, $format_value = true, $load_value = true)
{
    // complete loading
    acf()->complete();
    // compatibilty
    if (is_array($format_value)) {
        $format_value = acf_parse_args($format_value, array('format_value' => true, 'load_value' => true));
        extract($format_value);
    }
    // vars
    $override_name = false;
    // filter post_id
    $post_id = acf_get_valid_post_id($post_id);
    // load field reference if not a field_key
    if (!acf_is_field_key($selector)) {
        $override_name = $selector;
        $reference = acf_get_field_reference($selector, $post_id);
        if ($reference) {
            $selector = $reference;
        }
    }
    // get field key
    $field = acf_get_field($selector);
    // bail early if no field found
    if (!$field) {
        return false;
    }
    // override name?
    // This allows the $selector to be a sub field (images_0_image)
    if ($override_name) {
        $field['name'] = $override_name;
    }
    // load value
    if ($load_value) {
        $field['value'] = acf_get_value($post_id, $field);
    }
    // format value
    if ($format_value) {
        // get value for field
        $field['value'] = acf_format_value($field['value'], $post_id, $field);
    }
    // return
    return $field;
}
开发者ID:sdh100shaun,项目名称:pantheon,代码行数:44,代码来源:api-template.php

示例13: update_field

 function update_field($field)
 {
     // don't use acf_get_field. Instead, keep a global record of ID from each update_field and use this to get the parent ID => key
     if ($field['parent']) {
         if (acf_is_field_key($field['parent'])) {
             $parent = acf_get_field($field['parent']);
             $field['parent'] = $parent['ID'];
         }
     }
     return $field;
 }
开发者ID:dleatherman,项目名称:timbangular-js,代码行数:11,代码来源:acf-pro.php

示例14: wp_post_revision_fields

 function wp_post_revision_fields($fields, $post = null)
 {
     // validate page
     if (acf_is_screen('revision') || acf_is_ajax('get-revision-diffs')) {
         // allow
     } else {
         // bail early (most likely saving a post)
         return $fields;
     }
     // vars
     $append = array();
     $order = array();
     $post_id = acf_maybe_get($post, 'ID');
     // compatibility with WP < 4.5 (test)
     if (!$post_id) {
         global $post;
         $post_id = $post->ID;
     }
     // get all postmeta
     $meta = get_post_meta($post_id);
     // bail early if no meta
     if (!$meta) {
         return $fields;
     }
     // loop
     foreach ($meta as $name => $value) {
         // attempt to find key value
         $key = acf_maybe_get($meta, '_' . $name);
         // bail ealry if no key
         if (!$key) {
             continue;
         }
         // update vars
         $value = $value[0];
         $key = $key[0];
         // bail early if $key is a not a field_key
         if (!acf_is_field_key($key)) {
             continue;
         }
         // get field
         $field = acf_get_field($key);
         $field_title = $field['label'] . ' (' . $name . ')';
         $field_order = $field['menu_order'];
         $ancestors = acf_get_field_ancestors($field);
         // ancestors
         if (!empty($ancestors)) {
             // vars
             $count = count($ancestors);
             $oldest = acf_get_field($ancestors[$count - 1]);
             // update vars
             $field_title = str_repeat('- ', $count) . $field_title;
             $field_order = $oldest['menu_order'] . '.1';
         }
         // append
         $append[$name] = $field_title;
         $order[$name] = $field_order;
         // hook into specific revision field filter and return local value
         add_filter("_wp_post_revision_field_{$name}", array($this, 'wp_post_revision_field'), 10, 4);
     }
     // append
     if (!empty($append)) {
         // vars
         $prefix = '_';
         // add prefix
         $append = acf_add_array_key_prefix($append, $prefix);
         $order = acf_add_array_key_prefix($order, $prefix);
         // sort by name (orders sub field values correctly)
         array_multisort($order, $append);
         // remove prefix
         $append = acf_remove_array_key_prefix($append, $prefix);
         // append
         $fields = $fields + $append;
     }
     // return
     return $fields;
 }
开发者ID:developmentDM2,项目名称:Whohaha,代码行数:76,代码来源:revisions.php

示例15: acf_get_field

function acf_get_field($selector = null, $db_only = false)
{
    // vars
    $field = false;
    $type = 'ID';
    // is $selector an ID
    if (is_numeric($selector)) {
        // do nothing
        // is $selector a string (name|key)
    } elseif (is_string($selector)) {
        $type = 'name';
        if (acf_is_field_key($selector)) {
            $type = 'key';
        }
        // is $selector an object
    } elseif (is_object($selector)) {
        $selector = $selector->ID;
        // selector not valid
    } else {
        return false;
    }
    // get cache key
    $cache_key = "get_field/{$type}={$selector}";
    // get cache
    if (!$db_only) {
        $found = false;
        $cache = wp_cache_get($cache_key, 'acf', false, $found);
        if ($found) {
            return $cache;
        }
    }
    // get field group from ID or key
    if ($type == 'ID') {
        $field = _acf_get_field_by_id($selector, $db_only);
    } elseif ($type == 'name') {
        $field = _acf_get_field_by_name($selector, $db_only);
    } else {
        $field = _acf_get_field_by_key($selector, $db_only);
    }
    // bail early if db only value (no need to update cache)
    if ($db_only) {
        return $field;
    }
    // filter for 3rd party customization
    if ($field) {
        $field = apply_filters("acf/load_field", $field);
        $field = apply_filters("acf/load_field/type={$field['type']}", $field);
        $field = apply_filters("acf/load_field/name={$field['name']}", $field);
        $field = apply_filters("acf/load_field/key={$field['key']}", $field);
    }
    // set cache
    wp_cache_set($cache_key, $field, 'acf');
    // return
    return $field;
}
开发者ID:bself,项目名称:nuimage-wp,代码行数:55,代码来源:api-field.php


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