http://core.trac.wordpress.org/browser/tags/3.4.2/wp-includes/meta.php#L82: line 101 (does use stripslashes_deep) // update_option -> http://core.trac.wordpress.org/browser/tags/3.5.1/wp-includes/option.php#L0: line 215 (does not use stripslashes_deep) $value = stripslashes_deep($value); $this->update_option( $post_id . '_' . $field['name'], $value ); $this->update_option( '_' . $post_id . '_' . $field['name'], $field['key'] ); } // update the cache wp_cache_set( 'load_value/post_id=' . $post_id . '/name=' . $field['name'], $value, 'acf' ); } /* * update_option * * This function is a wrapper for the WP update_option but provides logic for a 'no' autoload * * @type function * @date 4/01/2014 * @since 5.0.0 * * @param $option (string) * @param $value (mixed) * @return (boolean) */ function update_option( $option = '', $value = false, $autoload = 'no' ) { // vars $deprecated = ''; $return = false; if( get_option($option) !== false ) { $return = update_option( $option, $value ); } else { $return = add_option( $option, $value, $deprecated, $autoload ); } // return return $return; } /* * delete_value * * @description: deletes a value from the database * @since: 3.6 * @created: 23/01/13 */ function delete_value( $post_id, $key ) { // if $post_id is a string, then it is used in the everything fields and can be found in the options table if( is_numeric($post_id) ) { delete_post_meta( $post_id, $key ); delete_post_meta( $post_id, '_' . $key ); } elseif( strpos($post_id, 'user_') !== false ) { $post_id = str_replace('user_', '', $post_id); delete_user_meta( $post_id, $key ); delete_user_meta( $post_id, '_' . $key ); } else { delete_option( $post_id . '_' . $key ); delete_option( '_' . $post_id . '_' . $key ); } wp_cache_delete( 'load_value/post_id=' . $post_id . '/name=' . $key, 'acf' ); } /* * load_field * * @description: loads a field from the database * @since 3.5.1 * @created: 14/10/12 */ function load_field( $field, $field_key, $post_id = false ) { // load cache if( !$field ) { $field = wp_cache_get( 'load_field/key=' . $field_key, 'acf' ); } // load from DB if( !$field ) { // vars global $wpdb; // get field from postmeta $sql = $wpdb->prepare("SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = %s", $field_key); if( $post_id ) { $sql .= $wpdb->prepare("AND post_id = %d", $post_id); } $rows = $wpdb->get_results( $sql, ARRAY_A ); // nothing found? if( !empty($rows) ) { $row = $rows[0]; /* * WPML compatibility * * If WPML is active, and the $post_id (Field group ID) was not defined, * it is assumed that the load_field functio has been called from the API (front end). * In this case, the field group ID is never known and we can check for the correct translated field group */ if( defined('ICL_LANGUAGE_CODE') && !$post_id ) { $wpml_post_id = icl_object_id($row['post_id'], 'acf', true, ICL_LANGUAGE_CODE); foreach( $rows as $r ) { if( $r['post_id'] == $wpml_post_id ) { // this row is a field from the translated field group $row = $r; } } } // return field if it is not in a trashed field group if( get_post_status( $row['post_id'] ) != "trash" ) { $field = $row['meta_value']; $field = maybe_unserialize( $field ); $field = maybe_unserialize( $field ); // run again for WPML // add field_group ID $field['field_group'] = $row['post_id']; } } } // apply filters $field = apply_filters('acf/load_field_defaults', $field); // apply filters foreach( array('type', 'name', 'key') as $key ) { // run filters $field = apply_filters('acf/load_field/' . $key . '=' . $field[ $key ], $field); // new filter } // set cache wp_cache_set( 'load_field/key=' . $field_key, $field, 'acf' ); return $field; } /* * load_field_defaults * * @description: applies default values to the field after it has been loaded * @since 3.5.1 * @created: 14/10/12 */ function load_field_defaults( $field ) { // validate $field if( !is_array($field) ) { $field = array(); } // defaults $defaults = array( 'key' => '', 'label' => '', 'name' => '', '_name' => '', 'type' => 'text', 'order_no' => 1, 'instructions' => '', 'required' => 0, 'id' => '', 'class' => '', 'conditional_logic' => array( 'status' => 0, 'allorany' => 'all', 'rules' => 0 ), ); $field = array_merge($defaults, $field); // Parse Values $field = apply_filters( 'acf/parse_types', $field ); // field specific defaults $field = apply_filters('acf/load_field_defaults/type=' . $field['type'] , $field); // class if( !$field['class'] ) { $field['class'] = $field['type']; } // id if( !$field['id'] ) { $id = $field['name']; $id = str_replace('][', '_', $id); $id = str_replace('fields[', '', $id); $id = str_replace('[', '-', $id); // location rules (select) does'nt have "fields[" in it $id = str_replace(']', '', $id); $field['id'] = 'acf-field-' . $id; } // _name if( !$field['_name'] ) { $field['_name'] = $field['name']; } // clean up conditional logic keys if( !empty($field['conditional_logic']['rules']) ) { $field['conditional_logic']['rules'] = array_values($field['conditional_logic']['rules']); } // return return $field; } /* * update_field * * @description: updates a field in the database * @since: 3.6 * @created: 24/01/13 */ function update_field( $field, $post_id ) { // sanitize field name // - http://support.advancedcustomfields.com/discussion/5262/sanitize_title-on-field-name // - issue with camel case! Replaced with JS //$field['name'] = sanitize_title( $field['name'] ); // filters $field = apply_filters('acf/update_field/type=' . $field['type'], $field, $post_id ); // new filter // clear cache wp_cache_delete( 'load_field/key=' . $field['key'], 'acf' ); // save update_post_meta( $post_id, $field['key'], $field ); } /* * delete_field * * @description: deletes a field in the database * @since: 3.6 * @created: 24/01/13 */ function delete_field( $post_id, $field_key ) { // clear cache wp_cache_delete( 'load_field/key=' . $field_key, 'acf' ); // delete delete_post_meta($post_id, $field_key); } /* * create_field * * @description: renders a field into a HTML interface * @since: 3.6 * @created: 23/01/13 */ function create_field( $field ) { // load defaults // if field was loaded from db, these default will already be appield // if field was written by hand, it may be missing keys $field = apply_filters('acf/load_field_defaults', $field); // create field specific html do_action('acf/create_field/type=' . $field['type'], $field); // conditional logic if( $field['conditional_logic']['status'] ) { $field['conditional_logic']['field'] = $field['key']; ?>