Exemplo n.º 1
0
function get_field_object($field_key, $post_id = false, $options = array())
{
    // make sure add-ons are included
    acf()->include_3rd_party();
    // filter post_id
    $post_id = apply_filters('acf/get_post_id', $post_id);
    $field = false;
    $orig_field_key = $field_key;
    // defaults for options
    $defaults = array('load_value' => true, 'format_value' => true);
    $options = array_merge($defaults, $options);
    // is $field_name a name? pre 3.4.0
    if (substr($field_key, 0, 6) !== 'field_') {
        // get field key
        $field_key = get_field_reference($field_key, $post_id);
    }
    // get field
    if (substr($field_key, 0, 6) === 'field_') {
        $field = apply_filters('acf/load_field', false, $field_key);
    }
    // validate field
    if (!$field) {
        // treat as text field
        $field = array('type' => 'text', 'name' => $orig_field_key, 'key' => 'field_' . $orig_field_key);
        $field = apply_filters('acf/load_field', $field, $field['key']);
    }
    // load value
    if ($options['load_value']) {
        $field['value'] = apply_filters('acf/load_value', false, $post_id, $field);
        // format value
        if ($options['format_value']) {
            $field['value'] = apply_filters('acf/format_value_for_api', $field['value'], $post_id, $field);
        }
    }
    return $field;
}
Exemplo n.º 2
0
 function is_protected_meta($protected, $meta_key, $meta_type)
 {
     // globals
     global $post;
     // if acf_get_field_reference returns a valid key, this is an acf value, so protect it!
     if (!$protected) {
         $reference = get_field_reference($meta_key, $post->ID);
         if (substr($reference, 0, 6) === 'field_') {
             $protected = true;
         }
     }
     // return
     return $protected;
 }
Exemplo n.º 3
0
function get_field_object($field_key, $post_id = false, $options = array())
{
    // filter post_id
    $post_id = acf_filter_post_id($post_id);
    $field = false;
    $orig_field_key = $field_key;
    // defaults for options
    $defaults = array('load_value' => true, 'format_value' => true);
    $options = array_merge($defaults, $options);
    // is $field_name a name? pre 3.4.0
    if (strpos($field_key, "field_") === false) {
        // get field key
        $field_key = get_field_reference($field_key, $post_id);
    }
    // get field
    if (strpos($field_key, "field_") !== false) {
        $field = apply_filters('acf/load_field', false, $field_key);
    }
    // validate field
    if (!$field) {
        // treat as text field
        $field = array('type' => 'text', 'name' => $orig_field_key, 'key' => 'temp_key_for_' . $orig_field_key);
    }
    // load value
    if ($options['load_value']) {
        $field['value'] = apply_filters('acf/load_value', false, $post_id, $field);
        // format value
        if ($options['format_value']) {
            $field['value'] = apply_filters('acf/format_value_for_api', $field['value'], $post_id, $field);
        }
    }
    return $field;
}
Exemplo n.º 4
0
 /**
  *
  * Loads the value for a property for a given propertyName, type and override key
  *
  * @param $propertyName
  * @param $type
  * @param bool $overrideKey
  * @author Tim Perry
  *
  */
 protected function loadPropertyValue($propertyName, $type, $overrideKey = false)
 {
     $propertyNameUnderscored = $this->getUnderscoredEquivalent($propertyName);
     switch ($type) {
         case "acf":
             if (!($key = $overrideKey)) {
                 $key = get_field_reference($this->prefixes["acf"] . $propertyNameUnderscored, $this->ID);
             }
             $this->{$propertyName} = get_field($key, $this->ID);
             break;
         case "tax":
             if (!($key = $overrideKey)) {
                 $key = $this->prefixes["tax"] . $propertyNameUnderscored;
             }
             if ($value = wp_get_object_terms($this->ID, $key)) {
                 if (!is_wp_error($value)) {
                     $this->{$propertyName} = $value;
                 }
             }
             break;
         case "meta":
             if (!($key = $overrideKey)) {
                 $key = $this->prefixes["meta"] . $propertyNameUnderscored;
             }
             $this->{$propertyName} = get_post_meta($this->ID, $key, true);
             break;
     }
 }