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


PHP acf_get_field_reference函数代码示例

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


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

示例1: acf_maybe_get_field

function acf_maybe_get_field($selector, $post_id = false, $strict = true)
{
    // complete init
    // this function may be used in a theme file before the init action has been run
    acf()->init();
    // 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:coreymargulis,项目名称:karenmargulis,代码行数:34,代码来源:api-field.php

示例2: acf_delete_value

function acf_delete_value($post_id = 0, $key = '')
{
    // vars
    $field = false;
    $return = false;
    // string
    if (is_string($key)) {
        // find selector
        $field = acf_get_field_reference($key, $post_id);
        // get field key
        $field = acf_get_field($field);
        // field
    } elseif (is_array($key)) {
        // set vars
        $field = $key;
        $key = $field['name'];
        // bail early if not valid key
    } else {
        return false;
    }
    // action for 3rd party customization
    do_action("acf/delete_value", $post_id, $key, $field);
    if ($field) {
        do_action("acf/delete_value/type={$field['type']}", $post_id, $key, $field);
        do_action("acf/delete_value/name={$field['_name']}", $post_id, $key, $field);
        do_action("acf/delete_value/key={$field['key']}", $post_id, $key, $field);
    }
    // post
    if (is_numeric($post_id)) {
        $return = delete_metadata('post', $post_id, $key);
        delete_metadata('post', $post_id, '_' . $key);
        // user
    } elseif (strpos($post_id, 'user_') !== false) {
        $user_id = str_replace('user_', '', $post_id);
        $return = delete_metadata('user', $user_id, $key);
        delete_metadata('user', $user_id, '_' . $key);
        // comment
    } elseif (strpos($post_id, 'comment_') !== false) {
        $comment_id = str_replace('comment_', '', $post_id);
        $return = delete_metadata('comment', $comment_id, $key);
        delete_metadata('comment', $comment_id, '_' . $key);
        // option
    } else {
        $return = delete_option($post_id . '_' . $key);
        delete_option('_' . $post_id . '_' . $key);
    }
    // clear cache
    wp_cache_delete("load_value/post_id={$post_id}/name={$key}", 'acf');
    // return
    return $return;
}
开发者ID:johannes-klaushofer,项目名称:modolab,代码行数:51,代码来源:api-value.php

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

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

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


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