From 452031bca6bb9fb623ffec2f9c548e3a89447f6b Mon Sep 17 00:00:00 2001 From: "Open-Steps.org" Date: Mon, 9 Feb 2015 09:44:08 +0100 Subject: [PATCH 01/11] renamed get_fields to acf_get_fields to avoid conflicts --- includes/acf/core/api.php | 1956 ++++++++++++++++++------------------- 1 file changed, 978 insertions(+), 978 deletions(-) diff --git a/includes/acf/core/api.php b/includes/acf/core/api.php index d2f070a..ed03af5 100755 --- a/includes/acf/core/api.php +++ b/includes/acf/core/api.php @@ -17,43 +17,43 @@ */ function get_field_reference( $field_name, $post_id ) { - - // cache - $found = false; - $cache = wp_cache_get( 'field_reference/post_id=' . $post_id . '/name=' . $field_name, 'acf', false, $found ); - - if( $found ) - { - return $cache; - } - - - // vars - $return = ''; - - - // get field key - if( is_numeric($post_id) ) - { - $return = get_post_meta($post_id, '_' . $field_name, true); - } - elseif( strpos($post_id, 'user_') !== false ) - { - $temp_post_id = str_replace('user_', '', $post_id); - $return = get_user_meta($temp_post_id, '_' . $field_name, true); - } - else - { - $return = get_option('_' . $post_id . '_' . $field_name); - } - - - // set cache - wp_cache_set( 'field_reference/post_id=' . $post_id . '/name=' . $field_name, $return, 'acf' ); - - - // return - return $return; + + // cache + $found = false; + $cache = wp_cache_get( 'field_reference/post_id=' . $post_id . '/name=' . $field_name, 'acf', false, $found ); + + if( $found ) + { + return $cache; + } + + + // vars + $return = ''; + + + // get field key + if( is_numeric($post_id) ) + { + $return = get_post_meta($post_id, '_' . $field_name, true); + } + elseif( strpos($post_id, 'user_') !== false ) + { + $temp_post_id = str_replace('user_', '', $post_id); + $return = get_user_meta($temp_post_id, '_' . $field_name, true); + } + else + { + $return = get_option('_' . $post_id . '_' . $field_name); + } + + + // set cache + wp_cache_set( 'field_reference/post_id=' . $post_id . '/name=' . $field_name, $return, 'acf' ); + + + // return + return $return; } @@ -73,75 +73,75 @@ function get_field_reference( $field_name, $post_id ) { */ function get_field_objects( $post_id = false, $options = array() ) { - - // global - global $wpdb; - - - // filter post_id - $post_id = apply_filters('acf/get_post_id', $post_id ); - - - // vars - $field_key = ''; - $value = array(); - - - // get field_names - if( is_numeric($post_id) ) - { - $keys = $wpdb->get_col($wpdb->prepare( - "SELECT meta_value FROM $wpdb->postmeta WHERE post_id = %d and meta_key LIKE %s AND meta_value LIKE %s", - $post_id, - '_%', - 'field_%' - )); - } - elseif( strpos($post_id, 'user_') !== false ) - { - $user_id = str_replace('user_', '', $post_id); - - $keys = $wpdb->get_col($wpdb->prepare( - "SELECT meta_value FROM $wpdb->usermeta WHERE user_id = %d and meta_key LIKE %s AND meta_value LIKE %s", - $user_id, - '_%', - 'field_%' - )); - } - else - { - $keys = $wpdb->get_col($wpdb->prepare( - "SELECT option_value FROM $wpdb->options WHERE option_name LIKE %s", - '_' . $post_id . '_%' - )); - } - - - if( is_array($keys) ) - { - foreach( $keys as $key ) - { - $field = get_field_object( $key, $post_id, $options ); - - if( !is_array($field) ) - { - continue; - } - - $value[ $field['name'] ] = $field; - } - } - - - // no value - if( empty($value) ) - { - return false; - } - - - // return - return $value; + + // global + global $wpdb; + + + // filter post_id + $post_id = apply_filters('acf/get_post_id', $post_id ); + + + // vars + $field_key = ''; + $value = array(); + + + // get field_names + if( is_numeric($post_id) ) + { + $keys = $wpdb->get_col($wpdb->prepare( + "SELECT meta_value FROM $wpdb->postmeta WHERE post_id = %d and meta_key LIKE %s AND meta_value LIKE %s", + $post_id, + '_%', + 'field_%' + )); + } + elseif( strpos($post_id, 'user_') !== false ) + { + $user_id = str_replace('user_', '', $post_id); + + $keys = $wpdb->get_col($wpdb->prepare( + "SELECT meta_value FROM $wpdb->usermeta WHERE user_id = %d and meta_key LIKE %s AND meta_value LIKE %s", + $user_id, + '_%', + 'field_%' + )); + } + else + { + $keys = $wpdb->get_col($wpdb->prepare( + "SELECT option_value FROM $wpdb->options WHERE option_name LIKE %s", + '_' . $post_id . '_%' + )); + } + + + if( is_array($keys) ) + { + foreach( $keys as $key ) + { + $field = get_field_object( $key, $post_id, $options ); + + if( !is_array($field) ) + { + continue; + } + + $value[ $field['name'] ] = $field; + } + } + + + // no value + if( empty($value) ) + { + return false; + } + + + // return + return $value; } @@ -161,25 +161,25 @@ function get_field_objects( $post_id = false, $options = array() ) { */ function get_fields( $post_id = false, $format_value = true ) { - - // vars - $options = array( - 'load_value' => true, - 'format_value' => $format_value - ); - - - $fields = get_field_objects( $post_id, $options ); - - if( is_array($fields) ) - { - foreach( $fields as $k => $field ) - { - $fields[ $k ] = $field['value']; - } - } - - return $fields; + + // vars + $options = array( + 'load_value' => true, + 'format_value' => $format_value + ); + + + $fields = get_field_objects( $post_id, $options ); + + if( is_array($fields) ) + { + foreach( $fields as $k => $field ) + { + $fields[ $k ] = $field['value']; + } + } + + return $fields; } @@ -187,7 +187,7 @@ function get_fields( $post_id = false, $format_value = true ) { * get_field() * * This function will return a custom field value for a specific field name/key + post_id. -* There is a 3rd parameter to turn on/off formating. This means that an Image field will not use +* There is a 3rd parameter to turn on/off formating. This means that an Image field will not use * its 'return option' to format the value but return only what was saved in the database * * @type function @@ -200,28 +200,28 @@ function get_fields( $post_id = false, $format_value = true ) { * * @return mixed $value: the value found */ - -function get_field( $field_key, $post_id = false, $format_value = true ) { - - // vars - $return = false; - $options = array( - 'load_value' => true, - 'format_value' => $format_value - ); - - - $field = get_field_object( $field_key, $post_id, $options); - - - if( is_array($field) ) - { - $return = $field['value']; - } - - - return $return; - + +function acf_get_field( $field_key, $post_id = false, $format_value = true ) { + + // vars + $return = false; + $options = array( + 'load_value' => true, + 'format_value' => $format_value + ); + + + $field = get_field_object( $field_key, $post_id, $options); + + + if( is_array($field) ) + { + $return = $field['value']; + } + + + return $return; + } @@ -244,69 +244,69 @@ function get_field( $field_key, $post_id = false, $format_value = true ) { */ 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; + + // 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; } @@ -327,15 +327,15 @@ function get_field_object( $field_key, $post_id = false, $options = array() ) { */ function the_field( $field_name, $post_id = false ) { - - $value = get_field($field_name, $post_id); - - if( is_array($value) ) - { - $value = @implode(', ',$value); - } - - echo $value; + + $value = acf_get_field($field_name, $post_id); + + if( is_array($value) ) + { + $value = @implode(', ',$value); + } + + echo $value; } @@ -354,141 +354,141 @@ function the_field( $field_name, $post_id = false ) { */ function have_rows( $field_name, $post_id = false ) { - - // vars - $depth = 0; - $row = array(); - $new_parent_loop = false; - $new_child_loop = false; - - - // reference - $_post_id = $post_id; - - - // filter post_id - $post_id = apply_filters('acf/get_post_id', $post_id ); - - - // empty? - if( empty($GLOBALS['acf_field']) ) - { - // reset - reset_rows( true ); - - - // create a new loop - $new_parent_loop = true; - } - else - { - // vars - $row = end( $GLOBALS['acf_field'] ); - $prev = prev( $GLOBALS['acf_field'] ); - - - // If post_id has changed, this is most likely an archive loop - if( $post_id != $row['post_id'] ) - { - if( $prev && $prev['post_id'] == $post_id ) - { - // case: Change in $post_id was due to a nested loop ending - // action: move up one level through the loops - reset_rows(); - } - elseif( empty($_post_id) && isset($row['value'][ $row['i'] ][ $field_name ]) ) - { - // case: Change in $post_id was due to this being a nested loop and not specifying the $post_id - // action: move down one level into a new loop - $new_child_loop = true; - } - else - { - // case: Chang in $post_id is the most obvious, used in an WP_Query loop with multiple $post objects - // action: leave this current loop alone and create a new parent loop - $new_parent_loop = true; - } - } - elseif( $field_name != $row['name'] ) - { - if( $prev && $prev['name'] == $field_name && $prev['post_id'] == $post_id ) - { - // case: Change in $field_name was due to a nested loop ending - // action: move up one level through the loops - reset_rows(); - } - elseif( isset($row['value'][ $row['i'] ][ $field_name ]) ) - { - // case: Change in $field_name was due to this being a nested loop - // action: move down one level into a new loop - $new_child_loop = true; - - } - else - { - // case: Chang in $field_name is the most obvious, this is a new loop for a different field within the $post - // action: leave this current loop alone and create a new parent loop - $new_parent_loop = true; - } - - - } - } - - - if( $new_parent_loop ) - { - // vars - $f = get_field_object( $field_name, $post_id ); - $v = $f['value']; - unset( $f['value'] ); - - - // add row - $GLOBALS['acf_field'][] = array( - 'name' => $field_name, - 'value' => $v, - 'field' => $f, - 'i' => -1, - 'post_id' => $post_id, - ); - - } - elseif( $new_child_loop ) - { - // vars - $f = acf_get_child_field_from_parent_field( $field_name, $row['field'] ); - $v = $row['value'][ $row['i'] ][ $field_name ]; - - $GLOBALS['acf_field'][] = array( - 'name' => $field_name, - 'value' => $v, - 'field' => $f, - 'i' => -1, - 'post_id' => $post_id, - ); - - } - - - // update vars - $row = end( $GLOBALS['acf_field'] ); - - - if( is_array($row['value']) && array_key_exists( $row['i']+1, $row['value'] ) ) - { - // next row exists - return true; - } - - - // no next row! - reset_rows(); - - - // return - return false; - + + // vars + $depth = 0; + $row = array(); + $new_parent_loop = false; + $new_child_loop = false; + + + // reference + $_post_id = $post_id; + + + // filter post_id + $post_id = apply_filters('acf/get_post_id', $post_id ); + + + // empty? + if( empty($GLOBALS['acf_field']) ) + { + // reset + reset_rows( true ); + + + // create a new loop + $new_parent_loop = true; + } + else + { + // vars + $row = end( $GLOBALS['acf_field'] ); + $prev = prev( $GLOBALS['acf_field'] ); + + + // If post_id has changed, this is most likely an archive loop + if( $post_id != $row['post_id'] ) + { + if( $prev && $prev['post_id'] == $post_id ) + { + // case: Change in $post_id was due to a nested loop ending + // action: move up one level through the loops + reset_rows(); + } + elseif( empty($_post_id) && isset($row['value'][ $row['i'] ][ $field_name ]) ) + { + // case: Change in $post_id was due to this being a nested loop and not specifying the $post_id + // action: move down one level into a new loop + $new_child_loop = true; + } + else + { + // case: Chang in $post_id is the most obvious, used in an WP_Query loop with multiple $post objects + // action: leave this current loop alone and create a new parent loop + $new_parent_loop = true; + } + } + elseif( $field_name != $row['name'] ) + { + if( $prev && $prev['name'] == $field_name && $prev['post_id'] == $post_id ) + { + // case: Change in $field_name was due to a nested loop ending + // action: move up one level through the loops + reset_rows(); + } + elseif( isset($row['value'][ $row['i'] ][ $field_name ]) ) + { + // case: Change in $field_name was due to this being a nested loop + // action: move down one level into a new loop + $new_child_loop = true; + + } + else + { + // case: Chang in $field_name is the most obvious, this is a new loop for a different field within the $post + // action: leave this current loop alone and create a new parent loop + $new_parent_loop = true; + } + + + } + } + + + if( $new_parent_loop ) + { + // vars + $f = get_field_object( $field_name, $post_id ); + $v = $f['value']; + unset( $f['value'] ); + + + // add row + $GLOBALS['acf_field'][] = array( + 'name' => $field_name, + 'value' => $v, + 'field' => $f, + 'i' => -1, + 'post_id' => $post_id, + ); + + } + elseif( $new_child_loop ) + { + // vars + $f = acf_get_child_field_from_parent_field( $field_name, $row['field'] ); + $v = $row['value'][ $row['i'] ][ $field_name ]; + + $GLOBALS['acf_field'][] = array( + 'name' => $field_name, + 'value' => $v, + 'field' => $f, + 'i' => -1, + 'post_id' => $post_id, + ); + + } + + + // update vars + $row = end( $GLOBALS['acf_field'] ); + + + if( is_array($row['value']) && array_key_exists( $row['i']+1, $row['value'] ) ) + { + // next row exists + return true; + } + + + // no next row! + reset_rows(); + + + // return + return false; + } @@ -506,23 +506,23 @@ function have_rows( $field_name, $post_id = false ) { */ function the_row() { - - // vars - $depth = count( $GLOBALS['acf_field'] ) - 1; - - - - // increase row - $GLOBALS['acf_field'][ $depth ]['i']++; - - - // get row - $value = $GLOBALS['acf_field'][ $depth ]['value']; - $i = $GLOBALS['acf_field'][ $depth ]['i']; - - - // return - return $value[ $i ]; + + // vars + $depth = count( $GLOBALS['acf_field'] ) - 1; + + + + // increase row + $GLOBALS['acf_field'][ $depth ]['i']++; + + + // get row + $value = $GLOBALS['acf_field'][ $depth ]['value']; + $i = $GLOBALS['acf_field'][ $depth ]['i']; + + + // return + return $value[ $i ]; } @@ -541,31 +541,31 @@ function the_row() { */ function reset_rows( $hard_reset = false ) { - - // completely destroy? - if( $hard_reset ) - { - $GLOBALS['acf_field'] = array(); - } - else - { - // vars - $depth = count( $GLOBALS['acf_field'] ) - 1; - - - // remove - unset( $GLOBALS['acf_field'][$depth] ); - - - // refresh index - $GLOBALS['acf_field'] = array_values($GLOBALS['acf_field']); - } - - - // return - return true; - - + + // completely destroy? + if( $hard_reset ) + { + $GLOBALS['acf_field'] = array(); + } + else + { + // vars + $depth = count( $GLOBALS['acf_field'] ) - 1; + + + // remove + unset( $GLOBALS['acf_field'][$depth] ); + + + // refresh index + $GLOBALS['acf_field'] = array_values($GLOBALS['acf_field']); + } + + + // return + return true; + + } @@ -573,7 +573,7 @@ function reset_rows( $hard_reset = false ) { * has_sub_field() * * This function is used inside a while loop to return either true or false (loop again or stop). -* When using a repeater or flexible content field, it will loop through the rows until +* When using a repeater or flexible content field, it will loop through the rows until * there are none left or a break is detected * * @type function @@ -587,20 +587,20 @@ function reset_rows( $hard_reset = false ) { */ function has_sub_field( $field_name, $post_id = false ) { - - // vars - $r = have_rows( $field_name, $post_id ); - - - // if has rows, progress through 1 row for the while loop to work - if( $r ) - { - the_row(); - } - - - // return - return $r; + + // vars + $r = have_rows( $field_name, $post_id ); + + + // if has rows, progress through 1 row for the while loop to work + if( $r ) + { + the_row(); + } + + + // return + return $r; } @@ -621,7 +621,7 @@ function has_sub_field( $field_name, $post_id = false ) { function has_sub_fields( $field_name, $post_id = false ) { - return has_sub_field( $field_name, $post_id ); + return has_sub_field( $field_name, $post_id ); } @@ -640,27 +640,27 @@ function has_sub_fields( $field_name, $post_id = false ) */ function get_sub_field( $field_name ) { - - // no field? - if( empty($GLOBALS['acf_field']) ) - { - return false; - } - - - // vars - $row = end( $GLOBALS['acf_field'] ); - - - // return value - if( isset($row['value'][ $row['i'] ][ $field_name ]) ) - { - return $row['value'][ $row['i'] ][ $field_name ]; - } - - - // return false - return false; + + // no field? + if( empty($GLOBALS['acf_field']) ) + { + return false; + } + + + // vars + $row = end( $GLOBALS['acf_field'] ); + + + // return value + if( isset($row['value'][ $row['i'] ][ $field_name ]) ) + { + return $row['value'][ $row['i'] ][ $field_name ]; + } + + + // return false + return false; } @@ -680,14 +680,14 @@ function get_sub_field( $field_name ) { function the_sub_field($field_name) { - $value = get_sub_field($field_name); - - if(is_array($value)) - { - $value = implode(', ',$value); - } - - echo $value; + $value = get_sub_field($field_name); + + if(is_array($value)) + { + $value = implode(', ',$value); + } + + echo $value; } @@ -702,26 +702,26 @@ function the_sub_field($field_name) * * @param string $field_name: the name of the field - 'sub_heading' * -* @return array $sub_field +* @return array $sub_field */ function get_sub_field_object( $child_name ) { - // no field? - if( empty($GLOBALS['acf_field']) ) - { - return false; - } + // no field? + if( empty($GLOBALS['acf_field']) ) + { + return false; + } + + // vars + $depth = count( $GLOBALS['acf_field'] ) - 1; + $parent = $GLOBALS['acf_field'][$depth]['field']; - // vars - $depth = count( $GLOBALS['acf_field'] ) - 1; - $parent = $GLOBALS['acf_field'][$depth]['field']; + // return + return acf_get_child_field_from_parent_field( $child_name, $parent ); - // return - return acf_get_child_field_from_parent_field( $child_name, $parent ); - } @@ -737,52 +737,52 @@ function get_sub_field_object( $child_name ) * @param string $child_name: the name of the field - 'sub_heading' * @param array $parent: the parent field object * -* @return array $sub_field +* @return array $sub_field */ function acf_get_child_field_from_parent_field( $child_name, $parent ) { - // vars - $return = false; - - - // find child - if( isset($parent['sub_fields']) && is_array($parent['sub_fields']) ) - { - foreach( $parent['sub_fields'] as $child ) - { - if( $child['name'] == $child_name || $child['key'] == $child_name ) - { - $return = $child; - break; - } - - // perhaps child has grand children? - $grand_child = acf_get_child_field_from_parent_field( $child_name, $child ); - if( $grand_child ) - { - $return = $grand_child; - break; - } - } - } - elseif( isset($parent['layouts']) && is_array($parent['layouts']) ) - { - foreach( $parent['layouts'] as $layout ) - { - $child = acf_get_child_field_from_parent_field( $child_name, $layout ); - if( $child ) - { - $return = $child; - break; - } - } - } - - - // return - return $return; - + // vars + $return = false; + + + // find child + if( isset($parent['sub_fields']) && is_array($parent['sub_fields']) ) + { + foreach( $parent['sub_fields'] as $child ) + { + if( $child['name'] == $child_name || $child['key'] == $child_name ) + { + $return = $child; + break; + } + + // perhaps child has grand children? + $grand_child = acf_get_child_field_from_parent_field( $child_name, $child ); + if( $grand_child ) + { + $return = $grand_child; + break; + } + } + } + elseif( isset($parent['layouts']) && is_array($parent['layouts']) ) + { + foreach( $parent['layouts'] as $layout ) + { + $child = acf_get_child_field_from_parent_field( $child_name, $layout ); + if( $child ) + { + $return = $child; + break; + } + } + } + + + // return + return $return; + } @@ -805,124 +805,124 @@ function acf_get_child_field_from_parent_field( $child_name, $parent ) function register_field_group( $array ) { - // add id - if( !isset($array['id']) ) - { - $array['id'] = uniqid(); - } - - - // 3.2.5 - changed show_on_page option - if( !isset($array['options']['hide_on_screen']) && isset($array['options']['show_on_page']) ) - { - $show_all = array('the_content', 'discussion', 'custom_fields', 'comments', 'slug', 'author'); - $array['options']['hide_on_screen'] = array_diff($show_all, $array['options']['show_on_page']); - unset( $array['options']['show_on_page'] ); - } - - - // 4.0.4 - changed location rules architecture - if( isset($array['location']['rules']) ) - { - // vars - $groups = array(); - $group_no = 0; - - - if( is_array($array['location']['rules']) ) - { - foreach( $array['location']['rules'] as $rule ) - { - $rule['group_no'] = $group_no; - - // sperate groups? - if( $array['location']['allorany'] == 'any' ) - { - $group_no++; - } - - - // add to group - $groups[ $rule['group_no'] ][ $rule['order_no'] ] = $rule; - - - // sort rules - ksort( $groups[ $rule['group_no'] ] ); - - } - - // sort groups - ksort( $groups ); - } - - $array['location'] = $groups; - } - - - $GLOBALS['acf_register_field_group'][] = $array; + // add id + if( !isset($array['id']) ) + { + $array['id'] = uniqid(); + } + + + // 3.2.5 - changed show_on_page option + if( !isset($array['options']['hide_on_screen']) && isset($array['options']['show_on_page']) ) + { + $show_all = array('the_content', 'discussion', 'custom_fields', 'comments', 'slug', 'author'); + $array['options']['hide_on_screen'] = array_diff($show_all, $array['options']['show_on_page']); + unset( $array['options']['show_on_page'] ); + } + + + // 4.0.4 - changed location rules architecture + if( isset($array['location']['rules']) ) + { + // vars + $groups = array(); + $group_no = 0; + + + if( is_array($array['location']['rules']) ) + { + foreach( $array['location']['rules'] as $rule ) + { + $rule['group_no'] = $group_no; + + // sperate groups? + if( $array['location']['allorany'] == 'any' ) + { + $group_no++; + } + + + // add to group + $groups[ $rule['group_no'] ][ $rule['order_no'] ] = $rule; + + + // sort rules + ksort( $groups[ $rule['group_no'] ] ); + + } + + // sort groups + ksort( $groups ); + } + + $array['location'] = $groups; + } + + + $GLOBALS['acf_register_field_group'][] = $array; } add_filter('acf/get_field_groups', 'api_acf_get_field_groups', 2, 1); function api_acf_get_field_groups( $return ) { - // validate - if( empty($GLOBALS['acf_register_field_group']) ) - { - return $return; - } - - - foreach( $GLOBALS['acf_register_field_group'] as $acf ) - { - $return[] = array( - 'id' => $acf['id'], - 'title' => $acf['title'], - 'menu_order' => $acf['menu_order'], - ); - } - - - // order field groups based on menu_order, title - // Obtain a list of columns - foreach( $return as $key => $row ) - { - $menu_order[ $key ] = $row['menu_order']; - $title[ $key ] = $row['title']; - } - - // Sort the array with menu_order ascending - // Add $array as the last parameter, to sort by the common key - if(isset($menu_order)) - { - array_multisort($menu_order, SORT_ASC, $title, SORT_ASC, $return); - } - - return $return; + // validate + if( empty($GLOBALS['acf_register_field_group']) ) + { + return $return; + } + + + foreach( $GLOBALS['acf_register_field_group'] as $acf ) + { + $return[] = array( + 'id' => $acf['id'], + 'title' => $acf['title'], + 'menu_order' => $acf['menu_order'], + ); + } + + + // order field groups based on menu_order, title + // Obtain a list of columns + foreach( $return as $key => $row ) + { + $menu_order[ $key ] = $row['menu_order']; + $title[ $key ] = $row['title']; + } + + // Sort the array with menu_order ascending + // Add $array as the last parameter, to sort by the common key + if(isset($menu_order)) + { + array_multisort($menu_order, SORT_ASC, $title, SORT_ASC, $return); + } + + return $return; } add_filter('acf/field_group/get_fields', 'api_acf_field_group_get_fields', 1, 2); function api_acf_field_group_get_fields( $fields, $post_id ) { - // validate - if( !empty($GLOBALS['acf_register_field_group']) ) - { - foreach( $GLOBALS['acf_register_field_group'] as $acf ) - { - if( $acf['id'] == $post_id ) - { - foreach( $acf['fields'] as $f ) - { - $fields[] = apply_filters('acf/load_field', $f, $f['key']); - } - - break; - } - } - } - - return $fields; + // validate + if( !empty($GLOBALS['acf_register_field_group']) ) + { + foreach( $GLOBALS['acf_register_field_group'] as $acf ) + { + if( $acf['id'] == $post_id ) + { + foreach( $acf['fields'] as $f ) + { + $fields[] = apply_filters('acf/load_field', $f, $f['key']); + } + + break; + } + } + } + + return $fields; } @@ -930,46 +930,46 @@ function api_acf_field_group_get_fields( $fields, $post_id ) add_filter('acf/load_field', 'api_acf_load_field', 1, 2); function api_acf_load_field( $field, $field_key ) { - // validate - if( !empty($GLOBALS['acf_register_field_group']) ) - { - foreach( $GLOBALS['acf_register_field_group'] as $acf ) - { - if( !empty($acf['fields']) ) - { - foreach( $acf['fields'] as $f ) - { - if( $f['key'] == $field_key ) - { - $field = $f; - break; - } - } - } - } - } - - return $field; + // validate + if( !empty($GLOBALS['acf_register_field_group']) ) + { + foreach( $GLOBALS['acf_register_field_group'] as $acf ) + { + if( !empty($acf['fields']) ) + { + foreach( $acf['fields'] as $f ) + { + if( $f['key'] == $field_key ) + { + $field = $f; + break; + } + } + } + } + } + + return $field; } add_filter('acf/field_group/get_location', 'api_acf_field_group_get_location', 1, 2); function api_acf_field_group_get_location( $location, $post_id ) { - // validate - if( !empty($GLOBALS['acf_register_field_group']) ) - { - foreach( $GLOBALS['acf_register_field_group'] as $acf ) - { - if( $acf['id'] == $post_id ) - { - $location = $acf['location']; - break; - } - } - } - - return $location; + // validate + if( !empty($GLOBALS['acf_register_field_group']) ) + { + foreach( $GLOBALS['acf_register_field_group'] as $acf ) + { + if( $acf['id'] == $post_id ) + { + $location = $acf['location']; + break; + } + } + } + + return $location; } @@ -977,20 +977,20 @@ function api_acf_field_group_get_location( $location, $post_id ) add_filter('acf/field_group/get_options', 'api_acf_field_group_get_options', 1, 2); function api_acf_field_group_get_options( $options, $post_id ) { - // validate - if( !empty($GLOBALS['acf_register_field_group']) ) - { - foreach( $GLOBALS['acf_register_field_group'] as $acf ) - { - if( $acf['id'] == $post_id ) - { - $options = $acf['options']; - break; - } - } - } - - return $options; + // validate + if( !empty($GLOBALS['acf_register_field_group']) ) + { + foreach( $GLOBALS['acf_register_field_group'] as $acf ) + { + if( $acf['id'] == $post_id ) + { + $options = $acf['options']; + break; + } + } + } + + return $options; } @@ -1008,11 +1008,11 @@ function api_acf_field_group_get_options( $options, $post_id ) function get_row_layout() { - // vars - $value = get_sub_field('acf_fc_layout'); - - - return $value; + // vars + $value = get_sub_field('acf_fc_layout'); + + + return $value; } @@ -1034,30 +1034,30 @@ function get_row_layout() function acf_shortcode( $atts ) { - // extract attributs - extract( shortcode_atts( array( - 'field' => "", - 'post_id' => false, - ), $atts ) ); - - - // $field is requird - if( !$field || $field == "" ) - { - return ""; - } - - - // get value and return it - $value = get_field( $field, $post_id ); - - - if( is_array($value) ) - { - $value = @implode( ', ',$value ); - } - - return $value; + // extract attributs + extract( shortcode_atts( array( + 'field' => "", + 'post_id' => false, + ), $atts ) ); + + + // $field is requird + if( !$field || $field == "" ) + { + return ""; + } + + + // get value and return it + $value = acf_get_field( $field, $post_id ); + + + if( is_array($value) ) + { + $value = @implode( ', ',$value ); + } + + return $value; } add_shortcode( 'acf', 'acf_shortcode' ); @@ -1078,50 +1078,50 @@ function acf_shortcode( $atts ) function acf_form_head() { - // global vars - global $post_id; - - - // verify nonce - if( isset($_POST['acf_nonce']) && wp_verify_nonce($_POST['acf_nonce'], 'input') ) - { - // $post_id to save against - $post_id = $_POST['post_id']; - - - // allow for custom save - $post_id = apply_filters('acf/pre_save_post', $post_id); - - - // save the data - do_action('acf/save_post', $post_id); - - - // redirect - if(isset($_POST['return'])) - { - wp_redirect($_POST['return']); - exit; - } - } - - - // need wp styling - wp_enqueue_style(array( - 'colors-fresh' - )); - - - // actions - do_action('acf/input/admin_enqueue_scripts'); - - add_action('wp_head', 'acf_form_wp_head'); - + // global vars + global $post_id; + + + // verify nonce + if( isset($_POST['acf_nonce']) && wp_verify_nonce($_POST['acf_nonce'], 'input') ) + { + // $post_id to save against + $post_id = $_POST['post_id']; + + + // allow for custom save + $post_id = apply_filters('acf/pre_save_post', $post_id); + + + // save the data + do_action('acf/save_post', $post_id); + + + // redirect + if(isset($_POST['return'])) + { + wp_redirect($_POST['return']); + exit; + } + } + + + // need wp styling + wp_enqueue_style(array( + 'colors-fresh' + )); + + + // actions + do_action('acf/input/admin_enqueue_scripts'); + + add_action('wp_head', 'acf_form_wp_head'); + } function acf_form_wp_head() { - do_action('acf/input/admin_head'); + do_action('acf/input/admin_head'); } @@ -1136,7 +1136,7 @@ function acf_form_wp_head() * * @param array $options: an array containing many options to customize the form * string + post_id: post id to get field groups from and save data to. Default is false -* array + field_groups: an array containing field group ID's. If this option is set, +* array + field_groups: an array containing field group ID's. If this option is set, * the post_id will not be used to dynamically find the field groups * boolean + form: display the form tag or not. Defaults to true * array + form_attributes: an array containg attributes which will be added into the form tag @@ -1144,165 +1144,165 @@ function acf_form_wp_head() * string + html_before_fields: html inside form before fields * string + html_after_fields: html inside form after fields * string + submit_value: value of submit button -* string + updated_message: default updated message. Can be false +* string + updated_message: default updated message. Can be false * * @return N/A */ function acf_form( $options = array() ) { - global $post; - - - // defaults - $defaults = array( - 'post_id' => false, - 'field_groups' => array(), - 'form' => true, - 'form_attributes' => array( - 'id' => 'post', - 'class' => '', - 'action' => '', - 'method' => 'post', - ), - 'return' => add_query_arg( 'updated', 'true', get_permalink() ), - 'html_before_fields' => '', - 'html_after_fields' => '', - 'submit_value' => __("Update", 'acf'), - 'updated_message' => __("Post updated", 'acf'), - ); - - - // merge defaults with options - $options = array_merge($defaults, $options); - - - // merge sub arrays - foreach( $options as $k => $v ) - { - if( is_array($v) ) - { - $options[ $k ] = array_merge($defaults[ $k ], $options[ $k ]); - } - } - - - // filter post_id - $options['post_id'] = apply_filters('acf/get_post_id', $options['post_id'] ); - - - // attributes - $options['form_attributes']['class'] .= 'acf-form'; - - - - // register post box - if( empty($options['field_groups']) ) - { - // get field groups - $filter = array( - 'post_id' => $options['post_id'] - ); - - - if( strpos($options['post_id'], 'user_') !== false ) - { - $user_id = str_replace('user_', '', $options['post_id']); - $filter = array( - 'ef_user' => $user_id - ); - } - elseif( strpos($options['post_id'], 'taxonomy_') !== false ) - { - $taxonomy_id = str_replace('taxonomy_', '', $options['post_id']); - $filter = array( - 'ef_taxonomy' => $taxonomy_id - ); - } - - - $options['field_groups'] = array(); - $options['field_groups'] = apply_filters( 'acf/location/match_field_groups', $options['field_groups'], $filter ); - } - - - // updated message - if(isset($_GET['updated']) && $_GET['updated'] == 'true' && $options['updated_message']) - { - echo '

' . $options['updated_message'] . '

'; - } - - - // display form - if( $options['form'] ): ?> -
$v){echo $k . '="' . $v .'" '; }} ?>> - - -
- - - - - -
- -
- '; - echo '

' . $acf['title'] . '

'; - echo '
'; - - do_action('acf/create_fields', $fields, $options['post_id']); - - echo '
'; - - }} - - - // html after fields - echo $options['html_after_fields']; - - ?> - - - -
- -
- - - - - - -
- false, + 'field_groups' => array(), + 'form' => true, + 'form_attributes' => array( + 'id' => 'post', + 'class' => '', + 'action' => '', + 'method' => 'post', + ), + 'return' => add_query_arg( 'updated', 'true', get_permalink() ), + 'html_before_fields' => '', + 'html_after_fields' => '', + 'submit_value' => __("Update", 'acf'), + 'updated_message' => __("Post updated", 'acf'), + ); + + + // merge defaults with options + $options = array_merge($defaults, $options); + + + // merge sub arrays + foreach( $options as $k => $v ) + { + if( is_array($v) ) + { + $options[ $k ] = array_merge($defaults[ $k ], $options[ $k ]); + } + } + + + // filter post_id + $options['post_id'] = apply_filters('acf/get_post_id', $options['post_id'] ); + + + // attributes + $options['form_attributes']['class'] .= 'acf-form'; + + + + // register post box + if( empty($options['field_groups']) ) + { + // get field groups + $filter = array( + 'post_id' => $options['post_id'] + ); + + + if( strpos($options['post_id'], 'user_') !== false ) + { + $user_id = str_replace('user_', '', $options['post_id']); + $filter = array( + 'ef_user' => $user_id + ); + } + elseif( strpos($options['post_id'], 'taxonomy_') !== false ) + { + $taxonomy_id = str_replace('taxonomy_', '', $options['post_id']); + $filter = array( + 'ef_taxonomy' => $taxonomy_id + ); + } + + + $options['field_groups'] = array(); + $options['field_groups'] = apply_filters( 'acf/location/match_field_groups', $options['field_groups'], $filter ); + } + + + // updated message + if(isset($_GET['updated']) && $_GET['updated'] == 'true' && $options['updated_message']) + { + echo '

' . $options['updated_message'] . '

'; + } + + + // display form + if( $options['form'] ): ?> +
$v){echo $k . '="' . $v .'" '; }} ?>> + + +
+ + + + + +
+ +
+ '; + echo '

' . $acf['title'] . '

'; + echo '
'; + + do_action('acf/create_fields', $fields, $options['post_id']); + + echo '
'; + + }} + + + // html after fields + echo $options['html_after_fields']; + + ?> + + + +
+ +
+ + + + + + +
+ false, - 'format_value' => false - ); - - $field = get_field_object( $field_key, $post_id, $options); - - - // sub fields? They need formatted data - if( $field['type'] == 'repeater' ) - { - $value = acf_convert_field_names_to_keys( $value, $field ); - } - elseif( $field['type'] == 'flexible_content' ) - { - if( $field['layouts'] ) - { - foreach( $field['layouts'] as $layout ) - { - $value = acf_convert_field_names_to_keys( $value, $layout ); - } - } - } - - - // save - do_action('acf/update_value', $value, $post_id, $field ); - - - return true; - + // filter post_id + $post_id = apply_filters('acf/get_post_id', $post_id ); + + + // vars + $options = array( + 'load_value' => false, + 'format_value' => false + ); + + $field = get_field_object( $field_key, $post_id, $options); + + + // sub fields? They need formatted data + if( $field['type'] == 'repeater' ) + { + $value = acf_convert_field_names_to_keys( $value, $field ); + } + elseif( $field['type'] == 'flexible_content' ) + { + if( $field['layouts'] ) + { + foreach( $field['layouts'] as $layout ) + { + $value = acf_convert_field_names_to_keys( $value, $layout ); + } + } + } + + + // save + do_action('acf/update_value', $value, $post_id, $field ); + + + return true; + } @@ -1380,7 +1380,7 @@ function update_field( $field_key, $value, $post_id = false ) function delete_field( $field_name, $post_id ) { - do_action('acf/delete_value', $post_id, $field_name ); + do_action('acf/delete_value', $post_id, $field_name ); } @@ -1400,7 +1400,7 @@ function delete_field( $field_name, $post_id ) function create_field( $field ) { - do_action('acf/create_field', $field ); + do_action('acf/create_field', $field ); } @@ -1421,64 +1421,64 @@ function create_field( $field ) function acf_convert_field_names_to_keys( $value, $field ) { - // only if $field has sub fields - if( !isset($field['sub_fields']) ) - { - return $value; - } - - - // define sub field keys - $sub_fields = array(); - if( $field['sub_fields'] ) - { - foreach( $field['sub_fields'] as $sub_field ) - { - $sub_fields[ $sub_field['name'] ] = $sub_field; - } - } - - - // loop through the values and format the array to use sub field keys - if( is_array($value) ) - { - foreach( $value as $row_i => $row) - { - if( $row ) - { - foreach( $row as $sub_field_name => $sub_field_value ) - { - // sub field must exist! - if( !isset($sub_fields[ $sub_field_name ]) ) - { - continue; - } - - - // vars - $sub_field = $sub_fields[ $sub_field_name ]; - $sub_field_value = acf_convert_field_names_to_keys( $sub_field_value, $sub_field ); - - - // set new value - $value[$row_i][ $sub_field['key'] ] = $sub_field_value; - - - // unset old value - unset( $value[$row_i][$sub_field_name] ); - - - } - // foreach( $row as $sub_field_name => $sub_field_value ) - } - // if( $row ) - } - // foreach( $value as $row_i => $row) - } - // if( $value ) - - - return $value; + // only if $field has sub fields + if( !isset($field['sub_fields']) ) + { + return $value; + } + + + // define sub field keys + $sub_fields = array(); + if( $field['sub_fields'] ) + { + foreach( $field['sub_fields'] as $sub_field ) + { + $sub_fields[ $sub_field['name'] ] = $sub_field; + } + } + + + // loop through the values and format the array to use sub field keys + if( is_array($value) ) + { + foreach( $value as $row_i => $row) + { + if( $row ) + { + foreach( $row as $sub_field_name => $sub_field_value ) + { + // sub field must exist! + if( !isset($sub_fields[ $sub_field_name ]) ) + { + continue; + } + + + // vars + $sub_field = $sub_fields[ $sub_field_name ]; + $sub_field_value = acf_convert_field_names_to_keys( $sub_field_value, $sub_field ); + + + // set new value + $value[$row_i][ $sub_field['key'] ] = $sub_field_value; + + + // unset old value + unset( $value[$row_i][$sub_field_name] ); + + + } + // foreach( $row as $sub_field_name => $sub_field_value ) + } + // if( $row ) + } + // foreach( $value as $row_i => $row) + } + // if( $value ) + + + return $value; } @@ -1487,7 +1487,7 @@ function acf_convert_field_names_to_keys( $value, $field ) /* * Depreceated Functions * -* @description: +* @description: * @created: 23/07/12 */ @@ -1499,12 +1499,12 @@ function acf_convert_field_names_to_keys( $value, $field ) * @author Elliot Condon * @depreciated: 3.3.4 - now use has_sub_field * @since 1.0.3 -* +* *-------------------------------------------------------------------------------------*/ function reset_the_repeater_field() { - // do nothing + // do nothing } @@ -1515,12 +1515,12 @@ function reset_the_repeater_field() * @author Elliot Condon * @depreciated: 3.3.4 - now use has_sub_field * @since 1.0.3 -* +* *-------------------------------------------------------------------------------------*/ function the_repeater_field($field_name, $post_id = false) { - return has_sub_field($field_name, $post_id); + return has_sub_field($field_name, $post_id); } @@ -1531,12 +1531,12 @@ function the_repeater_field($field_name, $post_id = false) * @author Elliot Condon * @depreciated: 3.3.4 - now use has_sub_field * @since 3.?.? -* +* *-------------------------------------------------------------------------------------*/ function the_flexible_field($field_name, $post_id = false) { - return has_sub_field($field_name, $post_id); + return has_sub_field($field_name, $post_id); } /* @@ -1555,7 +1555,7 @@ function the_flexible_field($field_name, $post_id = false) function acf_filter_post_id( $post_id ) { - return apply_filters('acf/get_post_id', $post_id ); + return apply_filters('acf/get_post_id', $post_id ); } -?> \ No newline at end of file +?> From 7c65b34616e978d8bff5883736c9520be05a706b Mon Sep 17 00:00:00 2001 From: Huy Eng Heng Date: Tue, 10 Feb 2015 22:30:45 +0700 Subject: [PATCH 02/11] Rename get_field by adding prefix acf_ --- includes/acf/acf.php | 2 +- .../add-ons/acf-website-field/website_url.php | 2 +- includes/acf/core/api.php | 1986 ++++++++--------- .../core/controllers/everything_fields.php | 8 +- includes/acf/core/controllers/export.php | 2 +- includes/acf/core/controllers/field_group.php | 12 +- includes/acf/core/controllers/location.php | 2 +- includes/acf/core/controllers/post.php | 12 +- includes/acf/core/controllers/revisions.php | 4 +- includes/acf/core/controllers/third_party.php | 2 +- includes/acf/core/controllers/upgrade.php | 2 +- includes/acf/core/views/meta_box_fields.php | 2 +- includes/acf/readme.txt | 34 +- wp-feature-box.php | 6 +- 14 files changed, 1038 insertions(+), 1038 deletions(-) diff --git a/includes/acf/acf.php b/includes/acf/acf.php index 59278cc..424a12a 100755 --- a/includes/acf/acf.php +++ b/includes/acf/acf.php @@ -202,7 +202,7 @@ function get_post_id( $post_id ) * Override for preview * * If the $_GET['preview_id'] is set, then the user wants to see the preview data. - * There is also the case of previewing a page with post_id = 1, but using get_field + * There is also the case of previewing a page with post_id = 1, but using acf_get_field * to load data from another post_id. * In this case, we need to make sure that the autosave revision is actually related * to the $post_id variable. If they match, then the autosave data will be used, otherwise, diff --git a/includes/acf/add-ons/acf-website-field/website_url.php b/includes/acf/add-ons/acf-website-field/website_url.php index fd669d0..4e51c5c 100644 --- a/includes/acf/add-ons/acf-website-field/website_url.php +++ b/includes/acf/add-ons/acf-website-field/website_url.php @@ -269,7 +269,7 @@ function create_options($field) -

If "Yes" than the get_field will return an array

+

If "Yes" than the acf_get_field will return an array

get_col($wpdb->prepare( - "SELECT meta_value FROM $wpdb->postmeta WHERE post_id = %d and meta_key LIKE %s AND meta_value LIKE %s", - $post_id, - '_%', - 'field_%' - )); - } - elseif( strpos($post_id, 'user_') !== false ) - { - $user_id = str_replace('user_', '', $post_id); - - $keys = $wpdb->get_col($wpdb->prepare( - "SELECT meta_value FROM $wpdb->usermeta WHERE user_id = %d and meta_key LIKE %s AND meta_value LIKE %s", - $user_id, - '_%', - 'field_%' - )); - } - else - { - $keys = $wpdb->get_col($wpdb->prepare( - "SELECT option_value FROM $wpdb->options WHERE option_name LIKE %s", - '_' . $post_id . '_%' - )); - } - - - if( is_array($keys) ) - { - foreach( $keys as $key ) - { - $field = get_field_object( $key, $post_id, $options ); - - if( !is_array($field) ) - { - continue; - } - - $value[ $field['name'] ] = $field; - } - } - - - // no value - if( empty($value) ) - { - return false; - } - - - // return - return $value; +function acf_get_field_objects( $post_id = false, $options = array() ) { + + // global + global $wpdb; + + + // filter post_id + $post_id = apply_filters('acf/get_post_id', $post_id ); + + + // vars + $field_key = ''; + $value = array(); + + + // get field_names + if( is_numeric($post_id) ) + { + $keys = $wpdb->get_col($wpdb->prepare( + "SELECT meta_value FROM $wpdb->postmeta WHERE post_id = %d and meta_key LIKE %s AND meta_value LIKE %s", + $post_id, + '_%', + 'field_%' + )); + } + elseif( strpos($post_id, 'user_') !== false ) + { + $user_id = str_replace('user_', '', $post_id); + + $keys = $wpdb->get_col($wpdb->prepare( + "SELECT meta_value FROM $wpdb->usermeta WHERE user_id = %d and meta_key LIKE %s AND meta_value LIKE %s", + $user_id, + '_%', + 'field_%' + )); + } + else + { + $keys = $wpdb->get_col($wpdb->prepare( + "SELECT option_value FROM $wpdb->options WHERE option_name LIKE %s", + '_' . $post_id . '_%' + )); + } + + + if( is_array($keys) ) + { + foreach( $keys as $key ) + { + $field = acf_get_field_object( $key, $post_id, $options ); + + if( !is_array($field) ) + { + continue; + } + + $value[ $field['name'] ] = $field; + } + } + + + // no value + if( empty($value) ) + { + return false; + } + + + // return + return $value; } /* -* get_fields() +* acf_get_fields() * * This function will return an array containing all the custom field values for a specific post_id. * The function is not very elegant and wastes a lot of PHP memory / SQL queries if you are not using all the values. @@ -160,34 +160,34 @@ function get_field_objects( $post_id = false, $options = array() ) { * @return array $return: an array containin the field values */ -function get_fields( $post_id = false, $format_value = true ) { - - // vars - $options = array( - 'load_value' => true, - 'format_value' => $format_value - ); - - - $fields = get_field_objects( $post_id, $options ); - - if( is_array($fields) ) - { - foreach( $fields as $k => $field ) - { - $fields[ $k ] = $field['value']; - } - } - - return $fields; +function acf_get_fields( $post_id = false, $format_value = true ) { + + // vars + $options = array( + 'load_value' => true, + 'format_value' => $format_value + ); + + + $fields = acf_get_field_objects( $post_id, $options ); + + if( is_array($fields) ) + { + foreach( $fields as $k => $field ) + { + $fields[ $k ] = $field['value']; + } + } + + return $fields; } /* -* get_field() +* acf_get_field() * * This function will return a custom field value for a specific field name/key + post_id. -* There is a 3rd parameter to turn on/off formating. This means that an Image field will not use +* There is a 3rd parameter to turn on/off formating. This means that an Image field will not use * its 'return option' to format the value but return only what was saved in the database * * @type function @@ -200,33 +200,33 @@ function get_fields( $post_id = false, $format_value = true ) { * * @return mixed $value: the value found */ - + function acf_get_field( $field_key, $post_id = false, $format_value = true ) { - - // vars - $return = false; - $options = array( - 'load_value' => true, - 'format_value' => $format_value - ); - - - $field = get_field_object( $field_key, $post_id, $options); - - - if( is_array($field) ) - { - $return = $field['value']; - } - - - return $return; - + + // vars + $return = false; + $options = array( + 'load_value' => true, + 'format_value' => $format_value + ); + + + $field = acf_get_field_object( $field_key, $post_id, $options); + + + if( is_array($field) ) + { + $return = $field['value']; + } + + + return $return; + } /* -* get_field_object() +* acf_get_field_object() * * This function will return an array containing all the field data for a given field_name * @@ -243,70 +243,70 @@ function acf_get_field( $field_key, $post_id = false, $format_value = true ) { * @return array $return: an array containin the field groups */ -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; +function acf_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 = acf_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; } @@ -314,7 +314,7 @@ function get_field_object( $field_key, $post_id = false, $options = array() ) { /* * the_field() * -* This function is the same as echo get_field(). +* This function is the same as echo acf_get_field(). * * @type function * @since 1.0.3 @@ -327,15 +327,15 @@ function get_field_object( $field_key, $post_id = false, $options = array() ) { */ function the_field( $field_name, $post_id = false ) { - - $value = acf_get_field($field_name, $post_id); - - if( is_array($value) ) - { - $value = @implode(', ',$value); - } - - echo $value; + + $value = acf_get_field($field_name, $post_id); + + if( is_array($value) ) + { + $value = @implode(', ',$value); + } + + echo $value; } @@ -354,141 +354,141 @@ function the_field( $field_name, $post_id = false ) { */ function have_rows( $field_name, $post_id = false ) { - - // vars - $depth = 0; - $row = array(); - $new_parent_loop = false; - $new_child_loop = false; - - - // reference - $_post_id = $post_id; - - - // filter post_id - $post_id = apply_filters('acf/get_post_id', $post_id ); - - - // empty? - if( empty($GLOBALS['acf_field']) ) - { - // reset - reset_rows( true ); - - - // create a new loop - $new_parent_loop = true; - } - else - { - // vars - $row = end( $GLOBALS['acf_field'] ); - $prev = prev( $GLOBALS['acf_field'] ); - - - // If post_id has changed, this is most likely an archive loop - if( $post_id != $row['post_id'] ) - { - if( $prev && $prev['post_id'] == $post_id ) - { - // case: Change in $post_id was due to a nested loop ending - // action: move up one level through the loops - reset_rows(); - } - elseif( empty($_post_id) && isset($row['value'][ $row['i'] ][ $field_name ]) ) - { - // case: Change in $post_id was due to this being a nested loop and not specifying the $post_id - // action: move down one level into a new loop - $new_child_loop = true; - } - else - { - // case: Chang in $post_id is the most obvious, used in an WP_Query loop with multiple $post objects - // action: leave this current loop alone and create a new parent loop - $new_parent_loop = true; - } - } - elseif( $field_name != $row['name'] ) - { - if( $prev && $prev['name'] == $field_name && $prev['post_id'] == $post_id ) - { - // case: Change in $field_name was due to a nested loop ending - // action: move up one level through the loops - reset_rows(); - } - elseif( isset($row['value'][ $row['i'] ][ $field_name ]) ) - { - // case: Change in $field_name was due to this being a nested loop - // action: move down one level into a new loop - $new_child_loop = true; - - } - else - { - // case: Chang in $field_name is the most obvious, this is a new loop for a different field within the $post - // action: leave this current loop alone and create a new parent loop - $new_parent_loop = true; - } - - - } - } - - - if( $new_parent_loop ) - { - // vars - $f = get_field_object( $field_name, $post_id ); - $v = $f['value']; - unset( $f['value'] ); - - - // add row - $GLOBALS['acf_field'][] = array( - 'name' => $field_name, - 'value' => $v, - 'field' => $f, - 'i' => -1, - 'post_id' => $post_id, - ); - - } - elseif( $new_child_loop ) - { - // vars - $f = acf_get_child_field_from_parent_field( $field_name, $row['field'] ); - $v = $row['value'][ $row['i'] ][ $field_name ]; - - $GLOBALS['acf_field'][] = array( - 'name' => $field_name, - 'value' => $v, - 'field' => $f, - 'i' => -1, - 'post_id' => $post_id, - ); - - } - - - // update vars - $row = end( $GLOBALS['acf_field'] ); - - - if( is_array($row['value']) && array_key_exists( $row['i']+1, $row['value'] ) ) - { - // next row exists - return true; - } - - - // no next row! - reset_rows(); - - - // return - return false; - + + // vars + $depth = 0; + $row = array(); + $new_parent_loop = false; + $new_child_loop = false; + + + // reference + $_post_id = $post_id; + + + // filter post_id + $post_id = apply_filters('acf/get_post_id', $post_id ); + + + // empty? + if( empty($GLOBALS['acf_field']) ) + { + // reset + reset_rows( true ); + + + // create a new loop + $new_parent_loop = true; + } + else + { + // vars + $row = end( $GLOBALS['acf_field'] ); + $prev = prev( $GLOBALS['acf_field'] ); + + + // If post_id has changed, this is most likely an archive loop + if( $post_id != $row['post_id'] ) + { + if( $prev && $prev['post_id'] == $post_id ) + { + // case: Change in $post_id was due to a nested loop ending + // action: move up one level through the loops + reset_rows(); + } + elseif( empty($_post_id) && isset($row['value'][ $row['i'] ][ $field_name ]) ) + { + // case: Change in $post_id was due to this being a nested loop and not specifying the $post_id + // action: move down one level into a new loop + $new_child_loop = true; + } + else + { + // case: Chang in $post_id is the most obvious, used in an WP_Query loop with multiple $post objects + // action: leave this current loop alone and create a new parent loop + $new_parent_loop = true; + } + } + elseif( $field_name != $row['name'] ) + { + if( $prev && $prev['name'] == $field_name && $prev['post_id'] == $post_id ) + { + // case: Change in $field_name was due to a nested loop ending + // action: move up one level through the loops + reset_rows(); + } + elseif( isset($row['value'][ $row['i'] ][ $field_name ]) ) + { + // case: Change in $field_name was due to this being a nested loop + // action: move down one level into a new loop + $new_child_loop = true; + + } + else + { + // case: Chang in $field_name is the most obvious, this is a new loop for a different field within the $post + // action: leave this current loop alone and create a new parent loop + $new_parent_loop = true; + } + + + } + } + + + if( $new_parent_loop ) + { + // vars + $f = acf_get_field_object( $field_name, $post_id ); + $v = $f['value']; + unset( $f['value'] ); + + + // add row + $GLOBALS['acf_field'][] = array( + 'name' => $field_name, + 'value' => $v, + 'field' => $f, + 'i' => -1, + 'post_id' => $post_id, + ); + + } + elseif( $new_child_loop ) + { + // vars + $f = acf_get_child_field_from_parent_field( $field_name, $row['field'] ); + $v = $row['value'][ $row['i'] ][ $field_name ]; + + $GLOBALS['acf_field'][] = array( + 'name' => $field_name, + 'value' => $v, + 'field' => $f, + 'i' => -1, + 'post_id' => $post_id, + ); + + } + + + // update vars + $row = end( $GLOBALS['acf_field'] ); + + + if( is_array($row['value']) && array_key_exists( $row['i']+1, $row['value'] ) ) + { + // next row exists + return true; + } + + + // no next row! + reset_rows(); + + + // return + return false; + } @@ -506,23 +506,23 @@ function have_rows( $field_name, $post_id = false ) { */ function the_row() { - - // vars - $depth = count( $GLOBALS['acf_field'] ) - 1; - - - - // increase row - $GLOBALS['acf_field'][ $depth ]['i']++; - - - // get row - $value = $GLOBALS['acf_field'][ $depth ]['value']; - $i = $GLOBALS['acf_field'][ $depth ]['i']; - - - // return - return $value[ $i ]; + + // vars + $depth = count( $GLOBALS['acf_field'] ) - 1; + + + + // increase row + $GLOBALS['acf_field'][ $depth ]['i']++; + + + // get row + $value = $GLOBALS['acf_field'][ $depth ]['value']; + $i = $GLOBALS['acf_field'][ $depth ]['i']; + + + // return + return $value[ $i ]; } @@ -541,31 +541,31 @@ function the_row() { */ function reset_rows( $hard_reset = false ) { - - // completely destroy? - if( $hard_reset ) - { - $GLOBALS['acf_field'] = array(); - } - else - { - // vars - $depth = count( $GLOBALS['acf_field'] ) - 1; - - - // remove - unset( $GLOBALS['acf_field'][$depth] ); - - - // refresh index - $GLOBALS['acf_field'] = array_values($GLOBALS['acf_field']); - } - - - // return - return true; - - + + // completely destroy? + if( $hard_reset ) + { + $GLOBALS['acf_field'] = array(); + } + else + { + // vars + $depth = count( $GLOBALS['acf_field'] ) - 1; + + + // remove + unset( $GLOBALS['acf_field'][$depth] ); + + + // refresh index + $GLOBALS['acf_field'] = array_values($GLOBALS['acf_field']); + } + + + // return + return true; + + } @@ -573,7 +573,7 @@ function reset_rows( $hard_reset = false ) { * has_sub_field() * * This function is used inside a while loop to return either true or false (loop again or stop). -* When using a repeater or flexible content field, it will loop through the rows until +* When using a repeater or flexible content field, it will loop through the rows until * there are none left or a break is detected * * @type function @@ -587,20 +587,20 @@ function reset_rows( $hard_reset = false ) { */ function has_sub_field( $field_name, $post_id = false ) { - - // vars - $r = have_rows( $field_name, $post_id ); - - - // if has rows, progress through 1 row for the while loop to work - if( $r ) - { - the_row(); - } - - - // return - return $r; + + // vars + $r = have_rows( $field_name, $post_id ); + + + // if has rows, progress through 1 row for the while loop to work + if( $r ) + { + the_row(); + } + + + // return + return $r; } @@ -621,7 +621,7 @@ function has_sub_field( $field_name, $post_id = false ) { function has_sub_fields( $field_name, $post_id = false ) { - return has_sub_field( $field_name, $post_id ); + return has_sub_field( $field_name, $post_id ); } @@ -640,27 +640,27 @@ function has_sub_fields( $field_name, $post_id = false ) */ function get_sub_field( $field_name ) { - - // no field? - if( empty($GLOBALS['acf_field']) ) - { - return false; - } - - - // vars - $row = end( $GLOBALS['acf_field'] ); - - - // return value - if( isset($row['value'][ $row['i'] ][ $field_name ]) ) - { - return $row['value'][ $row['i'] ][ $field_name ]; - } - - - // return false - return false; + + // no field? + if( empty($GLOBALS['acf_field']) ) + { + return false; + } + + + // vars + $row = end( $GLOBALS['acf_field'] ); + + + // return value + if( isset($row['value'][ $row['i'] ][ $field_name ]) ) + { + return $row['value'][ $row['i'] ][ $field_name ]; + } + + + // return false + return false; } @@ -680,14 +680,14 @@ function get_sub_field( $field_name ) { function the_sub_field($field_name) { - $value = get_sub_field($field_name); - - if(is_array($value)) - { - $value = implode(', ',$value); - } - - echo $value; + $value = get_sub_field($field_name); + + if(is_array($value)) + { + $value = implode(', ',$value); + } + + echo $value; } @@ -702,26 +702,26 @@ function the_sub_field($field_name) * * @param string $field_name: the name of the field - 'sub_heading' * -* @return array $sub_field +* @return array $sub_field */ function get_sub_field_object( $child_name ) { - // no field? - if( empty($GLOBALS['acf_field']) ) - { - return false; - } - + // no field? + if( empty($GLOBALS['acf_field']) ) + { + return false; + } - // vars - $depth = count( $GLOBALS['acf_field'] ) - 1; - $parent = $GLOBALS['acf_field'][$depth]['field']; + // vars + $depth = count( $GLOBALS['acf_field'] ) - 1; + $parent = $GLOBALS['acf_field'][$depth]['field']; - // return - return acf_get_child_field_from_parent_field( $child_name, $parent ); + // return + return acf_get_child_field_from_parent_field( $child_name, $parent ); + } @@ -737,52 +737,52 @@ function get_sub_field_object( $child_name ) * @param string $child_name: the name of the field - 'sub_heading' * @param array $parent: the parent field object * -* @return array $sub_field +* @return array $sub_field */ function acf_get_child_field_from_parent_field( $child_name, $parent ) { - // vars - $return = false; - - - // find child - if( isset($parent['sub_fields']) && is_array($parent['sub_fields']) ) - { - foreach( $parent['sub_fields'] as $child ) - { - if( $child['name'] == $child_name || $child['key'] == $child_name ) - { - $return = $child; - break; - } - - // perhaps child has grand children? - $grand_child = acf_get_child_field_from_parent_field( $child_name, $child ); - if( $grand_child ) - { - $return = $grand_child; - break; - } - } - } - elseif( isset($parent['layouts']) && is_array($parent['layouts']) ) - { - foreach( $parent['layouts'] as $layout ) - { - $child = acf_get_child_field_from_parent_field( $child_name, $layout ); - if( $child ) - { - $return = $child; - break; - } - } - } - - - // return - return $return; - + // vars + $return = false; + + + // find child + if( isset($parent['sub_fields']) && is_array($parent['sub_fields']) ) + { + foreach( $parent['sub_fields'] as $child ) + { + if( $child['name'] == $child_name || $child['key'] == $child_name ) + { + $return = $child; + break; + } + + // perhaps child has grand children? + $grand_child = acf_get_child_field_from_parent_field( $child_name, $child ); + if( $grand_child ) + { + $return = $grand_child; + break; + } + } + } + elseif( isset($parent['layouts']) && is_array($parent['layouts']) ) + { + foreach( $parent['layouts'] as $layout ) + { + $child = acf_get_child_field_from_parent_field( $child_name, $layout ); + if( $child ) + { + $return = $child; + break; + } + } + } + + + // return + return $return; + } @@ -805,124 +805,124 @@ function acf_get_child_field_from_parent_field( $child_name, $parent ) function register_field_group( $array ) { - // add id - if( !isset($array['id']) ) - { - $array['id'] = uniqid(); - } - - - // 3.2.5 - changed show_on_page option - if( !isset($array['options']['hide_on_screen']) && isset($array['options']['show_on_page']) ) - { - $show_all = array('the_content', 'discussion', 'custom_fields', 'comments', 'slug', 'author'); - $array['options']['hide_on_screen'] = array_diff($show_all, $array['options']['show_on_page']); - unset( $array['options']['show_on_page'] ); - } - - - // 4.0.4 - changed location rules architecture - if( isset($array['location']['rules']) ) - { - // vars - $groups = array(); - $group_no = 0; - - - if( is_array($array['location']['rules']) ) - { - foreach( $array['location']['rules'] as $rule ) - { - $rule['group_no'] = $group_no; - - // sperate groups? - if( $array['location']['allorany'] == 'any' ) - { - $group_no++; - } - - - // add to group - $groups[ $rule['group_no'] ][ $rule['order_no'] ] = $rule; - - - // sort rules - ksort( $groups[ $rule['group_no'] ] ); - - } - - // sort groups - ksort( $groups ); - } - - $array['location'] = $groups; - } - - - $GLOBALS['acf_register_field_group'][] = $array; + // add id + if( !isset($array['id']) ) + { + $array['id'] = uniqid(); + } + + + // 3.2.5 - changed show_on_page option + if( !isset($array['options']['hide_on_screen']) && isset($array['options']['show_on_page']) ) + { + $show_all = array('the_content', 'discussion', 'custom_fields', 'comments', 'slug', 'author'); + $array['options']['hide_on_screen'] = array_diff($show_all, $array['options']['show_on_page']); + unset( $array['options']['show_on_page'] ); + } + + + // 4.0.4 - changed location rules architecture + if( isset($array['location']['rules']) ) + { + // vars + $groups = array(); + $group_no = 0; + + + if( is_array($array['location']['rules']) ) + { + foreach( $array['location']['rules'] as $rule ) + { + $rule['group_no'] = $group_no; + + // sperate groups? + if( $array['location']['allorany'] == 'any' ) + { + $group_no++; + } + + + // add to group + $groups[ $rule['group_no'] ][ $rule['order_no'] ] = $rule; + + + // sort rules + ksort( $groups[ $rule['group_no'] ] ); + + } + + // sort groups + ksort( $groups ); + } + + $array['location'] = $groups; + } + + + $GLOBALS['acf_register_field_group'][] = $array; } -add_filter('acf/get_field_groups', 'api_acf_get_field_groups', 2, 1); -function api_acf_get_field_groups( $return ) +add_filter('acf/acf_get_field_groups', 'api_acf_acf_get_field_groups', 2, 1); +function api_acf_acf_get_field_groups( $return ) { - // validate - if( empty($GLOBALS['acf_register_field_group']) ) - { - return $return; - } - - - foreach( $GLOBALS['acf_register_field_group'] as $acf ) - { - $return[] = array( - 'id' => $acf['id'], - 'title' => $acf['title'], - 'menu_order' => $acf['menu_order'], - ); - } - - - // order field groups based on menu_order, title - // Obtain a list of columns - foreach( $return as $key => $row ) - { - $menu_order[ $key ] = $row['menu_order']; - $title[ $key ] = $row['title']; - } - - // Sort the array with menu_order ascending - // Add $array as the last parameter, to sort by the common key - if(isset($menu_order)) - { - array_multisort($menu_order, SORT_ASC, $title, SORT_ASC, $return); - } - - return $return; + // validate + if( empty($GLOBALS['acf_register_field_group']) ) + { + return $return; + } + + + foreach( $GLOBALS['acf_register_field_group'] as $acf ) + { + $return[] = array( + 'id' => $acf['id'], + 'title' => $acf['title'], + 'menu_order' => $acf['menu_order'], + ); + } + + + // order field groups based on menu_order, title + // Obtain a list of columns + foreach( $return as $key => $row ) + { + $menu_order[ $key ] = $row['menu_order']; + $title[ $key ] = $row['title']; + } + + // Sort the array with menu_order ascending + // Add $array as the last parameter, to sort by the common key + if(isset($menu_order)) + { + array_multisort($menu_order, SORT_ASC, $title, SORT_ASC, $return); + } + + return $return; } -add_filter('acf/field_group/get_fields', 'api_acf_field_group_get_fields', 1, 2); -function api_acf_field_group_get_fields( $fields, $post_id ) +add_filter('acf/field_group/acf_get_fields', 'api_acf_field_group_acf_get_fields', 1, 2); +function api_acf_field_group_acf_get_fields( $fields, $post_id ) { - // validate - if( !empty($GLOBALS['acf_register_field_group']) ) - { - foreach( $GLOBALS['acf_register_field_group'] as $acf ) - { - if( $acf['id'] == $post_id ) - { - foreach( $acf['fields'] as $f ) - { - $fields[] = apply_filters('acf/load_field', $f, $f['key']); - } - - break; - } - } - } - - return $fields; + // validate + if( !empty($GLOBALS['acf_register_field_group']) ) + { + foreach( $GLOBALS['acf_register_field_group'] as $acf ) + { + if( $acf['id'] == $post_id ) + { + foreach( $acf['fields'] as $f ) + { + $fields[] = apply_filters('acf/load_field', $f, $f['key']); + } + + break; + } + } + } + + return $fields; } @@ -930,46 +930,46 @@ function api_acf_field_group_get_fields( $fields, $post_id ) add_filter('acf/load_field', 'api_acf_load_field', 1, 2); function api_acf_load_field( $field, $field_key ) { - // validate - if( !empty($GLOBALS['acf_register_field_group']) ) - { - foreach( $GLOBALS['acf_register_field_group'] as $acf ) - { - if( !empty($acf['fields']) ) - { - foreach( $acf['fields'] as $f ) - { - if( $f['key'] == $field_key ) - { - $field = $f; - break; - } - } - } - } - } - - return $field; + // validate + if( !empty($GLOBALS['acf_register_field_group']) ) + { + foreach( $GLOBALS['acf_register_field_group'] as $acf ) + { + if( !empty($acf['fields']) ) + { + foreach( $acf['fields'] as $f ) + { + if( $f['key'] == $field_key ) + { + $field = $f; + break; + } + } + } + } + } + + return $field; } add_filter('acf/field_group/get_location', 'api_acf_field_group_get_location', 1, 2); function api_acf_field_group_get_location( $location, $post_id ) { - // validate - if( !empty($GLOBALS['acf_register_field_group']) ) - { - foreach( $GLOBALS['acf_register_field_group'] as $acf ) - { - if( $acf['id'] == $post_id ) - { - $location = $acf['location']; - break; - } - } - } - - return $location; + // validate + if( !empty($GLOBALS['acf_register_field_group']) ) + { + foreach( $GLOBALS['acf_register_field_group'] as $acf ) + { + if( $acf['id'] == $post_id ) + { + $location = $acf['location']; + break; + } + } + } + + return $location; } @@ -977,20 +977,20 @@ function api_acf_field_group_get_location( $location, $post_id ) add_filter('acf/field_group/get_options', 'api_acf_field_group_get_options', 1, 2); function api_acf_field_group_get_options( $options, $post_id ) { - // validate - if( !empty($GLOBALS['acf_register_field_group']) ) - { - foreach( $GLOBALS['acf_register_field_group'] as $acf ) - { - if( $acf['id'] == $post_id ) - { - $options = $acf['options']; - break; - } - } - } - - return $options; + // validate + if( !empty($GLOBALS['acf_register_field_group']) ) + { + foreach( $GLOBALS['acf_register_field_group'] as $acf ) + { + if( $acf['id'] == $post_id ) + { + $options = $acf['options']; + break; + } + } + } + + return $options; } @@ -1008,11 +1008,11 @@ function api_acf_field_group_get_options( $options, $post_id ) function get_row_layout() { - // vars - $value = get_sub_field('acf_fc_layout'); - - - return $value; + // vars + $value = get_sub_field('acf_fc_layout'); + + + return $value; } @@ -1029,35 +1029,35 @@ function get_row_layout() * string + field: the field name * mixed + post_id: the post_id to load from * -* @return string $value: the value found by get_field +* @return string $value: the value found by acf_get_field */ function acf_shortcode( $atts ) { - // extract attributs - extract( shortcode_atts( array( - 'field' => "", - 'post_id' => false, - ), $atts ) ); - - - // $field is requird - if( !$field || $field == "" ) - { - return ""; - } - - - // get value and return it - $value = acf_get_field( $field, $post_id ); - - - if( is_array($value) ) - { - $value = @implode( ', ',$value ); - } - - return $value; + // extract attributs + extract( shortcode_atts( array( + 'field' => "", + 'post_id' => false, + ), $atts ) ); + + + // $field is requird + if( !$field || $field == "" ) + { + return ""; + } + + + // get value and return it + $value = acf_get_field( $field, $post_id ); + + + if( is_array($value) ) + { + $value = @implode( ', ',$value ); + } + + return $value; } add_shortcode( 'acf', 'acf_shortcode' ); @@ -1078,50 +1078,50 @@ function acf_shortcode( $atts ) function acf_form_head() { - // global vars - global $post_id; - - - // verify nonce - if( isset($_POST['acf_nonce']) && wp_verify_nonce($_POST['acf_nonce'], 'input') ) - { - // $post_id to save against - $post_id = $_POST['post_id']; - - - // allow for custom save - $post_id = apply_filters('acf/pre_save_post', $post_id); - - - // save the data - do_action('acf/save_post', $post_id); - - - // redirect - if(isset($_POST['return'])) - { - wp_redirect($_POST['return']); - exit; - } - } - - - // need wp styling - wp_enqueue_style(array( - 'colors-fresh' - )); - - - // actions - do_action('acf/input/admin_enqueue_scripts'); - - add_action('wp_head', 'acf_form_wp_head'); - + // global vars + global $post_id; + + + // verify nonce + if( isset($_POST['acf_nonce']) && wp_verify_nonce($_POST['acf_nonce'], 'input') ) + { + // $post_id to save against + $post_id = $_POST['post_id']; + + + // allow for custom save + $post_id = apply_filters('acf/pre_save_post', $post_id); + + + // save the data + do_action('acf/save_post', $post_id); + + + // redirect + if(isset($_POST['return'])) + { + wp_redirect($_POST['return']); + exit; + } + } + + + // need wp styling + wp_enqueue_style(array( + 'colors-fresh' + )); + + + // actions + do_action('acf/input/admin_enqueue_scripts'); + + add_action('wp_head', 'acf_form_wp_head'); + } function acf_form_wp_head() { - do_action('acf/input/admin_head'); + do_action('acf/input/admin_head'); } @@ -1136,7 +1136,7 @@ function acf_form_wp_head() * * @param array $options: an array containing many options to customize the form * string + post_id: post id to get field groups from and save data to. Default is false -* array + field_groups: an array containing field group ID's. If this option is set, +* array + field_groups: an array containing field group ID's. If this option is set, * the post_id will not be used to dynamically find the field groups * boolean + form: display the form tag or not. Defaults to true * array + form_attributes: an array containg attributes which will be added into the form tag @@ -1144,165 +1144,165 @@ function acf_form_wp_head() * string + html_before_fields: html inside form before fields * string + html_after_fields: html inside form after fields * string + submit_value: value of submit button -* string + updated_message: default updated message. Can be false +* string + updated_message: default updated message. Can be false * * @return N/A */ function acf_form( $options = array() ) { - global $post; - - - // defaults - $defaults = array( - 'post_id' => false, - 'field_groups' => array(), - 'form' => true, - 'form_attributes' => array( - 'id' => 'post', - 'class' => '', - 'action' => '', - 'method' => 'post', - ), - 'return' => add_query_arg( 'updated', 'true', get_permalink() ), - 'html_before_fields' => '', - 'html_after_fields' => '', - 'submit_value' => __("Update", 'acf'), - 'updated_message' => __("Post updated", 'acf'), - ); - - - // merge defaults with options - $options = array_merge($defaults, $options); - - - // merge sub arrays - foreach( $options as $k => $v ) - { - if( is_array($v) ) - { - $options[ $k ] = array_merge($defaults[ $k ], $options[ $k ]); - } - } - - - // filter post_id - $options['post_id'] = apply_filters('acf/get_post_id', $options['post_id'] ); - - - // attributes - $options['form_attributes']['class'] .= 'acf-form'; - - - - // register post box - if( empty($options['field_groups']) ) - { - // get field groups - $filter = array( - 'post_id' => $options['post_id'] - ); - - - if( strpos($options['post_id'], 'user_') !== false ) - { - $user_id = str_replace('user_', '', $options['post_id']); - $filter = array( - 'ef_user' => $user_id - ); - } - elseif( strpos($options['post_id'], 'taxonomy_') !== false ) - { - $taxonomy_id = str_replace('taxonomy_', '', $options['post_id']); - $filter = array( - 'ef_taxonomy' => $taxonomy_id - ); - } - - - $options['field_groups'] = array(); - $options['field_groups'] = apply_filters( 'acf/location/match_field_groups', $options['field_groups'], $filter ); - } - - - // updated message - if(isset($_GET['updated']) && $_GET['updated'] == 'true' && $options['updated_message']) - { - echo '

' . $options['updated_message'] . '

'; - } - - - // display form - if( $options['form'] ): ?> -
$v){echo $k . '="' . $v .'" '; }} ?>> - - -
- - - - - -
- -
- '; - echo '

' . $acf['title'] . '

'; - echo '
'; - - do_action('acf/create_fields', $fields, $options['post_id']); - - echo '
'; - - }} - - - // html after fields - echo $options['html_after_fields']; - - ?> - - - -
- -
- - - - - - -
- false, + 'field_groups' => array(), + 'form' => true, + 'form_attributes' => array( + 'id' => 'post', + 'class' => '', + 'action' => '', + 'method' => 'post', + ), + 'return' => add_query_arg( 'updated', 'true', get_permalink() ), + 'html_before_fields' => '', + 'html_after_fields' => '', + 'submit_value' => __("Update", 'acf'), + 'updated_message' => __("Post updated", 'acf'), + ); + + + // merge defaults with options + $options = array_merge($defaults, $options); + + + // merge sub arrays + foreach( $options as $k => $v ) + { + if( is_array($v) ) + { + $options[ $k ] = array_merge($defaults[ $k ], $options[ $k ]); + } + } + + + // filter post_id + $options['post_id'] = apply_filters('acf/get_post_id', $options['post_id'] ); + + + // attributes + $options['form_attributes']['class'] .= 'acf-form'; + + + + // register post box + if( empty($options['field_groups']) ) + { + // get field groups + $filter = array( + 'post_id' => $options['post_id'] + ); + + + if( strpos($options['post_id'], 'user_') !== false ) + { + $user_id = str_replace('user_', '', $options['post_id']); + $filter = array( + 'ef_user' => $user_id + ); + } + elseif( strpos($options['post_id'], 'taxonomy_') !== false ) + { + $taxonomy_id = str_replace('taxonomy_', '', $options['post_id']); + $filter = array( + 'ef_taxonomy' => $taxonomy_id + ); + } + + + $options['field_groups'] = array(); + $options['field_groups'] = apply_filters( 'acf/location/match_field_groups', $options['field_groups'], $filter ); + } + + + // updated message + if(isset($_GET['updated']) && $_GET['updated'] == 'true' && $options['updated_message']) + { + echo '

' . $options['updated_message'] . '

'; + } + + + // display form + if( $options['form'] ): ?> +
$v){echo $k . '="' . $v .'" '; }} ?>> + + +
+ + + + + +
+ +
+ '; + echo '

' . $acf['title'] . '

'; + echo '
'; + + do_action('acf/create_fields', $fields, $options['post_id']); + + echo '
'; + + }} + + + // html after fields + echo $options['html_after_fields']; + + ?> + + + +
+ +
+ + + + + + +
+ false, - 'format_value' => false - ); - - $field = get_field_object( $field_key, $post_id, $options); - - - // sub fields? They need formatted data - if( $field['type'] == 'repeater' ) - { - $value = acf_convert_field_names_to_keys( $value, $field ); - } - elseif( $field['type'] == 'flexible_content' ) - { - if( $field['layouts'] ) - { - foreach( $field['layouts'] as $layout ) - { - $value = acf_convert_field_names_to_keys( $value, $layout ); - } - } - } - - - // save - do_action('acf/update_value', $value, $post_id, $field ); - - - return true; - + // filter post_id + $post_id = apply_filters('acf/get_post_id', $post_id ); + + + // vars + $options = array( + 'load_value' => false, + 'format_value' => false + ); + + $field = acf_get_field_object( $field_key, $post_id, $options); + + + // sub fields? They need formatted data + if( $field['type'] == 'repeater' ) + { + $value = acf_convert_field_names_to_keys( $value, $field ); + } + elseif( $field['type'] == 'flexible_content' ) + { + if( $field['layouts'] ) + { + foreach( $field['layouts'] as $layout ) + { + $value = acf_convert_field_names_to_keys( $value, $layout ); + } + } + } + + + // save + do_action('acf/update_value', $value, $post_id, $field ); + + + return true; + } @@ -1380,7 +1380,7 @@ function update_field( $field_key, $value, $post_id = false ) function delete_field( $field_name, $post_id ) { - do_action('acf/delete_value', $post_id, $field_name ); + do_action('acf/delete_value', $post_id, $field_name ); } @@ -1400,7 +1400,7 @@ function delete_field( $field_name, $post_id ) function create_field( $field ) { - do_action('acf/create_field', $field ); + do_action('acf/create_field', $field ); } @@ -1413,7 +1413,7 @@ function create_field( $field ) * @since 4.0.0 * @date 17/03/13 * -* @param array $value: the value returned via get_field +* @param array $value: the value returned via acf_get_field * @param array $field: the field or layout to find sub fields from * * @return N/A @@ -1421,64 +1421,64 @@ function create_field( $field ) function acf_convert_field_names_to_keys( $value, $field ) { - // only if $field has sub fields - if( !isset($field['sub_fields']) ) - { - return $value; - } - - - // define sub field keys - $sub_fields = array(); - if( $field['sub_fields'] ) - { - foreach( $field['sub_fields'] as $sub_field ) - { - $sub_fields[ $sub_field['name'] ] = $sub_field; - } - } - - - // loop through the values and format the array to use sub field keys - if( is_array($value) ) - { - foreach( $value as $row_i => $row) - { - if( $row ) - { - foreach( $row as $sub_field_name => $sub_field_value ) - { - // sub field must exist! - if( !isset($sub_fields[ $sub_field_name ]) ) - { - continue; - } - - - // vars - $sub_field = $sub_fields[ $sub_field_name ]; - $sub_field_value = acf_convert_field_names_to_keys( $sub_field_value, $sub_field ); - - - // set new value - $value[$row_i][ $sub_field['key'] ] = $sub_field_value; - - - // unset old value - unset( $value[$row_i][$sub_field_name] ); - - - } - // foreach( $row as $sub_field_name => $sub_field_value ) - } - // if( $row ) - } - // foreach( $value as $row_i => $row) - } - // if( $value ) - - - return $value; + // only if $field has sub fields + if( !isset($field['sub_fields']) ) + { + return $value; + } + + + // define sub field keys + $sub_fields = array(); + if( $field['sub_fields'] ) + { + foreach( $field['sub_fields'] as $sub_field ) + { + $sub_fields[ $sub_field['name'] ] = $sub_field; + } + } + + + // loop through the values and format the array to use sub field keys + if( is_array($value) ) + { + foreach( $value as $row_i => $row) + { + if( $row ) + { + foreach( $row as $sub_field_name => $sub_field_value ) + { + // sub field must exist! + if( !isset($sub_fields[ $sub_field_name ]) ) + { + continue; + } + + + // vars + $sub_field = $sub_fields[ $sub_field_name ]; + $sub_field_value = acf_convert_field_names_to_keys( $sub_field_value, $sub_field ); + + + // set new value + $value[$row_i][ $sub_field['key'] ] = $sub_field_value; + + + // unset old value + unset( $value[$row_i][$sub_field_name] ); + + + } + // foreach( $row as $sub_field_name => $sub_field_value ) + } + // if( $row ) + } + // foreach( $value as $row_i => $row) + } + // if( $value ) + + + return $value; } @@ -1487,7 +1487,7 @@ function acf_convert_field_names_to_keys( $value, $field ) /* * Depreceated Functions * -* @description: +* @description: * @created: 23/07/12 */ @@ -1499,12 +1499,12 @@ function acf_convert_field_names_to_keys( $value, $field ) * @author Elliot Condon * @depreciated: 3.3.4 - now use has_sub_field * @since 1.0.3 -* +* *-------------------------------------------------------------------------------------*/ function reset_the_repeater_field() { - // do nothing + // do nothing } @@ -1515,12 +1515,12 @@ function reset_the_repeater_field() * @author Elliot Condon * @depreciated: 3.3.4 - now use has_sub_field * @since 1.0.3 -* +* *-------------------------------------------------------------------------------------*/ function the_repeater_field($field_name, $post_id = false) { - return has_sub_field($field_name, $post_id); + return has_sub_field($field_name, $post_id); } @@ -1531,12 +1531,12 @@ function the_repeater_field($field_name, $post_id = false) * @author Elliot Condon * @depreciated: 3.3.4 - now use has_sub_field * @since 3.?.? -* +* *-------------------------------------------------------------------------------------*/ function the_flexible_field($field_name, $post_id = false) { - return has_sub_field($field_name, $post_id); + return has_sub_field($field_name, $post_id); } /* @@ -1555,7 +1555,7 @@ function the_flexible_field($field_name, $post_id = false) function acf_filter_post_id( $post_id ) { - return apply_filters('acf/get_post_id', $post_id ); + return apply_filters('acf/get_post_id', $post_id ); } -?> +?> \ No newline at end of file diff --git a/includes/acf/core/controllers/everything_fields.php b/includes/acf/core/controllers/everything_fields.php index 1e1152c..326830d 100755 --- a/includes/acf/core/controllers/everything_fields.php +++ b/includes/acf/core/controllers/everything_fields.php @@ -92,7 +92,7 @@ function attachment_fields_to_edit( $form_fields, $post ) } - $acfs = apply_filters('acf/get_field_groups', array()); + $acfs = apply_filters('acf/acf_get_field_groups', array()); if( is_array($acfs) ){ foreach( $acfs as $acf ){ @@ -105,7 +105,7 @@ function attachment_fields_to_edit( $form_fields, $post ) // load fields - $fields = apply_filters('acf/field_group/get_fields', array(), $acf['id']); + $fields = apply_filters('acf/field_group/acf_get_fields', array(), $acf['id']); if( is_array($fields) ){ foreach( $fields as $i => $field ){ @@ -654,7 +654,7 @@ function acf_everything_fields() // get acfs - $acfs = apply_filters('acf/get_field_groups', false); + $acfs = apply_filters('acf/acf_get_field_groups', false); // layout @@ -726,7 +726,7 @@ function acf_everything_fields() // load fields - $fields = apply_filters('acf/field_group/get_fields', array(), $acf['id']); + $fields = apply_filters('acf/field_group/acf_get_fields', array(), $acf['id']); if( is_array($fields) ){ foreach( $fields as $field ){ diff --git a/includes/acf/core/controllers/export.php b/includes/acf/core/controllers/export.php index ec77751..2ec4f65 100644 --- a/includes/acf/core/controllers/export.php +++ b/includes/acf/core/controllers/export.php @@ -358,7 +358,7 @@ function html_php() $var = array( 'id' => $acf->post_name, 'title' => $acf->post_title, - 'fields' => apply_filters('acf/field_group/get_fields', array(), $acf->ID), + 'fields' => apply_filters('acf/field_group/acf_get_fields', array(), $acf->ID), 'location' => apply_filters('acf/field_group/get_location', array(), $acf->ID), 'options' => apply_filters('acf/field_group/get_options', array(), $acf->ID), 'menu_order' => $acf->menu_order, diff --git a/includes/acf/core/controllers/field_group.php b/includes/acf/core/controllers/field_group.php index ef1f0fb..f3a468e 100755 --- a/includes/acf/core/controllers/field_group.php +++ b/includes/acf/core/controllers/field_group.php @@ -29,8 +29,8 @@ function __construct() // filters - add_filter('acf/get_field_groups', array($this, 'get_field_groups'), 1, 1); - add_filter('acf/field_group/get_fields', array($this, 'get_fields'), 5, 2); + add_filter('acf/acf_get_field_groups', array($this, 'acf_get_field_groups'), 1, 1); + add_filter('acf/field_group/acf_get_fields', array($this, 'acf_get_fields'), 5, 2); add_filter('acf/field_group/get_location', array($this, 'get_location'), 5, 2); add_filter('acf/field_group/get_options', array($this, 'get_options'), 5, 2); add_filter('acf/field_group/get_next_field_id', array($this, 'get_next_field_id'), 5, 1); @@ -49,14 +49,14 @@ function __construct() /* - * get_field_groups + * acf_get_field_groups * * @description: * @since: 3.6 * @created: 27/01/13 */ - function get_field_groups( $array ) + function acf_get_field_groups( $array ) { // cache $found = false; @@ -99,14 +99,14 @@ function get_field_groups( $array ) /* - * get_fields + * acf_get_fields * * @description: returns all fields for a field group * @since: 3.6 * @created: 26/01/13 */ - function get_fields( $fields, $post_id ) + function acf_get_fields( $fields, $post_id ) { // global global $wpdb; diff --git a/includes/acf/core/controllers/location.php b/includes/acf/core/controllers/location.php index ccba368..01c994e 100644 --- a/includes/acf/core/controllers/location.php +++ b/includes/acf/core/controllers/location.php @@ -146,7 +146,7 @@ function match_field_groups( $return, $options ) // find all acf objects - $acfs = apply_filters('acf/get_field_groups', array()); + $acfs = apply_filters('acf/acf_get_field_groups', array()); // blank array to hold acfs diff --git a/includes/acf/core/controllers/post.php b/includes/acf/core/controllers/post.php index ed627a3..e1611a1 100644 --- a/includes/acf/core/controllers/post.php +++ b/includes/acf/core/controllers/post.php @@ -176,7 +176,7 @@ function admin_head() // get field groups - $acfs = apply_filters('acf/get_field_groups', array()); + $acfs = apply_filters('acf/acf_get_field_groups', array()); if( $acfs ) @@ -292,7 +292,7 @@ function meta_box_input( $post, $args ) // HTML if( $args['show'] ) { - $fields = apply_filters('acf/field_group/get_fields', array(), $args['field_group']['id']); + $fields = apply_filters('acf/field_group/acf_get_fields', array(), $args['field_group']['id']); do_action('acf/create_fields', $fields, $args['post_id']); } @@ -464,14 +464,14 @@ function ajax_render_fields() // get acfs - $acfs = apply_filters('acf/get_field_groups', array()); + $acfs = apply_filters('acf/acf_get_field_groups', array()); if( $acfs ) { foreach( $acfs as $acf ) { if( $acf['id'] == $options['acf_id'] ) { - $fields = apply_filters('acf/field_group/get_fields', array(), $acf['id']); + $fields = apply_filters('acf/field_group/acf_get_fields', array(), $acf['id']); do_action('acf/create_fields', $fields, $options['post_id']); @@ -544,10 +544,10 @@ function is_protected_meta( $protected, $meta_key, $meta_type ) { global $post; - // if acf_get_field_reference returns a valid key, this is an acf value, so protect it! + // if acf_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 ); + $reference = acf_get_field_reference( $meta_key, $post->ID ); if( substr($reference, 0, 6) === 'field_' ) { diff --git a/includes/acf/core/controllers/revisions.php b/includes/acf/core/controllers/revisions.php index 83bc6db..802edf1 100644 --- a/includes/acf/core/controllers/revisions.php +++ b/includes/acf/core/controllers/revisions.php @@ -131,7 +131,7 @@ function wp_post_revision_fields( $return ) { // get field objects - $fields = get_field_objects( $post_id, array('format_value' => false ) ); + $fields = acf_get_field_objects( $post_id, array('format_value' => false ) ); if( $fields ) @@ -212,7 +212,7 @@ function wp_post_revision_field( $value, $field_name, $post = null, $direction = // load field - $field = get_field_object($field_name, $post_id, array('format_value' => false )); + $field = acf_get_field_object($field_name, $post_id, array('format_value' => false )); $value = $field['value']; diff --git a/includes/acf/core/controllers/third_party.php b/includes/acf/core/controllers/third_party.php index f3279c7..0d55b02 100644 --- a/includes/acf/core/controllers/third_party.php +++ b/includes/acf/core/controllers/third_party.php @@ -112,7 +112,7 @@ function tabify_posttypes( $posttypes ) function tabify_add_meta_boxes( $post_type ) { // get acf's - $acfs = apply_filters('acf/get_field_groups', array()); + $acfs = apply_filters('acf/acf_get_field_groups', array()); if($acfs) { diff --git a/includes/acf/core/controllers/upgrade.php b/includes/acf/core/controllers/upgrade.php index ae04715..0a236e2 100755 --- a/includes/acf/core/controllers/upgrade.php +++ b/includes/acf/core/controllers/upgrade.php @@ -227,7 +227,7 @@ function upgrade_ajax() case '3.0.0': - // upgrade options first as "field_group_layout" will cause get_fields to fail! + // upgrade options first as "field_group_layout" will cause acf_get_fields to fail! // get acf's $acfs = get_posts(array( diff --git a/includes/acf/core/views/meta_box_fields.php b/includes/acf/core/views/meta_box_fields.php index 0895359..33a03fa 100644 --- a/includes/acf/core/views/meta_box_fields.php +++ b/includes/acf/core/views/meta_box_fields.php @@ -15,7 +15,7 @@ // get fields -$fields = apply_filters('acf/field_group/get_fields', array(), $post->ID); +$fields = apply_filters('acf/field_group/acf_get_fields', array(), $post->ID); // add clone diff --git a/includes/acf/readme.txt b/includes/acf/readme.txt index 24abcd5..33093da 100755 --- a/includes/acf/readme.txt +++ b/includes/acf/readme.txt @@ -132,7 +132,7 @@ http://support.advancedcustomfields.com/ = 4.3.5 = * Textarea field: Added new `rows` setting -* API: Added `$format_value` parameter to the `get_fields` function +* API: Added `$format_value` parameter to the `acf_get_fields` function * Core: Improved conditional logic & tab JS performance * Core: Removed changelog anouncement in plugins update list * Core: Fixed anoying `wp is not defined` JS error @@ -174,7 +174,7 @@ http://support.advancedcustomfields.com/ = 4.3.1 = * API: Fixed bug with has_sub_field and have_rows functions causing complicated nested loops to produce incorrect results -* API: Fixed bug with get_fields function preventing values to be returned from options page and taxonomy terms +* API: Fixed bug with acf_get_fields function preventing values to be returned from options page and taxonomy terms * Core: Fixed bug causing some SQL LIKE statements to not work correctly on windows servers * Core: Removed __() wrappers from PHP export, as these did not work as expected * Core: Fixed bug with get_pages() causing sort order issue in child page location rule @@ -186,7 +186,7 @@ http://support.advancedcustomfields.com/ * Google maps field: Add refresh action when hidden / shown by a tab = 4.3.0 = -* Core: get_field can now be used within the functions.php file +* Core: acf_get_field can now be used within the functions.php file * Core: Added new Google maps field * Core: Added conditional logic support for sub fields - will also require an update to the repeater / flexible content field add-on to work * Core: Added required validation support for sub fields - will also require an update to the repeater / flexible content field add-on to work @@ -368,11 +368,11 @@ http://support.advancedcustomfields.com/ * [Added] Add field 'Email' * [Added] Add field 'Password' * [Added] Add field group title validation -* [Fixed] Fix issue where get_field_object returns the wrong field when using WPML +* [Fixed] Fix issue where acf_get_field_object returns the wrong field when using WPML * [Fixed] Fix duplicate functionality - http://support.advancedcustomfields.com/discussion/4471/duplicate-fields-in-admin-doesn039t-replicate-repeater-fields * [Added] Add conditional statements to tab field - http://support.advancedcustomfields.com/discussion/4674/conditional-tabs * [Fixed] Fix issue with Preview / Draft where preview would not save custom field data - http://support.advancedcustomfields.com/discussion/4401/cannot-preview-or-schedule-content-to-be-published -* [Added] Add function get_field_groups() +* [Added] Add function acf_get_field_groups() * [Added] Add function delete_field() - http://support.advancedcustomfields.com/discussion/4788/deleting-a-field-through-php * [Added] Add get_sub_field_object function - http://support.advancedcustomfields.com/discussion/4991/select-inside-repeaterfield * [Added] Add 'Top Level' option to page type location rule @@ -472,11 +472,11 @@ http://support.advancedcustomfields.com/ * [Added] Add Show / Hide for flexible content layouts * [Added] Add column width for flexible content - http://support.advancedcustomfields.com/discussion/3382/percentage-widths-on-fc-fields * [Added] Add instructions for flexible content sub fields -* [Added] Add new parameter to get_field to allow for no formatting - http://support.advancedcustomfields.com/discussion/3188/update_field-repeater +* [Added] Add new parameter to acf_get_field to allow for no formatting - http://support.advancedcustomfields.com/discussion/3188/update_field-repeater * [Fixed] Fix compatibility issue with post type switcher plugin - http://support.advancedcustomfields.com/discussion/3493/field-group-changes-to-post-when-i-save * [Added] Add new location rules for "Front Page" "Post Page" - http://support.advancedcustomfields.com/discussion/3485/groups-association-whit-page-slug-instead-of-id * [Fixed] Fix flexible content + repeater row limit bug - http://support.advancedcustomfields.com/discussion/3557/repeater-fields-inside-flexible-field-on-backend-not-visible-before-first-savingpublishing -* [Added] Add filter "acf_load_value" for values - http://support.advancedcustomfields.com/discussion/3725/a-filter-for-get_field +* [Added] Add filter "acf_load_value" for values - http://support.advancedcustomfields.com/discussion/3725/a-filter-for-acf_get_field * [Fixed] Fix choices backslash issue - http://support.advancedcustomfields.com/discussion/3796/backslash-simple-quote-bug-in-radio-button-values-fields * [Updated] acf_options_page_title now overrides the menu and title. If your field groups are not showing after update, please re-save them to update the location rules. * [Updated] Update location rules to show all post types in page / page_parent / post @@ -515,7 +515,7 @@ http://support.advancedcustomfields.com/ * Add "revisions" to list of hide-able options * [Fixed] Fix bug with custom post_id param in acf_form - http://support.advancedcustomfields.com/discussion/2991/acf_form-outside-loop * [Fixed] Fix bug in has_sub_field function where new values are not loaded for different posts if the field name is the same - http://support.advancedcustomfields.com/discussion/3331/repeater-field-templating-help-categories -* [Updated] Allow get_field to use field_key or field_name +* [Updated] Allow acf_get_field to use field_key or field_name * [Fixed] Fix update_field bug with nested repeaters * [Updated] Update German translation files - thanks to Martin Lettner @@ -531,7 +531,7 @@ http://support.advancedcustomfields.com/ * [Added] Color Picker Field: Default Value * [Added] Add custom save action for all saves - http://support.advancedcustomfields.com/discussion/2954/hook-on-save-options * [Updated] Update Dutch translations -* [Updated] Update get_field_object function to allow for field_key / field_name + option to load_value +* [Updated] Update acf_get_field_object function to allow for field_key / field_name + option to load_value = 3.4.1 = * [Added] Save user fields into wp_usermeta http://support.advancedcustomfields.com/discussion/2758/get_users-and-meta_key @@ -539,7 +539,7 @@ http://support.advancedcustomfields.com/ * [Added] Wysiwyg Field: Add Default value option * [Added] Number Field: Add Default value option * [Fixed] Validate relationship posts - http://support.advancedcustomfields.com/discussion/3033/relationship-field-throws-error-when-related-item-is-trashed -* [Added] Allow "options" as post_id for get_fields - http://support.advancedcustomfields.com/discussion/1926/3-1-8-broke-get_fields-for-options +* [Added] Allow "options" as post_id for acf_get_fields - http://support.advancedcustomfields.com/discussion/1926/3-1-8-broke-acf_get_fields-for-options * [Added] Repeater Field: Add sub field width option * [Added] Repeater Field: Add sub field description option * [Updated] Repeater Field: Update UI design @@ -552,7 +552,7 @@ http://support.advancedcustomfields.com/ * [Fixed] Fix special characters in registered options page - http://support.advancedcustomfields.com/discussion/comment/7500#Comment_7500 * [Updated] CSS tweak for relationship field - http://support.advancedcustomfields.com/discussion/2877/relation-field-with-multiple-post-types-css-styling-problem- * [Fixed] Fix datepicker blank option bug - http://support.advancedcustomfields.com/discussion/2896/3-3-9-date-picker-not-popping-up -* [Added] Add new function get_field_object to API - http://support.advancedcustomfields.com/discussion/290/field-label-on-frontend +* [Added] Add new function acf_get_field_object to API - http://support.advancedcustomfields.com/discussion/290/field-label-on-frontend * [Fixed] Fix field groups not showing for Shopp add new product - http://support.advancedcustomfields.com/discussion/3005/acf-shopp * [Fixed] Move acf.data outside of the doc.ready in input-ajax.js * [Fixed] Fix IE7 JS bug - http://support.advancedcustomfields.com/discussion/3020/ie7-fix-on-is_clone_field-function @@ -656,7 +656,7 @@ http://support.advancedcustomfields.com/ * [Added] Add in edit button to upload image / file thickbox * [Improved] Changed loading default values. Now behaves as expected! * [Fixed] Test / Fix full screen mode dissapearing from editor - http://www.advancedcustomfields.com/support/discussion/2124/full-screen-button-for-zen-mode-is-gone -* [Fixed] get_field returning false for 0 - http://advancedcustomfields.com/support/discussion/2115/get_field-returns-false-if-field-has-value-0 +* [Fixed] acf_get_field returning false for 0 - http://advancedcustomfields.com/support/discussion/2115/acf_get_field-returns-false-if-field-has-value-0 * [Improved] Improve relationship sortable code with item param - http://www.advancedcustomfields.com/support/discussion/comment/3536#Comment_3536 * [Fixed] IE category js bug - http://www.advancedcustomfields.com/support/discussion/2127/ie-78-category-checkbox-bug * [Fixed] Flexible content field row css bug - http://www.advancedcustomfields.com/support/discussion/2126/space-between-fields-is-a-little-tight-in-3.2.33.2.4 @@ -743,7 +743,7 @@ http://support.advancedcustomfields.com/ * New Option: Flexible content field can now have a custom button label * Improvement: Updated the HTML / CSS for file fields with icon * Bug Fix: Fixed multi upload / select image in repeater. -* Performance: Added caching to the get_field function. Templates will now render quicker. +* Performance: Added caching to the acf_get_field function. Templates will now render quicker. * Bug Fix: Fixed Post formats location rule - it now works. * Nested repeaters are now possible! @@ -839,16 +839,16 @@ http://support.advancedcustomfields.com/ * New Option for Relationship + Post Object: filter posts via meta_key and meta_value * Added new option: Image preview size (thumb, medium, large, full) * Fixed duplicate posts double value problem -* API update: get_field($repeater) will return an array of values in order, or false (like it used to!) +* API update: acf_get_field($repeater) will return an array of values in order, or false (like it used to!) * Radio Button: added labels around values * Post object + Page Link: select drop down is now hierarchal * Input save errors fixed -* Add 'return_id' option to get_field / get_sub_field +* Add 'return_id' option to acf_get_field / get_sub_field * Many bug fixes = 2.1.3 = * Fixed API returning true for repeater fields with no data -* Added get_fields back into the api! +* Added acf_get_fields back into the api! * Fixed field type select from showing multiple repeater activation messages = 2.1.2 = @@ -988,7 +988,7 @@ http://support.advancedcustomfields.com/ * Bug Fix: API will now work with looped posts = 1.0.1 = -* New Api Functions: get_fields(), get_field(), the_field() +* New Api Functions: acf_get_fields(), acf_get_field(), the_field() * New Field Type: Date Picker * New Field Type: File * Bug Fixes diff --git a/wp-feature-box.php b/wp-feature-box.php index 174efe0..fbb7598 100644 --- a/wp-feature-box.php +++ b/wp-feature-box.php @@ -307,7 +307,7 @@ protected function link_group_fields($key, $title) { } public function get_feature_box_field($id, $field) { - return get_field($this->fields_prefix . $field, $id); + return acf_get_field($this->fields_prefix . $field, $id); } /* @@ -356,12 +356,12 @@ public function get_feature_box_links($id) { $link_group = array(); - $link_group['title'] = get_field($this->fields_prefix . $key . '_title', $id); + $link_group['title'] = acf_get_field($this->fields_prefix . $key . '_title', $id); $link_group['links'] = array(); for($i = 1; $i <= $links_amount; $i++) { - $link = get_field($this->fields_prefix . $key . '_link_' . $i, $id); + $link = acf_get_field($this->fields_prefix . $key . '_link_' . $i, $id); if($link) $link_group['links'][] = $link; From b80ed88aadf49def5f3a4e0c3eeb67108ba6fe7c Mon Sep 17 00:00:00 2001 From: Huy Eng Heng Date: Wed, 18 Nov 2015 11:40:55 +0700 Subject: [PATCH 03/11] Fixes the confliction between feature box and margic field --- embed.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/embed.php b/embed.php index 54c0417..09a77c0 100644 --- a/embed.php +++ b/embed.php @@ -120,8 +120,8 @@ public function get_embed_settings($settings) { } public function print_embed_script() { - - header('Content-type: application/javascript'); + // header was hidden because it conflicts with magic field: file can't upload + //header('Content-type: application/javascript'); if(isset($_REQUEST['wp_feature_embed'])) { From d7dec37b386c72bbf802158736f50fab32fc3f5a Mon Sep 17 00:00:00 2001 From: Huy Eng Heng Date: Thu, 11 Feb 2016 14:39:23 +0700 Subject: [PATCH 04/11] Enhances plugin to be able to add further formate to the description --- css/feature-box.css | 12 ++++++++---- wp-feature-box.php | 4 +++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/css/feature-box.css b/css/feature-box.css index f71baaf..319cdb4 100644 --- a/css/feature-box.css +++ b/css/feature-box.css @@ -6,11 +6,14 @@ color: #f0f0f0; position: relative; padding: 0; - min-height: 350px; + min-height: 150px; +} +blockquote .wp-feature-box { + margin-bottom: 15px } .wp-feature-box .wp-feature-box-container { - padding: 5%; + padding: 2%; display: inline-block; width: 100%; box-sizing: border-box; @@ -18,6 +21,7 @@ -o-box-sizing: border-box; -khtml-box-sizing: border-box; -moz-box-sizing: border-box; + margin-top: 20px; } .wp-feature-box-slider-content { @@ -66,7 +70,7 @@ .wp-feature-box .wp-feature-box-header { text-align: center; - margin: 0 auto 40px; + margin: 0 auto 10px; } .wp-feature-box .wp-feature-box-header h2 { @@ -82,7 +86,7 @@ .wp-feature-box .wp-feature-box-header p { text-shadow: 1px 0 0 rgba(0,0,0,0.6); max-width: 600px; - margin: 0 auto 20px; + margin: 0 auto 0; } .wp-feature-box .wp-feature-box-main-link { diff --git a/wp-feature-box.php b/wp-feature-box.php index fbb7598..566befd 100644 --- a/wp-feature-box.php +++ b/wp-feature-box.php @@ -215,7 +215,9 @@ public function register_field_group() { 'key' => 'field_wp_feature_box_description', 'label' => __('Description', 'wp-feature-box'), 'name' => $this->fields_prefix . 'description', - 'type' => 'textarea', + //'type' => 'textarea', + 'type' => 'wysiwyg', + 'options' => array(), 'instructions' => __('In few words, describe the content inside this feature box', 'wp-feature-box'), 'default_value' => '', 'placeholder' => '', From 96e8e949e1612af8a08bde6bace4b00e9102848b Mon Sep 17 00:00:00 2001 From: Huy Eng Heng Date: Thu, 11 Feb 2016 14:53:16 +0700 Subject: [PATCH 05/11] Updates style for Feature box --- css/feature-box.css | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/css/feature-box.css b/css/feature-box.css index 319cdb4..9cdd8a3 100644 --- a/css/feature-box.css +++ b/css/feature-box.css @@ -11,7 +11,6 @@ blockquote .wp-feature-box { margin-bottom: 15px } - .wp-feature-box .wp-feature-box-container { padding: 2%; display: inline-block; @@ -72,6 +71,10 @@ blockquote .wp-feature-box { text-align: center; margin: 0 auto 10px; } + +.wp-feature-box-header blockquote { + padding: 15px 15px; +} .wp-feature-box .wp-feature-box-header h2 { font-size: 32px; From a527f177b449a8e6cd4ece56ff3f9daf07421415 Mon Sep 17 00:00:00 2001 From: huyeng Date: Thu, 8 Dec 2016 11:41:20 +0700 Subject: [PATCH 06/11] Enable defautl editor content of wp in wp-feature-box --- wp-feature-box.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/wp-feature-box.php b/wp-feature-box.php index 566befd..361d5ba 100644 --- a/wp-feature-box.php +++ b/wp-feature-box.php @@ -144,7 +144,7 @@ public function register_post_type() { 'labels' => $labels, 'hierarchical' => false, 'description' => __('Feature Box Items', 'wp-feature-box'), - 'supports' => array('title'), + 'supports' => array('title', 'editor'), 'public' => false, 'show_ui' => true, 'exclude_from_search' => true, @@ -215,7 +215,7 @@ public function register_field_group() { 'key' => 'field_wp_feature_box_description', 'label' => __('Description', 'wp-feature-box'), 'name' => $this->fields_prefix . 'description', - //'type' => 'textarea', + //'type' => 'textarea', 'type' => 'wysiwyg', 'options' => array(), 'instructions' => __('In few words, describe the content inside this feature box', 'wp-feature-box'), @@ -318,8 +318,13 @@ public function get_feature_box_field($id, $field) { public function get_feature_box_description($id) { global $post; $id = $id ? $id: $post->ID; - - return $this->get_feature_box_field($id, 'description'); + $get_content = get_post($id); + $post_content = apply_filters('translate_text', $get_content->post_content, odm_language_manager()->get_current_language()); + if($post_content): + return $post_content; + else: + return $this->get_feature_box_field($id, 'description'); + endif; } /* @@ -545,4 +550,4 @@ function get_feature_box_main_link($id = false) { function get_feature_box_links($id = false) { global $wp_feature_box; return $wp_feature_box->get_feature_box_links($id); -} \ No newline at end of file +} From 4990eb3114fd6c495b65c434f0d4d0a94567630c Mon Sep 17 00:00:00 2001 From: Alex Corbi Date: Thu, 8 Dec 2016 08:52:22 +0100 Subject: [PATCH 07/11] adding .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..59470bb --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.editorconfig +**/.DS_STORE +.remote-sync.json From a40b541024c219dc75fa4c5228564921fb2aa005 Mon Sep 17 00:00:00 2001 From: huyeng Date: Fri, 9 Dec 2016 11:55:06 +0700 Subject: [PATCH 08/11] Add option to be able to hide/show post title of Featurebox --- templates/feature-box.php | 16 +++++++++------- wp-feature-box.php | 8 ++++++++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/templates/feature-box.php b/templates/feature-box.php index 005b7fc..0db62ba 100644 --- a/templates/feature-box.php +++ b/templates/feature-box.php @@ -5,23 +5,25 @@ $links = get_feature_box_links(); ?>
data-itemid=""> - +
- +
- +
-

+ +

+

- + > - +
-
\ No newline at end of file + diff --git a/wp-feature-box.php b/wp-feature-box.php index 361d5ba..cc2ffff 100644 --- a/wp-feature-box.php +++ b/wp-feature-box.php @@ -224,6 +224,14 @@ public function register_field_group() { 'maxlength' => '', 'formatting' => 'br', ), + array ( + 'key' => 'field_wp_feature_box_title', + 'label' => __('Hide the title', 'wp-feature-box'), + 'name' => $this->fields_prefix . 'title', + 'type' => 'true_false', + 'message' => __('Enable', 'wp-feature-box'), + 'instructions' => __('Enable the option to hide the post title on fearture box', 'wp-feature-box'), + ), array ( 'key' => 'field_wp_feature_box_image', 'label' => __('Background image', 'wp-feature-box'), From 8921487bc98c8849724de9f5b0085e553cf815f0 Mon Sep 17 00:00:00 2001 From: huyeng Date: Fri, 9 Dec 2016 12:58:30 +0700 Subject: [PATCH 09/11] add margin bottom to make space between feature image and texts --- css/feature-box.css | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/css/feature-box.css b/css/feature-box.css index 9cdd8a3..cf00f0a 100644 --- a/css/feature-box.css +++ b/css/feature-box.css @@ -6,10 +6,11 @@ color: #f0f0f0; position: relative; padding: 0; - min-height: 150px; + min-height: 150px; + margin-bottom: 15px; } blockquote .wp-feature-box { - margin-bottom: 15px + margin-bottom: 15px } .wp-feature-box .wp-feature-box-container { padding: 2%; @@ -71,7 +72,7 @@ blockquote .wp-feature-box { text-align: center; margin: 0 auto 10px; } - + .wp-feature-box-header blockquote { padding: 15px 15px; } @@ -229,7 +230,7 @@ blockquote .wp-feature-box { font-size: 90%; } -/* +/* * Embed tool */ @@ -281,4 +282,4 @@ blockquote .wp-feature-box { color: #fff; font-weight: 600; text-decoration: none; -} \ No newline at end of file +} From 7fa4f1c0807ea7c84a22d18615b34ce452fe6aec Mon Sep 17 00:00:00 2001 From: huyeng Date: Fri, 9 Dec 2016 13:28:06 +0700 Subject: [PATCH 10/11] Add style of strong attr --- css/feature-box.css | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/css/feature-box.css b/css/feature-box.css index cf00f0a..1ddd52d 100644 --- a/css/feature-box.css +++ b/css/feature-box.css @@ -92,7 +92,9 @@ blockquote .wp-feature-box { max-width: 600px; margin: 0 auto 0; } - +.wp-feature-box .wp-feature-box-header strong { + color: #f0f0f0; +} .wp-feature-box .wp-feature-box-main-link { position: absolute; top: 0; From 183930d1d29fc37046bd969d2b1fa91c848c9056 Mon Sep 17 00:00:00 2001 From: huyeng Date: Fri, 9 Dec 2016 15:06:36 +0700 Subject: [PATCH 11/11] Increate version to 0.1.5 --- wp-feature-box.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/wp-feature-box.php b/wp-feature-box.php index 361d5ba..379d36e 100644 --- a/wp-feature-box.php +++ b/wp-feature-box.php @@ -3,7 +3,7 @@ Plugin Name: WP Feature Box Plugin URI: http://cardume.art.br/wp-feature-box Description: A simple WordPress feature box plugin -Version: 0.1.3 +Version: 0.1.5 Author: Miguel Peixe Author URI: http://ecolab.oeco.org.br/ License: GPLv3 @@ -224,6 +224,14 @@ public function register_field_group() { 'maxlength' => '', 'formatting' => 'br', ), + array ( + 'key' => 'field_wp_feature_box_title', + 'label' => __('Hide the title', 'wp-feature-box'), + 'name' => $this->fields_prefix . 'title', + 'type' => 'true_false', + 'message' => __('Enable', 'wp-feature-box'), + 'instructions' => __('Enable the option to hide the post title on fearture box', 'wp-feature-box'), + ), array ( 'key' => 'field_wp_feature_box_image', 'label' => __('Background image', 'wp-feature-box'),